Introduction to the Lego NXT Vasilis Spiliopoulos < - - PowerPoint PPT Presentation
Introduction to the Lego NXT Vasilis Spiliopoulos < - - PowerPoint PPT Presentation
Introduction to the Lego NXT Vasilis Spiliopoulos < ssssts > (special thanks to Andreas Sandberg) What is Lego Mindstorm? A kit containing: A Lego NXT computer
What is Lego Mindstorm?
A kit containing:
◮ A Lego NXT computer ◮ 3 motors ◮ Touch sensor ◮ Light sensor ◮ Sound sensor ◮ Ultrasonic range sensor ◮ Lots of Lego bricks ◮ . . . and plenty of fun!
The NXT
Hardware overview
Main CPU Atmel ARM7 Sound IO Processor Atmel AVR Display Bluetooth JTAG JTAG USB IO connectors
The NXT
CPUs
◮ The main CPU (AT91SAM7S256) is an ARM7TDMI based
µcontroller from Atmel.
◮ 32-bit RISC ◮ Running at 48 MHz ◮ 256 KiB Flash ◮ 64 KiB RAM
◮ IO coprocessor (Atmel ATmega 48)
◮ Running at 8 MHz ◮ 8-bit RISC (AVR) ◮ 4 KiB Flash ◮ 512 B RAM ◮ Samples analog sensors with @ 333 Hz ◮ Controls motors
The NXT
CPUs
◮ The main CPU (AT91SAM7S256) is an ARM7TDMI based
µcontroller from Atmel.
◮ 32-bit RISC ◮ Running at 48 MHz ◮ 256 KiB Flash ◮ 64 KiB RAM
◮ IO coprocessor (Atmel ATmega 48)
◮ Running at 8 MHz ◮ 8-bit RISC (AVR) ◮ 4 KiB Flash ◮ 512 B RAM ◮ Samples analog sensors with @ 333 Hz ◮ Controls motors
The NXT
External communication
◮ Bluetooth
◮ Only supports the serial profile (≈ 200 kb/s). ◮ Requires that devices have been paired. ◮ Useful for wireless debugging or robot cooperation. ◮ May sometimes be used to upload software to the NXT.
◮ USB
◮ Normally used for software upload ◮ Can be used for debugging ◮ Firmware uploading
◮ I2C
◮ Used for low-speed (9600 b/s) serial communication with
sensors.
◮ RS485
◮ High-speed (≈ 1 Mb/s) serial communication. ◮ Can be used for wired communication between robots. ◮ Not used in default firmware.
The NXT
External communication
◮ Bluetooth
◮ Only supports the serial profile (≈ 200 kb/s). ◮ Requires that devices have been paired. ◮ Useful for wireless debugging or robot cooperation. ◮ May sometimes be used to upload software to the NXT.
◮ USB
◮ Normally used for software upload ◮ Can be used for debugging ◮ Firmware uploading
◮ I2C
◮ Used for low-speed (9600 b/s) serial communication with
sensors.
◮ RS485
◮ High-speed (≈ 1 Mb/s) serial communication. ◮ Can be used for wired communication between robots. ◮ Not used in default firmware.
The NXT
External communication
◮ Bluetooth
◮ Only supports the serial profile (≈ 200 kb/s). ◮ Requires that devices have been paired. ◮ Useful for wireless debugging or robot cooperation. ◮ May sometimes be used to upload software to the NXT.
◮ USB
◮ Normally used for software upload ◮ Can be used for debugging ◮ Firmware uploading
◮ I2C
◮ Used for low-speed (9600 b/s) serial communication with
sensors.
◮ RS485
◮ High-speed (≈ 1 Mb/s) serial communication. ◮ Can be used for wired communication between robots. ◮ Not used in default firmware.
The NXT
External communication
◮ Bluetooth
◮ Only supports the serial profile (≈ 200 kb/s). ◮ Requires that devices have been paired. ◮ Useful for wireless debugging or robot cooperation. ◮ May sometimes be used to upload software to the NXT.
◮ USB
◮ Normally used for software upload ◮ Can be used for debugging ◮ Firmware uploading
◮ I2C
◮ Used for low-speed (9600 b/s) serial communication with
sensors.
◮ RS485
◮ High-speed (≈ 1 Mb/s) serial communication. ◮ Can be used for wired communication between robots. ◮ Not used in default firmware.
Motors
◮ Included motors linear and not step motors.
◮ Speed is controlled using Pulse Width Modulation. ◮ The AVR µcontroller handles PWM generation.
◮ Feedback is provided by a quadrature encoder attached to
the motor.
◮ Allows detection of rotation direction and amount.
Sensors
Light sensor
◮ Simple photo-sensor that detects the strength of the
incoming light.
◮ Has a LED mounted to provide illumination. ◮ Analog sensor
Sensors
Touch sensor
◮ Just a button with some Lego extras for mounting. Nothing
fancy.
◮ Analog sensor
Sensors
Sound sensor
◮ Measures sound intensity. ◮ Can be run in either DB or DBA mode. ◮ Analog sensor
Sensors
Ultrasonic range sensor
◮ “Smart” sensor – uses I2C for communication. ◮ Detects distance to objects using sound pulses.
Developing for the NXT
Overview
◮ NXT-G
◮ Bundled with the NXT. ◮ Graphical drag and drop flowchart programming. ◮ Doesn’t work for large applications, unstable. ◮ Requires Windows.
◮ RobotC
◮ Commercial, but the department has licenses. ◮ C-based language, but not “vanilla” C. ◮ Has an integrated development environment with
debugging.
◮ Requires Windows.
◮ Not eXactly C
◮ Has an IDE (Bricx Command Center) ◮ Debugger support ◮ Supports at least Windows and OSX ◮ No releases in a long time – development has stagnated?
Developing for the NXT
Overview
◮ NXT-G
◮ Bundled with the NXT. ◮ Graphical drag and drop flowchart programming. ◮ Doesn’t work for large applications, unstable. ◮ Requires Windows.
◮ RobotC
◮ Commercial, but the department has licenses. ◮ C-based language, but not “vanilla” C. ◮ Has an integrated development environment with
debugging.
◮ Requires Windows.
◮ Not eXactly C
◮ Has an IDE (Bricx Command Center) ◮ Debugger support ◮ Supports at least Windows and OSX ◮ No releases in a long time – development has stagnated?
Developing for the NXT
Overview
◮ NXT-G
◮ Bundled with the NXT. ◮ Graphical drag and drop flowchart programming. ◮ Doesn’t work for large applications, unstable. ◮ Requires Windows.
◮ RobotC
◮ Commercial, but the department has licenses. ◮ C-based language, but not “vanilla” C. ◮ Has an integrated development environment with
debugging.
◮ Requires Windows.
◮ Not eXactly C
◮ Has an IDE (Bricx Command Center) ◮ Debugger support ◮ Supports at least Windows and OSX ◮ No releases in a long time – development has stagnated?
Developing for the NXT
Overview (contd.)
◮ nxtOSEK
◮ GCC development environment (real C!) ◮ Uses some Japanese embedded OS used in the
automotive industry.
◮ C/C++ library for accessing IO devices.
◮ LEJOS
◮ Mini-Java implementation. ◮ Uses the standard Java compiler, but a limited class library. ◮ Has a plugin for Eclipse. ◮ Works on most operating systems (even Solaris1) ◮ Somewhat limited debugging capabilities. 1Requires patching and a sacrifice to Cthulhu.
Developing for the NXT
Overview (contd.)
◮ nxtOSEK
◮ GCC development environment (real C!) ◮ Uses some Japanese embedded OS used in the
automotive industry.
◮ C/C++ library for accessing IO devices.
◮ LEJOS
◮ Mini-Java implementation. ◮ Uses the standard Java compiler, but a limited class library. ◮ Has a plugin for Eclipse. ◮ Works on most operating systems (even Solaris1) ◮ Somewhat limited debugging capabilities. 1Requires patching and a sacrifice to Cthulhu.
Remote controlling
Overview
◮ The NXT can be controlled from a computer (or another
NXT!).
◮ Libraries exist for most common programming languages.
◮ Matlab ◮ Python ◮ Ruby ◮ Java ◮ . . .
LEJOS
Overview
◮ Requires custom firmware with a small Java Virtual
Machine
◮ Supports standard Java threads ◮ Almost the same code can used both on the NXT and on a
computer controlling the NXT
◮ Supports Bluetooth and for all communication with the NXT
LEJOS
Bluetooth – practical matters
◮ Bluetooth communication requires pairing to prevent
unauthorized access to wireless devices
◮ Process is OS dependent ◮ Requires a PIN code, the default one is ’1234’
◮ When communicating with the NXT you should normally
specify the name of the target device
◮ Unless your NXT has a ’good’ name, rename it to
something unique
LEJOS
Bluetooth – practical matters
◮ Bluetooth communication requires pairing to prevent
unauthorized access to wireless devices
◮ Process is OS dependent ◮ Requires a PIN code, the default one is ’1234’
◮ When communicating with the NXT you should normally
specify the name of the target device
◮ Unless your NXT has a ’good’ name, rename it to
something unique
Compiling and linking
nxjc 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 . nxj RobotTest Packages the class RobotTest and all its dependencies, including the class library. Similar to the jar tool in some ways. nxjupload −b −r RobotTest . nxj Uploads the packages to the NXT using Bluetooth.
Compiling and linking
nxjc 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 . nxj RobotTest Packages the class RobotTest and all its dependencies, including the class library. Similar to the jar tool in some ways. nxjupload −b −r RobotTest . nxj Uploads the packages to the NXT using Bluetooth.
Compiling and linking
nxjc 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 . nxj RobotTest Packages the class RobotTest and all its dependencies, including the class library. Similar to the jar tool in some ways. nxjupload −b −r RobotTest . nxj Uploads the packages to the NXT using Bluetooth.
Examples
Debug console
import l e j o s . nxt .comm. RConsole ; RConsole . openBluetooth ( 0 ) ; RConsole . p r i n t l n ( " Hello World ! " ) ; System . setErr (new PrintStream ( RConsole . openOutputStream ( ) ) ) ; System . err . p r i n t l n ( " This i s stde rr . " ) ;
Examples
Motors
import l e j o s . nxt . Motor ; Motor motor = Motor .A; motor . setSpeed (360); motor . forward ( ) ; Thread . sleep (1000); motor . stop ( ) ;
Examples
Light sensors
import l e j o s . nxt . SensorPort ; import l e j o s . nxt . LightSensor ; LightSensor sensor = new LightSensor ( SensorPort . S1 ) ; int value = sensor . readValue ( ) ;
Get started!
◮ Checkout the course homepage - examples will be
uploaded soon: ❤tt♣✿✴✴✇✇✇✳✐t✳✉✉✳s❡✴❡❞✉✴❝♦✉rs❡✴❤♦♠❡♣❛❣❡✴ ♣r♦❥❡❦ts②st❡❦✴❤t✶✶
◮ software, tutorials etc.
❤tt♣✿✴✴❧❡❥♦s✳s♦✉r❝❡❢♦r❣❡✳♥❡t✴
◮ Checkout a kit ◮ Get started!