Download presentation
Presentation is loading. Please wait.
1
Getting Ready to go with LeJos and an IDE NSF Workshop November 19-21, 2004 The University of Mississippi Pam Lawhead
2
Part 0 – Installing LeJos Taken from: http://lejos.sourceforge.net/tutorial/getstarted/first brick/win32.html
3
You will need: LEGO MINDSTORMS RCX, IR Tower and the leJOS environment and The Java TM 2 Platform, Standard Edition download it from http://java.sun.com/j2se/1.4/download.html and to consult the associated installation instructions (make sure to download the SDK, not the JRE!). Step 1
4
The leJOS environment may be downloaded from: Download section of http://www.lejos.org.Download section of http://www.lejos.org Installation of the leJOS environment 1.After you have downloaded the leJOS environment zip file, unzip it directly to your C: directory. 2.Add the SDK's bin directory to your PATH environment variable. (Using Start/Control Panel/System/ [advanced]/[environment variables] 3.In XP Start/Control Panel/Performance and Maintenance/System/[advanced]/ [environment variables] 4. Set the LEJOS_HOME environment variable to the directory you installed lejos into: set LEJOS_HOME= 5.Add leJOS's bin directory to your PATH environment variable: set PATH=%PATH%;%LEJOS_HOME%\bin 6.Add the leJOS classes to your CLASSPATH environment variable: set CLASSPATH=%CLASSPATH%;.;%LEJOS_HOME%/lib/classes.jar;%LEJOS_HOME %/lib/pcrcxcomm.jar 7.Set the RCXTTY environment variable to your 'tower' device: set RCXTTY=COM1 or set RCXTTY=USB
5
leJOS-enable your RCX To enable your RCX for the execution of leJOS programs, you will have to replace the original LEGO ® with the leJOS operating system. 1.Place the IR sensor of the RCX in front of the IR Tower 2.Turn on the RCX 3.Open a command shell and change to the bin directory of your leJOS installation call firmdl.bat 4.The progress of the download is displayed in the command shell and on the display of the RCX; the RCX will double beep when the download is complete and display the battery voltage OR… RCX Firmware
6
Use the RXC Direct Interface Available from: http://lejos.sourceforge.net/utilities.htmlhttp://lejos.sourceforge.net/utilities.html 1.Download the file RCXTools1.5.zip 2.Unpack "RCXTools_1_5.zipRCXTools_1_5.zip 3.doubleclick"RCXDownload.bat" 4.Set up preferences as in Get Started slide 5.Download firmware using button GETTING STARTED
7
Setting up the IDE NSF WorkshopNovember 19-21, 2004 The University of MississippiPam Lawhead
8
Setting up the IDE http://rcxtools.sourceforge.net/e_download.html Download RCXTools_1.5.zip Double Click "RCXDownload.bat" You will now participate in the dialog that follows
9
Here put the path to your lejos bin directory Here put the path to your JDK
10
Set Up Continues Used courtesy of RCX Tools Install page
11
Let us test it Create Program “Hello World” Save it as HelloWorld.java Run RCXDownload.bat Use the “Open” button to find the file Load the file Use the Compile button to compile
12
helloWorld.java import josx.platform.rcx.*; public class HelloWorld { public static void main (String[] aArg) throws Exception { LCD.clear(); TextLCD.print ("hello"); Thread.sleep(2000); TextLCD.print ("world"); Thread.sleep(2000); }
14
Download program to RCX Place robot in front of IR Tower Be careful to cover it if you are not alone Turn Robot on Click IDE Download Button Watch numbers on LCD if they are not increasing try again
15
Run the Program When the robot beeps twice Hit the RUN button You will see HELLO WORLD
16
LeJos, Mindstorm Links http://lejos.sourceforge.net/tutorial/index.html http://lejos.sourceforge.net/ http://dudley.wellesley.edu/~anderson/robots/lejosdocs/http://dudley.wellesley.edu/~anderson/robots/lejosdocs/ The Lejos API http://www.informatik.fh_muenchen.de/~schieder/usinglejos http://dudley.wellesley.edu/~anderson/robots/lejos/ http://lvi.sourceforge.net/http://lvi.sourceforge.net/ Another way to interface with LeJos http://rcxtools.sourceforge.net/http://rcxtools.sourceforge.net/ My Favorite IDE http://graphics.stanford.edu/~kekoa/rcx/http://graphics.stanford.edu/~kekoa/rcx/ How the internals of the RCX work http://www.informatik.fh_muenchen.de/~schieder/usinglejos/ “Instant Lejos” For a quick uncomplicated approach http://mindstorms.lego.com/eng/default.asphttp://mindstorms.lego.com/eng/default.asp The Official Lego Mindstorm site http://www.devdaily.com/java/lejos/GettingStartedWithLejos/ Another Introductory Site
17
Using LeJos NSF WorkshopNovember 19-21, 2004 The University of MississippiPam Lawhead
18
Button and LeJos All buttons my be re-programmed except “RUN” Controlled by a “button class” Polling or Using a Listener (Discuss) “listener” or directly using waitForPressAndRelease()
19
Button Example ( Polling) import josx.platform.rcx.*; public class RunButton { public static void main(String[] args) throws InterruptedException {// Move forward Motor.A.forward(); Motor.B.forward(); // just run until RUN button is pressed again Button.RUN.waitForPressAndRelease(); }
20
Button Example (listener) -from Tutorial public class MyButtonListener implements ButtonListener { public void buttonPressed(Button b) { // maybe do something here } // buttonPressed() public void buttonReleased(Button b) { // maybe do something here } // buttonReleased() } // class MyButtonListener //used it looks like this Button.RUN.addButtonListener(myButtonListener);
21
Motors Three Motors A, B, C Controlled using: public static void forward() public static void backward() public static void reverseDirection() public static void flt() public static void stop()
22
Motor Examples Motor.A.forward(); Motor.B.forward(); Motor.B.flt(); //like an idle Motor.A.reverseDirection(); Motor.A.setPower(3); //possible values 1-7 (deceptive – does not cause the motor to go slow it just causes to use less energy which, perhaps, might slow it down)
23
Sensors There are three possible Sensor.S1, Sensor.S2, Sensor.S3 You must “set type and mode” to know the type of the sensor setTypeAndMode(int aType, int aMode) Parameters include: aType _ 0 = RAW, 1 = TOUCH, 2 = TEMP, 3 = LIGHT, 4 = ROT aMode _ 0x00 = RAW, 0x20 = BOOL, 0x40 = EDGE, 0x60 = PULSE, 0x80 = PERCENT, 0xA0 = DEGC, 0xC0 = DEGF, 0xE0 = ANGLE Also, mode can be OR'd with slope (0..31).
24
More Sensors Sensor.S1.activate(); //turns the sensor on Sensor.S1.passivate(); //turns the sensor off Same argument exists: Do I want listeners or do I poll? (see Barnes article for full discussion)
25
Sensor Examples Sensor.S2.readRawValue(); (must be used if aType = 0) Sensor.S2.readBooleanValue(); (used if aMode = BOOL e.g. touch sensor) Sensor.S2.readValue(); (used for light sensor percentage aMode = 3 aType – 0x80)
26
Sensor Code Example import josx.platform.rcx.*; class LCDShowLight { public static void main(String[] args) { Sensor.S1.setTypeAndMode(3,0x80); Sensor.S1.activate(); while(true) LCD.showNumber(Sensor.S1.readValue()); }
27
Sound Uses RCX speaker – useful for debugging beep //one beep beepSequence() // a series of beeps going down buzz() playTone(int aFrequency, int aDuration) aFrequency – 31-2100 Hz //human sound range aDuration – 1 – 256 Centiseconds
28
Sound Example import josx.platform.rcx.*; class AudibleSounds { public static void main(String[] args) throws InterruptedException { for(int f = 440; f < 10000; f = 110*f/100) { LCD.showNumber(f); Sound.playTone(f, 50); Thread.sleep(500); } for(int f = 440; f > 20; f = 90*f/100) { LCD.showNumber(f); Sound.playTone(f, 50); Thread.sleep(500); } } }
29
Part 4 Doing an Assignment The Light Sensor NSF WorkshopNovember 19-21, 2004 The University of MississippiPam Lawhead
30
Assignment: The Light Sensor
31
The Sensors Normally, there are three types of sensors used programming the RCX, and they are: Touch Sensor Light Sensor Rotation Sensor This assignment will focus on the Light sensor.
32
Overview The purpose of this assignment is to give the student experience in Java event programming involving light sensors. It will give students more chances to practice using the RCX-Lejos LCD screen control, the If statement, and additional loop control skills.
33
The Lego Mindstorm with Light and Touch Sensor The sensor illuminates whatever is in front of it with an LED (light emitting diode) and records the amount of light it get back with a photo-sensitive device. This photo-sensitive device returns a signal that is amplified and digitized (transformed into a number). The range of values for the signal is 0(dark) to 100(bright). The value measured will vary with the surface it examines, the distance separating it, and the ambient light (environment)
34
The Lego Mindstorm with Light Sensor The LEGO Mindstorm’s light sensor has a range of about 3 inches. In Java, the sensor can measure the percentage of light received by the photo sensitive device. The RCX, displays a lower percentage of light on black colors and a higher percentage on white colors. The robot can follow a path by reacting to light percentages.
35
Problem Statement Write a small Java program to demonstrate to how the light sensor works. There are three different colors used on the background surface, (black, green, and white). Through the program, the LCD should show the percentage of light corresponding to different colors on the background. When the light sensor is on white, there should be a range of numbers, on green another, and finally on black another. ***Battery power and ambient light will affect how the machine behaves.*** Using data gained from above experiment, write a Java program to make an RCX, equipped with one light sensor and at least two wheels, navigate on flat surfaces and follow the black line.
36
Laboratory Preparation How does this program get input data or receive data in this lab? What is the difference from the previous labs? How many variables do you plan to use? And what data types are the variables? Write a small method called LeftAndRight that makes the RCX turn left or turn right based on some value that it receives? Write the program outline for the testing light sensor assignment. Write the method headers for this assignment. Once this is done write the full code. Bring this code to the lab.
37
Laboratory Robot Needed: RCX brick, 2 motors, 2 or 4 wheels, and 1 light sensor. Lejos classes and method needed: Motor: setPower (int aPower), forward(), backward(), stop() Sensor: activate(), passvate(), int readPercentage() (for light sensor) LCD: showNumber(int value) Other equipment: Track IR Tower
38
Solution Strategy Fix the light sensor at a 90 degree angle to surface. Allow no more than 3 inches from sensors to surface. The key to functionality is using the method readPercentage() of the class Sensor, Sensor.S1.readPercentage() returns an integer value representing the percentage of light received. The shape of the trace is ellipsoid. Set one Motor to stop and allow the other Motor to move forward, causing the RCX to turn left or right. When executing, watch direction RCX is moving. If the program allows the RCX to turn left, keep the left side of the RCX inside of the black line. Otherwise, place right side on the inside.
39
Testing Stand in different places when checking the color percentages. Start Robot on Green, on White, on Black What happens if you reverse directions? Could you adjust if you had to change directions? How?
40
Submissions Answers to Pre-Lab questions Brief description of expectations before lab Discussion of how time was spent in lab How long did lab take, including Pre-Lab preparation? A list of the problems encountered writing code for lab. A list of the problems had running and using lab. Names and roles of any collaborators Email program after demonstration
41
Assignment Array Sorter NSF WorkshopNovember 19-21, 2004 The University of MississippiPam Lawhead
42
Overview The purpose of this assignment is to give the student experience using Java arrays, light sensors and arrays to sort the sensor reading stored in an array. The text used for this class (Lambert and Osborne) provides code for sorting a simple on dimensional array. This code may be used in this assignment. The only sensor required is a light sensor. You need to read Chapter 7 in your textbook very carefully to understand classes. Next, you need to answer the following questions BEFORE you come to lab.
43
Background The array data structure is provided by the Java programming language to handle those situations where many similar items need to be read, manipulated, stored, written or dealt with by the computer in some way.. The actual assignment has an extensive background section
44
Problem Statement You have been chosen as the field tester for the Our Colors Don’t Fade in the Sun Paint company. The sun shines unrelentingly here in summertime Mississippi and you have decided that it is entirely too hot for you to go out each day and take the readings from each color sample to determine if there has been any change. The goal is to keep the colors stored in the company’s primary computer from lightest to darkest. To do this you must write a program that allows a robot to travel across a field of sample paint colors, take a reading of each using the light sensor, and then store that value in an array of colors. Once the colors have been collected, you need the robot to return those values to the main computer where they will be stored and sorted for future use. Your company is a start-up company so it is not making many different colors of paint at this time. In this case, “summer paint sun test” there are only 5 colors that are being tested. As profits increase, the company will add additional colors to it’s a pallette but, for now, 5 will do.
45
Lab Preparation 1. What is the Java syntax for declaring an array? 2. What new leJos classes will you need to complete this assignment? 3. What are constructors used for? How are they defined? 4. What is the simplest way that you can sort a list of numbers? 5. What are the classes that have you already written that can be reused here? 6. Will you need two arrays to sort the numbers? How will you handle that?
46
Laboratory Robot needed: RCX brick, two motors, 4 (or 2) wheels and one light sensor LeJos classes and methods needed: Motor: setPower(int aPower), forward(), backward(), stop(),flt() Sensor: activate(), passvate(), int readPercentage()(for light sensor ) LCD: showNumber(int value), RCXComm
47
Solution Strategy (Note: You might need to write a little test program to determine the light sensor percentage for the different colors.) You need to be sure that the paint colors are distinct enough that the different colors can be recognized by the. You might need to put a black line between the colors. You need to first identify the different parts of your program - objects, attributes and methods. Decide what variables that you will need. What methods will be required to access these variables? Using the description of a class template found in your book on p. 160 define each of the four parts of your robot class template.
48
Solution Strategy (continued) Write each of the methods that you have identified in step one. How will you get your robot to return values to the PC? What class will you use? What methods in that class will be required? What are the arguments required? Hint: You might have a problem with the robot running too fast to get accurate readings of each of the colors, what are some solutions to that problem?
49
Testing 1. What is the first thing that you need to test? 2. What should the output from this program look like? 3. What is the input? 4. What would be an example of the program not working? 5. What would you do to fix the problem identified in question 4? 6. What are the expected inputs and outputs of each module? 7. What would it mean for a value to be out of bounds for each module? 8. What are two different ways that an array could be out of bounds?
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.