Using LeJOS LMICSE Workshop June 14 - 17, 2005 Alma College.

Slides:



Advertisements
Similar presentations
Mindstorms State Machines A structured method for handling tasks and events using RoboLab and NQC Brian Smith
Advertisements

Robofest 2005 Introduction to Programming RIS 2.0 RCX Code.
RCX Workshop Day 2 Programming with Touch Sensor Light Sensor Repeat CJ Chung Associate Professor of Computer Science Lawrence Technological University.
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.
Sonar and Localization LMICSE Workshop June , 2005 Alma College.
Robotics Invention System 2.0
Robot Programming. Programming Behaviors Behaviors describe the actions and decisions of your robot.
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.
CS220 Software Development Lecture: Multi-threading A. O’Riordan, 2009.
Not Quite C: A CS 0 Option LMICSE Workshop June , 2005 Alma College.
The Turtle Laboratory Sequence LMICSE Workshop June , 2005 Alma College.
Using LeJOS LMICSE Workshop August , 2006 Villanova University.
An Intro to Robots and Computer Programming
©2006 CSUC Institute for Research in Intelligent Systems Introduction to Coding June 15, 2006.
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.
Threads II. Review A thread is a single flow of control through a program Java is multithreaded—several threads may be executing “simultaneously” If you.
1 ©2006 INSciTE Lab Two Task: Make the program from Lab One (Move forward 5 rotations and turn right 90 degrees) into a MyBlock.
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.
Interfacing the LEGO RCX to the outside world John M. Larkin Whitworth College Spokane, WA.
1 CS 177 Week 5 Recitation Slides Loops. 2 Announcements Project 2 due next Thursday at 9PM. Exam 1 this evening (switch and loop not covered) Old exams.
Department of Computing and Information Sciences Kansas State University Design Methodology for State based Embedded Systems Case Study: Robot Controller.
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.
NXT Development Tutorial Part 2: Sensor/ Motor Collaboration NTHU CS Freshman Camp Shu-Ting Wang.
LeJos Kyle Adams Rob Boorman. Overview of leJos leJos stands for LEGO Java Operating System. leJos was originally developed by Jose Solorzano, and is.
University of Sunderland Java Threading, Mutex and Synchronisation Lecture 02 COMM86 Concurrent and Distributed Software Systems.
Sound, Touch Sensor, and Motors. Wheeled Vehicles Using the Pilot class: –Constructor Pilot(float wheelDiameter, float trackWidth,Motor leftMotor, Motor.
Threads in Java. Processes and Threads Processes –A process has a self-contained execution environment. –Has complete set of runtime resources including.
Mindscript Presented by Dean Thomas Matthew Horoszowski.
Response actuatorcontrol program analog quantity, e.g. pulse train digital quantity, e.g. power % interface stimuli sensorcontrol program analog quantity,
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.
Introduction to Threads Session 01 Java Simplified / Session 14 / 2 of 28 Objectives Define a thread Define multithreading List benefits of multithreading.
Concurrent Computing CSCI 201L Jeffrey Miller, Ph.D. HTTP :// WWW - SCF. USC. EDU /~ CSCI 201 USC CSCI 201L.
SCJ and EV3 Robots Leadership Election. Background Safety Critical Java – A safety critical programming model in Java EV3 mindstorms Lego Robot – A robot.
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.
Multithreaded programming  Java provides built-in support for multithreaded programming. A multithreaded program contains two or more parts that can run.
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 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.
Threads b A thread is a flow of control in a program. b The Java Virtual Machine allows an application to have multiple threads of execution running concurrently.
MEH108 - Intro. To Engineering Applications KOU Electronics and Communications Engineering.
The George Washington University Department of ECE ECE Intro: Electrical & Computer Engineering Dr. S. Ahmadi Class 4.
Getting Ready to go with LeJos and an IDE
By Sanjay and Arvind Seshan
IT Basic Wednesday 14 April 2010
BEGINNER EV3 PROGRAMMING Lesson
BEGINNER PROGRAMMING LESSON
Line Following Behavior
The George Washington University Department of ECE ECE Intro: Electrical & Computer Engineering Dr. S. Ahmadi Class 5.
BEGINNER PROGRAMMING LESSON
Principles of Software Development
INTERMEDIATE PROGRAMMING LESSON
Lego MINDSTORMS EV3.
Programming Robots using Java
Programming Robots using Java
LEGO Mindstorms Robot and Java
Presentation transcript:

Using LeJOS LMICSE Workshop June , 2005 Alma College

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.