1 / 24

Reactions and Behavior Control

Reactions and Behavior Control. Dr. Paige H. Meeker. Programming. Programming is all about learning how to direct the computer. You are telling the computer what to do, step by step, and receiving its responses. What is programming?. Programming. Receive a problem UNDERSTAND the problem

vic
Download Presentation

Reactions and Behavior Control

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Reactions and Behavior Control Dr. Paige H. Meeker

  2. Programming Programming is all about learning how to direct the computer. You are telling the computer what to do, step by step, and receiving its responses. What is programming?

  3. Programming • Receive a problem • UNDERSTAND the problem • Formulate a solution (in English) • CODE the solution • TEST the solution • Fix the code • Test again!

  4. Simple Reactions… • Using the sensors on our robots allow us to program using the robots reactions to the input it is receiving from the sensors. • Simple, reactive, behaviors follow a pattern to create in a robot: while timeRemaining(<seconds>): <sense> <decide and then act>

  5. Simple Reactions… • Using the light sensors, the robot can detect varying light conditions in its environment. How would you write a program to detect bright light and orient the robot toward it? • Pseudocode: • for some amount of time… • If the left light is brighter than the right light, turn left • Otherwise, turn right

  6. Reactive Behaviors to Implement • Refrigerator Detective • Burglar Alarm • Wall Detector • Hall Monitor • “Head Toward the Light…” • Cockroach

  7. Reactive Behaviors to Implement • Refrigerator Detective • Ever wonder if the refrigerator light is always on? • Design a refrigerator detective robot that sits inside the fridge and tells you if the light is on or off. • Burglar Alarm • Watch your door. When the door opens, sound an alarm. • Wall Detector • Write a program that sends the robot straight until it senses a wall in front of it. Have it stop when it senses the wall.

  8. Reactive Behaviors to Implement • Hall Monitor • Write a program that sends the robot in a square through a hallway such that it doesn’t hit the wall. • “Head Toward the Light” • Your robot is seeking light and moving towards bright light at all times. • Cockroach • The light comes – the robot runs and hides in the darkest area possible!

  9. Reactive Programming • There is a basic outline for reactive-based programming: # some loop structure #sense and transform sensor values #reason/decide what to do next #do it

  10. Reactive Programming • Works well for simple tasks • Also called “Direct Control” • Purely sensor driven • Sensors drive the logic, not the goals of the task

  11. Behavior-based Control • What if you need to check on multiple sensors and do different things based on what those sensors are telling you? • In behavior-based programming, you don’t rely only on sensors – you design your programs based on the number and kinds of behaviors your robot needs to do.

  12. Behavior Example • Three behaviors to have our robots work with: • Cruise (keep moving) • Seek Light (if present) • Avoid Obstacles • For behavior based programming: • Define each of these as a separate unit. • Create a control program to decide between each unit • How do we design this?

  13. Behavior Program

  14. Behavior Program • Each of the three behaviors outputs three pieces of information (or a “triple”) of the following format: “yes/no” , translateSpeed , rotateSpeed • “Yes” implies that the unit has information and “no” implies that it does not. • Once each unit has reported, the control program needs to decide which to listen to – it needs an arbitrator!

  15. Behavior Program – The Arbitrator • There are lots of different arbitration schemes – our text uses a priority based scheme. Each behavior is assigned a priority and the arbitration program chooses the recommendation from the unit with the highest priority. • How do we write it?

  16. Behavior.py • Set some initial values: cruiseSpeed = 0.8 turnSpeed = 0.8 lightThresh = 80

  17. Behavior.py • Define each behavior unit – what does it decide and what does it return? def cruise(): # is always ON, just move forward return(True, -cruiseSpeed, 0)

  18. Behavior.py • Define each behavior unit – what does it decide and what does it return? def avoid(): # see if there are obstacles L, R = getIR() L = 1 - L R = 1 - R if getStall(): forward(cruiseSpeed,1) if L and R : return(True, 0, turnSpeed) elif (L): return(True, -cruiseSpeed, -turnSpeed) elif R: return(True, -cruiseSpeed, turnSpeed) else: return(False,0,0)

  19. Behavior.py • Define each behavior unit – what does it decide and what does it return? def seekLight(): L, C, R = getLight() if L < lightThresh: return(True, -cruiseSpeed/2.0, -turnSpeed) elif R < lightThresh: return(True, -cruiseSpeed/2.0, turnSpeed) else: return(False, 0, 0)

  20. Behavior.py • After the behaviors are defined, we need to construct a list of them, with the highest priority listed first. behaviors = [seekLight, avoid, cruise]

  21. Behavior.py • Our “arbitrator” is a simple function that queries each behavior in order of priority to see if it has a recommendation. The first one that does returns that recommendation. def arbitrate(): for behavior in behaviors: output, T, R = behavior() if output: return(T,R)

  22. Behavior.py • Finally, a simple main function will call our arbitrator and applies the values returned to the robot. def main(): while timeRemaining(30): T, R = arbitrate() move(T, R)

  23. Names and Return Values • Names can hold many different values – we’ve learned that they can represent numbers, Strings, pictures, or lists. • In the behavior.py program, the name “behaviors” is used to represent the name of each function as a list of values, in order of priority. • In the arbitrate function, a for loop is used to call each successive function and return the first one that returns a true output value.

  24. Calling Functions • Note: there is no function named “behavior()” in the program. Since the value of behavior is set to each successive function, the corresponding function is invoked as the for loop progresses.

More Related