forked from srmq/MobileSim
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathREADME.src.txt
413 lines (304 loc) · 17.3 KB
/
README.src.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
=========================================
MobileSim Source Code Information:
* Building MobileSim
* How MobileSim works
=========================================
Reed Hedges <[email protected]>
This document provides an overview of MobileSim for people interested in
compiling MobileSim from source, modifying MobileSim, or just understanding
how it works.
MobileSim is software for simulating MobileRobots mobile robots
and their environments, for debugging and experimentation.
MobileSim is based on the Stage library, created by the
Player/Stage project <http://playerstage.sourceforge.net>,
but modify to add some needed features.
All of the actual simulation is done by the Stage library,
as well as the graphical display of the robot, sensors and map.
MobileSim merely packages up the library into an easy to use
application, and interprets Pioneer robot-compatible commands
and data for Stage.
Player, Stage and all MobileSim components are free software,
distributed under the terms of the GNU General Public License:
see the file LICENSE.txt for details.
----------------------------
Modifying MobileSim or Stage
----------------------------
Both Stage and MobileSim are distributed to you under the terms of the
GNU General Public Lincese (GPL). See the file named LICENSE.txt for the
text of this copyright license, which in particular, requires you to
release source code of any modified versions make under the
GPL as well, if you also distribute the modified program. See
LICENSE.txt for the details.
If you do make any modifications and would like to share them, please
do so via the appropriate channel:
* For modifications to Stage (libstage), you can share the change with all
Stage developers and users (not just MobileSim developers and users) via
the patch tracker and mailing list at <http://playerstage.sf.net>.
* For modifications to just MobileSim (emulatePioneer; MobileSim main.cc or tools)
post them to the public aria-users mailing list or email them to MobileRobots
technical support. See <http://robots.mobilerobots.com>
If you have any questions about how MobileSim works or about modifying it,
please discuss on the aria-users mailing list.
----------------------------------
How to Compile Stage and MobileSim
----------------------------------
Linux
-----
To build MobileSim on Linux, you will need Aria 2.8 or later, GTK 2.x, including
development packages, and the full GNU development tools:
G++ (3.2 or later), make, libtool, automake, and autoconf.
If you have multiple versions of automake or autoconf, or have
them installed somewhere unusual, you can choose which commands
to use by setting the AUTOMAKE, AUTOCONF, AUTORECONF and ACLOCAL
environment variables before running make (e.g set them to
run the newer version). A modified version of Stage required by
MobileSim is included in the 'stage' subdirectory; you may enter
that directory and manually configure and build libstage if
required, or you may just run 'make' here in the main MobileSim
directory to build both libstage.a and MobileSim. Then run
'make install' to install MobileSim into /usr/local.
On Debian and Ubuntu Linux, you can use apt or apt-get to install the required
packages as follows:
apt install libgtk2.0-dev automake autoconf libtool make g++
Follow the instructions below to build MobileSim.
Windows (MinGW)
---------------
On Windows, you must use MinGW, MSYS and the MSYS DTK (http://www.mingw.org)
to build MobileSim. Download the MinGW-Get setup tool and run it to begin
installing MinGW. It will download and run the MinGW Installation Manager.
Select mingw-developer-toolkit, mingw32-base, mingw32-gcc-g++, msys-base,
and in the Libraries section, mingw32-pthreads-w32 (dev) and
mingw32-libpthreadgc (dev). ("Mark for Installation"). With these selections,
autotools, required compilation tools (pkg-config, binutils etc.) and various
shell utilities should be also selected automatically. You can select any
additional shell tools you may wish to have as well. Choose Apply Changes
from the Packages menu to install or upgrade any extra packages selected. After
installing, run the MinGW Shell from the Start menu (or run msys.bat
from C:\MinGW\msys\1.0). Enter the MobileSim directory (unpacked source
package), and follow the steps below to build MobileSim.
Note: ARIA is normally built using Visual C++ on Windows, but it must be rebuilt
using MinGW for use with MobileSim. In addition to being built with a different
compiler, ARIA uses pthreads and a few other POSIX features when built with
MinGW rather than Windows implementations; it will still use ws2_32
from Windows for network sockets, and winmm for sound playback, joystick
and other features however. When you run "make" to build MobileSim,
it will enter the Aria directory (see below) and rebuild ARIA using MinGW,
resulting in libAria.a in ARIA's lib directory. If the ARIA environment variable
is set, then that directory is used to build and find the ARIA library. It defaults
to /usr/local/Aria which is probably only valid on Linux, so set the ARIA environment
variable to a location containing the ARIA source code when building in MinGW.
Stage and MobileSim use GTK 2 for the GUI. GTK libraries for MinGW are
included in stage/gtk-win and are used automatically when built in MinGW.
The MobileSim Makefile uses the pkg-config tool to query required compiler and
linker flags for GTK, so the pkg-config tool must be installed and in
your path. (Or you can manually specify the location of the pkg-config
tool by setting a PKG_CONFIG variable.)
If you copy or unpack the ARIA source code to ../Aria (next to MobileSim source), then
after installing and setting up GTK, you can build MobileSim like this:
export ARIA=../Aria
make
If the ARIA source code is in a different directory name or location, change the
name above, using MinGW paths.
MobileSim looks for required resources such as the default model
definitions in a default installation directory. To instead use
the source directory, set the MOBILESIM environment variable prior
to running MobileSim. You can set to the directory from which
you launch MobileSim like this:
export MOBILESIM=.
Or use the "pwd" command to set it to the current directory at time
you set the variable:
export MOBILESIM=`pwd`
The GTK DLLs must be in the system path, or in the same directory as
MobileSim, in order to run MobileSim on Linux. (If not, you will see
an error such as "The program can't start because libgdk-win32-2.0-0.dll
is missing from your computer...". So to run MobileSim from
the MSYS shell after building, add stage/gtk-win/bin to your PATH:
export PATH=$PATH:stage/gtk-win/bin
Then you can run MobileSim:
./MobileSim.exe
(When installed on the system from an installer package, they
are placed in the same directory, which is why this is not neccesary
except after building from source code.)
More details on how the Windows/MinGW build of the Stage library with
GTK works is described in stage/README-Windows.txt, including how to
generate build files using autotools (additional options are required,
the MobileSim Makefile uses these if on MinGW).
Mac OSX
-------
It is possible to build MobileSim for OSX 10.04 (Tiger) or later using the
OSX port of GTK.
You will need to install XCode, and then install the command-line development
tools (Run XCode, then open "Preferences..." from the "XCode" application menu.
Select the "Downloads" tab. Select "Command Line Tools" and click its "Install"
button. This allows you to use Terminal shells to build using "make",
"c++" and other commands directly.
Follow the instructions at https://wiki.gnome.org/GTK+/OSX/Building to
download and build GTK 2 and other required libraries.
You will also need to downoald the ARIA source code. If the ARIA
environment variable is set, then that directory is used to build and
find the ARIA library. It defaults to /usr/local/Aria which is probably
only valid if installed, so set the ARIA environment variable to a
location containing the ARIA source code if in a different location.
Follow the instructions below to build MobileSim, but add the tools installed
for GTK to a GTK_DIR variable and your PATH first. For example, if you downloaded
and built GTK in a "gtk" directory in your home directory:
export GTK_DIR=~/gtk/inst
export PKG_CONFIG_PATH=$GTK_DIR/lib/pkgconfig
export PATH=$PATH:$GTK_DIR/bin
If you placed GTK in another directory instead, replace "~/gtk" with that
location.
MobileSim looks for required resources such as the default model
definitions in a default installation directory. To instead use
the source directory, set the MOBILESIM environment variable prior
to running MobileSim. You can set to the directory from which
you launch MobileSim like this:
export MOBILESIM=.
Or use the "pwd" command to set it to the current directory at time
you set the variable:
export MOBILESIM=`pwd`
Then you can run the bare MobileSim executable:
./MobileSim
An application bundle is also built, MobileSim.app, which you can
launch by double clicking in the Finder or with the open command:
open MobileSim.app
Building MobileSim
------------------
Unless an ARIA environment variable was set, MobileSim looks for
ARIA in an "../Aria" directory (in the parent directory, i.e.
both the Aria source code and MobileSim source code should be
in the same parent directory). If you want to use the version of
ARIA already installed on your system, set the ARIA environment variable to
its installation location:
For Linux:
export ARIA=/usr/local/Aria
For Windows with MinGW:
export ARIA="/c/Program Files/MobileRobots/Aria"
Or, if you have unpacked and built the ARIA source code in ~/ARIA-src-2.9.2:
export ARIA=~/ARIA-src-2.9.2
When building MobileSim, you can set environment variables that affect
compilation options:
CXX Set the C++ compiler; if unset, "c++" is used.
CC Set the C compiler; if unset, "cc" is used.
CFLAGS Additional compilation flags for C.
CXXFLAGS Additional compilation flags for C++.
LFLAGS Additional linker flags.
MOBILESIM_DEBUG Build MobileSim with optimizations disabled and
debugging enabled if set.
MOBILESIM_RELEASE Build with optimizations enabled and debugging
disabled. This is the default state.
MOBILESIM_PROFILE Build with profiling enabled with -pg; analyze later
with gprof.
prefix Installation directory base (default is /usr/local)
DESTDIR Alternate root for installation (default is none,
therefore the root filesystem is used).
STAGEDIR Alternate Stage directory (default is stage/)
STAGELIBDIR Alternate Stage library directory (default is
stage/src/.libs)
AUTORECONF autoreconf command
AUTOCONF autoconf command
ACLOCAL aclocal command
AUTOMAKE automake command
For example, to build with debugging options enabled:
make MOBILESIM_DEBUG=1
You can also edit Makefile if neccesary.
Note: MobileSim requires certain resources at runtime (such as the robot models definitions
file) to work correctly, so you must either install MobileSim with
'make install', or set a MOBILESIM environment variable to the MobileSim
source directory (or another directory containing MobileSim's resources):
For example:
export MOBILESIM=~/MobileSim-0.7.3
If you do not set this, MobileSim will attempt to load the robot models
definitions from /usr/local/MobileSim/PioneerRobotModels.world.inc, which
will fail if MobileSim is not installed or the MOBILESIM environment variable
was not set.
For example, if you want to run MobileSim after building it in a source
directory ~/MobileSim:
export MOBILESIM=~/MobileSim
./MobileSim
-------------------
How MobileSim Works
-------------------
MobileSim glues together three main components: Stage simulation; Pioneer emulation;
and various utilities from ARIA to load a map file and to send and
receive packets to and from clients. The source file "main.cc" contains
the main() function and brings these three components together, and provides
a command-line interface and also an initial dialog box for loading a map
file and selecting a robot model to create. The files RobotFactory.cc,
RobotFactory.hh, StageRobotFactory.cc and StageRobotFactory.hh implement
the "robot factory" feature (on-demand model creation).
Stage
-----
Stage is the core of the simulator. It provides the main GUI, and simulation of
all the robots, devices, their environment, and collisions between them.
Stage is not a MobileRobots project, but was created by a variety of individuals
and is related to the Player project. Stage consists of a library, libstage.a,
which MobileSim uses to set up the simulated world, the GUI, and requested
robots and their devices.
We have modified Stage to add some missing features and to allow it
to be built in MSYS/MinGW. This modified version of stage is included
in the source code package in the 'stage' subdirectory, and must be built
before building MobileSim. (Patches are available on the Stage project
patch tracker at http://sourceforge.net/p/playerstage/patches/)
The source code to Stage is in the 'stage/src' subdirectory. Simulation
of robots and devices ("models") are in files beginning with the "model_"
prefix. E.g. a movable robot base is a "position" model and is implemented
in "model_position.c". Sonar is a kind of "ranger" model. The laser LRF
is a "laser" model. Stage begins by creating a "world" (MobileSim creates
a temporary world file for Stage to start with). MobileSim then creates
models for the robots and devices, represented using stg_model_t structs
which store properties and other state. These are initialized with an init
function for the appropriate type (e.g. position_init for position models,
ranger_init for ranger models, etc.) which creates the model's property
objects, registers callbacks for future events, etc. It then calls the
load function (e.g. position_load for position models, etc.) which reads
configuration information from the world. Then, after the simulation has
been started, MobileSim's main loop calls Stage's main update function, which
calls the update functions for all model in the simulation (e.g. position_update
for position models) every 100ms (by default). This update function can examine
"command" properties and make appropriate changes, and otherwise maintain the
model's state in the simulation. Each model-specific function ends by calling
a common update function that updates the model's position in the simulated world
(based on its current velocity properties) and updates the GUI.
In setting up the world configuration for Stage, MobileSim relies on definitions of various
Pioneer robot models, which are kept in a file called PioneerRobotModels.world.inc.
When installed, this file is alongside the MobileSim program (e.g.
/usr/local/MobileSim directory on Linux).
More about Stage (including library API documentation) is on the web at
<http://playerstage.sf.net>.
Pioneer emulation
-----------------
The Pioneer emulator component encapsulates the Pioneer robot specific aspects
of the MobileSim code. The central class in this part is called EmulatePioneer.
EmulatePioneer accepts command packets and sends information packets through a
TCP port, the same way that a real Pioneer robot communicates over a serial port.
These commands are de-marshalled and EmulatePioneer makes appropriate calls into
a RobotInterface object. Likewise, information is retrieved from the
RobotInterface to be sent in information packets. RobotInterface is the
interface through which the Pioneer emulation component communicates with the
simulation component. In MobileSim, a subclass of RobotInterface called
StageInterface is used to connect the Pioneer server emulation with the Stage
simulation. The StageInterface class also contains a function to load the map
file and set up the Stage world accordingly.
For each robot requested, MobileSim's main() function creates a
StageInterface and an EmulatePioneer object. The StageInterface object
locates appropriate "model" pointers in the Stage simulation for the robot
(a "position" model), sonar (a "ranger" model) and possibly a laser model.
EmulatePioneer uses a StageInterface object to communicate with Stage
through it's public functional API or by getting and setting
"properties" (a generic data container) of these models.
GDB Crash Handler
-----------------
On Linux and MacOSX, when a fatal signal is received indicating the
program is crashing (SIGSEGV, SIGABRT, SIGILL, SIGILL, SIGFPE, SIGBUS),
MobileSim will try to run the gdb debugger and log stack traces for
each thread.
To allow gdb to do this on some systems such as Ubuntu,
you must change PTRACE level in Linux. You can do this temporarly
by modifying /proc/sys/kernel/yama/ptrace_scope:
sudo sh -c 'echo 0 >/proc/sys/kernel/yama/ptrace_scope'
or permanently by editing /etc/sysctl.d/10-ptrace.conf.
You can disable the crash handler with the --no-crash-debug
command-line options.
If in noninteractive mode, MobileSim will also try to restart after
logging crash information. This can be disabled wiht --no-crash-restart.
In the normal interactive mode, automatic restart is disabled by default.