marvin:ecp5
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
marvin:ecp5 [2009/01/27 22:28] – deva | marvin:ecp5 [2009/01/29 09:17] – deva | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | =====Stikord===== | + | <texit info> |
- | * Stadigt voksende klassediagram | + | author=Johnny Rieper, Bent Bisballe Nyeng and Kasper Sohn |
- | * Bluetooth | + | title=Marvin - The Balancing Robot. |
+ | </ | ||
- | ======End course project, lab report 5====== | + | ======Lab report 5 - Bluetooth controlled robot====== |
- | **Date:** January 19nd 2009\\ | + | **Date:** January 19nd and 20th 2009\\ |
- | **Duration of activity:** 8-16\\ | + | **Duration of activity:** 8-16 (both days)\\ |
**Participants: | **Participants: | ||
=====Project Goal===== | =====Project Goal===== | ||
- | Make robot communicate | + | Make robot remote controlled from the PC through bluetooth. |
=====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 a simple | + | * Make PC bluetooth |
- | =====Stikord===== | ||
- | * Stadigt voksende klassediagram | ||
- | ======End course project, lab report 6====== | ||
- | **Date:** January 20nd 2009\\ | ||
- | **Duration of activity:** 9.30-16\\ | ||
- | **Participants: | ||
- | =====Project Goal===== | + | =====The protocol===== |
- | Make robot remote controlled. | + | {{ : |
- | =====Plan===== | + | From wikipedia: //" |
- | * Make pc bluetooth | + | LeJOS has built an entire framework for bluetooth |
+ | (([[http:// | ||
+ | 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:// | ||
+ | |||
+ | 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/ | ||
+ | |||
+ | 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:// | ||
+ | {{youtube> | ||
+ | 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, | ||
=====The BTControl class===== | =====The BTControl class===== | ||
- | {{ : | + | {{ : |
- | Bluetooth control behavior. It reads integers from a bluetooth | + | Bluetooth control behavior. It reads integers from a bluetooth input stream, interpreting them as keycodes. |
- | 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 connectred with the arrow keys (up, | + | |
- | down, left, right) and tells Marvin to drive accordingly. | + | |
^ Key ^ KeyCode ^ Variable | ^ Key ^ KeyCode ^ Variable | ||
Line 57: | Line 64: | ||
while(true) { | while(true) { | ||
- | | + | |
- | else delay(200); | + | else delay(200); |
- | | + | |
+ | suppressLower(); | ||
switch(direction) { | switch(direction) { | ||
case directionLeft: | case directionLeft: | ||
Line 78: | Line 86: | ||
break; | break; | ||
} | } | ||
+ | unsuppressLower(); | ||
// Empty input buffer... we only want to use the latest keystroke. | // Empty input buffer... we only want to use the latest keystroke. | ||
Line 87: | Line 96: | ||
</ | </ | ||
- | And on the PC a window (JFrame) captures keyboard input and redirects their keycode values to the bluetooth stream: | + | On the PC, a window (JFrame) captures keyboard input and redirects their keycode values to the bluetooth stream: |
<code java> | <code java> | ||
NXTComm nxtComm = NXTCommFactory.createNXTComm(NXTCommFactory.BLUETOOTH); | NXTComm nxtComm = NXTCommFactory.createNXTComm(NXTCommFactory.BLUETOOTH); | ||
Line 107: | Line 116: | ||
}); | }); | ||
</ | </ | ||
+ | The full source code for both of these classes can be found in the files '' | ||
marvin/ecp5.txt · Last modified: 2009/01/29 10:58 by rieper