4a684ad632eb3609d85f91ea3c9f8a0c7569fd27
[bachelor-thesis/written-stuff.git] / Ausarbeitung / preliminaries.tex
1 \chapter{Preliminaries}
2 This chapter describes the preliminary topics. \todo .
3
4 \section{Dead reckoning}
5 The process of \definition{dead reckoning} describes an inexpensive method for
6 relative positioning by computing a vehicle's position from an initial
7 starting position and the covered distance and course it has moved. In the case
8 of mobile robots, the covered distance can be simply computed in real time from
9 the revolution of its wheels, or by accelerometers the robot may be equipped
10 with. However, since the vehicle's current position is based on its previous
11 position, and the distance measurement may be imprecise, dead reckoning has the
12 disadvantage that errors in position calculation can cumulate and the error
13 of the calculated position grows with time.
14
15 Another approach to determine a vehicle's position is absolute positioning, for
16 example satellite-based, over navigation beacons or by map matching. Still,
17 these techniques are rather expensive to deploy, cannot (yet) be used in real
18 time, or are even impreciser than relative approaches\cite{umbmark}, so dead
19 reckoning can still be useful for the time being.
20
21 In the following, the iRobot Roomba serves as an example of an autonomous,
22 mobile agent, which can be used to implement dead reckoning for lack of either
23 built-in absolute positioning and other relative approaches.
24
25 \section{iRobot Roomba 500}
26 Originally, the \definition{Roomba} is an autonomous vacuum cleaning robot,
27 manufactured by the US-based company \definition{iRobot}. The 500 series
28 currently represents the third generation of iRobot's cleaning robots, and the
29 first generation of robots controllable over an external interface.
30
31 \subsection{Hardware design}
32 \todo{diagram?}
33 \paragraph{Wheels}
34 The Roomba lives in a cylindrical case with diameter of about 34~cm and height
35 of about 7~cm. It has two main wheels which are positioned slightly behind the
36 centerline, so the Roomba leans forward due to gravity, and a small caster on
37 the front to prevent it from sliding on the floor. The main wheels can be
38 controlled over two independent motors, each one allowing to turn the connected
39 wheel with a minimum of 10~mm/s and a maximum of 500~mm/s in each direction.
40 One of the main wheel motors consumes about 300~mA in their slowest rotation
41 speed, and about 1000~mA when driving with normal speed. Each wheel is also
42 equipped with a drop sensor that tells if the respective wheel has dropped into
43 a hole or similar, and does not reach the ground anymore. These sensors are
44 realized with a spring pushing the wheel towards the ground, with the spring
45 force adjusted to the Roomba's weight, and a micro switch which triggers if the
46 wheel drops below a specified level. Furthermore, both wheels feature rotating,
47 toothed discs, which in conjunction with an LED and a photo-electric resistor
48 act as an optical interrupter. This system can be used to measure the wheel's
49 current speed by counting the optical interruptions the wheel causes while
50 moving.
51
52 \paragraph{Brushes}
53 In addition to the wheel motors, the Roomba has a motor which operates the
54 vacuum brush, and a small motor on the front connected to a side brush, to allow
55 cleaning of room corners.
56
57 \paragraph{Bumper shield}
58 Since the main movement direction in normal operation is forward, the front of
59 the Roomba consists of a crecent-shaped bumper shield which contains several
60 sensors. This bumper\index{Roomba!bumper} is spring-loaded and on the one
61 hand absorbs shock to reduce damage, on the other hand, it allows the Roomba to
62 detect obstacles in front of it, both via infrared sensors as well as by
63 mechanical means. There are two sensors for mechanical bump detection, located
64 30° to the left and to the right of the bumper's center, each implemented as
65 photo-electrical interruptors. Additionally, six infrared sensors are unevenly
66 distributed over the bumper, facing away from it in a star-like manner. Each one
67 of them allows the Roomba to recognize objects in a maxmimum distance of 10~cm.
68 Finally, the bumper shield contains four infrared sensors facing downwards,
69 acting as cliff sensors \index{Roomba!cliff sensor} to recognize steps or
70 similar chasms which could be dangerous for the Roomba to drive towards.
71
72 The back part of the Roomba contains the main vacuum brush\index{Roomba!vacuum
73 brush}, and the reservoir for holding dirt. Both of them can be removed, though
74 the removal of the main brush reduces the Roomba's weight and slightly
75 unbalances the Roomba so the springs used for the wheel drop sensors are not in
76 balance anymore and push the Roomba upwards, so it tilts more to the front when
77 accelerating forwards. There is also a sensor on the underside
78 \index{Roomba!dirt sensor} for detecting particularly dirty regions of the
79 floor, which is implemented as a capacitive touch sensor.
80
81 \paragraph{Battery}
82 The battery\index{Roomba!battery} is placed in the front part behind the bumper,
83 it is a rechargeable NiMH battery and holds a capacity of 3300~mAh which lasts
84 for about 90 to 120 minutes under normal operation. The Roomba can also find its
85 home base and charge itself when it has finished cleaning or runs out of energy
86 by using a special infrared sensor mounted on top of the Roomba. This sensor can
87 see in all directions and is able to detect the home base by looking for a
88 special infrared signal the home base\index{Roomba!home base} emits. The same
89 principle is used for so-called "`virtual walls"'\index{virtual wall} which can
90 be placed by the user in regions the Roomba should not move into.
91
92 \subsection{Behaviour}
93 \paragraph{Intended Behaviour}
94 The Roomba normally follows its own, non-customizable algorithm to detect dirt
95 and clean rooms. It is kind of a random walk\index{random walk}, controlled by
96 the internal logic, which tries to keep the Roomba away from dangers like
97 stairs and walls (by evaluating the cliff and bump sensors), and direct it to
98 the more dusty regions of the room (by using the dirt sensor). The random walk
99 concept allows a more or less complete coverage of the room, given the time for
100 cleaning is large enough, while at the same only needing very little information
101 about the environment. Of course, that concept is not very efficient when it
102 comes to cleaning rooms, but cleaning time is not neccessarily the constraining
103 factor, and the robot still saves the human some time.
104
105 \paragraph{Roomba Open Interface}
106 However, robots of the Roomba 500 series are also easily controllable over a
107 serial port, which provides a two-way communication at 5~V TTL levels over a
108 Mini-DIN connector, with a speed of either 19,200 or 115,200 Baud. Over this
109 serial port, the Roomba speaks a specified protocol, called the
110 \ignoreoutput{\ac{ROI}}\definition{\acl{ROI}} (\acs{ROI})~\cite{irobot-oi},
111 which allows the user to interact with the robot's internal logic, reading its
112 sensor values, and control its movements and cleaning behaviour.
113
114 After starting the communication with the Roomba by sending the \cmd{Start}
115 command, the robot is in a state called \definition{Passive mode}. In this mode,
116 the user cannot control the robot by himself, but the internal logic defines
117 icants behaviour. However, the user is able to read the internal sensors. The
118 \ac{ROI} then allows the user to set the Roomba into two different modes:
119 \begin{itemize}
120 \item In \definition{Safe mode}, the Roomba monitors the wheel drop, cliff
121 and internal charger sensors, and reverts into Passive mode if safety
122 conditions occur, so the Roomba is not harmed.
123 \item In \definition{Full mode}, the user has full control over the Roomba,
124 and has to take care not to harm the Roomba by evaluating the wheel drop,
125 cliff and internal charger sensors by himself.
126 \end{itemize}
127
128 In particular, every command is assigned an \ac{opcode} of one byte length,
129 followed by a fixed amount of bytes as parameters which depend on the opcode.
130 For example, to start the communication with the Roomba, the \cmd{Start}
131 command has to be sent, which has the \opcode{0x80} and takes no parameters. The
132 \cmd{Safe} command to put the Roomba into safe mode has \opcode{0x83}, and like
133 the \cmd{Full} command with \opcode{0x84}, it takes no parameters.
134
135 For example, to start the communication with the Roomba and set it into Safe
136 mode, one would send the following bytes over the serial interface:
137 \begin{verbatim}
138 0x80, // Start command
139 0x83 // Safe command
140 \end{verbatim}
141 The, additional commands can be sent over the \ac{ROI}, like actuator commands
142 for controlling the Roomba's driving behaviour.
143
144 \paragraph{Actuator commands}
145 The \ac{ROI} specifies various actuator commands to control the Roomba's wheels,
146 brushes and \ac{LED} displays, and let the Roomba play tunes. However, the
147 central command needed for the experiments in thie thesis is the \cmd{Drive}
148 command, \opcode{0x89}, which takes 4 additional bytes as parameter: the first
149 two bytes specify the velocity that the Roomba's centerpoint should travel with
150 while driving, and the third and fourth bytes specify the radius of the arc the
151 Roomba's centerpoint should describe. The Roomba then calculates the required
152 right and left wheel velocities internally without further interference of the
153 user.
154
155 The velocity is interpreted in mm/s, the value can range from -500~mm/s to
156 500~mm/s, with negative values implying backwards movement. The radius is
157 interpreted in mm, ranging from -2000~mm to 2000~mm. Negative values make the
158 Roomba turn toward the right, whereas positive values make it turn toward the
159 left. There are also four special values for the radius: \magicnumber{1} makes
160 the Roomba turn on the spot in counter-clockwise direction, \magicnumber{-1}
161 makes the Roomba turn on the spot in clockwise direction, and
162 \magicnumber{0x7fff} and \magicnumber{0x8000} make him drive straight.
163
164 For example, to drive straight with a velocity of 1000~mm, one would send the
165 following bytes over the serial interface:
166 \begin{verbatim}
167 0x89, // Drive command
168 0x03, 0xe8 // parameter velocity: 0x03e8 == 1000
169 0x80, 0x00 // parameter radius: special value "straight"
170 \end{verbatim}
171
172 A little disadvantage of the \ac{ROI} \cmd{Drive} command is that the robot is
173 modeled as a state machine. In the previous example, the Roomba would keep on
174 driving until it runs out of energy, or a safety condition occurs which causes
175 the Roomba to revert into Passive mode, or a new \cmd{Drive} command with the
176 velocity parameter set to zero is sent. Thus, if the user wants to drive a
177 specific distance, he has to calculate the time the robot needs to travel that
178 distance, measure the time, and stop the robot after that time interval has
179 passed. When using incorrect clocks, or when using inaccurate timers, this can
180 lead to errors in movement. Because of that, it is appropriate to monitor the
181 Roomba's movement, for example with its internal sensors.
182
183 \paragraph{Input commands}
184 The Roomba~500 series features a total of 49 different sensor values. Among the
185 sensors mentioned above, there are also some internal values concerning battery
186 charge, capacity, and temperature, motor currents, and even some more (or less)
187 useful variables like the characters read from the infrared remote control, the
188 current \ac{ROI} mode or the currently playing song. Nevertheless, there is
189 also the possibility to query the travelled distance, the turned angle and the
190 internal encoder counts ("`ticks"') for the left and right wheel. Each sensor
191 value is 1 or 2 bytes long and is assigned a specific \definition{packet ID}.
192 Some packet IDs also describe groups of multiple sensor values sent together.
193
194 Sensor values can be retrieved either by explicit polling or by enabling a
195 stream of values that is sent every 15~ms. Explicit polling works through the
196 \cmd{Sensors} command (\opcode{0x8e}), which takes the packet ID of a single
197 sensor as parameter, or through the \cmd{Query List} (\opcode{0x95}) command,
198 which takes multiple packet IDs headed by the total number of requested packets
199 as parameter. Both of these functions send back the requested values directly.
200
201 By using the \cmd{Stream} command (\opcode{0x94}), it is possible to receive
202 the requested sensor values every 15~ms. This is very convenient for real-time
203 behaviour, when the sensor values have to be evaluated very often. As the
204 \cmd{Query List} command, the \cmd{Stream} command takes the total number of
205 packet IDs followed by the requested packet IDs as parameter. It sends back the
206 sensor values in packets using the following format:\\
207 \verb|0x13|, $n, p_1, v(p_1), p_2, v(p_2), \ldots, p_n, v(p_n), c$\\
208 where:
209 \begin{description}
210 \item[$n$] is the number of bytes sent back, excluding $n$ and $c$,
211 \item[$p_i$] is a requested packet ID, $i = 1, \ldots, n$
212 \item[$v(p_i)$] is the value of the packet with the packet ID $p_i$
213 \item[$c$] is a checksum, with
214 $\sum_{i=1}^n\left(p_1 + v(p_1)\right) + c + n \equiv 0 \mod 256$
215 \end{description}
216
217 Example: The following byte sequence requests data from the left cliff
218 signal (packet~ID \magicnumber{0x1d}) and virtual wall sensor (packet~ID
219 \magicnumber{0x0d}):
220 \begin{verbatim}
221 0x94, // Stream command
222 0x02, // parameter: 2 packets following
223 0x1d, 0x0d // parameter: request packets 0x1d and 0x0d
224 \end{verbatim}
225
226 The Roomba then returns the following bytes every 15~ms:
227 \begin{verbatim}
228 0x13, // Header byte
229 0x05, // 5 bytes following, except checksum
230 0x1d, // Packet ID 0x1d following
231 0x02, 0x19, // Data for Packet ID 0x1d (2 byte)
232 0x0d, // Packet ID 0x1d following
233 0x00, // Data for Packet ID 0x0d (1 byte)
234 0xb6 // checksum: 0x5 + 0x1d + 0x2 + 0x19 + 0xd + 0x0 + 0xb6 = 256
235 \end{verbatim}
236
237 In our setup, an iRobot Roomba~530 is used as an instance of an autonomous,
238 mobile robot to conduct the experiments described afterwards. For that, the
239 Roomba's movements are controlled over a netbook mounted on top of the Roomba
240 (cf.~Figure~\ref{fig:roombasetup}), which is running Wiselib code. The Wiselib
241 code in turn uses the \ac{ROI} and especially the \cmd{Stream} and
242 \cmd{Drive} command to control the Roomba.
243
244 \section{Wiselib}
245 The \definition{Wiselib}\cite{wiselib} is a C++\index{C++} algorithm library for
246 sensor
247 networks, containing for example algorithms for routing, localization and time
248 synchronization, and is strongly focused on portability and cross-platform
249 development. In particular, it allows the user to develop applications that run
250 on different hardware platforms without the need to change the code, and it
251 strongly uses C++ templates to achieve that feature. Amongst the supported
252 platforms are diverse sensor node platforms, like iSense, Contiki and TinyOS,
253 but there are as well implementations for the diverse x86-compatible Personal
254 Computer platforms, and the Shawn sensor network simulator.
255
256 \subsection{Architecture}
257 \paragraph{Concepts and Models}
258 Wiselib makes strong uses of \definition{concepts} and \definition{models} as
259 central design objects. Concepts serve as an informal description of interfaces,
260 only existent in documentation, defining expected parameters and types. Models
261 however implement these interfaces in C++ code while fulfilling their
262 specification. The Wiselib algorithms can in turn rely on the concepts as a
263 generic specification, and take models as template parameters to use their
264 functionality, so a function call will be immediately resolved to a specific
265 model at compile time without the need for an additional function call as it is
266 the case with virtual inheritance.
267
268 This makes cross-platform development easily possible. For example, to implement
269 a routing algorithm, one can rely on the concept of a Radio to send and receive
270 data packets, without needing to implement code specific to the used radio
271 hardware. The users of that routing algorithm can now choose which radio model
272 they want to use, according to their needs and the underlying hardware, provided
273 that their radio model also implements the same Radio concept that the routing
274 algorithm uses.
275
276 \begin{figure}
277 \centering
278 \includegraphics[width=.8\textwidth]{images/Wiselib-Arch.pdf}
279 \caption{Wiselib architecture\label{fig:wiselib-arch}}
280 \end{figure}
281 Besides algorithms, the Wiselib also consists of two other main parts: the
282 internal interface and the external interface (see Figure
283 \ref{fig:wiselib-arch}).
284
285 \paragraph{}
286
287 \subsection{Roomba}
288 Moreover, the Wiselib includes code to control the iRobot
289 Roomba\index{Roomba} over a
290 serial interface, and getting access to its internal sensor data, using the
291 iRobot Roomba Open Interface mentioned earlier.
292
293 \todo{cite Wisebed book chapter on Roomba code}
294 \todo{which roomba sensors were used?}
This page took 0.052235 seconds and 3 git commands to generate.