deutsch     english    français     Print

Documentation robotics

Module import: from simrobot import *
from ev3robot import *
from nxtrobot import *

 

Sprites Library

LegoRobot:
Method Action
LegoRobot()

creates a robot (without motors/sensors) and establishes a communication link
[Simulation: displays the simulation window]

addPart(part) adds a part to the robot (motor, sensor, etc.)
clearDisplay() erases the display [Simulation: status bar]
drawString(text, x, y) draws text at position x, y [Simulation: in status bar, (x, y) irrelevant]
isDownHit() True, if DOWN button was hit [NXT and simulation: keyboard key Cursor-down]
isEnterHit() True, if ENTER button was hit [NXT and simulation: keyboard key Enter]
isEscapeHit() True, if ESCAPE button was hit [NXT and simulation: keyboard key Escape]
isLeftHit() True, if LEFT button was hit [NXT and simulation: keyboard key Cursor-left]
isRightHit() True, if RIGHT button was hit [NXT and simulation: keyboard key Cursor-right]
isUpHit() True, if UP button was hit [NXT and simulation: keyboard key Cursor-up]
playTone(frequency, duration) plays a tone with given frequency (in Hz) and duration (ms)
setVolume(volume) sets the sound volume for all sound emissions (0..100)
playSample(tag, volume) plays a WAV file using the given volume (0..100) from folder /home/root/music with file name song<tag>.wav (tag: integer) (non blocking). WAV format: mono, 8 bit unsigned or 16 bit signed with maximum sampling rate 11025 Hz [not available in sim]
playSampleWait(tag, volume) same, but blocking until play is finished [not available in sim]
setLED(pattern) sets the EV3 LEDS: 0: off, 1: green, 2: red, 3: red bright, 4: green blinking, 5: red blinking, 6: red blinking bright, 7: green double blinking , 8: red double blinking, 9: red double blinking brightl
exit() stops all motors and terminates the communication link
isConnected() returns True, if the communication link is established [Simulation: Window not closed]
reset() Simulation: sets the robot to the starting position/direction

Gear:
Gear() creates a vehicle with motors at port A and B
backward() moves backward (non-blocking method)
backward(ms) moves backward during given time (in ms) (blocking method)
isMoving() returns True, if the vehicle is not at rest
forward() starts moving forward (non-blocking method)
forward(ms) moves forward during given time (in ms) (blocking method)
left() starts turning left (non-blocking method)
left(ms) turns left during given time (in ms) (blocking method)
leftArc(radius) starts turning on left arc with given radius (approx. in m) left (non-blocking method)
leftArc(radius, ms) turns on left arc during given time (in ms) with given radius (approx. in m) left (blocking method)
right() starts turning right (non-blocking method)
right(ms) turns right during given time (in ms) (blocking method)
rightArc(radius) starts turning on right arc with given radius (approx. in m) left (non-blocking method)
rightArc(radius, ms) turns on right arc during given time (in ms) with given radius (approx. in m) left (blocking method)
setSpeed(speed) sets the vehicle speed (0..100)
stop() stops the vehicle
getLeftMotorCount() returns current value of left motor counter [not available in sim]
getRightMotorCount() returns current value of right motor counter [not available in sim]
resetLeftMotorCount() sets left motor counter to 0 [not available in sim]
resetRightMotorCount() sets right motor counter to 0 [not available in sim]

TurtleRobot:
TurtleRobot() creates a vehicle with motors at port A and B
backward() starts moving backward (non-blocking method)
backward(step) moves backward for the given number of steps (blocking method)
forward() starts moving forward (non-blocking method)
forward(step) moves forward for the given number of steps (blocking method)
left() starts turning left (non-blocking method)
left(angle) turns left for the given angel (approx. degrees) (blocking method)
right() starts turning right (non-blocking method)
right(angle) turns right for the given angel (approx. degrees) (blocking method)
setTurtleSpeed(speed) sets the vehicle speed (0..100)

