130 likes | 270 Views
Robot Programming. Programming Behaviors. Behaviors describe the actions and decisions of your robot. Basic Behaviors. Individual, bite-size functions that your robot performs directly. Basic Behavior Turn motor A on forwards. Simple Behaviors. Built of several basic behaviors
E N D
Programming Behaviors • Behaviors describe the actions and decisions of your robot
Basic Behaviors • Individual, bite-size functions that your robot performs directly Basic Behavior Turn motor A on forwards
Simple Behaviors • Built of several basic behaviors • Let you describe a full action of the robot Turn motor A on backwards Simple Behavior Go forward until you hit a wall and then turn Turn motor A on forwards Turn motor C on forwards Turn motor C on forwards Get touch sensor reading from Port 1 Compare sensor reading to constant 0 Turn off motors A & C
Complex Behaviors • Describe the full scope of what the robot can do • Always composed of smaller behaviors, so you can break them down Turn right Drive forward Complex Behavior Navigate a maze Stop when you hit a wall Stop when you hit a wall Turn right Drive forward Turn left Drive forward Stop when you hit a wall
No Start End Yes Have you hit a wall? Flowcharts • Visually organizes steps in different shaped bubbles • Good way to work out steps before you translate them into code Drive forward Stop motors
Have you hit a wall? Flowcharts End of Program - Marks the end of the program. If you reach this point, the program is done! • Parts of a Flowchart No Start Drive forward Stop motors End Yes Start of Program — Marks the beginning of the program. Begin here. Follow the line to get to the next block. Statement Block — A statement to execute,or a behavior to perform. Yes/No (also True/False, etc.) — Answers to the question posed in the decision block. Follow the line labeled with the appropriate answer. Decision Block — A decision point in your program. Ask a simple question, and do different things depending on the answer.
Start Start End End Touch sensor pushed? Flowcharts What does this flowchart describe? Filling a tire No Yes Tire at rated pressure? Pump air What about this one? Go when touch sensor is pushed Yes Stop Motors Start motors No
Pseudocode • Halfway inbetween English and computer code • Describe what sensors and motors do and see with simple behaviors
Pseudocode What behavior does this pseudocode describe? • Move forward until the touch sensor is pressed • Stop all motors • Reverse for 1 second • Stop all motors • Turn right Back up when you hit a wall and turn right
Review • Basic behaviors are actions the robot performs directly • Simple behaviors are actions like we think about them • Complex behaviors describe more interesting functions of the robot • Flowcharts organize the steps • Pseudocode describes the steps using the robot’s motors and sensors