Vasilis Spiliopoulos

30
Introduction to the Lego NXT Vasilis Spiliopoulos < > (special thanks to Andreas Sandberg)

Transcript of Vasilis Spiliopoulos

Page 1: Vasilis Spiliopoulos

Introduction to the Lego NXT

Vasilis Spiliopoulos <[email protected]>(special thanks to Andreas Sandberg)

Page 2: Vasilis Spiliopoulos

What is Lego Mindstorm?

A kit containing:I A Lego NXT computerI 3 motorsI Touch sensorI Light sensorI Sound sensorI Ultrasonic range sensorI Lots of Lego bricksI . . . and plenty of fun!

Page 3: Vasilis Spiliopoulos

The NXTHardware overview

Main CPUAtmel ARM7

Sound

IO ProcessorAtmel AVR

Display Bluetooth

JTAG

JTAG

USBIO

con

nect

ors

Page 4: Vasilis Spiliopoulos

The NXTCPUs

I The main CPU (AT91SAM7S256) is an ARM7TDMI basedµcontroller from Atmel.

I 32-bit RISCI Running at 48 MHzI 256 KiB FlashI 64 KiB RAM

I IO coprocessor (Atmel ATmega 48)I Running at 8 MHzI 8-bit RISC (AVR)I 4 KiB FlashI 512 B RAMI Samples analog sensors with @ 333 HzI Controls motors

Page 5: Vasilis Spiliopoulos

The NXTCPUs

I The main CPU (AT91SAM7S256) is an ARM7TDMI basedµcontroller from Atmel.

I 32-bit RISCI Running at 48 MHzI 256 KiB FlashI 64 KiB RAM

I IO coprocessor (Atmel ATmega 48)I Running at 8 MHzI 8-bit RISC (AVR)I 4 KiB FlashI 512 B RAMI Samples analog sensors with @ 333 HzI Controls motors

Page 6: Vasilis Spiliopoulos

The NXTExternal communication

I BluetoothI Only supports the serial profile (≈ 200 kb/s).I Requires that devices have been paired.I Useful for wireless debugging or robot cooperation.I May sometimes be used to upload software to the NXT.

I USBI Normally used for software uploadI Can be used for debuggingI Firmware uploading

I I2CI Used for low-speed (9600 b/s) serial communication with

sensors.I RS485

I High-speed (≈ 1 Mb/s) serial communication.I Can be used for wired communication between robots.I Not used in default firmware.

Page 7: Vasilis Spiliopoulos

The NXTExternal communication

I BluetoothI Only supports the serial profile (≈ 200 kb/s).I Requires that devices have been paired.I Useful for wireless debugging or robot cooperation.I May sometimes be used to upload software to the NXT.

I USBI Normally used for software uploadI Can be used for debuggingI Firmware uploading

I I2CI Used for low-speed (9600 b/s) serial communication with

sensors.I RS485

I High-speed (≈ 1 Mb/s) serial communication.I Can be used for wired communication between robots.I Not used in default firmware.

Page 8: Vasilis Spiliopoulos

The NXTExternal communication

I BluetoothI Only supports the serial profile (≈ 200 kb/s).I Requires that devices have been paired.I Useful for wireless debugging or robot cooperation.I May sometimes be used to upload software to the NXT.

I USBI Normally used for software uploadI Can be used for debuggingI Firmware uploading

I I2CI Used for low-speed (9600 b/s) serial communication with

sensors.I RS485

I High-speed (≈ 1 Mb/s) serial communication.I Can be used for wired communication between robots.I Not used in default firmware.

Page 9: Vasilis Spiliopoulos

The NXTExternal communication

I BluetoothI Only supports the serial profile (≈ 200 kb/s).I Requires that devices have been paired.I Useful for wireless debugging or robot cooperation.I May sometimes be used to upload software to the NXT.

I USBI Normally used for software uploadI Can be used for debuggingI Firmware uploading

I I2CI Used for low-speed (9600 b/s) serial communication with

sensors.I RS485

I High-speed (≈ 1 Mb/s) serial communication.I Can be used for wired communication between robots.I Not used in default firmware.

Page 10: Vasilis Spiliopoulos

Motors

I Included motors linear and not step motors.I Speed is controlled using Pulse Width Modulation.I The AVR µcontroller handles PWM generation.

I Feedback is provided by a quadrature encoder attached tothe motor.

I Allows detection of rotation direction and amount.

Page 11: Vasilis Spiliopoulos

SensorsLight sensor

I Simple photo-sensor that detects the strength of theincoming light.

I Has a LED mounted to provide illumination.I Analog sensor

Page 12: Vasilis Spiliopoulos

SensorsTouch sensor

I Just a button with some Lego extras for mounting. Nothingfancy.

I Analog sensor

Page 13: Vasilis Spiliopoulos

SensorsSound sensor

I Measures sound intensity.I Can be run in either DB or DBA mode.I Analog sensor

Page 14: Vasilis Spiliopoulos

SensorsUltrasonic range sensor

I “Smart” sensor – uses I2C for communication.I Detects distance to objects using sound pulses.

Page 15: Vasilis Spiliopoulos

Developing for the NXTOverview

I NXT-GI Bundled with the NXT.I Graphical drag and drop flowchart programming.I Doesn’t work for large applications, unstable.I Requires Windows.

I RobotCI Commercial, but the department has licenses.I C-based language, but not “vanilla” C.I Has an integrated development environment with

debugging.I Requires Windows.

I Not eXactly CI Has an IDE (Bricx Command Center)I Debugger supportI Supports at least Windows and OSXI No releases in a long time – development has stagnated?

Page 16: Vasilis Spiliopoulos

Developing for the NXTOverview

