Line 62: | Line 62: | ||
</ul> | </ul> | ||
<div class="section-sub-text container"> | <div class="section-sub-text container"> | ||
− | <b>Tab 1: </b>List of commands and the corresponding functionality in the servercode. | + | <b>Tab. 1: </b>List of commands and the corresponding functionality in the servercode. |
</div> | </div> | ||
Line 86: | Line 86: | ||
<code>drive</code> sent to the robot to signal an open path ahead.</p> | <code>drive</code> sent to the robot to signal an open path ahead.</p> | ||
</li> | </li> | ||
+ | |||
+ | <div class="section-sub-text container"> | ||
+ | <b>Tab. 2: </b>List of commands for server interaction. | ||
+ | </div> | ||
+ | |||
<li class="row list-group-item"> | <li class="row list-group-item"> | ||
<code class="col-1 server-command">obstacle</code> | <code class="col-1 server-command">obstacle</code> | ||
Line 121: | Line 126: | ||
</ul> | </ul> | ||
</p> | </p> | ||
+ | <!-- HTML generated using hilite.me --><div style="background: #f8f8f8; overflow:auto;width:auto;border:solid gray;border-width:.1em .1em .1em .8em;padding:.2em .6em;"><table><tr><td><pre style="margin: 0; line-height: 125%"> 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</pre></td><td><pre style="margin: 0; line-height: 125%"><span style="color: #8f5902; font-style: italic">#!/usr/sbin/python3</span> | ||
+ | <span style="color: #8f5902; font-style: italic"># ColiBot Client</span> | ||
+ | <span style="color: #8f5902; font-style: italic"># -</span> | ||
+ | <span style="color: #8f5902; font-style: italic"># A minimal udp messaging client to send (test) messages to the ColiBot server.</span> | ||
+ | <span style="color: #8f5902; font-style: italic">#</span> | ||
+ | <span style="color: #204a87; font-weight: bold">import</span> <span style="color: #000000">socket</span> | ||
+ | <span style="color: #204a87; font-weight: bold">import</span> <span style="color: #000000">sys</span> | ||
+ | |||
+ | <span style="color: #8f5902; font-style: italic"># create datagram udp socket</span> | ||
+ | <span style="color: #204a87; font-weight: bold">try</span><span style="color: #000000; font-weight: bold">:</span> | ||
+ | <span style="color: #000000">sock</span> <span style="color: #ce5c00; font-weight: bold">=</span> <span style="color: #000000">socket</span><span style="color: #ce5c00; font-weight: bold">.</span><span style="color: #000000">socket</span><span style="color: #000000; font-weight: bold">(</span><span style="color: #000000">socket</span><span style="color: #ce5c00; font-weight: bold">.</span><span style="color: #000000">AF_INET</span><span style="color: #000000; font-weight: bold">,</span> <span style="color: #000000">socket</span><span style="color: #ce5c00; font-weight: bold">.</span><span style="color: #000000">SOCK_DGRAM</span><span style="color: #000000; font-weight: bold">)</span> | ||
+ | <span style="color: #204a87; font-weight: bold">except</span> <span style="color: #000000">socket</span><span style="color: #ce5c00; font-weight: bold">.</span><span style="color: #000000">error</span><span style="color: #000000; font-weight: bold">:</span> | ||
+ | <span style="color: #204a87">print</span><span style="color: #000000; font-weight: bold">(</span><span style="color: #4e9a06">'Failed to create socket'</span><span style="color: #000000; font-weight: bold">)</span> | ||
+ | <span style="color: #000000">sys</span><span style="color: #ce5c00; font-weight: bold">.</span><span style="color: #000000">exit</span><span style="color: #000000; font-weight: bold">()</span> | ||
+ | |||
+ | <span style="color: #000000">host</span> <span style="color: #ce5c00; font-weight: bold">=</span> <span style="color: #4e9a06">'192.168.0.4'</span> | ||
+ | <span style="color: #000000">port</span> <span style="color: #ce5c00; font-weight: bold">=</span> <span style="color: #0000cf; font-weight: bold">4343</span> | ||
+ | |||
+ | <span style="color: #204a87; font-weight: bold">while</span><span style="color: #000000; font-weight: bold">(</span><span style="color: #0000cf; font-weight: bold">1</span><span style="color: #000000; font-weight: bold">):</span> | ||
+ | <span style="color: #000000">msg</span> <span style="color: #ce5c00; font-weight: bold">=</span> <span style="color: #204a87">input</span><span style="color: #000000; font-weight: bold">(</span><span style="color: #4e9a06">'Enter message to send : '</span><span style="color: #000000; font-weight: bold">)</span> | ||
+ | <span style="color: #204a87; font-weight: bold">try</span><span style="color: #000000; font-weight: bold">:</span> | ||
+ | <span style="color: #8f5902; font-style: italic"># Send string</span> | ||
+ | <span style="color: #000000">sock</span><span style="color: #ce5c00; font-weight: bold">.</span><span style="color: #000000">sendto</span><span style="color: #000000; font-weight: bold">(</span><span style="color: #204a87">str</span><span style="color: #ce5c00; font-weight: bold">.</span><span style="color: #000000">encode</span><span style="color: #000000; font-weight: bold">(</span><span style="color: #000000">msg</span><span style="color: #000000; font-weight: bold">),</span> <span style="color: #000000; font-weight: bold">(</span><span style="color: #000000">host</span><span style="color: #000000; font-weight: bold">,</span> <span style="color: #000000">port</span><span style="color: #000000; font-weight: bold">))</span> | ||
+ | |||
+ | <span style="color: #8f5902; font-style: italic"># receive data from client (data, addr)</span> | ||
+ | <span style="color: #000000">d</span> <span style="color: #ce5c00; font-weight: bold">=</span> <span style="color: #000000">sock</span><span style="color: #ce5c00; font-weight: bold">.</span><span style="color: #000000">recvfrom</span><span style="color: #000000; font-weight: bold">(</span><span style="color: #0000cf; font-weight: bold">1024</span><span style="color: #000000; font-weight: bold">)</span> | ||
+ | <span style="color: #000000">reply</span> <span style="color: #ce5c00; font-weight: bold">=</span> <span style="color: #000000">d</span><span style="color: #000000; font-weight: bold">[</span><span style="color: #0000cf; font-weight: bold">0</span><span style="color: #000000; font-weight: bold">]</span> | ||
+ | <span style="color: #000000">addr</span> <span style="color: #ce5c00; font-weight: bold">=</span> <span style="color: #000000">d</span><span style="color: #000000; font-weight: bold">[</span><span style="color: #0000cf; font-weight: bold">1</span><span style="color: #000000; font-weight: bold">]</span> | ||
+ | |||
+ | <span style="color: #204a87">print</span><span style="color: #000000; font-weight: bold">(</span><span style="color: #4e9a06">'Server reply : '</span> <span style="color: #ce5c00; font-weight: bold">+</span> <span style="color: #204a87">str</span><span style="color: #000000; font-weight: bold">(</span><span style="color: #000000">reply</span><span style="color: #000000; font-weight: bold">))</span> | ||
+ | <span style="color: #204a87; font-weight: bold">if</span> <span style="color: #000000; font-weight: bold">(</span><span style="color: #000000">reply</span><span style="color: #ce5c00; font-weight: bold">.</span><span style="color: #000000">decode</span><span style="color: #000000; font-weight: bold">(</span><span style="color: #4e9a06">"utf-8"</span><span style="color: #000000; font-weight: bold">)</span> <span style="color: #ce5c00; font-weight: bold">==</span> <span style="color: #4e9a06">'turn'</span><span style="color: #000000; font-weight: bold">):</span> | ||
+ | <span style="color: #204a87">print</span><span style="color: #000000; font-weight: bold">(</span><span style="color: #4e9a06">"Got 'turn' message."</span><span style="color: #000000; font-weight: bold">)</span> | ||
+ | <span style="color: #204a87; font-weight: bold">if</span> <span style="color: #000000; font-weight: bold">(</span><span style="color: #000000">reply</span><span style="color: #ce5c00; font-weight: bold">.</span><span style="color: #000000">decode</span><span style="color: #000000; font-weight: bold">(</span><span style="color: #4e9a06">"utf-8"</span><span style="color: #000000; font-weight: bold">)</span> <span style="color: #ce5c00; font-weight: bold">==</span> <span style="color: #4e9a06">'drive'</span><span style="color: #000000; font-weight: bold">):</span> | ||
+ | <span style="color: #204a87">print</span><span style="color: #000000; font-weight: bold">(</span><span style="color: #4e9a06">"Got 'drive' message."</span><span style="color: #000000; font-weight: bold">)</span> | ||
+ | |||
+ | <span style="color: #204a87; font-weight: bold">except</span> <span style="color: #000000">socket</span><span style="color: #ce5c00; font-weight: bold">.</span><span style="color: #000000">error</span> <span style="color: #204a87; font-weight: bold">as</span> <span style="color: #000000">e</span><span style="color: #000000; font-weight: bold">:</span> | ||
+ | <span style="color: #204a87">print</span><span style="color: #000000; font-weight: bold">(</span><span style="color: #4e9a06">'Socket Error: {}'</span><span style="color: #ce5c00; font-weight: bold">.</span><span style="color: #000000">format</span><span style="color: #000000; font-weight: bold">(</span><span style="color: #000000">e</span><span style="color: #000000; font-weight: bold">))</span> | ||
+ | <span style="color: #000000">sock</span><span style="color: #ce5c00; font-weight: bold">.</span><span style="color: #000000">close</span><span style="color: #000000; font-weight: bold">()</span> | ||
+ | <span style="color: #000000">sys</span><span style="color: #ce5c00; font-weight: bold">.</span><span style="color: #000000">exit</span><span style="color: #000000; font-weight: bold">()</span> | ||
+ | |||
+ | <span style="color: #204a87; font-weight: bold">except</span> <span style="color: #cc0000; font-weight: bold">KeyboardInterrupt</span><span style="color: #000000; font-weight: bold">:</span> | ||
+ | <span style="color: #000000">sock</span><span style="color: #ce5c00; font-weight: bold">.</span><span style="color: #000000">close</span><span style="color: #000000; font-weight: bold">()</span> | ||
+ | <span style="color: #000000">sys</span><span style="color: #ce5c00; font-weight: bold">.</span><span style="color: #000000">exit</span><span style="color: #000000; font-weight: bold">()</span> | ||
+ | </pre></td></tr></table></div> | ||
+ | |||
</div> | </div> | ||
</div> | </div> |
Revision as of 00:01, 2 November 2017
CONTROL SYSTEMS
The
Server
Our server was built and programmed as centerpiece of the control architecture that encompasses the bioreactor and measurement
system of
The server code controls the interaction modules, the measurement chambers and the communication with the robot in the arena. It listens for commands that are sent by either the robot or the client software and reacts by executing the following functions.
Directly available
-Server functions activated by commands sent from client:
-
heat
Starts the heating module for 5 seconds. -
pump_1
Start all pumps for 11 seconds (the length of one measure cycle) to flush the system and fill it with fresh suspension from the reactor. -
temp
Get the current temperature reading from the themperature sensor in the Temperature Interaction Module. -
cam
Take a testpicture with the master camera and report the measurement result. -
drive
Send out adrive
command to the Robot to test range and connection. -
turn
Send out aturn
command to the Robot to calibrate the radius.
In the case of a real experiment run in the temperature setup, the robot sends one of the following messages to the server according to it's position and orientation in the arena and the sensor input perceives. The server reacts by initiating the corresponding processes as described below.
Robot - Server interaction :
-
clear
The server starts a waiting loop to cool down the potentially still hot heating chamber to prevent tainting of the current run by previous runs. After this cooldown period, fresh suspension is pumped into the measurement chamber and a baseline measurement is conducted. To prevent any unknown or outside influences, another waiting loop, identical in duration to the activation heating period during a run with activated temperature interaction, is started now. Finally, the suspension is now pumped into the measurement chamber and a measurement is taken. The baseline measurement and actual measurement data is now compared and in case the difference surpasses a given threshold, the server sends the
turn
command to the robot. Otherwisedrive
sent to the robot to signal an open path ahead. -
obstacle
The server starts with a cooldown period to prevent tainted measuring results. A baselinge measurement is made with fresh suspension. Fresh suspension is pumped into the temperature interaction module and heated to target temperature. The heated and activated suspension is pumped into the measurement chamber and a measurement is taken and compared to the baseline value. If the baseline and the actual measurement have a differnece equal or grater than the given threshold, the server sends the
turn
command to the robot. Otherwisedrive
sent to the robot to signal an open path ahead.
The
Client
To be able to test all of the control systems functionality (pump control, heating, measurements) without having
to actually run the full experiments, a small command line application was written in Python3. Intended to being
run on any computer in the same network as the
The commands are sent and answers are received over UDP, a common data transfer protocol. Although not reliable for critical communication because of missing error checking and guaranteed order of the packets arriving, for the small data packets we are sending here it is sufficient.
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 | #!/usr/sbin/python3 # ColiBot Client # - # A minimal udp messaging client to send (test) messages to the ColiBot server. # import socket import sys # create datagram udp socket try: sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) except socket.error: print('Failed to create socket') sys.exit() host = '192.168.0.4' port = 4343 while(1): msg = input('Enter message to send : ') try: # Send string sock.sendto(str.encode(msg), (host, port)) # receive data from client (data, addr) d = sock.recvfrom(1024) reply = d[0] addr = d[1] print('Server reply : ' + str(reply)) if (reply.decode("utf-8") == 'turn'): print("Got 'turn' message.") if (reply.decode("utf-8") == 'drive'): print("Got 'drive' message.") except socket.error as e: print('Socket Error: {}'.format(e)) sock.close() sys.exit() except KeyboardInterrupt: sock.close() sys.exit() |