Download - Vasilis Spiliopoulos
Introduction to the Lego NXT
Vasilis Spiliopoulos <[email protected]>(special thanks to Andreas Sandberg)
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!
The NXTHardware overview
Main CPUAtmel ARM7
Sound
IO ProcessorAtmel AVR
Display Bluetooth
JTAG
JTAG
USBIO
con
nect
ors
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
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
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.
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.
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.
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.
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.
SensorsLight sensor
I Simple photo-sensor that detects the strength of theincoming light.
I Has a LED mounted to provide illumination.I Analog sensor
SensorsTouch sensor
I Just a button with some Lego extras for mounting. Nothingfancy.
I Analog sensor
SensorsSound sensor
I Measures sound intensity.I Can be run in either DB or DBA mode.I Analog sensor
SensorsUltrasonic range sensor
I “Smart” sensor – uses I2C for communication.I Detects distance to objects using sound pulses.
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?
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?
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?
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.
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.
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 . . .
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
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
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
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.
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.
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.
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 . " ) ;
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 ( ) ;
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 ( ) ;
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!