Download presentation
Presentation is loading. Please wait.
1
Building Complex Behaviors: Actions and States
2
How do we get… From This To This
3
Roll Camera…Action! One way to start thinking about this is to figure about a way for our robot to do actions We program: A rule for what to do (behavior) A rule for when to stop (stop condition) Examples of Actions: Baking a cake, Doing homework, Erasing a chalkboard, and pretty much anything else you can think of!
4
What does a behavior look like in code?
5
Without a stopping condition
Do it Forever Turn Left if the Color is White Turn Right if the Color is Black
6
With a stopping condition
Turn Left if the Color is White Turn Right if the Color is Black Stop Looping if you see a different color
7
What behaviors/stopping conditions could we try?
Follow line Turn Left Turn Right Move Block Stopping Conditions: See Color that isn’t Black or White See Red Time Distance See Red or Green
8
Then we can combine them!
Follow Line See Red Turn Left See Black Behavior Stopping Condition Behavior Stopping Condition
9
Drive until you see Green
So we could do this Drive until you see Red Clear Block Drive until you see Green
11
Take Advantage of Patterns
Instead of deciding when to stop, we decide what to do next Then we just keep doing that, forever What Action am I supposed to be doing Do a little bit of that behavior Write down what to do next What we write down is a STATE and this process is called a STATE MACHINE
12
State Machine Pick next State Behavior 1 What State am I in?
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.