programming design robotc software © 2012 project lead the way, inc.principles of engineering
TRANSCRIPT
![Page 1: Programming Design ROBOTC Software © 2012 Project Lead The Way, Inc.Principles of Engineering](https://reader035.vdocuments.mx/reader035/viewer/2022062408/56649ef25503460f94c04446/html5/thumbnails/1.jpg)
Programming Design
ROBOTC Software
© 2012 Project Lead The Way, Inc.Principles of Engineering
![Page 2: Programming Design ROBOTC Software © 2012 Project Lead The Way, Inc.Principles of Engineering](https://reader035.vdocuments.mx/reader035/viewer/2022062408/56649ef25503460f94c04446/html5/thumbnails/2.jpg)
Behavior-Based Programming• A behavior is anything your robot does
– Example: Turn on a single motor or servo
• Three main types of behavior – Complex behavior: Robot performs a complex task
Example: automate fan control– Simple behavior: Robot performs a simple task
Example: fan stops when sensor is activated– Basic behavior: Single command to a robot
Example: start a motor
• Complex behaviors are broken down into simple behaviors, which are broken down into basic behaviors
![Page 3: Programming Design ROBOTC Software © 2012 Project Lead The Way, Inc.Principles of Engineering](https://reader035.vdocuments.mx/reader035/viewer/2022062408/56649ef25503460f94c04446/html5/thumbnails/3.jpg)
Complex Behaviors
• Describe a task or overall goal that a program will accomplish– A fan runs until someone needs it
to stop.– A safety device warning light turns
on before a fan turns on.– Another light indicates that a fan
has stopped.• This can be described as one or
more complex behaviors
![Page 4: Programming Design ROBOTC Software © 2012 Project Lead The Way, Inc.Principles of Engineering](https://reader035.vdocuments.mx/reader035/viewer/2022062408/56649ef25503460f94c04446/html5/thumbnails/4.jpg)
Creating Pseudocode
• Break down behaviors into individual actions
• Do not be concerned about syntax or which commands will be used with ROBOTC
• Simply describe them in short phrases• Example
– Turn a motor on for three seconds– Follow a line until it runs into a wall
![Page 5: Programming Design ROBOTC Software © 2012 Project Lead The Way, Inc.Principles of Engineering](https://reader035.vdocuments.mx/reader035/viewer/2022062408/56649ef25503460f94c04446/html5/thumbnails/5.jpg)
Simple Behaviors
• Break each complex behavior down into simple behaviors
• List simple behaviors line by line in the correct sequence
• Describe actions and the prompt for each action to start
![Page 6: Programming Design ROBOTC Software © 2012 Project Lead The Way, Inc.Principles of Engineering](https://reader035.vdocuments.mx/reader035/viewer/2022062408/56649ef25503460f94c04446/html5/thumbnails/6.jpg)
Creating Pseudocode
• Example– Warning light turns on before the fan starts for
three seconds– Fan turns on and runs until a button is
pressed– A different light turns on for three seconds
before the program stops
![Page 7: Programming Design ROBOTC Software © 2012 Project Lead The Way, Inc.Principles of Engineering](https://reader035.vdocuments.mx/reader035/viewer/2022062408/56649ef25503460f94c04446/html5/thumbnails/7.jpg)
Basic Behaviors
• Break each simple behavior down further into basic behaviors
• Write in terms of the input and output relative to the device
![Page 8: Programming Design ROBOTC Software © 2012 Project Lead The Way, Inc.Principles of Engineering](https://reader035.vdocuments.mx/reader035/viewer/2022062408/56649ef25503460f94c04446/html5/thumbnails/8.jpg)
Creating Pseudocode
• Example– Program starts– Light 1 (LED 1) turns on for three seconds– Fan (Motor 1) turns on until a button (bumper
switch) is pressed– Light 2 (LED 2) turns on for 3 seconds– Program ends
![Page 9: Programming Design ROBOTC Software © 2012 Project Lead The Way, Inc.Principles of Engineering](https://reader035.vdocuments.mx/reader035/viewer/2022062408/56649ef25503460f94c04446/html5/thumbnails/9.jpg)
Identify Inputs and Outputs
• Identify the ports by which each input and output will be connected to the Cortex
• Be conscious which sensors are analog and which are digital
• Label a planning diagram
![Page 10: Programming Design ROBOTC Software © 2012 Project Lead The Way, Inc.Principles of Engineering](https://reader035.vdocuments.mx/reader035/viewer/2022062408/56649ef25503460f94c04446/html5/thumbnails/10.jpg)
PLTW ROBOTC Program Template
• Open Sample Program PLTWtemplate• Enter an initial task description of the
overall program goal in terms of complex behaviors
• Enter pseudocode in terms of basic behaviors in the pseudocode section of the PLTW ROBOTC program template
![Page 11: Programming Design ROBOTC Software © 2012 Project Lead The Way, Inc.Principles of Engineering](https://reader035.vdocuments.mx/reader035/viewer/2022062408/56649ef25503460f94c04446/html5/thumbnails/11.jpg)
PLTW ROBOTC Program Template
![Page 12: Programming Design ROBOTC Software © 2012 Project Lead The Way, Inc.Principles of Engineering](https://reader035.vdocuments.mx/reader035/viewer/2022062408/56649ef25503460f94c04446/html5/thumbnails/12.jpg)
Program Design
• Enter label for inputs and outputs in the Motors and Sensors Setup window and change drop down to identify
• Use the Program Debugger to confirm that all inputs and outputs are working as expected
![Page 13: Programming Design ROBOTC Software © 2012 Project Lead The Way, Inc.Principles of Engineering](https://reader035.vdocuments.mx/reader035/viewer/2022062408/56649ef25503460f94c04446/html5/thumbnails/13.jpg)
Motor 2 for 5 Seconds
![Page 14: Programming Design ROBOTC Software © 2012 Project Lead The Way, Inc.Principles of Engineering](https://reader035.vdocuments.mx/reader035/viewer/2022062408/56649ef25503460f94c04446/html5/thumbnails/14.jpg)
Motor 2 for 5 Seconds
All commands belonging to task main must be in between these curly braces.
![Page 15: Programming Design ROBOTC Software © 2012 Project Lead The Way, Inc.Principles of Engineering](https://reader035.vdocuments.mx/reader035/viewer/2022062408/56649ef25503460f94c04446/html5/thumbnails/15.jpg)
Motor 2 for 5 Seconds
![Page 16: Programming Design ROBOTC Software © 2012 Project Lead The Way, Inc.Principles of Engineering](https://reader035.vdocuments.mx/reader035/viewer/2022062408/56649ef25503460f94c04446/html5/thumbnails/16.jpg)
Motor 2 for 5 Seconds
![Page 17: Programming Design ROBOTC Software © 2012 Project Lead The Way, Inc.Principles of Engineering](https://reader035.vdocuments.mx/reader035/viewer/2022062408/56649ef25503460f94c04446/html5/thumbnails/17.jpg)
Motor 2 for 5 Seconds
Stops the port2 rightMotor.
End Result: rightMotor spins for 5.0 seconds
![Page 18: Programming Design ROBOTC Software © 2012 Project Lead The Way, Inc.Principles of Engineering](https://reader035.vdocuments.mx/reader035/viewer/2022062408/56649ef25503460f94c04446/html5/thumbnails/18.jpg)
Program Design
• Generally basic behaviors combine to create a complex behavior
• Troubleshoot basic behaviors individually as method of troubleshooting a complex behavior
![Page 19: Programming Design ROBOTC Software © 2012 Project Lead The Way, Inc.Principles of Engineering](https://reader035.vdocuments.mx/reader035/viewer/2022062408/56649ef25503460f94c04446/html5/thumbnails/19.jpg)
Program Design
• Create code and test small behaviors or sets of behaviors individually
• Edit or add comments as you build code
![Page 20: Programming Design ROBOTC Software © 2012 Project Lead The Way, Inc.Principles of Engineering](https://reader035.vdocuments.mx/reader035/viewer/2022062408/56649ef25503460f94c04446/html5/thumbnails/20.jpg)
Program Design
• Continue programming while testing individual behaviors
• Temporarily turn sections of code into comments using /* followed by */
![Page 21: Programming Design ROBOTC Software © 2012 Project Lead The Way, Inc.Principles of Engineering](https://reader035.vdocuments.mx/reader035/viewer/2022062408/56649ef25503460f94c04446/html5/thumbnails/21.jpg)
Program Design
• Sections of code can also be temporarily turned into comments using Toggle Comment under the Edit and Code Formatting menus
![Page 22: Programming Design ROBOTC Software © 2012 Project Lead The Way, Inc.Principles of Engineering](https://reader035.vdocuments.mx/reader035/viewer/2022062408/56649ef25503460f94c04446/html5/thumbnails/22.jpg)
Sample Programs
![Page 23: Programming Design ROBOTC Software © 2012 Project Lead The Way, Inc.Principles of Engineering](https://reader035.vdocuments.mx/reader035/viewer/2022062408/56649ef25503460f94c04446/html5/thumbnails/23.jpg)
ROBOTC Natural Language
• Language developed especially for PLTW• Lines of code for common robot behaviors
are consolidated into single commands– forward();– lineTrackforTime();– stop();– untilBump();
![Page 24: Programming Design ROBOTC Software © 2012 Project Lead The Way, Inc.Principles of Engineering](https://reader035.vdocuments.mx/reader035/viewer/2022062408/56649ef25503460f94c04446/html5/thumbnails/24.jpg)
ROBOTC Natural Language
Natural Language is a ROBOTC Platform Type
![Page 25: Programming Design ROBOTC Software © 2012 Project Lead The Way, Inc.Principles of Engineering](https://reader035.vdocuments.mx/reader035/viewer/2022062408/56649ef25503460f94c04446/html5/thumbnails/25.jpg)
ROBOT Motion
Commands that cause the entire robot to perform a behavior
![Page 26: Programming Design ROBOTC Software © 2012 Project Lead The Way, Inc.Principles of Engineering](https://reader035.vdocuments.mx/reader035/viewer/2022062408/56649ef25503460f94c04446/html5/thumbnails/26.jpg)
Movement
Commands that allow control of individual motors or servos
![Page 27: Programming Design ROBOTC Software © 2012 Project Lead The Way, Inc.Principles of Engineering](https://reader035.vdocuments.mx/reader035/viewer/2022062408/56649ef25503460f94c04446/html5/thumbnails/27.jpg)
Motor Reversal
• Reversing motor polarity– Check Reverse in Motors and Setup– Change speed + / - in program
startMotor(rightMotor, 63); startMotor(rightMotor, -63);
![Page 28: Programming Design ROBOTC Software © 2012 Project Lead The Way, Inc.Principles of Engineering](https://reader035.vdocuments.mx/reader035/viewer/2022062408/56649ef25503460f94c04446/html5/thumbnails/28.jpg)
Special
Commands that control unique VEX® Hardware: LEDs and Flashlights
![Page 29: Programming Design ROBOTC Software © 2012 Project Lead The Way, Inc.Principles of Engineering](https://reader035.vdocuments.mx/reader035/viewer/2022062408/56649ef25503460f94c04446/html5/thumbnails/29.jpg)
Until
Commands that allow behaviors to be created for the robot to perform until an event occurs such as:– Button Press– Encoder Count
Reached
![Page 30: Programming Design ROBOTC Software © 2012 Project Lead The Way, Inc.Principles of Engineering](https://reader035.vdocuments.mx/reader035/viewer/2022062408/56649ef25503460f94c04446/html5/thumbnails/30.jpg)
Wait
Commands that wait for an amount of time measured in seconds or milliseconds
![Page 31: Programming Design ROBOTC Software © 2012 Project Lead The Way, Inc.Principles of Engineering](https://reader035.vdocuments.mx/reader035/viewer/2022062408/56649ef25503460f94c04446/html5/thumbnails/31.jpg)
Wait States Accuracy
• Motor Speed is affected by battery power– Motors rotate faster when using a fully
charged battery– Motors rotate slower when using a partially
depleted battery– Device or robot does not move consistently as
the battery power drains
![Page 32: Programming Design ROBOTC Software © 2012 Project Lead The Way, Inc.Principles of Engineering](https://reader035.vdocuments.mx/reader035/viewer/2022062408/56649ef25503460f94c04446/html5/thumbnails/32.jpg)
Touch Sensors• Digital sensor
– Pressed = 1 and Released = 0• Caution
– When sensor is pressed or released, its value may rapidly bounce between 0 and 1 briefly
– A brief wait command can reduce the bounce effect
![Page 33: Programming Design ROBOTC Software © 2012 Project Lead The Way, Inc.Principles of Engineering](https://reader035.vdocuments.mx/reader035/viewer/2022062408/56649ef25503460f94c04446/html5/thumbnails/33.jpg)
References
Carnegie Mellon Robotics Academy. (2011). ROBOTC. Retrieved from http://www.robotc.net