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

Slides:



Advertisements
Similar presentations
1chung Robofest 2005 RCX code Workshop Jan 29, 2005 CJ Chung.
Advertisements

Robofest 2005 Introduction to Programming RIS 2.0 RCX Code.
Chung for Robofest 05 1 Introduction to RoboLab CJ Chung Lawrence Technological University.
RCX Workshop Day 2 Programming with Touch Sensor Light Sensor Repeat CJ Chung Associate Professor of Computer Science Lawrence Technological University.
VEX and Robot C Chris Patterson Presented by Modified by J. Andazola.
Intro to Robots Lab 6: Robot Behaviours. Intro to Robots Further Braitenberg Vehicles: Timid: –Moves forward in a straight line –One threshold light sensor.
The Turtle Laboratory Sequence Myles McNally LMICSE Workshop November , 2004 University of Mississippi.
The Turtle Laboratory Sequence LMICSE Workshop August , 2006 Villanova University.
The Turtle Laboratory Sequence LMICSE Workshop June , 2005 Alma College.
ENGR 101: Robotics Lecture 1 – Introduction Outline  The Scribbler's Sensors  Demo Modes  Graphical Programming References 
©2006 CSUC Institute for Research in Intelligent Systems Introduction to Coding June 15, 2006.
Tasks An NQC program consists of at most 10 tasks. Each task has a name. One task must have the name main, and this task will be executed. The other tasks.
Introduction to Sensors
Jennifer Goodall, Nick Webb, Katy DeCorah
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.
Testbed: Exercises.
Loops and Switches. 1. What kind of blocks are these? 2. Name two kinds of controls that can be specified to determine how long a loop repeats. 3. Give.
Flowol subroutines Subroutines are used to:  Simplify your code to make it easier to read (or for someone.
Department of Computing and Information Sciences Kansas State University Design Methodology for State based Embedded Systems Case Study: Robot Controller.
CSC Intro. to Computing Lecture 16: Robotran.
Using Waits, Loops and Switches WAIT please!. Waits, Loops and Switches Pre-Quiz 1. In programming, what is a loop? When is a loop useful? 2. How can.
Robotics Overview of NXT-G Actuators in Mindstorms. Touch sensor Labwork: Right turn. Touch/bump. [Explore move versus Motor Move mini & motor mini. Motor*.]
2 3  A machine  Built to help us  Autonomous (not remote control)  If we want robots to do things for us, we have.
This presentation is intended to offer a set of activity cards, which are ideal for introducing the Robolab. The cards cover a range of basic skills, that.
Motors and Sound Troubleshooting Tips. © H-CCS Problem 1 Why can’t I download my program to the RCX?
Robotics in the Classroom Using Lego Mindstorms. Getting to know Lego Mindstorms We all are familiar with Legos We need to add motors and a brain.
Technical Writing for Robotic Coding!.  du/products/teaching_robotc_cort ex/fundamentals/introtoprogramm ing/thinking/videos/fundamentals.
Wall Encounter By Made easy by Dwayne Abuel.
2008 SBPLI/FIRST Programming Workshop Tom Boehm Patchogue Medford High School, Team 329 Motorola Inc. Mark McLeod Hauppauge High School Team 358 Northrop.
Sentry System Multiple Sensors
Robotics Challenges. Challenge Slide 2 Have your robot make a left curved turn around your Lego person. Go forward, then reverse. Come to a stop, play.
The George Washington University Department of ECE ECE Intro: Electrical & Computer Engineering Dr. S. Ahmadi Class 4.
Rascalbot EEL4665 Eric Page. Problem Dogs have been shown to increase the happiness and well being of their owners Keeps elderly active Many people are.
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.
Robotics NXT-G: variables, file Rotation sensor Lab: Use buttons to hit specific ball. Homework: Postings. Start planning mapping the room.
NQC / BricxCC Brief Introduction David Schilling.
Variables and Functions ROBOTC Software © 2012 Project Lead The Way, Inc.Principles of Engineering.
Vex Robotics Program four: reversing and turning.
ECE 002 Robots and Sensors Group 14. Objectives Research sensors and their usefulness to analyze data Research sensors and their usefulness to analyze.
Oregon Robotics Tournament and Outreach Program RCX Basics.
By Droids Robotics INTERMEDIATE PROGRAMMING LESSON BRICK BUTTONS AS SENSORS.
BEGINNER FLL PROGRAMMING WORKSHOP BY DROIDS ROBOTICS & EV3LESSONS.
VEX and Robot C Chris Patterson Frisco ISD CTE Center Presented by.
Lesson 1: Motors and Sound Programming Solutions.
Deriving Consistency from LEGOs What we have learned in 6 years of FLL by Austin and Travis Schuh © 2005 Austin and Travis Schuh, all rights reserved.
Obstacle Detection. In the previous program the robot moves forward and then checks for something in the way. As we observed it only checks for things.
Casne.ncl.ac.uk Taking care of the CrumbleBot Please do NOT stress the robot's motors 1.Do NOT push the robot 2.Do NOT hold the.
DPS Secondary Science Institute 1 Agenda 8:30-8:45 Introduction and Overview 8:45-9:15 The Bumper Car 9:15-10:15 The Line Follower 10:15-10:30 Questions.
ROBOTC for VEX Online Professional Development. Homework Questions Thoughts? Questions?
1 ©2006 INSciTE Lab Three Task: Move forward for 2 feet, turn right 90º repeat to complete a square path. End up exactly where you started.
Robotics Programming Wall Follow Line tracking for a set amount of time Line tracking for a distance.
The George Washington University Department of ECE ECE Intro: Electrical & Computer Engineering Dr. S. Ahmadi Class 4.
Presentation Outline I. Background Information II. Design Project
Introduction to Programming in RobotC
VEX IQ Curriculum Smart Machines Lesson 09 Lesson Materials:
Deriving Consistency from LEGOs
ROBOTC for VEX Online Professional Development
ROBOTC for VEX Online Professional Development
Touch Sensor.
IMDL Summer 2007: RoBeDeS by David Ladolcetta.
Loops and Switches Pre-Quiz
Learning Outcomes Understand While Loop
Line Following Behavior
Line Following Behavior
Compiled from various Internet sources Presented by Mr. Hatfield
Obstacle Detection.
Lego MINDSTORMS EV3.
Oregon Robotics Tournament and Outreach Program
Implementing Variables in Your Programs
Presentation transcript:

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

What is a State Machine? A state machine is a model of the behavior of a system – in this case an autonomous robot – consisting of states, transitions, and actions

States What the robot is doing Following a line, avoiding an obstacle, turning, or operating an arm are states Doing nothing is also a state

Transitions A change in condition that causes the robot to change states A bumper touch, an increase or decrease in a light sensor value, or receiving a message from another robot are transitions

Actions How the robot changes states, or what the robot does in a state Stopping all motors to change the robot's state from moving to stopped or following a line in the line following state are actions

State Machine Example A Light Seeking Robot Step 1 - Define the states Seek Locate bright light

State Machine Example A Light Seeking Robot Step 1 - Define the states SeekAvoid Avoid an obstacle

State Machine Example A Light Seeking Robot Step 1 - Define the states SeekAvoid Follow Follow bright light

State Machine Example A Light Seeking Robot Step 2 - Define the transition events SeekAvoid Follow Light High Sensor detect increase in light

State Machine Example A Light Seeking Robot Step 2 - Define the transition events SeekAvoid Follow Light High Light Low Sensor detects decrease in light

State Machine Example A Light Seeking Robot Step 2 - Define the transition events SeekAvoid Follow Light High Light Low Obstacle Sensor detects an obstacle in the robot's path

State Machine Example A Light Seeking Robot Step 3 - Define the transitions SeekAvoid Follow Light High Light Low Obstacle Light High from Seek – go to Follow

State Machine Example A Light Seeking Robot Step 3 - Define the transitions SeekAvoid Follow Light High Light Low Obstacle Light Low from Follow – go to Seek

State Machine Example A Light Seeking Robot Step 3 - Define the transitions SeekAvoid Follow Light High Light Low Obstacle Obstacle from Follow or Seek – go to Avoid

State Machine Example A Light Seeking Robot Step 3 - Define the transitions SeekAvoid Follow Light High Light Low Obstacle Avoid Complete – go to Seek

State Machine Example A Light Seeking Robot We now have a model of the behavior of a light seeking robot This model doesn't require any particular robot design, sensors, or programming language All the robot needs is a way to move, a way to detect a change in light, and a way to detect an obstacle in it's path

State Machine Example A Light Seeking Robot We'll use an RCX differential drive robot with a touch bumper and a light sensor.

State Machine Example A Light Seeking Robot To write the program in RoboLab we need:

State Machine Example A Light Seeking Robot To write the program in RoboLab we need: A task to watch the touch sensor

State Machine Example A Light Seeking Robot To write the program in RoboLab we need: A task to watch the touch sensor A task to watch the light sensor

State Machine Example A Light Seeking Robot To write the program in RoboLab we need: A task to watch the touch sensor A task to watch the light sensor A subroutine to do the Seek actions

State Machine Example A Light Seeking Robot To write the program in RoboLab we need: A task to watch the touch sensor A task to watch the light sensor A subroutine to do the Seek actions A subroutine to do the Follow actions

State Machine Example A Light Seeking Robot To write the program in RoboLab we need: A task to watch the touch sensor A task to watch the light sensor A subroutine to do the Seek actions A subroutine to do the Follow actions A subroutine to do the Avoid actions

State Machine Example A Light Seeking Robot To write the program in RoboLab we need: A task to watch the touch sensor A task to watch the light sensor A subroutine to do the Seek actions A subroutine to do the Follow actions A subroutine to do the Avoid actions A task to handle switching between states

State Machine Example A Light Seeking Robot To write the program in RoboLab we need: A task to watch the touch sensor A task to watch the light sensor A subroutine to do the Seek actions A subroutine to do the Follow actions A subroutine to do the Avoid actions A task to handle switching between states Containers for current and next states

State Machine Example A Light Seeking Robot RoboLab Containers RoboLab provides 23 containers for programmers to use – red (0), blue(1), yellow(2) and user containers 3 to 22. User container 21 will hold a value representing the current state. Container 22 will hold the value representing the next state. The values assigned will be 1 for Seek, 2 for Avoid, and 3 for Follow.

State Machine Example A Light Seeking Robot Light Task - RoboLab

State Machine Example A Light Seeking Robot Obstacle Task - RoboLab

State Machine Example A Light Seeking Robot Follow Subroutine - RoboLab

State Machine Example A Light Seeking Robot Avoid Subroutine - RoboLab

State Machine Example A Light Seeking Robot Seek Subroutine - RoboLab

State Machine Example A Light Seeking Robot State Change Task - RoboLab

State Machine Example A Light Seeking Robot Complete RoboLab program

State Machine Example NQC Implementation The robot behavior described by our state machine model doesn't require a specific language. We could write the program in NQC, Java, or any other language that has support for our controller The following slides show how it could be implemented in NQC

State Machine Example NQC Implementation Instead of containers, NQC uses integer (int) variables to hold values. '#define' allows you to substitute words for values to make your program easier to read – the value 1 can be replaced by the word stateSeek in your program #define stateUndefined -1 #define stateInitialization 0 #define stateSeek 1 #define stateAvoid 2 #define stateFollow 3 int nCurrState; int nNextState;

State Machine Example A Light Seeking Robot Light Task - NQC // // task to watch the light sensor // wait for high light, set state to 'stateFollow' // --- then --- // wait for low light, set state to 'stateSeek' // NOTE: // this assumes that robot is not facing the bright light when this task starts // task taskLight() { // loop forever while(true) { // loop until a bright light is found while(lightSensor < 45) { } // stop motors SetOutput(motorLeft + motorRight, OUT_OFF); // turn A and C off // set state to follow nNextState = stateFollow; // wait 1 second Wait(100); // loop until bright light is lost while(lightSensor >= 45) { } nNextState = stateSeek; }

State Machine Example A Light Seeking Robot Obstacle Task - NQC // // task to watch the bumper sensor // on bump, change next state to 'stateAvoid' // task taskObstacle() { // monitor forever while(true) { // loop until an obstacle is found while(obstacleSensor == 0) { } // set state to avoid nNextState = stateAvoid; }

State Machine Example A Light Seeking Robot Follow Subroutine - NQC // // subroutine for follow state action // no need to monitor for state changes - this just sets the // motors forward at full power and exits // sub subFollow() { // set and display current state nCurrState = stateFollow; SetUserDisplay(nCurrState, 0); PlaySound(SOUND_DOUBLE_BEEP); // set both motors forward and exit // they will stay forward until something else changes their direction SetDirection(motorLeft + motorRight, OUT_FWD); SetOutput(motorLeft + motorRight, OUT_FULL); On(motorLeft + motorRight); }

State Machine Example A Light Seeking Robot Avoid Subroutine - NQC // // subroutine for avoid state action // back up, turn right or left, then set next state to seek // this subroutine doesn't look for state changes - it runs to completion // sub subAvoid() { // set and display current state nCurrState = stateAvoid; SetUserDisplay(nCurrState, 0); PlaySound(SOUND_DOUBLE_BEEP); // reverse for 1 second SetDirection(motorLeft + motorRight, OUT_REV); SetOutput(motorLeft + motorRight, OUT_FULL); On(motorLeft + motorRight); Wait(100); // turn right or left for 1 second if(Random(1) == 0) { SetDirection(motorLeft, OUT_FWD); } else { SetDirection(motorRight, OUT_FWD); } Wait(100); // stop both motors Off(motorLeft + motorRight); nNextState = stateSeek; }

State Machine Example A Light Seeking Robot Seek Subroutine - NQC // subroutine for seek state action // drive forward for a random time <= 5 seconds, then spin for a random time <= 2 seconds // this subroutine needs to allow itself to be interrupted by state changes // sub subSeek() { // set and display current state nCurrState = stateSeek; SetUserDisplay(nCurrState, 0); PlaySound(SOUND_DOUBLE_BEEP); int mSecs = 0; // loop until next state changes while(true) { // forward <= 5 seconds mSecs = Random(500); ClearTimer(T1); // forward <= 5 seconds SetDirection(motorLeft + motorRight, OUT_FWD); SetOutput(motorLeft + motorRight, OUT_FULL); On(motorLeft + motorRight); // this loops until the timer reached the desired value or the state changes while((Timer(T1) <= mSecs) && (nNextState == nCurrState)) { } // break while(true) loop if state has changed if(nNextState != nCurrState) { break; }

State Machine Example A Light Seeking Robot Seek Subroutine – NQC (cont) // turn <= 2 seconds mSecs = Random(200); ClearTimer(T1); // turn right or left <= 2 seconds if(Random(1) == 0) { SetDirection(motorLeft, OUT_REV); // reverse left motor } else { SetDirection(motorRight, OUT_REV); // reverse right } On(motorLeft + motorRight); // this loops until the timer reached the desired value or the state changes while((Timer(T1) <= mSecs) && (nNextState == nCurrState)) { } // break while(true) loop if state has changed if(nNextState != nCurrState) { break; } // gets here if state has changed (break statements) // turn right and left motors off Off(motorLeft + motorRight); return; }

State Machine Example A Light Seeking Robot State Change Task - NQC // initial setup, handle state changes task main() { // One-time startup code SetSensor(obstacleSensor, SENSOR_TOUCH); SetSensor(lightSensor, SENSOR_LIGHT); nCurrState = stateUndefined; nNextState = stateInitialization; // Continuous loop for state machine while (true) { // don't change state unless needed if(nCurrState == nNextState) { continue; } // change to next state switch (nNextState) { // initialization to start tasks and set first running state case stateInitialization: start taskLight; start taskObstacle; nNextState = stateSeek; break;

State Machine Example A Light Seeking Robot State Change Task – NQC (cont) // go into seek state (from avoid or follow) case stateSeek: subSeek(); break; // go into avoid state (from seek or follow) case stateAvoid: subAvoid(); break; // go into follow state (from seek only) case stateFollow: if(nCurrState == stateSeek) { subFollow(); } else { nNextState = nCurrState; } break; // Should never get here. Play warning message and restart default: PlaySound(SOUND_DOUBLE_BEEP); SetUserDisplay(9999, 0); Wait(100); stop taskLight; stop taskObstacle; nCurrState = stateUndefined; nNextState = stateInitialization; break; }