1 / 19

LEGO Mindstorms Robot and Java

LEGO Mindstorms Robot and Java. Fall 2004. http://marsrovers.jpl.nasa.gov/mission/spacecraft_surface_rover.html. Java as a Platform. Sun Microsystem has different Java sizes (virtual machines sizes) for devices with different capabilities Java 2 Enterprise Edition (J2EE) for big machines

plaura
Download Presentation

LEGO Mindstorms Robot and Java

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. LEGO Mindstorms Robot and Java Fall 2004

  2. http://marsrovers.jpl.nasa.gov/mission/spacecraft_surface_rover.htmlhttp://marsrovers.jpl.nasa.gov/mission/spacecraft_surface_rover.html

  3. Java as a Platform • Sun Microsystem has different Java sizes (virtual machines sizes) for devices with different capabilities • Java 2 Enterprise Edition (J2EE) for big machines • Java 2 Standard Edition (J2SE) • Java 2 Micro Edition (J2ME) designed for use with memory-constrained devices • Mobile phones, pagers, PDA’s • JavaCard which is 4KB

  4. LEGO Mindstorms Robot • Robot Kit includes: • RCX (Robotics Command Explorer) • 2 Motors • 2 touch sensors • 1 light sensor • USB infrared transmitter tower • A “gazillion” lego parts to build a robot

  5. LEGO Mindstorms Robot • Robotics Command Explorer (RCX) • Small computer based on the Hitachi H8 microprocessor • Equipped with: • 16 Kb ROM • 32 Kb RAM • 3 motor ports for output • 3 sensor ports for input • 1 LCD display • 1 sound unit • 4 system timers • 6 1.5V batteries • IR port transmitter and receiver

  6. LEGO Mindstorms Robot • RCX runs on 6 AA batteries • When batteries are low, battery icon with an “X” across it will appear in the display • 3 gray ports labeled 1, 2, 3 • Sensor ports • 3 black ports labeled A, B, C • Motor ports

  7. LEGO Mindstorms Robot • 4 buttons • On-Off • Run to executed and stop a loaded program • Prgm to scroll through the loaded programs • May load up to 5 programs at one time • View allows you to view information on a sensor or motor

  8. LEGO Mindstorms Robot • Display Window • A little person standing or running • Indicates that a program is loaded or running respectively • To the right of the little person, a number indicating which of 5 programs will be active when the Run program is pressed • To the left of the little person, the Software Watch • Shows program being downloaded. It counts units of 100 bytes, so a 3 Kb program counts up to ~ 30 • Shows the voltage level of the battery

  9. Programming the RCX • Write a Java program in Eclipse using a LeJOS (LEGO Java Operating System) plug-in • Compile the program transforming it into bytecode • Download the program (bytecode) to the RCX using the IR tower • Firmware interprets the bytecode converting it into machine code • Processor executes the machine code

  10. LEGO Java Operating System • LeJOS is an open source project for UNIX-like and Win 32 systems • Fully functional implementation of Java language • Similar to Java 2 Micro Edition (J2ME) • Originally developed by Jose Solorzano, but is now maintained by Paul Andrews and Jurgen Stuber

  11. LEGO Java Operating System • Limitations of LeJOS: • No garbage collection – garbage collection reclaims memory taken up by objects that are not used in your program • No switch statements; must use nested if….else • No arithmetic on long data type • Maximum array length is 511

  12. LEGO Java Operating System • Provides a Java package to control the RCX: josx.platform.rcx.* • Provides Java classes for working with the RCX features: • Motors • Sensors • Display • Sound • Buttons • IR tower

  13. LEGO Java Operating System TextLCD class: • Uses the display to show text messages. This class uses a great deal of memory. The letters are approximations since the display was originally intended for numbers. public static final void print (String text) - prints the string text on the LCD. Only the first five letters are displayed. public static final void print (char [ ] text) - prints the first five characters of the text array on the display.

  14. LEGO Java Operating System Motorclass: • Used to control the RCX output ports which control the motors. The class contains 3 static Motor instances, A, B, and C, which correspond to the 3 output ports. public final void setPower(int power) - sets the current power level of the motor from 0 to 7. public final void backward( ) - moves the motor backwards. public final void forward( ) - moves the motor forwards. public final void stop( ) - stops the motor. public final void reverseDirection( ) - no matter which way the motor is turning, it makes it turn the other way.

  15. LEGO Java Operating System Buttonclass: • Encapsules 3 RCX buttons View, Prgm, Run. You may call a static instance of each button using VIEW, PRGM, and RUN. public void addButtonListener( ButtoneListener listener) - add a ButtonListener to this Button public final boolean isPressed( ) - returns true is the button is pressed, false otherwise public final void waitForPressAndRelease( ) throws InterrupedException - wait until the button is released

  16. Let’s Try • Create a simple program together that: • Displays a word to the LCD • Start one motor • Run until the RUN button is pressed

  17. You Try • Add to the existing program: • Start the other motor • Play a descending arpeggio before the motors start

  18. Robot Races • Each team must program their robot to complete the race course. Your robot may not go outside the borders of the race course: • Go forward • Stop • Turn 360 degrees to the right and display the message “RIGHT” • Go forward • Turn 360 degree to the left and display the message “LEFT” • Go forward • Play a sound for at least 10 seconds • Go backward • Go forward across the finish line

More Related