
Embedded Robotics (Thomas Braunl, 2 ed, 2006)
.pdf
13 Simulation Systems
Figure 13.3: Generated camera images
use a standard Gaussian distribution for fault values added to sensor readings or actuator positions. From the user interface, error percentages can be selected for each sensor/actuator. Error values are added to distance measurement sensors (infrared, encoders) or the robot’s [x, y] coordinates and orientation.
Simulated communication errors include also the partial or complete loss or corruption of a robot-to-robot data transmission.
For the generated camera images, some standard image noise methods have been implemented, which correspond to typical image transmission errors and dropouts (Figure 13.4):
•Salt-and-pepper noise
a percentage of random black and white pixels is inserted.
•100s&1000s noise
a percentage of random colored pixels is inserted.
•Gaussian noise
a percentage of pixels are changed by a zero mean random process.
Figure 13.4: Camera image, salt-and-pepper, 100s&1000s, Gaussian noise
176

Multiple Robot Simulation
13.3 Multiple Robot Simulation
Avoid global variables
A multi-robot simulation can be initiated by specifying several robots in the parameter file. Concurrency occurs at three levels:
•Each robot may contain several threads for local concurrent processing.
•Several robots interact concurrently in the same simulation environment.
•System updates of all robots’ positions and velocities are executed asynchronously in parallel with simulation display and user input.
Individual threads for each robot are created at run-time. Posix threads and semaphores are used for synchronization of the robots, with each robot receiving a unique id-number upon creation of its thread.
In a real robot scenario, each robot interacts with all other robots in two ways. Firstly, by moving around and thereby changing the environment it is part of. Secondly, by using its radio communication device to send messages to other robots. Both of these methods are also simulated in the EyeSim system.
Since the environment is defined in 2D, each line represents an obstacle of unspecified height. Each of the robot’s distance sensors measures the free space to the nearest obstacle in its orientation and then returns an appropriate signal value. This does not necessarily mean that a sensor will return the physically correct distance value. For example, the infrared sensors only work within a certain range. If a distance is above or below this range, the sensor will return out-of-bounds values and the same behavior has been modeled for the simulation.
Whenever several robots interact in an environment, their respective threads are executed concurrently. All robot position changes (through driving) are made by calling a library function and will so update the common environment. All subsequent sensor readings are also library calls, which now take into account the updated robot positions (for example a robot is detected as an obstacle by another robot’s sensor). Collisions between two robots or a robot and an obstacle are detected and reported on the console, while the robots involved are stopped.
Since we used the more efficient thread model to implement multiple robots as opposed to separate processes, this restricts the use of global (and static) variables. Global variables can be used when simulating a single robot; however, they can cause problems with multiple robots, i.e. only a single copy exists and will be accessible to threads from different robots. Therefore, whenever possible, global and static variables should be avoided.
177

13 Simulation Systems
13.4 EyeSim Application
The sample application in Program 13.1 lets a robot drive straight until it comes too close to an obstacle. It will then stop, back up, and turn by a random angle, before it continues driving in a straight line again. Each robot is equipped with three PSD sensors (infrared distance sensors). All three sensors plus the stall function of each robot are being monitored. Figure 13.5 shows simulation experiments with six robots driving concurrently.
Program 13.1: Random drive
1#include "eyebot.h"
2#include <stdlib.h>
3#include <math.h>
4#define SAFETY 300
6int main ()
7{ PSDHandle front, left, right;
8 |
VWHandle |
vw; |
9 |
float |
dir; |
10
11LCDPrintf("Random Drive\n\n");
12LCDMenu("", "", "", "END");
13vw=VWInit(VW_DRIVE,1);
14VWStartControl(vw, 7.0,0.3,10.0,0.1);
15front = PSDInit(PSD_FRONT);
16left = PSDInit(PSD_LEFT);
17right = PSDInit(PSD_RIGHT);
18PSDStart(front | left | right , TRUE);
20while(KEYRead() != KEY4)
21{ if ( PSDGet(left) >SAFETY && PSDGet(front)>SAFETY
22&& PSDGet(right)>SAFETY && !VWStalled(vw) )
23 |
VWDriveStraight(vw, 0.5, 0.3); |
24else
25{ LCDPutString("back up, ");
26VWDriveStraight(vw,-0.04,0.3);
27VWDriveWait(vw);
28 |
LCDPutString("turn\n"); |
/* |
random |
angle */ |
|
29 |
dir = M_PI * (drand48() |
- 0.5); /* |
-90 .. |
+90 |
*/ |
30VWDriveTurn(vw, dir, 0.6);
31VWDriveWait(vw);
32}
33OSWait(10);
34}
35VWRelease(vw);
36return 0;
37}
178

