lecture 17: finite state machines, behavior-based ... › engi128 › handouts ›...
TRANSCRIPT
![Page 1: Lecture 17: Finite State Machines, Behavior-Based ... › engi128 › Handouts › Lec17-Robotics.pdfthe sensors and controls the robot •Each behavior only does one simple thing](https://reader033.vdocuments.us/reader033/viewer/2022060418/5f15a741f43fb54dd778b5d3/html5/thumbnails/1.jpg)
1
ENGI 128 INTRODUCTION TO ENGINEERING SYSTEMS
Lecture 17: Finite State Machines,
Behavior-Based Programming, Final Design Challenge
“Understand Your Technical World”
![Page 2: Lecture 17: Finite State Machines, Behavior-Based ... › engi128 › Handouts › Lec17-Robotics.pdfthe sensors and controls the robot •Each behavior only does one simple thing](https://reader033.vdocuments.us/reader033/viewer/2022060418/5f15a741f43fb54dd778b5d3/html5/thumbnails/2.jpg)
2
Finite-State Machines (Discrete Finite Automata)
![Page 3: Lecture 17: Finite State Machines, Behavior-Based ... › engi128 › Handouts › Lec17-Robotics.pdfthe sensors and controls the robot •Each behavior only does one simple thing](https://reader033.vdocuments.us/reader033/viewer/2022060418/5f15a741f43fb54dd778b5d3/html5/thumbnails/3.jpg)
3
Finite-State Machines (Discrete Finite Automata)
It sounds complicated, but you’ve been using them for a while:
Sample FSM diagram:
Q: What does this program do?
waiting blink blue
lights
no button press
button press
reset
reset transition
transition
state
transition condition
![Page 4: Lecture 17: Finite State Machines, Behavior-Based ... › engi128 › Handouts › Lec17-Robotics.pdfthe sensors and controls the robot •Each behavior only does one simple thing](https://reader033.vdocuments.us/reader033/viewer/2022060418/5f15a741f43fb54dd778b5d3/html5/thumbnails/4.jpg)
4
An Example FSM: Wall detection
[Demo dark avoid code on robot]
![Page 5: Lecture 17: Finite State Machines, Behavior-Based ... › engi128 › Handouts › Lec17-Robotics.pdfthe sensors and controls the robot •Each behavior only does one simple thing](https://reader033.vdocuments.us/reader033/viewer/2022060418/5f15a741f43fb54dd778b5d3/html5/thumbnails/5.jpg)
5
An Example FSM: Wall detection
reset move
forward
![Page 6: Lecture 17: Finite State Machines, Behavior-Based ... › engi128 › Handouts › Lec17-Robotics.pdfthe sensors and controls the robot •Each behavior only does one simple thing](https://reader033.vdocuments.us/reader033/viewer/2022060418/5f15a741f43fb54dd778b5d3/html5/thumbnails/6.jpg)
6
An Example FSM: Wall detection
reset move
forward
?
?
![Page 7: Lecture 17: Finite State Machines, Behavior-Based ... › engi128 › Handouts › Lec17-Robotics.pdfthe sensors and controls the robot •Each behavior only does one simple thing](https://reader033.vdocuments.us/reader033/viewer/2022060418/5f15a741f43fb54dd778b5d3/html5/thumbnails/7.jpg)
7
An Example FSM: Wall detection
reset move
forward
rotate left
rotate right
?
?
?
![Page 8: Lecture 17: Finite State Machines, Behavior-Based ... › engi128 › Handouts › Lec17-Robotics.pdfthe sensors and controls the robot •Each behavior only does one simple thing](https://reader033.vdocuments.us/reader033/viewer/2022060418/5f15a741f43fb54dd778b5d3/html5/thumbnails/8.jpg)
8
An Example FSM: Wall detection
no wall
reset move
forward
rotate left
rotate right
right sensor detect wall
left sensor detect wall
Q: Note that the left sensor triggers a right rotate. Does this make sense?
![Page 9: Lecture 17: Finite State Machines, Behavior-Based ... › engi128 › Handouts › Lec17-Robotics.pdfthe sensors and controls the robot •Each behavior only does one simple thing](https://reader033.vdocuments.us/reader033/viewer/2022060418/5f15a741f43fb54dd778b5d3/html5/thumbnails/9.jpg)
9
An Example FSM: Wall detection
reset
? move
forward
rotate left
rotate right
?
?
?
no wall
right sensor detect wall
left sensor detect wall
![Page 10: Lecture 17: Finite State Machines, Behavior-Based ... › engi128 › Handouts › Lec17-Robotics.pdfthe sensors and controls the robot •Each behavior only does one simple thing](https://reader033.vdocuments.us/reader033/viewer/2022060418/5f15a741f43fb54dd778b5d3/html5/thumbnails/10.jpg)
10
An Example FSM: Wall detection
reset
|angle| < p/2
move forward
rotate left
rotate right
|angle| < p/2
|angle| ≥ p/2
|angle| ≥ p/2
[Review dark avoid code in editor]
no wall
right sensor detect wall
left sensor detect wall
![Page 11: Lecture 17: Finite State Machines, Behavior-Based ... › engi128 › Handouts › Lec17-Robotics.pdfthe sensors and controls the robot •Each behavior only does one simple thing](https://reader033.vdocuments.us/reader033/viewer/2022060418/5f15a741f43fb54dd778b5d3/html5/thumbnails/11.jpg)
11
Finite-State Machines (Quidditch Version)
![Page 12: Lecture 17: Finite State Machines, Behavior-Based ... › engi128 › Handouts › Lec17-Robotics.pdfthe sensors and controls the robot •Each behavior only does one simple thing](https://reader033.vdocuments.us/reader033/viewer/2022060418/5f15a741f43fb54dd778b5d3/html5/thumbnails/12.jpg)
For example
Let’s say you are programming a “Seeker” robot…
reset move
around
![Page 13: Lecture 17: Finite State Machines, Behavior-Based ... › engi128 › Handouts › Lec17-Robotics.pdfthe sensors and controls the robot •Each behavior only does one simple thing](https://reader033.vdocuments.us/reader033/viewer/2022060418/5f15a741f43fb54dd778b5d3/html5/thumbnails/13.jpg)
For example
Let’s say you are programming a “Seeker” robot…
no event
wall detector reset
wait for
timer timer done
move around
avoid wall
![Page 14: Lecture 17: Finite State Machines, Behavior-Based ... › engi128 › Handouts › Lec17-Robotics.pdfthe sensors and controls the robot •Each behavior only does one simple thing](https://reader033.vdocuments.us/reader033/viewer/2022060418/5f15a741f43fb54dd778b5d3/html5/thumbnails/14.jpg)
For example
Let’s say you are programming a “Seeker” robot…
no event
wall detector reset
wait for
timer timer done
detect snitch
no snitch
move around
avoid wall
move to snitch
![Page 15: Lecture 17: Finite State Machines, Behavior-Based ... › engi128 › Handouts › Lec17-Robotics.pdfthe sensors and controls the robot •Each behavior only does one simple thing](https://reader033.vdocuments.us/reader033/viewer/2022060418/5f15a741f43fb54dd778b5d3/html5/thumbnails/15.jpg)
For example
Let’s say you are programming a “Seeker” robot…
no event
wall detector reset
wait for
timer timer done
detect snitch
capture snitch
no snitch
move around
avoid wall
move to snitch
score!
![Page 16: Lecture 17: Finite State Machines, Behavior-Based ... › engi128 › Handouts › Lec17-Robotics.pdfthe sensors and controls the robot •Each behavior only does one simple thing](https://reader033.vdocuments.us/reader033/viewer/2022060418/5f15a741f43fb54dd778b5d3/html5/thumbnails/16.jpg)
Yikes!
Don’t worry, it looks simpler in code…
![Page 17: Lecture 17: Finite State Machines, Behavior-Based ... › engi128 › Handouts › Lec17-Robotics.pdfthe sensors and controls the robot •Each behavior only does one simple thing](https://reader033.vdocuments.us/reader033/viewer/2022060418/5f15a741f43fb54dd778b5d3/html5/thumbnails/17.jpg)
17
Behavior-Based Robot Programming
![Page 18: Lecture 17: Finite State Machines, Behavior-Based ... › engi128 › Handouts › Lec17-Robotics.pdfthe sensors and controls the robot •Each behavior only does one simple thing](https://reader033.vdocuments.us/reader033/viewer/2022060418/5f15a741f43fb54dd778b5d3/html5/thumbnails/18.jpg)
18
Behavior-Based Control
A behavior is a small program (or finite-state machine) that reads the sensors and controls the robot
• Each behavior only does one simple thing • Each behavior has access to all the sensors of the robot and
produces motor outputs (tv, rv, active)
Only one behavior can be active at a time • There is a prioritization of behaviors • More important ones override, or subsume, less important ones
![Page 19: Lecture 17: Finite State Machines, Behavior-Based ... › engi128 › Handouts › Lec17-Robotics.pdfthe sensors and controls the robot •Each behavior only does one simple thing](https://reader033.vdocuments.us/reader033/viewer/2022060418/5f15a741f43fb54dd778b5d3/html5/thumbnails/19.jpg)
19
An Example Behavior-Based Program
Follow a robot • Sensor: IR Communications • Behavior: Follow another robot
Avoid Obstacles • Sensors: Bump sensor to detect wall • Behavior: Move away from wall
Wander • Sensor: Encoders • Behavior: Move forward and turn
Q: Which behavior should have the highest priority?
Q: Which behavior should have the lowest priority?
![Page 20: Lecture 17: Finite State Machines, Behavior-Based ... › engi128 › Handouts › Lec17-Robotics.pdfthe sensors and controls the robot •Each behavior only does one simple thing](https://reader033.vdocuments.us/reader033/viewer/2022060418/5f15a741f43fb54dd778b5d3/html5/thumbnails/20.jpg)
Combining Behaviors
We combine behaviors by overriding, or subsuming lower-priority behaviors if a higher-priority behavior becomes active
Wander
Behavior: move and turn
Avoid Obstacle
Behavior: avoid walls
Follow a robot
Behavior: Follow another robot Senso
rs
Actu
ato
rs
S
S
subsume operator
highest priority
lowest priority
![Page 21: Lecture 17: Finite State Machines, Behavior-Based ... › engi128 › Handouts › Lec17-Robotics.pdfthe sensors and controls the robot •Each behavior only does one simple thing](https://reader033.vdocuments.us/reader033/viewer/2022060418/5f15a741f43fb54dd778b5d3/html5/thumbnails/21.jpg)
Genghis
The behavior-based poster child
Really simple hardware • 6 legs, 2 motors per leg
• a-motor for forward/back, b-motor for up/down
• 2 bump sensors (feelers) • 2 ground detection sensors (switches) • 6 heat sensors (but they weren’t used for walking)
R. Brooks. “A Robot that Walks; Emergent Behavior from a Carefully Evolved Network”, ICRA 1989
![Page 22: Lecture 17: Finite State Machines, Behavior-Based ... › engi128 › Handouts › Lec17-Robotics.pdfthe sensors and controls the robot •Each behavior only does one simple thing](https://reader033.vdocuments.us/reader033/viewer/2022060418/5f15a741f43fb54dd778b5d3/html5/thumbnails/22.jpg)
Genghis in Action
![Page 23: Lecture 17: Finite State Machines, Behavior-Based ... › engi128 › Handouts › Lec17-Robotics.pdfthe sensors and controls the robot •Each behavior only does one simple thing](https://reader033.vdocuments.us/reader033/viewer/2022060418/5f15a741f43fb54dd778b5d3/html5/thumbnails/23.jpg)
Subsumption Architecture
R. Brooks. “A robust layered control system for a mobile robot”, ICRA 1986
![Page 24: Lecture 17: Finite State Machines, Behavior-Based ... › engi128 › Handouts › Lec17-Robotics.pdfthe sensors and controls the robot •Each behavior only does one simple thing](https://reader033.vdocuments.us/reader033/viewer/2022060418/5f15a741f43fb54dd778b5d3/html5/thumbnails/24.jpg)
Combining Behaviors
We combine behaviors by overriding, or subsuming lower-priority behaviors if a higher-priority behavior becomes active
Wander
Behavior: move and turn
Follow a robot
Behavior: Follow another robot
Avoid Dark
Behavior: avoid shadow at walls Senso
rs
Actu
ato
rs
S
S
subsume operator
highest priority
lowest priority
![Page 25: Lecture 17: Finite State Machines, Behavior-Based ... › engi128 › Handouts › Lec17-Robotics.pdfthe sensors and controls the robot •Each behavior only does one simple thing](https://reader033.vdocuments.us/reader033/viewer/2022060418/5f15a741f43fb54dd778b5d3/html5/thumbnails/25.jpg)
25
Great, but how to you program this?
You can abstract this a bit more: • Write each behavior as a function that returns a tuple of
(tv, rv, active) • write a beh_subsume(high_priority, low_priority) function that
returns the high_priority or low_priority output, depending on which has active == True
• If neither behavior is active, it returns the INACTIVE_BEH output
INACTIVE_BEH = (False, 0.0, 0.0)
wander_out = wander(foo, bar)
gps_out = gps_navigation(bang, zoom)
obstacle_out = obstacle_avoidance(bif, bop)
beh = beh_subsume(gps_out, wander_out)
beh = beh_subsume(obstacle_out, beh)
velocity.set_tvrv(beh_get_tv(beh), beh_get_rv(beh))
![Page 26: Lecture 17: Finite State Machines, Behavior-Based ... › engi128 › Handouts › Lec17-Robotics.pdfthe sensors and controls the robot •Each behavior only does one simple thing](https://reader033.vdocuments.us/reader033/viewer/2022060418/5f15a741f43fb54dd778b5d3/html5/thumbnails/26.jpg)
26
Great, but how to you program this?
There are several ways: • Write each behavior as a function that returns a tuple of
(active, tv, rv) • Write getters to extract the different parts of the tuple • Use if statements to overwrite the outputs of lower-priority
behaviors
INACTIVE_BEH = (False, 0.0, 0.0)
wander_out = wander(foo, bar)
gps_navigation_out = gps_navigation(bang, zoom)
obstacle_avoidance_out = obstacle_avoidance(bif, bop)
beh = INACTIVE_BEH
if beh_get_active(wander_out):
beh = wander_out
if beh_get_active(gps_navigation_out ):
beh = gps_navigation_out
if beh_get_active(obstacle_avoidance_out):
beh = obstacle_avoidance_out
velocity.set_tvrv(beh_get_tv(beh), beh_get_rv(beh))