UserPreferences

PyroModuleDirectControlKhepera


Pyro Module: Direct Control, Khepera

In addition to motor commands (translate, rotate, move), you can also access the values reported by a robot's sensors. Each robot comes equipped with a unique sensor suite. For example, the Khepera robot has infra-red (IR) and light sensors around its perimeter. Additionally, a Khepera robot may also have a camera. We will learn to use the basic Khepera sensors: IR and light.

Example: Reading Khepera IR and light sensors

Each Khepera robot comes equipped with a set of 8 IR and light sensors. The figure below shows the sensor topology and the numbering scheme used to refer to the sensors.

http://cs.brynmawr.edu/~dkumar/wikigifs/KheperaSensors.gif

Below is a simple program that prints out the values of the IR and light sensors for say, sensor number 0, on a Khepera.

from pyrobot.brain import Brain

class SensorKhepera(Brain):

    # print ir and light values of khepera sensor 0
    def step(self):
        self.move(0.1, 0)
        print "ir(0):", self.robot.ir[0][0].value,
        print "light(0):", self.robot.light[0]][0].value

def INIT(engine):
   return SensorKhepera('SensorKhepera', engine)

Save the program above in a file called, SensorKhepera.py, load it and run it. You will see a continous stream of ir(0) and light(0) values printed in your console window. If you are running the program on the actual robot, try moving an object close to sensor 0 and watch the values change. Try again using a flash light and observe how the values change. Try covering the sensor with your finger and notice the values reported. This should give you a good idea of the range of values reported in the two modes.

If you are running the program in the simulator, then try positioning the robot near an obstacle or a light to see the values change. In the simulator, you will have to move the robot via the interface:

  1. Press "run" so that the simulator is no longer running (the button is no longer depressed)

  2. Press "move robot"

  3. Click to a place where you would like to place the simulated robot

  4. Press "run" again so that the simulator is running again (the button is depressed)

Exercise 1: Simple Behaviors

Write robot control programs for each of the following behaviors:

  1. Follow a light.

  2. Wander about, avoiding obstacles.

  3. Follow a wall.