Motor:
Motor(MotorPort.port) creates a motor at Motorport A, B, C or D
backward() starts rotating forward
forward() starts rotating backward
setSpeed(speed) sets the motor speed (0..100)
isMoving() returns True, if the motor is not at rest
stop() stops the motor
getMotorCount() returns current value of motor counter [not in sim]
resetMotorCount() sets motor counter to 0 [not in sim]
rotateTo(count) sets counter to 0, moves motor until count and stops (blocking) [not available in sim]
rotateTo(count, blocking) same as rotateTo(count), but not blocking for blocking = False [not available in sim]
continueTo(count) same as rotateTo(count), but counter is not set to 0 [not available in sim]
continueTo(count, blocking) same as rotateTo(count, blocking), but counter is not set to 0 [not available in sim]
continueRelativeTo(count) same as continueTo(count), but count is increment [not available in sim]
continueRelativeTo(count, blocking) same as continueTo(count, blocking), but count is increment [not available in sim]

Light Sensor:
LightSensor(SensorPort.port)

creates a light sensor at SensorPort S1, S2, S3 or S4
Simulation mode: Port S1: front right, S2: front left, S3: front center, S4: rear center

LightSensor(SensorPort.port, bright = onBright, dark = onDark) same with registered event callbacks onBright(port, value), onDark(port, value) while crossing the trigger level
LightSensor(SensorPort.port, True) Simulationsmode only: creates an upward directed light sensor at SensorPort S1, S2, S3 or S4. Port S1: front right, S2: front left, S3: rear right, S4: rear left
LightSensor(SensorPort.port, True, bright = onBright, dark = onDark) same with registered event callbacks onBright(port, value), onDark(port, value) while crossing the trigger level
getValue() returns the measured light level value (0...1000 approx.)
activate(bool) turns on/off the LED of a NXT LightSensor
setTriggerLevel(level) sets the trigger level (default: 500)

ColorSensor:
ColorSensor(SensorPort.port) creates a color sensor at SensorPort S1, S2, S3 or S4
Simulation mode: Port S1: front right, S2: front left, S3: front center, S4: rear center
getColor() returns the measured color as Color object with methods getRed(), getGreen(), getBlue() (RGB value 0..255)
getColorID() returns a color identifier: 0: undefined, 1: black, 2: blue, 3:green, 4: yellow, 5: red, 6: white
getColorStr() returns the measured color as string ("UNDEFINED", "BLACK", "BLUE", "GREEN", "YELLOW", "RED", "WHITE")
getLightValue() returns the luminosity (in HSG model) of the measured color

Touch Sensor:
TouchSensor(SensorPort.port)

creates a touch sensor at SensorPort S1, S2, S3 or S4
Simulation mode: Port S1: front right, S2: front left, S3: front center, S4: rear center

TouchSensor(SensorPort.port, pressed = onPressed, released = onReleased) same with registered event callbacks onPressed(port), onReleased(port)
isPressed() returns True, if the button is pressed

SoundSensor:
SoundSensor(SensorPort.port)

creates a sound sensor at SensorPort S1, S2, S3 or S4
Simulation mode: Sound card input. For EV3, use the NXT sound sensor: NxtSoundSensor(SensorPort.port)

SoundSensor(SensorPort.port, loud = onLoud, quiet = onQuiet) same with registered event callbacks onLoud(port, value), onQuiet(port, value) while crossing the trigger level
getValue() returns the measured sound level value (0...100 approx.)
setTriggerLevel(level) sets the trigger level (default: 50)

UltrasonicSensor:
UltrasonicSensor(SensorPort.port) creates a ultrasonic sensor at SensorPort S1, S2, S3 or S4
Simulation mode: S1: forward; S2: left, S3: backward

UltrasonicSensor(SensorPort.port, far = onFar, near = onNear)

same with registered event callbacks onFar(port, value), onNear(port, value) while crossing the trigger level
getDistance() returns the measured distance (in cm approx.; 255, if measurement fails)
setTriggerLevel(level) sets the trigger level (default: 10)
far(port, level), near(port, level) callback functions that may be registered by named parameters
setProximityCircleColor(color) Simulation: sets the color of the proximity circle
setMeshTriangleColor(color) Simulation: sets the color of the mesh triangles
eraseBeamArea() Simulation: erases the beam area

