added tools section
[des2015.git] / marsrover / document / robot.tex
1 \section{Robot architecture}
2 \subsection{Tools}
3 \paragraph{\emph{LeJOS}~\cite{lejos_team_lejos_2015}} is an alternative
4 operating system for the \textsc{lego}$^{\small\textcopyright}$ \textsc{EV3}
5 bricks. By default the bricks come preinstalled with their own operating system
6 in which you can write programs. The programs have to be written in a
7 \textsc{C} dialect or in a graphical programming tool. \emph{LeJOS} on the
8 other hand is a constantly developed toolkit to write the programs in Java.
9 Because of this we can reuse Java standard libraries and program in a familiar
10 language that allows enough detail for the task.
11
12 \paragraph{\emph{XText}, \emph{XTend} and \emph{Antlr}} are a collection of
13 tools working together to provide the functionality for writing, parsing,
14 generating and validating the DSL. \emph{XText} is the format used to write the
15 concrete syntax in. The \emph{XText} syntax is converted to a so called
16 \emph{ecore} model which can be read by \emph{XTend} programs. \emph{XTend}
17 program can do code generation and validation. All the parsing is done by the
18 parser generator library \emph{Antlr}.
19
20 \paragraph{\emph{eclipse}} is the integrated development environment that ties
21 all the tools together. The DSL is developed in \emph{eclipse} and when the
22 language infrastructure is generated you can open a new instance of
23 \emph{eclipse} to write the actual DSL code in. In this way the user of the
24 child-instance of \emph{eclipse} has no view on the underlying mechanisms
25 generating the code and processing the data.
26
27 \subsection{Design patterns}
28 \subsubsection{Producer-Consumer}
29 Ultimately we want to only program one robot. The fact that the one robot
30 contains multiple control bricks is something that needs to be abstracted away
31 from following a low level paradigm called \emph{producer-consumer}. As will be
32 discussed in Section~\ref{sec:mapping} the first brick, from now on
33 \emph{Consumer}, has the direct control over all the motors. However the second
34 brick, from now on \emph{Producer}, controls no motors. Both the
35 \emph{Consumer} and the \emph{Producer} control $4$ sensors. Because of this
36 configuration the \emph{Producer} only needs to send its sensor data to the
37 \emph{Consumer}. There is no need to communicate anything back since the
38 \emph{Producer} can not respond in any physical way. An option could be to
39 distribute the processing power but due to the strength of the bricks and the
40 limitation of the Bluetooth this is very hard or even impossible to achieve.
41
42 The \emph{producer-consumer} paradigm always requires to certain parameters to
43 be set. It could very well be the case that the \emph{Producer} produces more
44 then the \emph{Consumer} can process. There are several strategies one could
45 use. For example we could send the sensor data from the \emph{Producer} all
46 the time, even when there are no updates. Since all communication happens via
47 Bluetooth it could be the case that the bandwidth is not high enough and
48 reading are queued and therefore reach the \emph{Consumer} too late. Another
49 approach would be to only send the differences in sensor values. In this way we
50 limit the needed bandwidth and still the \emph{Producer} can send its data
51 immediately without having to queue a lot. To keep the \emph{Producer} as dumb
52 as possible we do all the interpretation of the sensor values on the
53 \emph{Consumer}.
54
55 All of this combined leads to the visualization of the low level architecture
56 as seen in \autoref{fig:arch}
57
58 \begin{figure}[H]
59 \centering
60 $\xymatrix@C=.5pc@R=1pc{
61 *+[F]{\text{front-ultra}}\ar[ddr]
62 & *+[F]{\text{color}}\ar[dd]
63 & *+[F]{\text{left-touch}}\ar[ddl]
64 & *+[F]{\text{right-touch}}\ar[ddll]
65 & *+[F]{\text{left-light}}\ar[ddrr]
66 & *+[F]{\text{right-light}}\ar[ddr]
67 & *+[F]{\text{back-ultra}}\ar[dd]
68 & *+[F]{\text{gyro}}\ar[ddl]\\\\
69 & *+[F]{\text{producer}}\ar[rrrrr]^{\text{Bluetooth}}
70 & & & & & *+[F]{\text{consumer}}\ar[ddl]\ar[dd]\ar[ddr]\\\\
71 & & & & & *+[F]{\text{left-motor}}
72 & *+[F]{\text{right-motor}}
73 & *+[F]{\text{meas-motor}}
74 }$
75 \caption{Low level robot architecture visualizing data flow}\label{fig:arch}
76 \end{figure}
77
78 \subsubsection{Subsumption}
79 As the higher level architecture we use a slightly adapted version of the
80 subsumption architecture first described by Brooks~\cite{brooks_robust_1986}.
81
82 In the subsumption behaviour there is an arbitrator and several behaviours. A
83 behaviour is a class that contains three functionalities.
84 \begin{itemize}
85 \item \texttt{takeControl} is the function that is called every cycle
86 to determine which behaviour wants to be in control. The
87 execution of the function should always be very fast to make
88 sure behaviours can get control as soon as possible if they
89 need to.
90 \item \texttt{action} is the function that runs after the behaviour is
91 set to be active. The action function must be suppressible at
92 all times within a very short time period. In this way a
93 behaviour can be interrupted by a more important behaviour. When an
94 action stops it should always stop the robot in a \emph{safe} position.
95 \item \texttt{suppress} is the function that is called when a behaviour
96 becomes active while some other behaviour was active before.
97 When it is called the \texttt{action} function of the old
98 behaviour should terminate as soon as possible.
99 \end{itemize}
100
101 The basic architecture is visualized in \autoref{fig:sub} where the behaviour
102 with the lowest number has the highest priority and thus gets control over the
103 actuators when asked for.
104
105 \begin{figure}[H]
106 \centering
107 $\xymatrix{
108 & *+[F]{b_n}\ar[r] & \ar[d]\\
109 & *+[F]{b_{\ldots}}\ar[rr] & & \ar[d]\\
110 & *+[F]{b_2}\ar[rrr] & & & \ar[d]\\
111 *+[F]{\text{Sensors}}\ar[uuur]\ar[uur]\ar[ur]\ar[r]
112 & *+[F]{b_1}\ar[rrrr] & & & & *+[F]{\text{actuators}}
113 }$
114 \caption{Subsumption architecture}\label{fig:sub}
115 \end{figure}
116
117
118 We use the pre-implemented architecture from the \emph{LeJOS} where with the
119 use of a \texttt{suppressed} flag in every behaviour. The \texttt{suppressed}
120 variable is a flag that is set when \texttt{suppress} is called and the
121 \texttt{action} function will monitor said variable to be able to stop when it
122 is suppressed. To be able to let the robot finish some critical actions (eg.\
123 turning a specific number of degrees) we need some changes to the standard
124 architecture. More concretely we change the standard \texttt{suppressed}
125 boolean to a three state variable.
126
127 When such a task is started and said behaviour does not ask for control the
128 behaviour can still finish if it is not interrupted. For example when the left
129 light sensor detects that the robot is driving of the planet a right turn of
130 $90$ degrees may be initiated. This right turn will be completed even when the
131 left light sensor is not detecting a dangerous value. The suppressed flag can
132 take three states. \texttt{IDLE}, \texttt{IN\_ACTION} and \texttt{SUPPRESSED}.
133 By default all behaviours have the \texttt{IDLE} state. When a behaviour is
134 started the state will change to \texttt{IN\_ACTION} and when a behaviour
135 finished the state will be reset to \texttt{IDLE}. When a behaviour needs to be
136 interrupted the state is set to \texttt{SUPPRESSED} and since the behaviour is
137 always monitoring the state it will shutdown as soon as possible and reset the
138 state.
139
140 Since the task of the robot is to perform certain missions in sequence we also
141 added a special kind of behaviour to the standard architecture. This behaviour,
142 from now on \emph{Shutdownbehaviour}, is a behaviour has a special
143 \texttt{takeControl} function. This function returns true when the end
144 condition of the mission occurs and the action will stop the arbitrator. The
145 main control loop of the program will then setup a new arbitrator to perform a
146 new mission.
147
148 \subsection{Mapping of the sensors and actuators}\label{sec:mapping}
149 For the first proposal we were required to opt for a mapping for the sensors.
150 After some discussion the initial proposed mapping also became the final
151 mapping of actuators and sensors because of the reasons explained below.
152
153 The actuators are all plugged into the \emph{Consumer} to achieve the maximum
154 safety in case the \emph{Bluetooth} connection fails between the
155 \emph{Consumer} and the \emph{Producer} and one of the actuators is moving.
156 All the safety-critical sensors for movement are placed on the \emph{Consumer}
157 brick too. All other sensors are placed on the \emph{Producer} brick. Any
158 increased latency on those sensors will not danger the safety. The final
159 mapping is described in \autoref{tab:mapping}.
160
161 \begin{table}[H]
162 \centering
163 \begin{tabular}{lll}
164 \toprule
165 & \emph{Consumer} & \emph{Producer}\\
166 \midrule
167 \multirow{2}{*}{Actuators} & Left motor\\
168 & Right motor & \\
169 & Measurement motor\\
170 \midrule
171 \multirow{4}{*}{Sensors} & Left light sensor & Color sensor\\
172 & Right light sensor & Front ultrasone sensor\\
173 & Back ultrasone sensor & Left touch sensor\\
174 & Gyro sensor & Right touch sensor\\
175 \bottomrule
176 \end{tabular}
177 \caption{Mapping of the sensors and actuators}\label{tab:mapping}
178 \end{table}
179
180 \subsection{Domain Specific Language}
181
182
183 \subsection{Code Structure}