1 / 19

Conditions and Reactions

Conditions and Reactions. Dr. Paige H. Meeker Chapter 6. R E M E M B E R ? ? ?. Reminder - Python’s Senses. To get a quick, overall look at the behavior of the senses of the robot’s sensors, use the Myro function “senses()”

karl
Download Presentation

Conditions and Reactions

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. Conditions and Reactions Dr. Paige H. Meeker Chapter 6

  2. R E M E M B E R ? ? ?

  3. Reminder - Python’s Senses • To get a quick, overall look at the behavior of the senses of the robot’s sensors, use the Myro function “senses()” • You will see the results of all the sensor calls in real time (except the camera)

  4. Moving the Robot • Using the sensors and the motors, we can make the robot move. We can also give some conditions of movement using the if statement. Let’s explore “if” some more.

  5. This, That, or the Other if <condition>: <this> Depending on what condition is true, <this>is carried out. If not, <this> never happens

  6. This, That, or the Other if <condition>: <this> else: <that> If condition is true, <this> is carried out. If not, then <other> will be carried out.

  7. This, That, or the Other if <condition>: <this> elif <condition>: <that> else: <other> Depending on what condition is true, <this>, or <that> is carried out. If no conditions are true, then <other> will be carried out.

  8. This, That, or the Other if <condition>: <this> elif <condition>: <that> elif <condition>: <something else> else: <other> Depending on what condition is true, <this>, <that>, or <something else>. If no conditions are true, then <other> will be carried out.

  9. Simple Reactions… • Simple, reactive, behaviors follow a pattern to create in a robot: while timeRemaining(<seconds>): <sense> <decide and then act> OR while <light sensors are within a given range>: <sense> <decide and then act>

  10. 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

  11. Head Toward the Light… Using the three light sensors the robot can detect varying light conditions in its environment. Let us write a robot program that makes it detect and orient towards bright light.

  12. Pseudocode – Describes Behavior, doesn’t Work (More for Planning Purposes) do for a given amount of time if left light is brighter than right light turn left else turn right Sort of like your outline for a paper.

  13. Still Pseudocode, but Closer to Actual Code while timeRemaining(30): if left light is brighter that right light: turnLeft(1.0) else: turnRight(1.0) Sort of like your rough draft for a paper.

  14. Where would this go? • getLight('left') < getLight('right') • How would you write a complete program that implements the above behavior and test it on your robot?

  15. Code to turn toward light (with a thresh hold added) thresh = 50 while timeRemaining(30): # Get sensor values for left and right light sensors L = getLight('left') R = getLight('right') # decide how to act based on sensors values if (L - R) > thresh: # left is seeing less light than right so turn right turnRight(1.0) elif (R - L) > thresh: # right is seeing less light than left, so turn left turnLeft(1.0) else: # the difference is less than the threshold, stay put stop()

  16. Things to Try… • Type in the “light following” code on p. 147 of your text. • Type in and try the “obstacle” code on p. 149 of your text. http://cs.brynmawr.edu/~dkumar/Myro/Text/June09/PDF/Chapter6.pdf • NOTE: Sometimes the textbook code does not work as you may think it should – how can you alter the code to make it do what you want?

  17. Reactive Behaviors to Implement • Refrigerator Detective • Burglar Alarm • Wall Detector • Hallway Cruiser

  18. 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. • Hallway Cruiser • Imagine the robot is in a walled corridor going around a 2ft by 2ft square box. Write a program that will enable the robot to go around the box.

  19. Assignment Navigating Mazes Due Thursday, November 4th HINT: There’s code to help you in chapter 6. “Plus it” to get your robot to work the best!

More Related