User Tools

Site Tools


marvin:ecp5

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
marvin:ecp5 [2009/01/28 16:25] devamarvin:ecp5 [2009/01/29 10:58] (current) rieper
Line 5: Line 5:
  
 ======Lab report 5 - Bluetooth controlled robot====== ======Lab report 5 - Bluetooth controlled robot======
-**Date:** January 19nd and 20th 2009\\ +**Date:** January 19nd 2009\\ 
-**Duration of activity:** 8-16 (both days)\\+**Duration of activity:** 8-16\\
 **Participants:** Kasper, Bent and Johnny\\ **Participants:** Kasper, Bent and Johnny\\
  
Line 14: Line 14:
 =====Plan===== =====Plan=====
   * Make a bluetooth client code Behaviour on the Marvin, that can receive numbers and act on them.   * Make a bluetooth client code Behaviour on the Marvin, that can receive numbers and act on them.
-  * Make pc bluetooth app read from keyboard arrows to determine control direction.+  * Make PC bluetooth application read from keyboard arrows to determine control direction.
  
-=====The protocol===== +=====Theory==== 
-From wikipedia//"Bluetooth is a wireless protocol for exchanging data over short distances"//(([[http://en.wikipedia.org/wiki/Bluetooth]])). The NXT hosts a bluetooth communication device, and is capable of communicating at up to approximately 10 metres distance.\\ +====The Protocol==== 
-Lejos has built an entire framework for bluetooth communication, over normal Java input/output streams. +{{ :marvin:bluetoothlogo.png |The Bluetooth Logo}}
-(([[http://lejos.sourceforge.net/nxt/nxj/api/lejos/nxt/comm/BTConnection.html]]))\\ +
-We do not want to go further into the details of the protocol itself, but the way the device is shared can eventually end up in data loss(([[http://lejos.sourceforge.net/nxt/nxj/api/lejos/nxt/comm/BTConnection.html]])). We however do not care about this, since we intend to use it to send loads of control keycodes to the robot without worrying whether they will all arrive safely at the destination. +
  
-=====The 'Server'=====+From wikipedia: //"Bluetooth is a wireless protocol for exchanging data over short distances"//(([[http://en.wikipedia.org/wiki/Bluetooth|Bluetooth on Wikipedia]])). The NXT hosts a bluetooth communication device, and is capable of communicating at up to approximately 10 metres distance.\\ 
 +LeJOS has built an entire framework for bluetooth communication, over normal Java input/output streams. 
 +(([[http://lejos.sourceforge.net/nxt/nxj/api/lejos/nxt/comm/BTConnection.html|The LeJOS Bluetooth class]]))\\ 
 +We do not want to go further into the details of the protocol itself, but the way the device is shared can eventually end up in data loss(([[http://lejos.sourceforge.net/nxt/nxj/api/lejos/nxt/comm/BTConnection.html|The LeJOS Bluetooth class]])). We however do not care about this, since we intend to use it to send loads of control keycodes to the robot without worrying whether they will all arrive safely at the destination. 
  
-=====The Client=====+On the PC LeJOS has also made a bluetooth interface. This works exactly the same as the one on the NXT, and we therefore simply had to make a connection (listening on the NXT and connecting on the PC) and then creating input/output streams, to make the communication work as intended. 
  
-FIXME: Insert the right video and thumbnail (marvin being remote controlled)\\+LeJOS has put a lot of effort into making the bluetooth communication easy to use, and the implementation were therefore quite straight forward. Observe the resulting code below. 
 + 
 +We experienced a lot of slowdown in the balancing thread whenever the bluetooth communication was running, and we had to disable it entirely at numerous occasions to avoid the robot falling over.\\ 
 +We later discovered that the problem could be worked around by disabling some of the other behaviour threads to release more resources, and make Marvin rebalance itself while driving around remote controlled
 + 
 +Here is a movie of the resulting remote controlled robot, with all other behaviours disabled:\\
 [[http://www.youtube.com/watch?v=CBRJdHbWyV4|{{:marvin:remote.jpg?255x210}}]] [[http://www.youtube.com/watch?v=CBRJdHbWyV4|{{:marvin:remote.jpg?255x210}}]]
 {{youtube>CBRJdHbWyV4?small}} {{youtube>CBRJdHbWyV4?small}}
  
-=====The BTControl class=====+As it can be seen from the video, Marvin is not exactly reacting real-time to the control changes. This is due to the way the BTControl has been implemented, but also because the tilt reference must be incremented gradually, but still has to reach a certain level before an actual forward or backward motion can be seen. Making this incrementation more rapid (and thereby making the reaction faster) will cause Marvin to nosedive. 
 + 
 +=====Implementation===== 
 +====The BTControl Class====
 {{ :marvin:bluetooth.png?450 }} {{ :marvin:bluetooth.png?450 }}
-Bluetooth control behavior. It reads integers from a bluetooth input stream, interpreting them as keycodes. +Bluetooth control behaviour. It reads integers from a bluetooth input stream, interpreting them as keycodes. 
-It reacts only on the keycodes connectred with the arrow keys (up, down, left, right) and tells Marvin to drive accordingly.+It reacts only on the keycodes connected with the arrow keys (up, down, left, right) and tells Marvin to drive accordingly.
  
 ^ Key   ^ KeyCode ^ Variable          ^ ^ Key   ^ KeyCode ^ Variable          ^
Line 63: Line 72:
         case directionLeft:         case directionLeft:
           left(200);           left(200);
 +
 +
           break;           break;
  
Line 87: Line 98:
 </code> </code>
  
-And on the PC a window (JFrame) captures keyboard input and redirects their keycode values to the bluetooth stream:+====The PCController Class==== 
 +On the PC, we use a window (JFrame) to capture keyboard input and redirect their keycode values to the bluetooth stream.
 <code java> <code java>
 NXTComm nxtComm = NXTCommFactory.createNXTComm(NXTCommFactory.BLUETOOTH); NXTComm nxtComm = NXTCommFactory.createNXTComm(NXTCommFactory.BLUETOOTH);
marvin/ecp5.1233156357.txt.gz · Last modified: 2009/01/28 16:25 by deva