InfraredSensor (only EV3):
IRRemoteSensor(SensorPort.port) creates an infrared sensor for remote control at SensorPort S1, S2, S3 or S4
getCommand() returns the current command ID: 0:Nothing,1: TopLeft,2:BottomLeft,3:TopRight, 4:bottomRight
5:TopLeft&TopRight, 6:TopLeft&BottomRight,7:BottomLeft&TopRight,
8:bottomLeft&BottomRight, 9:Centre,10:BottomLeft&TopLeft,11:TopRight&BottomRight
The channel is selected by the red slider switch: 1: top, 4: bottom. It corresponds to the port number, where the sensor is attached.
actionPerformed(port, command)

callback function that may be registered by a named parameter


IRSeekSensor(SensorPort.port)

creates tn infrared search sensor at SensorPort S1, S2, S3 or S4 .
The active IR source of the remote control must be switched on (centre button)

v = getValue() v.bearing returns the direction (-12..12) and v.distance the distance (in cm) to the source.
The channel is selected by the red slider switch: 1: top, 4: bottom. It corresponds to the port number, where the sensor is attached.

IRDistanceSensor(SensorPort.port) creates a infrared distance sensorer at SensorPort S1, S2, S3 or S4 (reflecting target).
getDistance() returns the distance to the target (in cm)

ArduinoLink (only EV3):
ArduinoLink(SensorPort.port) creates an I2C master for the connection to the Arduino at SensorPort S1, S2, S3, S4

getReply(request, reply)

sends the request (integer 0..255) to the Arduino and returns the answer in the given list reply (max.16 integers 0..255)
getReplyInt(request) sends the request (integer 0..255) to the Arduino und returns the answer as integer 0..255
getReplyString(request)

sends the request (integer 0..255) to the Arduino und returns the answer as string (max. 15 ASCII-characters)


TemperatureSensor (only EV3):
TemperatureSensor(SensorPort.port) creates a temperature sensor at SensorPort S1, S2, S3, S4 (Lego NXT Temperature Sensor 9749)
getTemperature() returns the temperature in range -55..128 degrees Celsius

I2CExpander (only EV3):
I2CExpander(SensorPort.port, deviceType, slaveAddress) creates an I2C expander at SensorPort S1, S2, S3, S4. deviceType = 0: PCF8574, 1: PCF8574A, 2: PCF8591; slaveAddress: 8-bit I2C address
I2CExpander(SensorPort.port, deviceType, inputMode, slaveAddress) same, but defines inputMode: 0: single ended, 2: three differential, 3: mixed, 4: two differential (see data sheet PCF8591)

writeDigital(out)

sets the digital input/output (8 bits) and returns the current value. To define a pin as input, the port bit is set to 1. (Only for PCF8574/PCF8574A)
writeAnalog(out) sets the analog ouput (8 bits). (Only for PCF8591)
readAnalog(channel)

returns the current value of channel 0..3 (0..255 for single ended, -128..127 for differential). (Only for PCF8591)

readAnalog() returns list of currenet values of all channels. (Only for PCF8591)

For simulation mode only: RobotContext
setStartDirection(angle) sets the starting direction (0 to east, positive clockwise)
setStartPosition(x, y) sets the starting position (in pixels, zero at upper-left vertex)
showStatusBar(height) adds a status bar with given height at the bottom of the window
setStatusText(text) inserts text into the status bar (old text is erased)
useBackground(filename) inserts the given image into the background to be used by a light or color sensor
useObstacle(filename, x, y) inserts an obstacle at given position to be used by a the touch sensor
useTarget(filename, mesh, x, y) inserts a target at given position to be used by the ultrasonic sensor
useTorch(power, x, y, z) insert ein spot light source with given power at position (x, y, z) (draggable, z: height over floor). The light is detected by light sensors pointing upwards
useShadow(ulx, ul.y, lrx, lry) inserts a rectangle shadow area with upper left vertex (ulx, uly) and lower right vertex (lrx, lry). The shadow absorbs the light from all spot lights.

Sprites library

Complete Online-JavaDoc : EV3JLibA (Autonomous mode)
  EV3JLib (Direct mode)
  NxtJLib (Direct mode)
  RobotSim (Simulation)