E-puck Programming Interface
This document describes the current Myro interface for the e-puck robot based on
the SVN repository version of Myro
available here.
Please note that this interface is still undergoing active development, and
may change significantly in the upcoming weeks.
Constructor
- Epuck(robot_ID_number)
- Constructs a new Epuck
object for the specified robot and establishes a Bluetooth serial
connection to it. The selector switch on the robot must be in position
3.
Example usage:
robot = Epuck(1602)
Movement
- robot.move(translate_speed, rotate_speed)
- Sets
the speed of the robot to the specified values. Speeds must be between -1
and +1. Positive translation moves forward, negative translation moves
backward. Positive rotation is to the left (counterclockwise); negative
rotation is to the right (clockwise).
- robot.translate(speed)
- Sets the translation speed to the
specified value, which must be between -1 and +1. The rotation speed is not
affected.
- robot.rotate(speed)
- Sets the rotation speed to the
specified value, which must be between -1 and +1. The translation speed is
not affected.
- robot.stop()
- Stops the robot. Equivalent
to robot.move(0, 0).
- robot.forward(speed, time=seconds).
- Moves the
robot foward at the specified speed, which must be between 0 and 1. The
rotation speed is not affected. If the optional time argument is
given, the robot moves for the specified number of seconds and then
stops.
- robot.backward(speed, time=seconds)
- Moves the
robot backward at the specified speed, which must be between 0 and 1. The
rotation speed is not affected. If the optional time argument is
given, the robot moves for the specified number of seconds and then
stops.
- robot.turnLeft(speed, time=seconds)
- Rotates the
robot to the left (counterclockwise) at the specified speed, which must be
between 0 and 1. The translation speed is not affected. If the
optional time argument is given, the robot moves for the specified
number of seconds and then stops.
- robot.turnRight(speed, time=seconds)
- Rotates the
robot to the right (clockwise) at the specified speed, which must be
between 0 and 1. The translation speed is not affected. If the
optional time argument is given, the robot moves for the specified
number of seconds and then stops.
- robot.motors(left_speed, right_speed)
- Sets the
motor speeds independently to the specified values, which must be between -1
and +1.
- robot.getSpeed()
- Returns the current speed of the robot as a
tuple (translate_speed, rotate_speed). Both speeds are in
the range -1 to +1.
- robot.getTranslate()
- Returns the current translation speed of
the robot, in the range -1 to +1.
- robot.getRotate()
- Returns the current rotation speed of
the robot, in the range -1 (clockwise) to +1 (counterclockwise).
- robot.getMotors()
- Returns the current left and right motor
speeds as a tuple (left_speed, right_speed). Both speeds are
in the range -1 to +1.
Sensors
- robot.getLight()
- Returns a list of sensor readings from the
light sensors. Sensor readings range from 0 (maximum light) to 4000 (no
light).
- robot.getLight(sensor_number)
- Returns a single sensor
reading from the specified light sensor. Sensor readings range from 0
(maximum light) to 4000 (no light). Sensors are numbered clockwise from 0
to 7, starting from the front of the robot.
- robot.getProximity()
- Returns a list of sensor readings from the
proximity sensors. Sensor readings range from 0 (no object in range) to
4000 (object at closest range).
- robot.getProximity(sensor_number)
- Returns a single
sensor reading from the specified proximity sensor. Sensor readings range
from 0 (no object in range) to 4000 (object at closest range). Sensors are
numbered clockwise from 0 to 7, starting from the front of the
robot.
- robot.getDistance()
robot.getDistance(sensor_number) - Equivalent
to getProximity method.
- robot.getIR()
robot.getIR(sensor_number) - Equivalent
to getProximity method.
- robot.getIRAngle(sensor_number)
- Returns the angle offset
in degrees of the specified IR (light/proximity) sensor on the robot's
body, measured clockwise from the front of the robot. Sensors are numbered
clockwise from 0 to 7, starting from the front.
- robot.getAmbientLight()
- Returns the average of all light sensor
readings. Sensor readings range from 0 (maximum light) to 4000 (no
light).
- robot.getAccel()
- Returns a list of the the accelerometer
readings as [x, y, z].
- robot.getSound()
- Returns a list of the microphone readings as
[front_right, front_left, rear].
- robot.getWheels()
- Returns a list of the left and right wheel
encoder values as [left_wheel, right_wheel]. Encoder values
go from 0 to 65535 then wrap around to 0 again.
- robot.resetWheels()
- Resets the wheel encoders to 0.
- robot.getSelector()
- Returns the current position of the
selector switch on the robot (0-15).
Camera
- robot.getCameraMode()
- Returns the current camera mode settings
as a tuple (mode, width, height, zoom, bytes),
where mode is 'color' or 'gray', width
and height are the image dimensions in pixels, zoom is the
zoom level, and bytes is the number of bytes used to transmit the
image.
- robot.setCameraMode(mode=m, width=w, height=h,
zoom=z)
- Changes the camera mode settings, where m
is 'color' or 'gray', w and h are the width
and height of the camera image in pixels, and z is the zoom level.
All arguments are optional.
- robot.takePicture()
- Takes a picture using the current camera mode.
Returns a new Picture object.
- robot.takePicture(mode)
- Sets the camera mode to the
specified mode and takes a picture, where mode is 'color'
or 'gray'. Returns a new Picture object.
Picture methods
- picture.show()
- Displays the Picture object in a
graphics window.
- picture.repaint()
- Same as picture.show().
- picture.getWidth()
- Returns the width of the picture in pixels.
- picture.getHeight()
- Returns the height of the picture in pixels.
- picture.getRGB(x, y)
- Returns a tuple of the
red, green, and blue color channel intensities (R, G, B) of the pixel at
position (x, y). Intensity values are in the range 0-255.
- picture.setRGB(x, y, RGB_tuple)
- Sets the pixel at
position (x, y) to the color specified by RGB_tuple, which
must be a tuple of red, green, and blue color intensities in the range
0-255.
- picture.getPixel(x, y)
- Returns the pixel at
position (x, y).
- picture.getPixels()
- Returns a generator object representing all
pixels in left-to-right order from the top row to the bottom row of the
Picture.
Example usage:
picture = robot.takePicture()
for pixel in picture.getPixels():
print pixel.getRGB()
Pixel methods
- pixel.getX()
- Returns the x-coordinate (column number) of the pixel.
- pixel.getY()
- Returns the y-coordinate (row number) of the pixel.
- pixel.getRGB()
- Returns a tuple of the red, green,
and blue color channel intensities (R, G, B) of the pixel.
Intensity values are in the range 0-255.
- pixel.setRGB(RGB_tuple)
- Sets the pixel to
the color specified by RGB_tuple, which must be a tuple of red,
green, and blue color intensities in the range 0-255.
Sounds
- robot.playSound(sound_number)
- Plays the specified
built-in sound. Sounds are numbered from 1 to 5, or 0 for silence.
- robot.shush()
- Equivalent to robot.playSound(0).
LEDs
- robot.getLEDnumber(sensor_number)
- Returns the LED number
of the LED closest to the specified IR sensor on the robot's body. Sensors
and LEDs are numbered clockwise from 0 to 7, starting from the
front.
- robot.onLED(LED_descriptor)
- Turns
on the specified LEDs. LED_descriptor can be any of the following:
- 'all' turns on all rim LEDs simultaneously.
- 'front' turns on the red front spotlight LED.
- 'body' turns on the green body LED.
- A number from 0 to 7 turns on the corresponding rim LED. LEDs are
numbered clockwise starting from the front of the robot.
- robot.offLED(LED_descriptor)
- Turns
off the specified LEDs. LED_descriptor can be any of the following:
- 'all' turns off all rim LEDs simultaneously.
- 'front' turns off the red front spotlight LED.
- 'body' turns off the green body LED.
- A number from 0 to 7 turns off the corresponding rim LED. LEDs are
numbered clockwise starting from the front of the robot.
- robot.toggleLED(LED_descriptor)
- Toggles the specified
LEDs on or off. LED_descriptor can be any of the following:
- 'all' toggles all rim LEDs simultaneously.
- 'front' toggles the red front spotlight LED.
- 'body' toggles the green body LED.
- A number from 0 to 7 toggles the corresponding rim LED. LEDs are
numbered clockwise starting from the front of the robot.
- robot.flashLED(LED_descriptor,
delay=seconds)
- Flashes the specified LEDs once. The
optional delay argument specifies the duration of the flash in
seconds. LED_descriptor can be any of the following:
- 'all' flashes all rim LEDs simultaneously.
- 'front' flashes the red front spotlight LED.
- 'body' flashes the green body LED.
- A number from 0 to 7 flashes the corresponding rim LED. LEDs are
numbered clockwise starting from the front of the robot.
- robot.onCycleLED(delay=seconds)
- Turns on all rim LEDs
sequentially in a clockwise cycle. The optional delay argument
specifies the delay between LED updates in seconds.
- robot.offCycleLED(delay=seconds)
- Turns off all rim LEDs
sequentially in a clockwise cycle. The optional delay argument
specifies the delay between LED updates in seconds.
- robot.toggleCycleLED(delay=seconds)
- Toggles all rim
LEDs sequentially in a clockwise cycle. The optional delay argument
specifies the delay between LED updates in seconds.
- robot.flashCycleLED(delay=seconds)
- Flashes all rim LEDs
sequentially in a clockwise cycle. The optional delay argument
specifies the duration of each flash in seconds.
Miscellaneous
- robot.calibrateSensors()
- Calibrates the proximity sensors.
This method should only be called interactively.
- robot.reset()
- Resets the robot. Clears the serial port and
sets the camera to its default mode. This method should only be called
interactively. The selector switch on the robot must be in position 3.
- robot.close()
- Closes the serial connection to the robot.
- robot.currentTime()
- Returns the current time in seconds since
the Epoch (an arbitrary starting point in the past).
- robot.version()
- Prints out information about the firmware
running on the robot. This method should only be called
interactively.
- robot.help()
- Prints out the low-level serial port commands
recognized by the robot. This method should only be called
interactively.