EyeSim Environment and Parameter Files
Figure 13.5: Random drive of six robots
13.5 EyeSim Environment and Parameter Files
All environments are modeled by 2D line segments and can be loaded from text files. Possible formats are either the world format used in the Saphira robot operating system [Konolige 2001] or the maze format developed by Bräunl following the widely used “Micro Mouse Contest” notation [Bräunl 1999].
179

13 Simulation Systems
World format The environment in world format is described by a text file. It specifies walls as straight line segments by their start and end points with dimensions in millimeters. An implicit stack allows the specification of a substructure in local coordinates, without having to translate and rotate line segments. Comments are allowed following a semicolon until the end of a line.
The world format starts by specifying the total world size in mm, for example:
width 4680 height 3240
Wall segments are specified as 2D lines [x1,y1, x2,y2], so four integers are required for each line, for example:
;rectangle 0 0 0 1440 0 0 2880 0
0 1440 2880 1440
2880 0 2880 1440
Through an implicit stack, local poses (position and orientation) can be set. This allows an easier description of an object in object coordinates, which may be offset and rotated in world coordinates. To do so, the definition of an object (a collection of line segments) is enclosed within a push and pop statement, which may be nested. Push requires the pose parameters [x, y, phi], while pop does not have any parameters. For example:
;two lines translated to [100,100] and rotated by 45 deg. push 100 100 45
0 |
0 |
200 |
0 |
0 |
0 |
200 |
200 |
pop |
|
|
The starting position and orientation of a robot may be specified by its pose [x, y, M], for example:
position 180 1260 -90
Maze format The maze format is a very simple input format for environments with orthogonal walls only, such as the Micro Mouse competitions. We wanted the simulator to be able to read typical natural graphics ASCII maze representations, which are available from the web, like the one below.
Each wall is specified by single characters within a line. A “_” (at odd positions in a line, 1, 3, 5, ..) denotes a wall segment in the y-direction, a “B” (at even positions in a line, 2, 4, 6, ..) is a wall segment in the x-direction. So, each line contains in fact the horizontal walls of its coordinate and the vertical wall segments of the line above it.
180

EyeSim Environment and Parameter Files
_________________
| |
_________| |
|
| |
|
| | |
_____ |
| |
|___| |
|
| | |_____ |
| |
| |
| | |
|
| | |
_ __|___| |
_| |
| |_|____________ |
| |
||||
| |___ |
| |
_ |
| |
| |
|
| |
_ | |___| | __| |
||||
| |
| | | |
| |
____ |
|
| |
|S|_____|_______|_|
The example below defines a rectangle with two dividing walls:
_ _ |
_ |
| |
_| |
|_|_ |
_| |
The following shows the same example in a slightly different notation, which avoids gaps in horizontal lines (in the ASCII representation) and therefore looks nicer:
_____
| _| |_|___|
Extra characters may be added to a maze to indicate starting positions of one or multiple robots. Upper-case characters assume a wall below the character, while lower-case letters do not. The letters U (or S), D, L, R may be used in the maze to indicate a robot’s start position and orientation: up (equal to start), down, left, or right. In the last line of the maze file, the size of a wall segment can be specified in mm (default value 360mm) as a single integer number.
A ball can be inserted by using the symbol “o”, a box can be inserted with the symbol “x”. The robots can then interact with the ball or box by pushing or kicking it (see Figure 13.6).
| |
_____________________________________________________ |
| |
||
|
|
|
||
| |
r |
|
l |
| |
| |
|
| |
||
| |
|
|
|
| |
_| |
r |
|
l |
|_ |
| |
|
| |
||
| |
r |
o |
l |
| |
| |
| |
|||
| |
r |
|
l |
| |
|_ |
|
_| |
||
| |
|
|
|
| |
| |
r |
|
l |
| |
| |
|
| |
||
| |
|
|
|
| |
|_____________________________________________________| 100
181

