Using LeJOS LMICSE Workshop August 11 - 14, 2006 Villanova University.

Slides:



Advertisements
Similar presentations
1chung 5 th Annual Robofest 2004 Informational Meeting Mar. 20, 2004 Chan Jin Chung Ali Khazaal Jason Lo Computer Science Lawrence Technological University.
Advertisements

Robofest 2005 Introduction to Programming RIS 2.0 RCX Code.
Jason Howard. Agenda I. How to download robotc II. What is tele-op used for? III. How to build a basic tele-op program IV. Getting the robot to drive.
EducateNXT Enter the name “Sound Graphing” for your experiment. Real-time Data Logging Click the Switch to NXT Data Logging icon in the top-left corner.
Robotics Invention System 2.0
Getting Ready to go with LeJos and an IDE NSF Workshop November 19-21, 2004 The University of Mississippi Pam Lawhead.
Building robots Spring Mindstorms Programming Java + leJOS, NQC, and others.
The Turtle Laboratory Sequence Myles McNally LMICSE Workshop November , 2004 University of Mississippi.
Introduction to Lego Mindstorms LMICSE Workshop June , 2005 Alma College.
The Turtle Laboratory Sequence LMICSE Workshop August , 2006 Villanova University.
Not Quite C: A CS 0 Option LMICSE Workshop June , 2005 Alma College.
The Turtle Laboratory Sequence LMICSE Workshop June , 2005 Alma College.
An Intro to Robots and Computer Programming
©2006 CSUC Institute for Research in Intelligent Systems Introduction to Coding June 15, 2006.
Using LeJOS LMICSE Workshop June , 2005 Alma College.
Programming with Lejos Part 1. What is lejos? Cut-down version of Java for the RCX platform Includes: –Lejos API –JVM API includes functionality needed.
Conceptual Model by Aaron Garrett and David Thornton Mindstorms Internet Control Environment.
LEGO Mindstorms Robotic Invention System Barb Ericson Georgia Institute of Technology.
1 ©2006 INSciTE Lab Two Task: Make the program from Lab One (Move forward 5 rotations and turn right 90 degrees) into a MyBlock.
The NXT is the brain of a MINDSTORMS® robot. It’s an intelligent, computer-controlled LEGO® brick that lets a MINDSTORMS robot come alive and perform.
Reviewing Common Blocks for St. Agnes Elementary School Teachers by Jenny Chang Feb. 26th, 2007 USC & University Neighborhood Outreach Robotics STEM program.
LEGO Mindstorms NXT Programming We will be using the Common Palette for our Robots This is how you download your program onto the brick Drag and drop a.
What is RobotC?!?! Team 2425 Hydra. Overview What is RobotC What is RobotC used for What you need to program a robot How a robot program works Framework.
LEGO NXT Robot Programming Introduction to Programming a Lego NXT robot in Java.
Interfacing the LEGO RCX to the outside world John M. Larkin Whitworth College Spokane, WA.
GIRLS Robotic Camp. Let’s Begin Meet and Greet – Camp leaders introduce themselves – Students introduce themselves.
Programming 101 The Common Palette Content provided by Connor Statham (6 th Grade Student) Formatting by Shannon Sieber.
LeJos Kyle Adams Rob Boorman. Overview of leJos leJos stands for LEGO Java Operating System. leJos was originally developed by Jose Solorzano, and is.
T HE F INCH R OBOT AND THE W HILE L OOP Pepper. T HE R OBOT Developed by Carnegie Mellon students to teach CS Supports many compilers, including Java.
Thank you for your decision to try vTreePro Practice Tree Software! Your satisfaction is very important to us. Please feel free to send us an if.
Sound, Touch Sensor, and Motors. Wheeled Vehicles Using the Pilot class: –Constructor Pilot(float wheelDiameter, float trackWidth,Motor leftMotor, Motor.
9/2/ CS171 -Math & Computer Science Department at Emory University.
EIE375 BlueJ: Getting Started Dr Lawrence Cheung.
Event Driven Programming Minus the GUI Plus a Robot By Charlie Vick.
The George Washington University Department of ECE ECE Intro: Electrical & Computer Engineering Dr. S. Ahmadi Class 4.
CSE 1341 Honors Professor Mark Fontenot Southern Methodist University Note Set 11.
Lego MindStorm An Introduction to Blocks. Blocks Blocks are used to give instructions to your robot. There are many types of blocks You can use the blocks.
Castor Bot. Now, we will begin creating a robot Log onto your computer On your screen, click on the website labeled “castor bot” Your building instructions.
Building robots Spring Building Braitenberg Vehicles From Abstraction to Realization.
Minds and Computers 2.1 The RCX l Hitachi H8/3297 series processor l 3 inputs/sensors (1, 2, 3) l 3 outputs/motors (A, B, C) l 32k RAM/ 16k ROM ä 12 kB.
Computer Science I Programming in Java (programming using Processing IN Java, using IntelliJ IDE) Classwork/Homework: copy your Processing projects over.
Vex Robotics Program four: reversing and turning.
Mindstorms 1.1 Today’s topics l AI l History of Robotics l Uses of robots l The RCX l ROBOLAB l Upcoming ä Basic control ä Kinematics ä Robot architectures.
The George Washington University Department of ECE ECE Intro: Electrical & Computer Engineering Dr. S. Ahmadi Class 4/Lab3.
The George Washington University Electrical & Computer Engineering Department ECE 002 Dr. S. Ahmadi Class3/Lab 2.
By Droids Robotics INTERMEDIATE PROGRAMMING LESSON BRICK BUTTONS AS SENSORS.
Decisions, Looping, and input sensors Mindstorms, Eclipse and Java.
Programming 101 The Common Palette Content provided by Connor Statham (9 th Grade Student) Formatting by Shannon Sieber.
BEGINNER FLL PROGRAMMING WORKSHOP BY DROIDS ROBOTICS & EV3LESSONS.
Using the BlueJ IDE with Mindstorms LMICSE Workshop June , 2005 Alma College.
Automation and Robotics.  First you select the platform type so that you can use Natural Language PLTW.
Vex Robotics program three: using motors and sensors together.
MEH108 - Intro. To Engineering Applications KOU Electronics and Communications Engineering.
Lego Mindstorm Robots 9797 kit.  Students will learn how to identify how to detect a change in a condition.  Students will learn where and how to identify.
Robotics Programming Wall Follow Line tracking for a set amount of time Line tracking for a distance.
Exploring Computer Science Lesson 6-5
Getting Ready to go with LeJos and an IDE
Java on the LEGO Mindstorms EV3
IT Basic Wednesday 14 April 2010
The Finch Robot and the While Loop
RobotC Sensors.
Exploring Computer Science Lesson 6-5
INTERMEDIATE PROGRAMMING LESSON
LEGO Education - Mindstorms EV3 - Computer/control center – The Brick
Lego MINDSTORMS EV3.
Programming Robots using Java
Programming Robots using Java
LEGO Mindstorms Robot and Java
LEGO MINDSTORMS NXT PROGRAMMING
Presentation transcript:

Using LeJOS LMICSE Workshop August , 2006 Villanova University

Presentation Outline LeJOS Overview An Example Program Controlling Motors Sleeping Using Sensors Generating Sounds Using Buttons Defining Listeners LeJOS Resources

LeJOS Overview LeJOS is an open source project is based on a subset of Java with extensions for the RCX missing Java features hard to predict (i.e., no switch statement) contains as well some advanced robotics libraries navigation (odometry) behaviors (subsumption architecture) image processing (vision) is available at lejos.sourceforge.netlejos.sourceforge.net

An Example Program import josx.platform.rcx.*; class GoForward implements SensorConstants { public static void main(String[] args) { Sensor.S2.setTypeAndMode(SENSOR_TYPE_TOUCH, SENSOR_MODE_BOOL); Motor.A.forward(); Motor.C.forward(); while( Sensor.S2.readValue() != 1 ) ; } import the basic LeJOS package set up a bump sensor “poll” the sensor turn on the motors sensor constants Move forward until a bump

Controlling 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() public static void setpower()

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)

Sleeping Put the thread to sleep in order to time movements import josx.platform.rcx.*; class Patrol { public static void main(String[] args) throws InterruptedException { Motor.A.forward(); while (true) { Motor.C.forward(); // go forward Thread.sleep (5000); Motor.C.reverse(); // turn around Thread.sleep (1000); } Patrol back and forth timing is in milliseconds threads can be interrupted

Using Sensors I Three Sensors: S1, S2, S3 First you must “set type and mode” of the sensor setTypeAndMode(int aType, int aMode) use the SensorConstants for aType and aMode: aType SENSOR_TYPE_RAW= 0; SENSOR_TYPE_TOUCH= 1; SENSOR_TYPE_TEMP= 2; SENSOR_TYPE_LIGHT= 3; SENSOR_TYPE_ROT = 4; aMode SENSOR_MODE_RAW= 0x00; SENSOR_MODE_BOOL= 0x20; SENSOR_MODE_EDGE= 0x40; SENSOR_MODE_PULSE= 0x60; SENSOR_MODE_PCT= 0x80; SENSOR_MODE_DEGC= 0xa0; SENSOR_MODE_DEGF= 0xc0; SENSOR_MODE_ANGLE= 0xe0;

Using Sensors II Sensor.S1.activate(); // turns the sensor on Sensor.S1.passivate(); // turns the sensor off - required for “active” sensors

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)

Sensor Code Example import josx.platform.rcx.*; class LCDShowLight implements SensorConstants { public static void main(String[] args) { Sensor.S1.setTypeAndMode(SENSOR_TYPE_LIGHT, SENSOR_MODE_PCT); Sensor.S1.activate(); while(true) LCD.showNumber(Sensor.S1.readValue()); } Repeatedly display the reading of the light sensor light sensors must be activated use the LCD class for display

Sound Uses RCX speaker – useful for debugging beep() // one beep beepSequence() // a series of beeps going down buzz()// a buzz playTone(int aFrequency, int aDuration) aFrequency: Hz //human sound range aDuration: 1 – 256 Centiseconds

Sound Code 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); } Play an ascending and then a descending series of tones ascendingdescending

The RCX Buttons All buttons may be re-programmed except “RUN” Controlled by a “button class” Polling or Using a Listener (Discuss) “listener” or directly using waitForPressAndRelease()

Button Code Example 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(); } Move forward until RUN button is pressed blocks until button click

Using Listeners Just as with standard Java, you can define listeners. Perhaps most useful with sensors, particularly touch sensors. You need to implement the SensorListener interface by defining a stateChanged method. register the listener with the appropriate sensor(s).

Listener Example An extended example: The robot patrols back and forth. While it patrols, it plays (without stopping) a low tone when its left bump sensor is pressed. a high tone when its right bump sensor is pressed.

Listener Example Part 1 import josx.platform.rcx.*; class ListenerExample implements SensorConstants, SensorListener { public static void main(String[] args) { ListenerExample exam = new ListenerExample(); Sensor.S1.setTypeAndMode(SENSOR_TYPE_TOUCH, SENSOR_MODE_BOOL); Sensor.S3.setTypeAndMode(SENSOR_TYPE_TOUCH, SENSOR_MODE_BOOL); Sensor.S1.addSensorListener(exam); Sensor.S3.addSensorListener(exam); exam.patrol(); } The beginning of the class definition and the main method implement SensorListener register the listeners can’t register a listener in a static object

Listener Example Part 2 public void patrol () { try { Motor.A.forward(); while (true) { Motor.C.forward(); Thread.sleep(3000); Motor.C.backward(); Thread.sleep(1000); } } catch (Exception e) { } The patrol method sleeping does not affect the listener

Listener Example Part 3 public void stateChanged(Sensor source, int oldValue, int newValue) { if (newValue == 1) if (source.getId() == 0) // left bumper Sound.playTone(220, 50); else if (source.getId() == 2) // right bumper Sound.playTone(660, 50); } } // end class ListenerExample The stateChanged method and class definition end on a press, not a release id is either 0, 1, or 2

Where to Learn More The LeJOS Tutorial: an online resource which is part of the LeJOS project.LeJOS Tutorial Books such as: Core Lego Mindstorms Programming, by Brian Bagnall (Prentice-Hall, 2002), Programming Lego Mindstorms in Java, by Giulio Ferrari, et al (Syngress, 2002), and many others.

The BlueJ IDE and MindStorms A popular integrated development environment for Java developed by Michael Kolling and others Often used in introductory CS courses Available at easy to installwww.bluej.org, Go ahead and open BlueJ on your PC

Setting up BlueJ for MindStorms Two requirements: Install LeJOS Available from lejos.sourceforge.comlejos.sourceforge.com Just do the basic install Add the BMJT plugin to BlueJ Available from ddi.uni- paderborn.de/mindstormstools/bjmtddi.uni- paderborn.de/mindstormstools/bjmt Good instructions available online These steps are already done for you on your PC!

Once the BMJT Plugin is installed You need to configure it This is already done for you on your PC! set the path to the JDK set the path to LeJOS just say usb there is a 1.5 option in newer versions choose configure

Firmware Now you can download the firmware to the RCX Plug the tower into a usb port if on a PC you may need to install the usb drivers Place the RCX in front of the tower, turn it on Choose Firmware You will see a progress dialog on the PC On the RCX you will see an ascending series of numbers choose firmware

Compiling an Existing File Right-click (Command-click) on the file icon Choose Compile from the pop-up menu choose compile not this one!

Downloading a Project Robot must be on and in front of tower Right-click (Command-click) on the file icon for the main class Choose Download from the pop-up menu choose download

Try it Out! Place the robot in its play area. Press run. It should move forward until it hits an obstacle.