programming for lego mindstorms using eclipse to take you back to your childhood!

22
Programming for Lego® Mindstorms™ using Eclipse to take you back to your childhood! Benjamin Cabé Oct 28 th , 2009

Upload: benjamin-cabe

Post on 19-May-2015

5.401 views

Category:

Technology


2 download

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

Page 1: Programming for Lego Mindstorms using Eclipse to take you back to your childhood!

Programming forLego® Mindstorms™using Eclipseto take you back to your childhood!

Benjamin CabéOct 28th, 2009

Page 2: Programming for Lego Mindstorms using Eclipse to take you back to your childhood!

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

Page 3: Programming for Lego Mindstorms using Eclipse to take you back to your childhood!

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

Page 4: Programming for Lego Mindstorms using Eclipse to take you back to your childhood!

4 input ports

©2009 Sierra Wireless inc. – Made available under EPL v1.0

Page 5: Programming for Lego Mindstorms using Eclipse to take you back to your childhood!

3 output ports (motors)

©2009 Sierra Wireless inc. – Made available under EPL v1.0

Page 6: Programming for Lego Mindstorms using Eclipse to take you back to your childhood!

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

Page 7: Programming for Lego Mindstorms using Eclipse to take you back to your childhood!

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

Page 8: Programming for Lego Mindstorms using Eclipse to take you back to your childhood!

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

Page 9: Programming for Lego Mindstorms using Eclipse to take you back to your childhood!

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

Page 10: Programming for Lego Mindstorms using Eclipse to take you back to your childhood!

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

Page 11: Programming for Lego Mindstorms using Eclipse to take you back to your childhood!

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

Page 12: Programming for Lego Mindstorms using Eclipse to take you back to your childhood!

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

Page 13: Programming for Lego Mindstorms using Eclipse to take you back to your childhood!

Robot behavior

©2009 Sierra Wireless inc. – Made available under EPL v1.0

Page 14: Programming for Lego Mindstorms using Eclipse to take you back to your childhood!

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

Page 15: Programming for Lego Mindstorms using Eclipse to take you back to your childhood!

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

Page 16: Programming for Lego Mindstorms using Eclipse to take you back to your childhood!

©2009 Sierra Wireless inc. – Made available under EPL v1.0

Page 17: Programming for Lego Mindstorms using Eclipse to take you back to your childhood!

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

Page 18: Programming for Lego Mindstorms using Eclipse to take you back to your childhood!

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

Page 19: Programming for Lego Mindstorms using Eclipse to take you back to your childhood!

©2009 Sierra Wireless inc. – Made available under EPL v1.0

Page 20: Programming for Lego Mindstorms using Eclipse to take you back to your childhood!

©2009 Sierra Wireless inc. – Made available under EPL v1.0

Page 21: Programming for Lego Mindstorms using Eclipse to take you back to your childhood!

Questions?

Benjamin Cabé[email protected]

Page 22: Programming for Lego Mindstorms using Eclipse to take you back to your childhood!

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