fun with java™ technology on lego mindstorms · lejos architecture atmega i/o controller spi i2c...
TRANSCRIPT
![Page 1: Fun with Java™ Technology on Lego Mindstorms · LeJOS Architecture ATMega I/O Controller SPI I2C TWI USART USB Flash File System Flash I/O Garbage Collector Timers Thread Scheduler](https://reader033.vdocuments.mx/reader033/viewer/2022051909/5ffd99a3235d225ab82de397/html5/thumbnails/1.jpg)
Fun with Java™ Technology on Lego®
Mindstorms®
Roger GlasseyUniversity of California, Berkeley
Andy ShawSun Microsystems
Speaker logocentered below photo
LEGO, the LEGO logo, MINDSTORMS, the Brick and Knob configurations are trademarks of the LEGO Group.
![Page 2: Fun with Java™ Technology on Lego Mindstorms · LeJOS Architecture ATMega I/O Controller SPI I2C TWI USART USB Flash File System Flash I/O Garbage Collector Timers Thread Scheduler](https://reader033.vdocuments.mx/reader033/viewer/2022051909/5ffd99a3235d225ab82de397/html5/thumbnails/2.jpg)
2
Lego Mindstorms – A little history > Originally launched 1998
● The Lego Mindstorms Robot Invention System (RCX “Brick”)
● Simple visual programming system● Reverse engineered
> Major update 2006● Lego Mindstorms NXT● Open source hardware & firmware● Lego Mindstorms NXT V2.0 Aug 2009
![Page 3: Fun with Java™ Technology on Lego Mindstorms · LeJOS Architecture ATMega I/O Controller SPI I2C TWI USART USB Flash File System Flash I/O Garbage Collector Timers Thread Scheduler](https://reader033.vdocuments.mx/reader033/viewer/2022051909/5ffd99a3235d225ab82de397/html5/thumbnails/3.jpg)
3
Lego NXT > Atmel Arm7TDMI + Atmel ATMega 48
● 64Kb Ram● 256Kb Flash
> 3 Motor ports, PWM + Tachometers> 4 Sensor ports
● Analogue/Digital I2C● Standard: Ultrasonic, Touch, Light, Sound● Additional: Lots!
> Bluetooth, USB, RS485> LCD 100x64 display/PDM sound output
![Page 4: Fun with Java™ Technology on Lego Mindstorms · LeJOS Architecture ATMega I/O Controller SPI I2C TWI USART USB Flash File System Flash I/O Garbage Collector Timers Thread Scheduler](https://reader033.vdocuments.mx/reader033/viewer/2022051909/5ffd99a3235d225ab82de397/html5/thumbnails/4.jpg)
4
> Evolved from TinyVM/leJOS for the RCX: 10Kb JVM!> Firmware 53Kb
● Threads: pre-emptive, priority based, 2ms time slice● Interpreter: Fast table based dispatch● GC: concurrent, very low pause time● Native methods: I2C, Bluetooth, USB, Motor, LCD,
Sound, Flash, RS485 > Language
● Most 1.5+ features iterators, generics, enums, nested classes, etc.
● longs, floats, doubles, arrays, strings etc.●
●
Java on the NXT - leJOS
![Page 5: Fun with Java™ Technology on Lego Mindstorms · LeJOS Architecture ATMega I/O Controller SPI I2C TWI USART USB Flash File System Flash I/O Garbage Collector Timers Thread Scheduler](https://reader033.vdocuments.mx/reader033/viewer/2022051909/5ffd99a3235d225ab82de397/html5/thumbnails/5.jpg)
5
Java on the NXT - leJOS NXJ> Classes
● classes.jar: 300+ classes● Support for more than 36 sensor types.● Unified communications for Bluetooth/USB/RS485● Sophisticated motor control● Robotics: Subsumption, navigation, localization● Flash based file system● Data logging● Remote control - Lego command protocol● Remote console, basic debugging
![Page 6: Fun with Java™ Technology on Lego Mindstorms · LeJOS Architecture ATMega I/O Controller SPI I2C TWI USART USB Flash File System Flash I/O Garbage Collector Timers Thread Scheduler](https://reader033.vdocuments.mx/reader033/viewer/2022051909/5ffd99a3235d225ab82de397/html5/thumbnails/6.jpg)
6
Java on the NXT – Host tools/classes> Support for Windows/Linux/Mac> Tools
● Firmware upload, program upload, linker ● Browsers: files, data logging, remote console
> Plugins for NetBeans/Eclipse> Classes
● Communications: Bluetooth, USB● Remote control: Lego Control Protocol● Over 100 classes
> Mobile devices, Java ME
![Page 7: Fun with Java™ Technology on Lego Mindstorms · LeJOS Architecture ATMega I/O Controller SPI I2C TWI USART USB Flash File System Flash I/O Garbage Collector Timers Thread Scheduler](https://reader033.vdocuments.mx/reader033/viewer/2022051909/5ffd99a3235d225ab82de397/html5/thumbnails/7.jpg)
7
LeJOS Architecture
ATMegaI/O
Controller
TWI USARTSPI I2C USB
FlashFile
System
FlashI/O Garbage Collector TimersThread
Scheduler
Loader Byte Code Interpreter Native Methods
SPIPDMRS485 PDMPDM
Driver ClassesMotor/SensorsFile System Java Language Support
Enum/Exception/StringDisplay/Sound
CommsUSB/BTRS485
DataLogger
Collections/ArrayList Etc.
DataLogger NavigationBehaviorsRemote
CommandsData
LoggerUI/Notes/
Wav AudioDebug/Trace
LeJOS System Menu User Programs
![Page 8: Fun with Java™ Technology on Lego Mindstorms · LeJOS Architecture ATMega I/O Controller SPI I2C TWI USART USB Flash File System Flash I/O Garbage Collector Timers Thread Scheduler](https://reader033.vdocuments.mx/reader033/viewer/2022051909/5ffd99a3235d225ab82de397/html5/thumbnails/8.jpg)
8
Architecture> Firmware v Java
● Java whenever possible● Easier to change● More team members
> Enabled by firmware● Priority based threading● GC low pause time (< 1ms)● Allows many real time functions in Java
● Motor control PID tasks● Sensor processing● Communications
![Page 9: Fun with Java™ Technology on Lego Mindstorms · LeJOS Architecture ATMega I/O Controller SPI I2C TWI USART USB Flash File System Flash I/O Garbage Collector Timers Thread Scheduler](https://reader033.vdocuments.mx/reader033/viewer/2022051909/5ffd99a3235d225ab82de397/html5/thumbnails/9.jpg)
9
Building applications
> Standard tools to create and compile● NetBeans, Eclipse, vi, emacs!● Javac
> Linker● No class loader● Combines application classes with classes.jar● Eliminates unused code (50%-60% reduction)● Creates image that can be executed from flash
DownloadCompile LinkCreate Run
![Page 10: Fun with Java™ Technology on Lego Mindstorms · LeJOS Architecture ATMega I/O Controller SPI I2C TWI USART USB Flash File System Flash I/O Garbage Collector Timers Thread Scheduler](https://reader033.vdocuments.mx/reader033/viewer/2022051909/5ffd99a3235d225ab82de397/html5/thumbnails/10.jpg)
10
Alpha Rex> The Mindstorms “poster robot”> Rex is “helping out” by greeting
delegates at JavaOne
● Waits looking around● Pays attention when approached● Walks forwards to meet● Reads the badge● Greets the delegate
![Page 11: Fun with Java™ Technology on Lego Mindstorms · LeJOS Architecture ATMega I/O Controller SPI I2C TWI USART USB Flash File System Flash I/O Garbage Collector Timers Thread Scheduler](https://reader033.vdocuments.mx/reader033/viewer/2022051909/5ffd99a3235d225ab82de397/html5/thumbnails/11.jpg)
11
Demonstration> Let's see Rex in action...
● View a video by clicking here
![Page 12: Fun with Java™ Technology on Lego Mindstorms · LeJOS Architecture ATMega I/O Controller SPI I2C TWI USART USB Flash File System Flash I/O Garbage Collector Timers Thread Scheduler](https://reader033.vdocuments.mx/reader033/viewer/2022051909/5ffd99a3235d225ab82de397/html5/thumbnails/12.jpg)
12
Main Components> Head
● Ultrasonic sensor “eyes”: Distance> Body
● Single motor moves head/arms● Right Arm – RFID Sensor● Left Arm – Light Sensor “torch”
> Legs● Hip Motor – rocks side to side● Leg Motor – moves legs
![Page 13: Fun with Java™ Technology on Lego Mindstorms · LeJOS Architecture ATMega I/O Controller SPI I2C TWI USART USB Flash File System Flash I/O Garbage Collector Timers Thread Scheduler](https://reader033.vdocuments.mx/reader033/viewer/2022051909/5ffd99a3235d225ab82de397/html5/thumbnails/13.jpg)
13
Additional Components> On/Off button
● Touch sensor – starts/stops Rex> Sound
● Plays wav files - greeting> LCD
● Displays status> Bluetooth
● Connects to remote console● Displays detailed status● Shows LCD screen
![Page 14: Fun with Java™ Technology on Lego Mindstorms · LeJOS Architecture ATMega I/O Controller SPI I2C TWI USART USB Flash File System Flash I/O Garbage Collector Timers Thread Scheduler](https://reader033.vdocuments.mx/reader033/viewer/2022051909/5ffd99a3235d225ab82de397/html5/thumbnails/14.jpg)
14
Behavior model
UltrasonicSensor.ProvidesDistance
Input
On/Off Button
WaitDo nothing
Pay AttentionRock hips to show attention
ApproachTurn on torch, move forwards
GreetRaise RFID sensor, identify, greet
OnOffSwitch the robot on or off
Nothing
Approaching
In Range
Close By
PressedHigh priority
Low priority
> 50 cm
< 50cm
< 35cm
< 20cm
![Page 15: Fun with Java™ Technology on Lego Mindstorms · LeJOS Architecture ATMega I/O Controller SPI I2C TWI USART USB Flash File System Flash I/O Garbage Collector Timers Thread Scheduler](https://reader033.vdocuments.mx/reader033/viewer/2022051909/5ffd99a3235d225ab82de397/html5/thumbnails/15.jpg)
15
Let's look a little deeper> So what is actually happening...
● Look at the Remote Console● See a video by clicking here
● Look at the code● The code is available here
![Page 16: Fun with Java™ Technology on Lego Mindstorms · LeJOS Architecture ATMega I/O Controller SPI I2C TWI USART USB Flash File System Flash I/O Garbage Collector Timers Thread Scheduler](https://reader033.vdocuments.mx/reader033/viewer/2022051909/5ffd99a3235d225ab82de397/html5/thumbnails/16.jpg)
LejosNXJ
in Engineering EducationRoger Glassey
Professor, IE & OR
![Page 17: Fun with Java™ Technology on Lego Mindstorms · LeJOS Architecture ATMega I/O Controller SPI I2C TWI USART USB Flash File System Flash I/O Garbage Collector Timers Thread Scheduler](https://reader033.vdocuments.mx/reader033/viewer/2022051909/5ffd99a3235d225ab82de397/html5/thumbnails/17.jpg)
IEOR140: Introduction to mobile robots
• Course Objectives: Develop engineering skills– Analysis and design of moderately complex
systems• interactions between the hardware and software
design. – Effective project team membership– Report writing
![Page 18: Fun with Java™ Technology on Lego Mindstorms · LeJOS Architecture ATMega I/O Controller SPI I2C TWI USART USB Flash File System Flash I/O Garbage Collector Timers Thread Scheduler](https://reader033.vdocuments.mx/reader033/viewer/2022051909/5ffd99a3235d225ab82de397/html5/thumbnails/18.jpg)
Course structure> Teams of 2 or 3> Weekly project> Translate performance
specifications into hardware and software design.
> Project based learning plus interactive web based individual Java instruction.
> Class size: 20 – 30> 3rd or 4th year engineering
students
![Page 19: Fun with Java™ Technology on Lego Mindstorms · LeJOS Architecture ATMega I/O Controller SPI I2C TWI USART USB Flash File System Flash I/O Garbage Collector Timers Thread Scheduler](https://reader033.vdocuments.mx/reader033/viewer/2022051909/5ffd99a3235d225ab82de397/html5/thumbnails/19.jpg)
19
Projects> Start simply> Build a robot to trace a
simple shape> Hardware: robot with 2
wheels, independently controlled
> Square:● Repeat 4 times: ● travel in straight line● 90 degree turn
import lejos.nxt.*;
public class SquareBot{ private void square(int length) { for (int i = 0; i < 4; i++) { Motor.A.rotate(degPerDistance * length, true); Motor.C.rotate(degPerDistance * length); Motor.A.rotate(-90 * turnRatio, true); Motor.C.rotate(90 * turnRatio); } }
![Page 20: Fun with Java™ Technology on Lego Mindstorms · LeJOS Architecture ATMega I/O Controller SPI I2C TWI USART USB Flash File System Flash I/O Garbage Collector Timers Thread Scheduler](https://reader033.vdocuments.mx/reader033/viewer/2022051909/5ffd99a3235d225ab82de397/html5/thumbnails/20.jpg)
Demonstration
> Let's see the the robot in action● Sorry we don't have a video of this part of the
demo. But I'm sure you can work it out!
![Page 21: Fun with Java™ Technology on Lego Mindstorms · LeJOS Architecture ATMega I/O Controller SPI I2C TWI USART USB Flash File System Flash I/O Garbage Collector Timers Thread Scheduler](https://reader033.vdocuments.mx/reader033/viewer/2022051909/5ffd99a3235d225ab82de397/html5/thumbnails/21.jpg)
Grid Navigation> Prototype of materials
handling robot> Navigate a
rectangular grid● Line follower
> Detect obstacles - adaptive path planning
> Remote control and mapping via Bluetooth
> Sensors: ● 2 Light sensors● Ultrasonic sensor
![Page 22: Fun with Java™ Technology on Lego Mindstorms · LeJOS Architecture ATMega I/O Controller SPI I2C TWI USART USB Flash File System Flash I/O Garbage Collector Timers Thread Scheduler](https://reader033.vdocuments.mx/reader033/viewer/2022051909/5ffd99a3235d225ab82de397/html5/thumbnails/22.jpg)
Grid navigation tasks
• Accept destination• Go to destination
1.Detect obstacle2.Decide on direction of
turn - Dijkstra’s algorithm
3.Execute turn4.Travel to next
intersection5.Repeat 1 – 4 until at
destination
![Page 23: Fun with Java™ Technology on Lego Mindstorms · LeJOS Architecture ATMega I/O Controller SPI I2C TWI USART USB Flash File System Flash I/O Garbage Collector Timers Thread Scheduler](https://reader033.vdocuments.mx/reader033/viewer/2022051909/5ffd99a3235d225ab82de397/html5/thumbnails/23.jpg)
23
Grid NavigationClass Dependencies
Grid navigator
Communicator
Qnode
Tracker
Grid Queue
Node
![Page 24: Fun with Java™ Technology on Lego Mindstorms · LeJOS Architecture ATMega I/O Controller SPI I2C TWI USART USB Flash File System Flash I/O Garbage Collector Timers Thread Scheduler](https://reader033.vdocuments.mx/reader033/viewer/2022051909/5ffd99a3235d225ab82de397/html5/thumbnails/24.jpg)
Demonstration
> Let's see the Grid Navigator in action● You can view a video by clicking here
![Page 25: Fun with Java™ Technology on Lego Mindstorms · LeJOS Architecture ATMega I/O Controller SPI I2C TWI USART USB Flash File System Flash I/O Garbage Collector Timers Thread Scheduler](https://reader033.vdocuments.mx/reader033/viewer/2022051909/5ffd99a3235d225ab82de397/html5/thumbnails/25.jpg)
25
Follow me + Voice control> Simple co-operation
between robots.> First robot has sensors
● Obstacle detection● Audio Input
> Linked to second via Bluetooth
> Second robot follows commands from first
![Page 26: Fun with Java™ Technology on Lego Mindstorms · LeJOS Architecture ATMega I/O Controller SPI I2C TWI USART USB Flash File System Flash I/O Garbage Collector Timers Thread Scheduler](https://reader033.vdocuments.mx/reader033/viewer/2022051909/5ffd99a3235d225ab82de397/html5/thumbnails/26.jpg)
Demonstration
> Let's see the two robots in action● See a video by clicking here
![Page 27: Fun with Java™ Technology on Lego Mindstorms · LeJOS Architecture ATMega I/O Controller SPI I2C TWI USART USB Flash File System Flash I/O Garbage Collector Timers Thread Scheduler](https://reader033.vdocuments.mx/reader033/viewer/2022051909/5ffd99a3235d225ab82de397/html5/thumbnails/27.jpg)
Conclusions
> Decomposing robot performance specifications into tasks and sub-tasks can result in a clean, modular design of classes and methods.
> Many students report that this course, while requiring more work than most, is also more fun than most.
![Page 28: Fun with Java™ Technology on Lego Mindstorms · LeJOS Architecture ATMega I/O Controller SPI I2C TWI USART USB Flash File System Flash I/O Garbage Collector Timers Thread Scheduler](https://reader033.vdocuments.mx/reader033/viewer/2022051909/5ffd99a3235d225ab82de397/html5/thumbnails/28.jpg)
28
More information> http://lejos.sourceforge.net/> http://mindstorms.lego.com/
![Page 29: Fun with Java™ Technology on Lego Mindstorms · LeJOS Architecture ATMega I/O Controller SPI I2C TWI USART USB Flash File System Flash I/O Garbage Collector Timers Thread Scheduler](https://reader033.vdocuments.mx/reader033/viewer/2022051909/5ffd99a3235d225ab82de397/html5/thumbnails/29.jpg)