This document contains additional information on how to program robots in Playground, a multi-robot simulator bundled with Aseba.
The code following the instruction onevent ir_sensors will be executed at regular intervals, just after the distance to obstacles (prox) has been updated.
The code following the instruction onevent camera will be executed at regular intervals, just after the linear camera pixels camR, camG, camB have been updated.
emit name [arguments]
emit specifies that a given robot should send an event of type name to all other robots. The event may contain up to 32 arguments. Note that you cannot choose to which robot the event will be sent, since just like a radio signal, it is broadcast to all robots (see the example below in [args] for how you can address individual robots). Note also that the name of the event and the number of arguments have to be declared in the Global Events pane of Aseba Studio.
An identifier whose value is unique for every robot.
The id of the robot from which the most recent event was received.
The arguments of the most recent event received on this robot.
Example: This example shows how events can target individual robots even if the signal was broadcast to all robots. The idea is to use a vector in which each position is allocated to a specific robot: when receiving the event a robot will read only a specific part of this vector.
The robot 1 sends a move-ahead event to robot 2, waits, then sends a move-ahead event to robot 3 and a stop to robot 2, waits, and finally sends a general stop message.
Code for robot 1:
# variables
var counter = 0
onevent ir_sensors
if counter == 10 then
emit move [1,0]
end
if counter == 100 then
emit move [0,1]
end
counter += 1
Code for robot 2:
# events
onevent move
if args[0] == 1 then
leftSpeed = 400
rightSpeed = 400
else
leftSpeed = 0
rightSpeed = 0
end
onevent stop
leftSpeed = 0
rightSpeed = 0
Code for robot 3:
# events
onevent move
if args[1] == 1 then
leftSpeed = 400
rightSpeed = 400
else
leftSpeed = 0
rightSpeed = 0
end
onevent stop
leftSpeed = 0
rightSpeed = 0
Wheel speed. Choose 400 for slow motion.
The red, green and blue components of the robot's colour.
The distance to obstacles perceived by the sensors. Note that noise produces fluctuations in the measurements. See schema here.
Array of length 60. The red, green and blue components of values returned by the robot's camera.
Integer: [0 9]. The robot's energy level.
Playground allows specific simulation environments to be defined. For instance, the following code creates a box containing four robots:
<!DOCTYPE aseba-playground>
<aseba-playground>
<color name="wall" r="0.9" g="0.9" b="0.9" />
<color name="red" r="0.77" g="0.2" b="0.15" />
<color name="green" r="0" g="0." b="0.17" />
<color name="blue" r="0" g="0.38" b="0.61" />
<world w="110.4" h="110.4" color="wall"/>
<e-puck x="40" y="40"/>
<e-puck x="40" y="60"/>
<e-puck x="60" y="40"/>
<e-puck x="60" y="60"/>
</aseba-playground>
Example: Get here a model of the German Pavilion, 1929, designed by Mies van der Rohe.