13
SIM parameter file
Simulation Systems
Figure 13.6: Ball simulation
A number of parameter files are used for the EyeSim simulator, which determine simulation parameters, physical robot description, and robot sensor layout, as well as the simulation environment and graphical representation:
•myfile.sim
Main simulation description file, contains links to environment and robot application binary.
•myfile.c (or .cpp) and myfile.dll
Robot application source file and compiled binary as dynamic link library (DLL).
The following parameter files can be supplied by the application programmer, but do not have to be. A number of environment, as well as robot description and graphics files are available as a library:
•myenvironment.maz or myenvironment.wld
Environment file in maze or world format (see Section 13.5).
•myrobot.robi
Robot description file, physical dimensions, location of sensors, etc.
•myrobot.ms3d
Milkshape graphics description file for 3D robot shape (graphics representation only).
Program 13.2 shows an example for a “.sim” file. It specifies which environment file (here: “maze1.maz”) and which robot description file (here: S4.robi”) are being used.
The robot’s starting position and orientation may be specified in the “robi” line as optional parameters. This is required for environments that do not specify a robot starting position. E.g.:
robi S4.robi DriveDemo.dll 400 400 90
182

EyeSim Environment and Parameter Files
Program 13.2: EyeSim parameter file “.sim”
1 |
# world description file (either maze or world) |
2 |
maze maze1.maz |
3 |
|
4# robot description file
5robi S4.robi DriveDemo.dll
ROBI parameter file
There is a clear distinction between robot and simulation parameters, which is expressed by using different parameter files. This split allows the use of different robots with different physical dimensions and equipped with different sensors in the same simulation.
Program 13.3: Robot parameter file “.robi” for S4 soccer robot
1# the name of the robi
2name S4
3
4# robot diameter in mm
5diameter 186
6 |
# max |
linear velocity in mm/s |
7 |
||
8 |
speed |
600 |
9 |
# max |
rotational velocity in deg/s |
10 |
||
11 |
turn |
300 |
12 |
# file name of the graphics model used for this robi |
|
13 |
||
14 |
model |
S4.ms3d |
15 |
|
|
16# psd sensor definition: (id-number from "hdt_sem.h")
17# "psd", name, id, relative position to robi center(x,y,z)
18# in mm, angle in x-y plane in deg
19 |
psd PSD_FRONT |
-200 |
60 |
20 |
30 |
0 |
|
20 |
psd |
PSD_LEFT |
-205 |
56 |
45 |
30 |
90 |
21 |
psd |
PSD_RIGHT |
-210 |
56 |
-45 |
30 |
-90 |
22 |
|
|
|
|
|
|
|
23# color camera sensor definition:
24# "camera", relative position to robi center (x,y,z),
25# pan-tilt-angle (pan, tilt), max image resolution
26 |
camera 62 0 60 |
0 -5 |
80 60 |
27 |
|
|
|
28# wheel diameter [mm], max. rotational velocity [deg/s],
29# encoder ticks/rev., wheel-base distance [mm]
30 |
wheel 54 3600 1100 90 |
31 |
|
32# motors and encoders for low level drive routines
33# Diff.-drive: left motor, l. enc, right motor, r. enc
34 |
drive DIFFERENTIAL_DRIVE MOTOR_LEFT QUAD_LEFT |
35 |
MOTOR_RIGHT QUAD_RIGHT |
183