I NXT-GI Bundled with the NXT.I Graphical drag and drop flowchart programming.I Doesn’t work for large applications, unstable.I Requires Windows.

I RobotCI Commercial, but the department has licenses.I C-based language, but not “vanilla” C.I Has an integrated development environment with

debugging.I Requires Windows.

I Not eXactly CI Has an IDE (Bricx Command Center)I Debugger supportI Supports at least Windows and OSXI No releases in a long time – development has stagnated?

Page 17: Vasilis Spiliopoulos

Developing for the NXTOverview

I NXT-GI Bundled with the NXT.I Graphical drag and drop flowchart programming.I Doesn’t work for large applications, unstable.I Requires Windows.

I RobotCI Commercial, but the department has licenses.I C-based language, but not “vanilla” C.I Has an integrated development environment with

debugging.I Requires Windows.

I Not eXactly CI Has an IDE (Bricx Command Center)I Debugger supportI Supports at least Windows and OSXI No releases in a long time – development has stagnated?

Page 18: Vasilis Spiliopoulos

Developing for the NXTOverview (contd.)

I nxtOSEKI GCC development environment (real C!)I Uses some Japanese embedded OS used in the

automotive industry.I C/C++ library for accessing IO devices.

I LEJOSI Mini-Java implementation.I Uses the standard Java compiler, but a limited class library.I Has a plugin for Eclipse.I Works on most operating systems (even Solaris1)I Somewhat limited debugging capabilities.

1Requires patching and a sacrifice to Cthulhu.

Page 19: Vasilis Spiliopoulos

Developing for the NXTOverview (contd.)

I nxtOSEKI GCC development environment (real C!)I Uses some Japanese embedded OS used in the

automotive industry.I C/C++ library for accessing IO devices.

I LEJOSI Mini-Java implementation.I Uses the standard Java compiler, but a limited class library.I Has a plugin for Eclipse.I Works on most operating systems (even Solaris1)I Somewhat limited debugging capabilities.

1Requires patching and a sacrifice to Cthulhu.

Page 20: Vasilis Spiliopoulos

Remote controllingOverview

I The NXT can be controlled from a computer (or anotherNXT!).

I Libraries exist for most common programming languages.I MatlabI PythonI RubyI JavaI . . .

Page 21: Vasilis Spiliopoulos

LEJOSOverview

I Requires custom firmware with a small Java VirtualMachine

I Supports standard Java threadsI Almost the same code can used both on the NXT and on a

computer controlling the NXTI Supports Bluetooth and for all communication with the NXT

Page 22: Vasilis Spiliopoulos

LEJOSBluetooth – practical matters

I Bluetooth communication requires pairing to preventunauthorized access to wireless devices

I Process is OS dependentI Requires a PIN code, the default one is ’1234’

I When communicating with the NXT you should normallyspecify the name of the target device

I Unless your NXT has a ’good’ name, rename it tosomething unique

Page 23: Vasilis Spiliopoulos

LEJOSBluetooth – practical matters

I Bluetooth communication requires pairing to preventunauthorized access to wireless devices

I Process is OS dependentI Requires a PIN code, the default one is ’1234’

I When communicating with the NXT you should normallyspecify the name of the target device

I Unless your NXT has a ’good’ name, rename it tosomething unique

Page 24: Vasilis Spiliopoulos

Compiling and linking

nx jc RobotTest . java

Compiles the RobotTest.java class and all its dependencies,similar to the javac command.

n x j l i n k −o RobotTest . nx j RobotTest

Packages the class RobotTest and all its dependencies,including the class library. Similar to the jar tool in some ways.

nx jup load −b −r RobotTest . nx j

Uploads the packages to the NXT using Bluetooth.

Page 25: Vasilis Spiliopoulos

Compiling and linking

nx jc RobotTest . java

Compiles the RobotTest.java class and all its dependencies,similar to the javac command.

n x j l i n k −o RobotTest . nx j RobotTest

Packages the class RobotTest and all its dependencies,including the class library. Similar to the jar tool in some ways.

nx jup load −b −r RobotTest . nx j

Uploads the packages to the NXT using Bluetooth.

Page 26: Vasilis Spiliopoulos

Compiling and linking

nx jc RobotTest . java

Compiles the RobotTest.java class and all its dependencies,similar to the javac command.

n x j l i n k −o RobotTest . nx j RobotTest

Packages the class RobotTest and all its dependencies,including the class library. Similar to the jar tool in some ways.

nx jup load −b −r RobotTest . nx j

Uploads the packages to the NXT using Bluetooth.

Page 27: Vasilis Spiliopoulos

ExamplesDebug console

import l e j o s . nx t .comm. RConsole ;

RConsole . openBluetooth ( 0 ) ;RConsole . p r i n t l n ( " He l lo World ! " ) ;

System . se tE r r (new Pr intSt ream (RConsole . openOutputStream ( ) ) ) ;

System . e r r . p r i n t l n ( " This i s s t d e r r . " ) ;

Page 28: Vasilis Spiliopoulos

ExamplesMotors

import l e j o s . nx t . Motor ;

Motor motor = Motor .A ;motor . setSpeed ( 3 6 0 ) ;motor . forward ( ) ;Thread . s leep (1000) ;motor . stop ( ) ;

Page 29: Vasilis Spiliopoulos

ExamplesLight sensors

import l e j o s . nx t . SensorPort ;import l e j o s . nx t . L ightSensor ;

L ightSensor sensor = new LightSensor (SensorPort . S1 ) ;

i n t value = sensor . readValue ( ) ;

Page 30: Vasilis Spiliopoulos

Get started!

I Checkout the course homepage - examples will beuploaded soon:http://www.it.uu.se/edu/course/homepage/

projektsystek/ht11

I software, tutorials etc.http://lejos.sourceforge.net/

I Checkout a kitI Get started!