update frontpage and finalize report"
[ri1617.git] / final_review / a.tex
1 %&a
2 \begin{document}
3 \maketitleru[authorstext={Author:},
4 course={Research Intership},
5 subtitle={Final review},
6 righttextheader={Supervisors:},
7 righttext={prof.~dr.~dr.h.c.~ir~M.J.~Plasmeijer\\dr.~P.W.M.~Koopman}]
8
9 \section{Activities}
10 % Activities Describe which activities you have carried our, incl. how you have
11 % documented or recorded your work.
12 The internship started with exploring the possibilities of adding embedded
13 devices that are typical to the internet of things (IoT) to the iTasks
14 framework. A lot of communication in the IoT goes via low-powered low-bandwidth
15 networks to ensure maximum battery life. Moreover the devices often have little
16 memory and little processing power for the same reasons. Therefore such devices
17 can not run an entire iTasks system.
18
19 Communication with these devices must be simple and energy and processing power
20 limited. Much of the communication goes via simple serial connections and
21 therefore the first practical problem to tackle was to add this communication
22 type to Clean and iTasks.
23
24 In the last stage I have created an application that can send on the fly
25 compiled bytecode to embedded devices to run imperative tasks called mTasks
26 using sensor, actuators and communicate data via shares.
27
28 \subsection{Serial port communication in Clean and iTasks}
29 In the first exploration stage I added duplex serial port communication to
30 iTasks in the same way as TCP is added. To make it work several changes had to
31 be done to the iTasks core to allow backgroundtasks to be added at runtime. The
32 function shown in Listing~\ref{lst:serialtask} results into a task that
33 sends the data added to the output queue through the serial port and adds data
34 received to the input queue for the user to process.
35
36 \begin{lstlisting}[caption={Serial port communication in iTasks},
37 language=Clean,label={lst:serialtask}]
38 syncSerialChannel :: String TTYSettings (Shared ([String],[String],Bool)) -> Task ()
39
40 :: ByteSize = BytesizeFive | BytesizeSix | BytesizeSeven | BytesizeEight
41 :: Parity = ParityNone | ...ParityOdd | ParityEven | ParitySpace | ParityMark
42 :: BaudRate = ... | B9600 | B19200 | ...
43 :: TTYSettings = {
44 baudrate :: BaudRate,
45 bytesize :: ByteSize,
46 parity :: Parity,
47 stop2bits :: Bool,
48 xonxoff :: Bool}
49 \end{lstlisting}
50
51 \subsection{mTasks}
52 The core of the project revolves around the embedded domain specific language
53 (EDSL) called mTask designed by Pieter Koopman. mTasks is used to use the task
54 oriented programming on microcontrollers in a type-safe environment. Originally
55 mTasks are compiled to c code that could be compiled for arduino compatible
56 devices. Such generated code will be flashed to the program memory once. In
57 short, the original mTask system is comparable to an entire iTasks sytem
58 including the engine.
59
60 For this project the imperative language constructs of the mTask DSL are used.
61 Listing~\ref{lst:mtask} shows some of these class base DSL components for
62 things like arithmetics, sequencing, conditionals, shared data sources and
63 interaction with the user LEDs. Together with some helper functions code
64 programmed in this DSL can be compiled to bytecode and sent to a device.
65
66 \begin{lstlisting}[language=Clean,label={lst:mtask},
67 caption={Parts of the mTask DSL}]
68 :: Upd = Upd
69 :: Expr = Expr
70 :: Stmt = Stmt
71 :: UserLED = LED1 | LED2 | LED3
72
73 :: Main a = {main :: a}
74
75 class arith v where
76 lit :: t -> v t Expr | ...
77 (+.) infixl 6 :: (v t p) (v t q) -> v t Expr | ...
78 class IF v where
79 IF :: (v Bool p) (v t q) (v s r) -> v () Stmt | isExpr p
80 class sds v where
81 sds :: ((v t Upd)->In t (Main (v c s))) -> (Main (v c s)) | ...
82 pub :: (v t Upd) -> v t Expr | ...
83 class seq v where
84 (:.) infixr 0 :: (v t p) (v u q) -> v u Stmt | ...
85 class assign v where
86 (=.) infixr 2 :: (v t Upd) (v t p) -> v t Expr | ...
87 class noOp v where noOp :: v t p
88 class userLed v where
89 ledOn :: UserLED -> (v () Stmt)
90 ledOff :: UserLED -> (v () Stmt)
91 \end{lstlisting}
92
93 \subsection{iTasks}
94 In iTasks several tasks have been devised to handle the communication. Moreover
95 the tasks will synchronize the shared data sources in the mTask domain with
96 real SDSs in the iTasks domain allowing for communication between mTasks and
97 iTasks tasks. To not clutter the communication channels the SDSs are not
98 synchronized on every change on the device. When a share changes on the server
99 his new value will be pushed to the device immediately. When a share is updated
100 on the client it must be explicitly published using. This approach has been
101 taken because some shares might be only used internally and therefore would
102 clutter the communication channels that could be low-bandwidth.
103
104
105 \subsection{Devices}
106 For the devices an engine has been built that can receive mTasks and SDSs and
107 execute them accordingly. To add a new device to the list the programmer just
108 has to implement a relatively small interface. All the other functionality is
109 using standard C or the interface. This interface is listed in~%
110 \ref{lst:interface} and includes reading and writing data, controlling the
111 peripherals and some auxiliary functions.
112
113 \begin{lstlisting}[language=c,caption={Device interface},label={lst:interface}]
114 uint8_t read_byte(void);
115 void write_byte(uint8_t b);
116
117 void write_dpin(uint8_t i, bool b);
118 bool read_dpin(uint8_t i);
119
120 void write_apin(uint8_t i, uint8_t a);
121 uint8_t read_apin(uint8_t i);
122
123 long millis(void);
124 bool input_available(void);
125 void delay(long ms);
126
127 void setup(void);
128 void debug(char *fmt, ...);
129 void pdie(char *s);
130 void die(char *fmt, ...);
131 \end{lstlisting}
132
133 mTasks run either at a fixed interval or are one-shot which is added to the
134 message. The entire protocol specification can be found in the code that is
135 available. When an mTask is one-shot it will only be executed once and then
136 removed. This can be useful for user related tasks such as shutting down blinds
137 or turning on lights for an indefinite time. mTasks that run at a fixed
138 interval time can be used to monitor sensors or to periodically communicate
139 with peripherals like LCD screens.
140
141 \section{Results}
142 % Results What were the results and contributions? How did you document these?
143 %
144 % Only give a very brief description of the outcome of the research. Where
145 % possible give pointers to places where more can be found about this. E.g. if
146 % you have produced or contributed to software, data sets, articles, technical
147 % reports, or other forms of documentation, then give pointers to these, but
148 % don't include all this in this final report.
149 The overall results are very promising and are to be continued in the Master's
150 thesis. The foundations have been laid out to make a seamless ecosystem that
151 allows small devices to interact with iTasks programs and the other way
152 around.
153
154 All code is available on the university's gitlab website. The serial port
155 library written for clean can be found here~%
156 \footnote{\url{https://gitlab.science.ru.nl/mlubbers/CleanSerial}}.
157 All mTask code can be found here~%
158 \footnote{\url{https://gitlab.science.ru.nl/mlubbers/mTask}}. This repository
159 is also the main documentation for the code. While some parts of the
160 architecture have been documented in the following repository, this will be the
161 main source.
162 All source code for the reports and presentations can be found here~%
163 \footnote{\url{https://git.martlubbers.net/?p=ri1617.git;a=summary}}.
164
165 There are many things to be improved upon in future research. Most likely these
166 points will be touched upon in my Master's thesis research.
167 \begin{itemize}
168 \item Support task combinators and functions.
169
170 The mTask language already supports the step combinator and it might be
171 fruitful to add for more expressively. Moreover functions would also
172 add a lot. They can be used to share code between tasks to reduce the
173 bytecode size.
174 \item Seamless integration with iTasks.
175
176 At the moment everything works but is hacked together. I would like to
177 extend this with a more robust system that allows adding devices on the
178 fly and adds functionality to monitor the mTask devices.
179 \item Dynamic mTask/SDS allocation.
180
181 Currently all client data for mTask and SDS storage is statically
182 allocated. This means that when only a few tasks are used the memory
183 needed is too high. This can be improved upon by only allocating
184 resources for tasks when they are requested and this would allow the
185 system to run on low memory devices like arduino's.
186 \item Extend on SDSs.
187
188 In the current system the shared data sources used in mTask programs
189 live in a different domain and are synchronized with an iTask
190 counterpart. Programming mTasks could be made more intuitive if you
191 could use standard SDSs from iTasks. Moreover, at the moment only
192 integer and boolean shares are allowed. This really should be extended
193 to at least strings.
194 \item Slicing tasks.
195
196 Every mTask runs in its entirety and to not run into race and
197 scheduling problems loops are not allowed in the mTasks. An improvement
198 to this could be multithreading the tasks by giving them slices of
199 computation and pausing them every slice. In this way loops could be
200 allowed without blocking the entire system. It does require more memory
201 however.
202 \item Run tasks when an interrupt fires.
203
204 Tasks can be scheduled either one-shot or at an interval. It might be
205 useful to tie mTasks to hardware interrupts to increase responsiveness
206 and possibly battery life. These interrupts do not need to be hardware
207 based. A usecase might be to run a task when some other task is
208 yielding a value (see task combinators) or to run a task when a shared
209 data source is received from the server.
210 \end{itemize}
211
212 \section{Reflection \& Evaluation}
213 %Don't just evaluate and reflect on your results, but also on what you've done
214 %to get there.
215 The results are positive, however the process was far from seamless. At several
216 points in time the hardware was causing a lot of problems that required a lot
217 of intensive debugging and redoing a lot of work in different frameworks. It
218 would have been much worse if these struggles took place in the Master's Thesis
219 project. However, I could spend enough time to fix the issues because the focus
220 of a research internship is not to answer discreet research questions. It could
221 also be supporting work or very exploratory research. The final presentation of
222 the internship also went very well in my idea. It brought new and interesting
223 ideas for the future. The presentation was held in a meeting for iTasks users
224 to notify eachother of the research that is going on in the topic.
225
226 %What went well/not so well/(not) according to plan? What was harder/easier
227 %than expected? (Either due to the subject matter, or your skills and
228 %experience.) Are there particular activities that you found hard or easy, or
229 %that you are not (or not yet) good at? If you were to start over on the
230 %internship, what would you do differently?
231 I would have done some things a little different. At one point in the
232 internship it was not clear for the supervisors what I was doing. While we had
233 weekly meetings there were no clear milestones and deliverables every week. We
234 solved this by producing a support document that introduced the architecture.
235 This document was never finished but could serve as a base of my thesis and
236 cleared things up for the supervisors. In the future I would take more care in
237 having agreements like that to force myself to work in more discreet steps and
238 plan more ahead.
239
240 Regarding the research matters itself I was unpleasantly surprised how much
241 time went in getting the basics up and running. Hardware is a pain to debug and
242 it took some iterations to get a stable system. However, this time is well
243 spent because it will most likely be part of the foundations for my thesis.
244
245 %Look ahead to your Master thesis, and to your future career: also given your
246 %experiences in the research intership, what kind of research would you (not)
247 %like to do for your Master thesis? Would you want to do your Master thesis
248 %internally at the university or at an external organisation? What are topics,
249 %skills, or activities that you want to work at during your Master thesis or
250 %your future career? Are there topics or activities that you want to avoid in
251 %the future? Or that you would to specialise in your future career?
252 For my master's thesis I am very happy that the days of debugging hardware are
253 over and that I can focus on the interesting bits. When the foundations are
254 strong enough that you can trust the abstraction layers the real fun starts. My
255 dream is to get my doctorate and continue working in the academic as a teacher
256 and researcher. This internship strengthened this dream and therefore I will
257 continue to aspire it.
258 \end{document}