programming for lego mindstorms using eclipse to take you back to your childhood!
DESCRIPTION
Did the little boy -or girl- in you ever wondered if Eclipse was cool enough to develop code for Lego Mindstorms? The answer is definitively yes, and this talk will show you how fun it is to use Eclipse technologies dedicated to embedded development (CDT, TM, ...) to create the brain of your future cybernetic buddy!TRANSCRIPT
Programming forLego® Mindstorms™using Eclipseto take you back to your childhood!
Benjamin CabéOct 28th, 2009
Agenda
The Mindstorms NXT brick
The LeJOS VM
Eclipse + Mindstorms = FUN!• Implementing an RSE connector• Data visualization inside an Eclipse editor• State machines modeling and code generation
©2009 Sierra Wireless inc. – Made available under EPL v1.0
The NXT brick
32-bit ARM7 processor @48MHz
256kB of Flash
64kB of RAM
100x64 pixel LCD display
USB 2.0
Bluetooth
Open Source firmware!©2009 Sierra Wireless inc. – Made available under EPL v1.0
4 input ports
©2009 Sierra Wireless inc. – Made available under EPL v1.0
3 output ports (motors)
©2009 Sierra Wireless inc. – Made available under EPL v1.0
LeJOS NXJ VM
A tiny (10kb) but still cool Java VM• Threads / Synchronization• Exceptions• Most of the java.lang, java.util and java.io
classes• Generics, enums, « for each » loops• A “robotics”, event-based, API• Open Source!
Limitations• No Garbage Collector• No switch()
©2009 Sierra Wireless inc. – Made available under EPL v1.0
LeJOS NXJ Eclipse plug-in
Useful to upload firmware and/or programs to the brick
Not much integrated in the IDE…
… how about leveraging DSDP/TM?!
©2009 Sierra Wireless inc. – Made available under EPL v1.0
TM/RSE hacking
LeJOS NXJ comes with APIs to :• List/get/send files• Execute programs• Get sensor states
… it should be possible to define an RSE connector and a file subsystem…!
©2009 Sierra Wireless inc. – Made available under EPL v1.0
Brief RSE introduction
A framework at Eclipse to connect to remote systems and provide:• remote file systems through SSH, FTP, a dedicated
agent, or whatever• remote shell access• remote process monitoring• remote debugging (gdb)
It comes with generic, reusable, UI
©2009 Sierra Wireless inc. – Made available under EPL v1.0
TM/RSE hacking (2)
In a couple of hours:• A new 'LeJOS' system is available• An RSE file 'subsystem' allows to:
–Browse the brick's filesystem–Remotely execute programs
• Another subystem could bewritten to retrieve sensors values
Nota: Communication with the brick can be done using either BT or USB
©2009 Sierra Wireless inc. – Made available under EPL v1.0
TM/RSE hacking (3)
Very straightforward 1..1 mapping between RSE and LEJOS APIs
Example: LejosRemoteFile implementation
public void launch() throws IOException {
LejosConnectorService connector = (LejosConnectorService) getParentRemoteFileSubSystem()
.getConnectorService();
connector.getComm().startProgram(_hostFile.getName());
}
RSE
LEJOS©2009 Sierra Wireless inc. – Made available under EPL v1.0
Let’s toy a cool sonar!
Follows a closed track
Scans the interior of the track with the ultrasonic sensor
Writes a binary output file into flash memory• The file will be retrieved using the RSE connector
©2009 Sierra Wireless inc. – Made available under EPL v1.0
Robot behavior
©2009 Sierra Wireless inc. – Made available under EPL v1.0
Robot Java program
public static void main(String[] args) {
tachoNav = new TachoNavigator(5.6f, 11.5f, Motor.A, Motor.B);
File fRadar = new File("result.radar");
FileOutputStream fosRadar = new FileOutputStream(fRadar);
tachoNav.goTo(0, TERRAIN_WIDTH, true);
while (tachoNav.isMoving()) {
int dist = ultrasonic.getDistance();
fosRadar.writeInt(dist);
}
}
©2009 Sierra Wireless inc. – Made available under EPL v1.0
Display captured data
In an Eclipse editor associated to .radar files• Parse binary files• Process signal • sin(α)… cos(α)… Remember?!
Since the ambient noise level is also recorded, we can display it in a similar manner http://www.sxc.hu/photo/1099687
©2009 Sierra Wireless inc. – Made available under EPL v1.0
©2009 Sierra Wireless inc. – Made available under EPL v1.0
17
State machines modeling
LeJOS comes with an event-based robotics API, remember?
Eclipse has a bunch of cool modeling/diagramming/code generation technologies
… how about mixing both?!
©2009 Sierra Wireless inc. – Made available under EPL v1.0
18
LeJOS Visual Development Toolkit
A state machine framework on top of LeJOS
A GMF editor
Xpand templates for code generation
An integration with the LeJOS Eclipse plugin• Auto-deployment of the binary• Communication between the brick and the IDE to
monitor the state machine
©2009 Sierra Wireless inc. – Made available under EPL v1.0
©2009 Sierra Wireless inc. – Made available under EPL v1.0
©2009 Sierra Wireless inc. – Made available under EPL v1.0
If you wanna play by yourself!
http://www.mindstorms.com
http://lejos.sourceforge.net
http://www.juanantonio.info/p_articles/archive/2008/leJOSStatemachineDevelopmentToolkit.pdf
http://www.eclipse.org/dsdp/tm/
©2009 Sierra Wireless inc. – Made available under EPL v1.0