State Machines are Your Friends! Sean Donovan. What is a state machine? A state machine is a way of expressing an algorithm or procedure by breaking it.

Slides:



Advertisements
Similar presentations
Reading for an English Class (created by Jim Burke)
Advertisements

NXTG Workshop Day 2 Programming with Touch Sensor Light Sensor Ultrasonic Sensor Repeat CJ Chung Associate Professor of Computer Science Lawrence Technological.
Gears.
NEWTON’S FIRST LAW OF MOTION By Stacie Green  We know that “motion” is any object that is moving.  We know that we describe motion in 3 ways: ◦ HOW.
Flipping Across the Axis
Add and Use a Sensor & Autonomous For FIRST Robotics
Public speaking: the basics
Top Seven Homework Tips and Strategies 1. Share your homework routine with a partner. Discuss positive and negative habits. 2.
TRANSFORMATIONS.
Automation and Robotics
One of the most common types of drivetrain is known as a skid steer drivetrain, which may also be referred to as a tank drive. A skid steer drivetrain.
Autonomy using Encoders Intro to Robotics. Goal Our new task is to navigate a labyrinth. But this time we will NOT use motor commands in conjunction with.
FUNCTIONS AND MODELS Chapter 1. Preparation for calculus :  The basic ideas concerning functions  Their graphs  Ways of transforming and combining.
Mrs. Chapman. Tabs (Block Categories) Commands Available to use Script Area where you type your code Sprite Stage All sprites in this project.
Translations, Rotations, Reflections, and Dilations M7G2.a Demonstrate understanding of translations, dilations, rotations, reflections, and relate symmetry.
Mr. Wortzman. Tabs (Block Categories) Available Blocks Script Area Sprite Stage All sprites in this project.
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.
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.
1 Ch5 Circular Motion and Force. 2 Centripetal Force - Swinging Ball Any body rotating about a fixed point will experience a centripetal (center seeking)
Your Python program uses the create library. It supplies functions that send commands: to your laptop’s Bluetooth radio, then to the BAM on the Create,
Programming 101 The Common Palette Content provided by Connor Statham (6 th Grade Student) Formatting by Shannon Sieber.
Available at: Lesson 3.6 – Program Line Follower in Autonomous Mode Program Line Follower in Autonomous Mode.
Lecture 03: Theory of Automata:08 Finite Automata.
Sight Words List 1 Mr. Matthews Grade One can.
Translations, Rotations, and Reflections
Lecture 07: Formal Methods in SE Finite Automata Lecture # 07 Qaisar Javaid Assistant Professor.
12-CRS-0106 REVISED 8 FEB 2013 KUG1C3 Dasar Algoritma dan Pemrograman.
Alternative Squaring on a Line
The Wait-Until-Event pattern Has it happened  Yes, it happened!
Autonomy using Encoders Intro to Robotics. Autonomy/Encoders Forward for Distance In this unit, you will learn to use the encoders to control the distance.
Does white candles burn faster than color candles Yesenia Roa 018.
Q and A for Chapter 7 Students of CS104, and me, your benevolent professor, Victor T. Norman, PhD.
District 200 High frequency words
Translations, Rotations, Reflections, and Dilations.
Translations, Rotations, Reflections, and Dilations
Algorithms Writing instructions in the order they should execute.
CONTROL FLOW The order in which blocks are executed is called the “control flow” of the script So far all our scripts have just executed blocks in the.
Ch5 Circular Motion and Force
The Ten Study Habits of Successful Students
 In this packet we will look at:  The meaning of acceleration  How acceleration is related to velocity and time  2 distinct types acceleration  A.
