introduction to the lego nxt - uppsala university · lego hardware developing for the nxt remote...
TRANSCRIPT
Introduction to the Lego NXT
Andreas Sandberg <[email protected]>
Lego Hardware Developing for the NXT
What is Lego Mindstorm?
A kit containing:A Lego NXT computer3 motorsTouch sensorLight sensorSound sensorUltrasonic range sensorLots of Lego bricks. . . and plenty of fun!
2 | Introduction to the Lego NXT
Lego Hardware Developing for the NXT
The NXTHardware overview
Main CPUAtmel ARM7
Sound
IO ProcessorAtmel AVR
Display Bluetooth
JTAG
JTAG
USB
IO c
onne
ctor
s
3 | Introduction to the Lego NXT
Lego Hardware Developing for the NXT
The NXTCPUs
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
4 | Introduction to the Lego NXT
Lego Hardware Developing for the NXT
The NXTExternal 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.
5 | Introduction to the Lego NXT
Lego Hardware Developing for the NXT
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 tothe motor.
� Allows detection of rotation direction and amount.
6 | Introduction to the Lego NXT
Lego Hardware Developing for the NXT
SensorsLight sensor
Simple photo-sensor that detects the strength of theincoming light.Has a LED mounted to provide illumination.Analog sensor
7 | Introduction to the Lego NXT
Lego Hardware Developing for the NXT
SensorsTouch sensor
Just a button with some Lego extras for mounting. Nothingfancy.Analog sensor
8 | Introduction to the Lego NXT
Lego Hardware Developing for the NXT
SensorsSound sensor
Measures sound intensity.Can be run in either DB or DBA mode.Analog sensor
9 | Introduction to the Lego NXT
Lego Hardware Developing for the NXT
SensorsUltrasonic range sensor
“Smart” sensor – uses I2C for communication.Detects distance to objects using sound pulses.
10 | Introduction to the Lego NXT
Lego Hardware Developing for the NXT
Developing for the NXTOverview
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?
11 | Introduction to the Lego NXT
Lego Hardware Developing for the NXT
Developing for the NXTOverview (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.12 | Introduction to the Lego NXT
Lego Hardware Developing for the NXT
Remote controllingOverview
The NXT can be controlled from a computer (or anotherNXT!).Libraries exist for most common programming languages.
� Matlab� Python� Ruby� Java� . . .
13 | Introduction to the Lego NXT
Lego Hardware Developing for the NXT
LEJOSOverview
Requires custom firmware with a small Java VirtualMachineSupports standard Java threadsAlmost the same code can used both on the NXT and on acomputer controlling the NXTSupports Bluetooth and for all communication with the NXT
14 | Introduction to the Lego NXT
Lego Hardware Developing for the NXT
LEJOSBluetooth – practical matters
Bluetooth communication requires pairing to preventunauthorized access to wireless devices
� Process is OS dependent� Requires a PIN code, the default one is ’1234’
When communicating with the NXT you should normallyspecify the name of the target deviceUnless your NXT has a ’good’ name, rename it tosomething unique
15 | Introduction to the Lego NXT
Lego Hardware Developing for the NXT
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.
16 | Introduction to the Lego NXT
Lego Hardware Developing for the NXT
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 . " ) ;
17 | Introduction to the Lego NXT
Lego Hardware Developing for the NXT
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 ( ) ;
18 | Introduction to the Lego NXT
Lego Hardware Developing for the NXT
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 = myLightSensor . readValue ( ) ;
19 | Introduction to the Lego NXT
Lego Hardware Developing for the NXT
Hardware demonstration
The source code is available on the course homepage.
20 | Introduction to the Lego NXT
Lego Hardware Developing for the NXT
Get started!
Checkout the course homepage:http://www.it.uu.se/edu/course/homepage/
styrsystem/vt10/
Checkout a kitGet started!
21 | Introduction to the Lego NXT