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.
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:
-
Press "run" so that the simulator is no longer running (the button is no longer depressed)
-
Press "move robot"
-
Click to a place where you would like to place the simulated robot
-
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:
-
Follow a light.
-
Wander about, avoiding obstacles.
-
Follow a wall.
