vex and robot c
DESCRIPTION
VEX and Robot C. Presented by. Chris Patterson. Modified by J. Andazola. Robot C and Natural Language. Natural Language. In short, Natural Language is a form of C based programming that cuts down on coding and makes things a bit simpler. Natural Language. Example 1. For Example, - PowerPoint PPT PresentationTRANSCRIPT
![Page 1: VEX and Robot C](https://reader035.vdocuments.site/reader035/viewer/2022081503/5681327e550346895d991931/html5/thumbnails/1.jpg)
VEX and Robot C
Chris Patterson
Presented by
Modified by J. Andazola
![Page 2: VEX and Robot C](https://reader035.vdocuments.site/reader035/viewer/2022081503/5681327e550346895d991931/html5/thumbnails/2.jpg)
Robot C and Natural Language
![Page 3: VEX and Robot C](https://reader035.vdocuments.site/reader035/viewer/2022081503/5681327e550346895d991931/html5/thumbnails/3.jpg)
Natural Language
In short, Natural Language is a form of C based programming that cuts down on coding and makes things a bit simpler.
![Page 4: VEX and Robot C](https://reader035.vdocuments.site/reader035/viewer/2022081503/5681327e550346895d991931/html5/thumbnails/4.jpg)
Natural Language
• For Example,– What do you think startMotor(rightMotor, 127);
does?
Example 1
![Page 5: VEX and Robot C](https://reader035.vdocuments.site/reader035/viewer/2022081503/5681327e550346895d991931/html5/thumbnails/5.jpg)
Natural Language - Until
• For example, what might you expect the following to do?
untilTouch(bumpSwitch);
startMotor(leftMotor, 63);
Example 2
![Page 6: VEX and Robot C](https://reader035.vdocuments.site/reader035/viewer/2022081503/5681327e550346895d991931/html5/thumbnails/6.jpg)
EXAMPLE 3
![Page 7: VEX and Robot C](https://reader035.vdocuments.site/reader035/viewer/2022081503/5681327e550346895d991931/html5/thumbnails/7.jpg)
Example 3
• A motor turns on once the bump switch is touched and then turns off once the limit switch is touched.
![Page 8: VEX and Robot C](https://reader035.vdocuments.site/reader035/viewer/2022081503/5681327e550346895d991931/html5/thumbnails/8.jpg)
Basic Output Programming
EXAMPLE 4 • Let’s turn on the rightMotor for 4 seconds and
then off for 4 seconds. Repeat this operation twice.
![Page 9: VEX and Robot C](https://reader035.vdocuments.site/reader035/viewer/2022081503/5681327e550346895d991931/html5/thumbnails/9.jpg)
Basic Output Programming – Example 4
![Page 10: VEX and Robot C](https://reader035.vdocuments.site/reader035/viewer/2022081503/5681327e550346895d991931/html5/thumbnails/10.jpg)
![Page 11: VEX and Robot C](https://reader035.vdocuments.site/reader035/viewer/2022081503/5681327e550346895d991931/html5/thumbnails/11.jpg)
Basic Output Programming
![Page 12: VEX and Robot C](https://reader035.vdocuments.site/reader035/viewer/2022081503/5681327e550346895d991931/html5/thumbnails/12.jpg)
Basic Output Programming – Example 5
• Turn on a motor and then wait 5 seconds. Set servo to position 127 for 3 seconds and then position 96 for 4 seconds.
![Page 13: VEX and Robot C](https://reader035.vdocuments.site/reader035/viewer/2022081503/5681327e550346895d991931/html5/thumbnails/13.jpg)
EXAMPLE 5
• A motor turns on clockwise at full power when the potentiometer is greater than 3000 and turns counterclockwise at full power when the potentiometer is less than 2000.
![Page 14: VEX and Robot C](https://reader035.vdocuments.site/reader035/viewer/2022081503/5681327e550346895d991931/html5/thumbnails/14.jpg)
Example 5
![Page 15: VEX and Robot C](https://reader035.vdocuments.site/reader035/viewer/2022081503/5681327e550346895d991931/html5/thumbnails/15.jpg)
Example 6 - What will this program do?
![Page 16: VEX and Robot C](https://reader035.vdocuments.site/reader035/viewer/2022081503/5681327e550346895d991931/html5/thumbnails/16.jpg)
Basic Output Programming – Example
![Page 17: VEX and Robot C](https://reader035.vdocuments.site/reader035/viewer/2022081503/5681327e550346895d991931/html5/thumbnails/17.jpg)
Natural Language - Until
• The program will wait at the “Until” line of code. Once the condition for that sensor is true, the program continues.
![Page 18: VEX and Robot C](https://reader035.vdocuments.site/reader035/viewer/2022081503/5681327e550346895d991931/html5/thumbnails/18.jpg)
Behavior-Based Programming• A behavior is anything your robot does
– Turning on a single motor or servo
• Three main types of behaviors 1. Complex behaviors – Robot performs a complex
task (automated fan control)
2. Simple behaviors – Simple task performed by the robot (fan stops when sensor activated)
3. Basic behaviors – Single commands to the robot (turn on a motor)
• Complex behaviors can always be broken down into simple behaviors, which are then broken down into basic behaviors
![Page 19: VEX and Robot C](https://reader035.vdocuments.site/reader035/viewer/2022081503/5681327e550346895d991931/html5/thumbnails/19.jpg)
VEX Motion Subsystem – Servos
• Similar in appearance to the 3-wire motor• Very different in operation
– Rotates between 0 and 120 degrees– Motor is set to a “power value” – Servo is set to a “position value”– -127 = 0 degrees, 0 = 60 degrees, 127 = 120
degrees, etc.– Natural Language command
• setServo()
![Page 20: VEX and Robot C](https://reader035.vdocuments.site/reader035/viewer/2022081503/5681327e550346895d991931/html5/thumbnails/20.jpg)
Programming with Sensor Feedback
![Page 21: VEX and Robot C](https://reader035.vdocuments.site/reader035/viewer/2022081503/5681327e550346895d991931/html5/thumbnails/21.jpg)
• Analog Sensors:-Light Sensor
-Potentiometer
-Line follower
• Digital Sensors:-Bumper Switch
-Limit Switch
-Optical Shaft
Encoder
-Ultrasonic Range
Finder
VEX Sensors Subsystem
![Page 22: VEX and Robot C](https://reader035.vdocuments.site/reader035/viewer/2022081503/5681327e550346895d991931/html5/thumbnails/22.jpg)
While and If-Else Loops
![Page 23: VEX and Robot C](https://reader035.vdocuments.site/reader035/viewer/2022081503/5681327e550346895d991931/html5/thumbnails/23.jpg)
While Loops• While loop is a structure within ROBOTC• Allows a section of code to be repeated as
long as a certain condition remains true
• Three main parts to every while loop1. The word “while”
2. The condition
3. Commands to be repeated
![Page 24: VEX and Robot C](https://reader035.vdocuments.site/reader035/viewer/2022081503/5681327e550346895d991931/html5/thumbnails/24.jpg)
The Condition• Condition controls how long or how many
times a while loop repeats– When condition is true, the while loop repeats– When condition is false, the while loop ends and
the remainder of the program executes
• Condition is checked once every time loop repeats before commands between curly braces are run
![Page 25: VEX and Robot C](https://reader035.vdocuments.site/reader035/viewer/2022081503/5681327e550346895d991931/html5/thumbnails/25.jpg)
Revisit Example 1
EXAMPLE 1 • Let’s turn on the rightMotor for 4 seconds and
then off for 4 seconds. Repeat this operation twice.
• Instead of running it twice, let’s loop it continuously. (running it twice would require a variable, and we aren’t there quite yet)
![Page 26: VEX and Robot C](https://reader035.vdocuments.site/reader035/viewer/2022081503/5681327e550346895d991931/html5/thumbnails/26.jpg)
While Loops – Example 1 Revisited
![Page 27: VEX and Robot C](https://reader035.vdocuments.site/reader035/viewer/2022081503/5681327e550346895d991931/html5/thumbnails/27.jpg)
While Loops• The while loop has a true condition so it will
always run. If the condition is always true, you cannot leave the while loop.
• While loops can be based on a sensor condition as well. For example:
![Page 28: VEX and Robot C](https://reader035.vdocuments.site/reader035/viewer/2022081503/5681327e550346895d991931/html5/thumbnails/28.jpg)
While Loops – Using a sensor condition
![Page 29: VEX and Robot C](https://reader035.vdocuments.site/reader035/viewer/2022081503/5681327e550346895d991931/html5/thumbnails/29.jpg)
While Loops – Using Multiple Conditions
![Page 30: VEX and Robot C](https://reader035.vdocuments.site/reader035/viewer/2022081503/5681327e550346895d991931/html5/thumbnails/30.jpg)
While Loop – Timers as ConditionsTimer T1 is used as the condition for the while loop, which will run for 30 seconds
![Page 31: VEX and Robot C](https://reader035.vdocuments.site/reader035/viewer/2022081503/5681327e550346895d991931/html5/thumbnails/31.jpg)
If Statements• If statement in the program is evaluated by condition
contained in parentheses– If condition is true, commands between braces are
run– If condition is false, those commands are ignored
• Very similar to how a while loop works, but does not repeat the code
![Page 32: VEX and Robot C](https://reader035.vdocuments.site/reader035/viewer/2022081503/5681327e550346895d991931/html5/thumbnails/32.jpg)
If-Else Statements
• If-else statement is an expansion of if statement– If checks condition and runs appropriate
commands when it evaluates to true– Else allows code to run when condition is false– Either if or else branch is always run once
![Page 33: VEX and Robot C](https://reader035.vdocuments.site/reader035/viewer/2022081503/5681327e550346895d991931/html5/thumbnails/33.jpg)
If Statements Example
![Page 34: VEX and Robot C](https://reader035.vdocuments.site/reader035/viewer/2022081503/5681327e550346895d991931/html5/thumbnails/34.jpg)
Let’s revisit Example 4• A motor turns on clockwise at full power when
the potentiometer is greater than 3000 and turns counterclockwise at full power when the potentiometer is less than 2000
![Page 35: VEX and Robot C](https://reader035.vdocuments.site/reader035/viewer/2022081503/5681327e550346895d991931/html5/thumbnails/35.jpg)
Example 4 – While loop and If-Else Statements
![Page 36: VEX and Robot C](https://reader035.vdocuments.site/reader035/viewer/2022081503/5681327e550346895d991931/html5/thumbnails/36.jpg)
This is just the beginning…
• You have been given enough tools to go out and EXPLORE on your own time.
• Use the lessons in the PLTW curriculums to try out some of the activities and projects.
![Page 37: VEX and Robot C](https://reader035.vdocuments.site/reader035/viewer/2022081503/5681327e550346895d991931/html5/thumbnails/37.jpg)
Questions?