Presentation is loading. Please wait.

Presentation is loading. Please wait.

LEGO Mindstorms Robot and Java

Similar presentations


Presentation on theme: "LEGO Mindstorms Robot and Java"— Presentation transcript:

1 LEGO Mindstorms Robot and Java
Fall 2004

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

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

10 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

11 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

12 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

13 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

14 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.

15 LEGO Java Operating System
Motor class: 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.

16 LEGO Java Operating System
Button class: 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

17 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

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

19 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” Turn 360 degree to the left and display the message “LEFT” Play a sound for at least 10 seconds Go backward Go forward across the finish line


Download ppt "LEGO Mindstorms Robot and Java"

Similar presentations


Ads by Google