Robot Programming Programming Behaviors Behaviors describe the actions
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 • Let you describe a full action of the robot Turn motor A on forwards Turn motor C on forwards Get touch sensor reading from Port 1 Turn motor A on backwards Simple Behavior Go forward until you hit a wall and then turn Compare sensor reading to constant 0 Turn motor C on forwards 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 Drive forward Stop when you hit a wall Turn right Drive forward Complex Behavior Navigate a maze Stop when you hit a wall Turn left Turn right Stop when you hit a wall Drive forward
Flowcharts • Visually organizes steps in different shaped bubbles • Good way to work out steps before you translate them into code No Start Drive forward Have you hit a wall? Yes Stop motors End
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 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. Have you hit a wall? Yes Stop motors Decision Block — A decision point in your program. Ask a simple question, and do different things depending on the answer. End Yes/No (also True/False, etc. ) — Answers to the question posed in the decision block. Follow the line labeled with the appropriate answer.
Flowcharts What does this flowchart describe? Filling a tire No Start Pump air Tire at rated pressure? What about this one? Start Stop Motors Touch sensor pushed? No Yes End Go when touch sensor is pushed Yes Start motors End
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? 1. Move forward until the touch sensor is pressed 2. Stop all motors 3. Reverse for 1 second 4. Stop all motors 5. 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
- Slides: 11