13 Simulation Systems
Each robot type is described by two files: the “.robi” parameter file, which contains all parameters of a robot relevant to the simulation, and the default Milkshape “.ms3d” graphics file, which contains the robot visualization as a colored 3D model (see next section). With this distinction, we can have a number of physically identical robots with different shapes or color representation in the simulation visualization. Program 13.3 shows an example of a typical “.robi” file, which contains:
•Robot type name
•Physical size
•Maximum speed and rotational speed
•Default visualization file (may be changed in “.sim” file)
•PSD sensor placement
•Digital camera placement and camera resolution in pixels
•Wheel velocity and dimension
•Drive system to enable low-level (motoror wheel-level) driving, supported drive systems are DIFFERENTIAL_DRIVE, ACKERMANN_
DRIVE, and OMNI_DRIVE
With the help of the robot parameter file, we can run the same simulation with different robot sensor settings. For example, we can change the sensor mounting positions in the parameter file and find the optimal solution for a given problem by repeated simulation runs.
13.6 SubSim Simulation System
SubSim is a simulation system for Autonomous Underwater Vehicles (AUVs) and therefore requires a full 3D physics simulation engine. The simulation software is designed to address a broad variety of users with different needs, such as the structure of the user interface, levels of abstraction, and the complexity of physics and sensor models. As a result, the most important design goal for the software is to produce a simulation tool that is as extensible and flexible as possible. The entire system was designed with a plug-in based architecture. Entire components, such as the end-user API, the user interface and the physics simulation library can be exchanged to accommodate the users’ needs. This allows the user to easily extend the simulation system by adding custom plug-ins written in any language supporting dynamic libraries, such as standard C or C++.
The simulation system provides a software developer kit (SDK) that contains the framework for plug-in development, and tools for designing and visualizing the submarine. The software packages used to create the simulator include:
•wxWidgets [wxWidgets 2006] (formerly wxWindows)
A mature and comprehensive open source cross platform C++ GUI framework. This package was selected as it greatly simplifies the task
184

SubSim Simulation System
Physics simulation
Application programmer interface
of cross platform interface development. It also offers straightforward plug-in management and threading libraries.
•TinyXML [tinyxml 2006]
This XML parser was chosen because it is simple to use and small enough to distribute with the simulation.
•Newton Game Dynamics Engine [Newton 2006]
The physics simulation library is exchangeable and can be selected by the user. However, the Newton system, a fast and deterministic physics solver, is SubSim’s default physics engine.
The underlying low-level physics simulation library is responsible for calculating the position, orientation, forces, torques and velocities of all bodies and joints in the simulation. Since the low-level physics simulation library performs most of the physics calculations, the higher-level physics abstraction layer (PAL) is only required to simulate motors and sensors. The PAL allows custom plug-ins to be incorporated to the existing library, allowing custom sensor and motor models to replace, or supplement the existing implementations.
The simulation system implements two separate application programmer interfaces (APIs). The low-level API is the internal API, which is exposed to developers so that they can encapsulate the functionality of their own controller API. The high-level API is the RoBIOS API (see Appendix B.5), a user friendly API that mirrors the functionality present on the EyeBot controller used in both the Mako and USAL submarines.
The internal API consists of only five functions:
SSID InitDevice(char *device_name);
SSERROR QueryDevice (SSID device, void *data);
SSERROR SetData(SSID device, void *data);
SSERROR GetData(SSID device, void *data);
SSERROR GetTime(SSTIME time);
The function InitDevice initializes the device given by its name and stores it in the internal registry. It returns a unique handle that can be used to further reference the device (e.g. sensors, motors). QueryDevice stores the state of the device in the provided data structure and returns an error if the execution failed. GetTime returns a time stamp holding the execution time of the submarine’s program in ms. In case of failure an error code is returned.
The functions that are actually manipulating the sensors and actuators and therefore affect the interaction of the submarine with its environment are either the GetData or SetData function. While the first one retrieves the data (e.g. sensor readings) the latter one changes the internal state of a device by passing control and/or information data to the device. Both functions return appropriate error codes if the operation fails.
185