The George Washington University Electrical & Computer Engineering Department ECE 002 Dr. S. Ahmadi Class3/Lab 2.
The Ten Study Habits of Successful Students. 1.Try not to do too much studying at one time, you will tire and your studying will not be very effective.
Winter 2006CISC121 - Prof. McLeod1 Stuff No stuff today!
Programming 101 The Common Palette Content provided by Connor Statham (9 th Grade Student) Formatting by Shannon Sieber.
Mindstorm NXT-G Introduction Towson University Robotics.
Repetition everywhere – comparing while in a method and as an event Susan Rodger Duke University July 2010.
Objectives. Objective The purpose of this tutorial is to teach the viewer how to solve for the acceleration of each mass in a standard two- body pulley.
DO NOW Prepare for Vocabulary Quiz over chapter % words Pick up notes sheet when you turn it in.
Looking is showing that you’re paying attention and listening to what the teacher has to say. Don’t have side talks with your friend when the teacher.
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.
Planning and Scheduling.  A job can be made up of a number of smaller tasks that can be completed by a number of different “processors.”  The processors.
How Tall Are You? Introducing Functions for Alice 3 By Jenna Hayes under the direction of Professor Susan Rodger Duke University July 2008 Updates made.
Get your software working before putting it on the robot!
Physics 141MechanicsLecture 2 Kinematics in One Dimension Kinematics is the study of the motion of an object. We begin by studying a single particle in.
Translations, Rotations, Reflections, and Dilations
Understanding Communication with a Robot? Activity (60 minutes)
Basics for Robotics Programming
Autonomy using Encoders
Introduction To Robot Decision Making
Loops and Switches Pre-Quiz
Better Line Following with PID
An Introduction to VEX IQ Programming with Modkit
An Introduction to VEX IQ Programming with Modkit
Introduction To Robot Decision Making
Planning and Scheduling
Loops and Switches How Do You Make Loops and Switches? lesson > TeachEngineering.org Center for Computational Neurobiology, University of Missouri.
Building Complex Behaviors: Actions and States
© A+ Computer Science -
ECE 352 Digital System Fundamentals
Presentation transcript:

State Machines are Your Friends! Sean Donovan

What is a state machine? A state machine is a way of expressing an algorithm or procedure by breaking it down into “states” and “transitions” A state machine has one “starting state”

What is a State? States usually consist of 2 components: a name and an associated action. A name could be: “Goto Dentist” and the action could be making yourself goto the dentist. The “starting state” is the state where the state machine starts in.

What is a Transition? Transitions are conditions that must be satisfied to go from one state to another. A transition could be: “Time is greater than 2pm”, or “Wheel rotated 14 times” There can be more than one transition per State A transition can start in one state and loop back to that same state

An Example State Machine Your daily plan could be shown as a State Machine. Name:Sleep Action: Sleep Name: Work Action: Do work Name: Dentist Appointment Action: Goto Dentist Name: Eat Dinner Action: Prepare dinner, eat Time = 8AM Time = 2PM Hungry = True Tired = True

Explanation The Bubbles represent States The Connection Arrows represent Transitions

Robot Related Usefulness In an Autonomous Program, State Machines are usually a good way of planning what to do

Robot Related Usefulness (cont.) Say you wanted to follow a line and you have 3 reflective sensors watching the line. Sensor Line

Line Following Example One question you must ask is how many states can there be?

Line Following Example (cont.) As we can see, there are six States. It is nice to name these states, so they have been numbered to simplify drawing later on. Since we’ve found out what the states are, we must say what we want to do when each of these states occurs. At this point we can determine the starting state. We can assign state 3 to be starting state, as ideally the robot would start positioned over the line. Try to determine what to do before going on with this slide show

Line Following Example (cont.) For State 1: Turn to the left For State 2: Turn a little to the left For State 3: Go Straight For State 4: Turn a little to the right For State 5: Turn to the right For State 6: At the end of the line, stop

Line Following Example (cont.) The next step in creating a state machine is to create the transitions. In this case, the transitions will be simply moving over the new lines, so you do not have to give a reason. Try to draw a picture of the state machine before going on.

Line Following Example (cont.) Start

Line Following Example (cont.) As you can see, there is a transition from 1 to 2 and a transition from 2 to 1. This is very possible, and quite common Also not that State 6 stays looping back to itself at the end all the time.

Another Example Suppose this autonomous mode has been planed out: –Go straight for 3 seconds –Turn left for 1 second –Go strait for 3 seconds –Then spin around for the remaining 8 seconds

Another Example (cont.) Below is code that could do just that: Drive(60,0);//straight Wait(3000); Drive(0,60);//turn Wait(1000); Drive(60,0);//straight Wait(3000); Drive(0,60);//spin Wait(8000); Drive(0,0);

Another Example (cont.) This could be put into a loop that checks to see if the robot is in autonomous mode ever time it goes through the loop. (Soon to be implemented in the WPI Framework) while(IsAutonomous()) { //run the state machine }

Another Example (cont.) First step: Identify the states Very simple this time: –State 1: Go straight –State 2: Turn –State 3: Go straight –State 4: Spin

Another Example (cont.) Next: Identify the Transitions This is a bit more difficult. Fortunately you may notice that there are only 2 transitions per state. One being a loop back (to self). Try to determine the transitions before going on.

Another Example (cont.) Start Driver Mode IsAutonomous != True >=4000 ms <3000 ms <4000 ms <7000 ms IsAutonomous == True >=3000 ms >=7000 ms

Another Example (cont.) This can be coded in a variety of ways –switch statements –if-else if statements Code Examples will be posted later in the season