Download presentation
Presentation is loading. Please wait.
1
ROBOTC for CORTEX
2
Thinking about Programming
ROBOTC Overview Thinking about Programming
3
Background Information
ROBOTC is developed specifically with teachers, classrooms, and competitions in mind Complete programming solution for the VEX PIC, VEX Cortex, and several other popular robot platforms Only programming language for the VEX PIC and VEX Cortex with a real-time debugger You’ll learn more about this feature later on Very similar to industry-standard C programming Students get real-world programming experience Trainer Notes: The next few slides are meant to highlight features in ROBOTC that will help trainees succeed as they program and answer their own questions.
4
Industry Standard Skillsets
Java and C++, along with the Eclipse and Visual Studio IDE’s have been used to program: Microsoft Windows Mac OSX US Navy UAV Drones Flight Simulators DVD Player Firmware Video Games Microwaves CAT Scanners Smart Cars Satellites Cell Phones Electronic Toys ROBOTC! Much, much more!
5
ROBOTC Features
6
Platform Type Trainer Notes: The next few slides are meant to highlight features in ROBOTC that will help trainees succeed as they program and answer their own questions. When beginning to work with ROBOTC, one of the first things users should check is that their Platform Type matches up with the microcontroller they are using. Doing so will enable menu options and ROBOTC commands specifically for that microcontroller. Allows you to toggle ROBOTC’s programming mode between the VEX PIC and VEX Cortex, will enable features and commands for the system
7
ROBOTC Start Page Trainer Note: PLTW build of ROBOTC now has a special page dedicated to PLTW schools! Displays the latest ROBOTC news, version of ROBOTC, and ROBOTC Resources
8
Sample Programs Trainer Notes: One of the easiest ways to begin programming is to start with existing code, try it out, and then modify it. Mention that all of the ROBOTC sample programs have “comments” that tell how the robot should be configured, and how it will behave when the program runs. Over 75 Included ROBOTC Sample programs, organized by robot behavior
9
ROBOTC Help In-depth explanations about the ROBOTC interface, commands, debugger, etc
10
Function Library Lists the available functions, with a description.
List of available functions will expand or shrink depending on the “Menu Level”
11
Menu Level Customizes the ROBOTC interface and Function Library based on the user’s experience level
12
Motors and Sensor Setup
One central place to configure and name all of the motors and sensors attached to your Cortex
13
VEX Cortex Download Method
Allows you to specify: How programs are downloaded Whether the Cortex looks for a VEXnet connection when it starts up “Download Using VEXnet or USB” is always the safe choice, but the Cortex will look for a VEXnet connection for up to10 seconds before running code
14
Planning and Behaviors
Program Planning Trainer Notes: The following slides detail program planning. At this point the Program Planning doc can be distributed or referenced during the training. All group exercises should follow the program planning steps to get in the habit of following it. Planning and Behaviors
15
Behavior Based Programming
A behavior is anything your robot does: turning on a single motor, moving forward, tracking a line, navigating a maze Three main types of behaviors: basic behaviors – single commands to the robot (turn on a motor) simple behaviors – simple task performed by the robot (move forward, track a line) and complex behaviors – robot performs a complex task (solve the maze) Complex behaviors can always be broken down into simple behaviors, which are then broken down into basic behaviors Trainer notes: Supplementary printouts found in the Fundamentals > Introduction to Programming section can be printed and handed outs.
16
The Labyrinth Challenge
Trainer Notes: Introduce the Labyrinth challenge as a possible programming challenge. Additional challenge description / schematic can be found in the VEX Cortex Video Trainer > Movement > Challenge Description Section. This can be printed and handed out, if desired. The Labyrinth was chosen for this example because it allows for a very simple, visual representation of the topics. Things like the PLTW Material Sorter could also be discussed, as that would resonate well with the PLTW network.
17
The Labyrinth Challenge
Trainer notes: this is the path the robot will have to take to complete the labyrinth, broken down from a complex behavior, into simple behaviors
18
Programming Discussion
The Challenge: The Labyrinth The Solution: ??? The Programmer’s (your) Role Plan out the robot’s path / actions - Pseudocoding Understanding Program Flow and Behavior Based Programming Translate the Pseudocode into real code The Robot’s role To carry out your instructions! The Solution: Programmer and Robot working together, fulfilling their roles True for all robotic challenges!
19
Comments Comments are used to make notes in code for the human programmers Every sample program contains comments pertaining to robot configuration, ROBOTC commands, robot behavior, etc // Single line comment – everything after “//” is ignored by the ROBOTC compiler /* Multi-line comment*/ - everything between the “/*” and “*/” symbols is ignored by the ROBOTC compiler
20
Pseudocode Pseudocode is a shorthand notation for programming which uses informal programming structures (if touch1 is pressed…) verbal descriptions of code (move forward, stop) Emphasis is placed on expressing the behavior or outcome of each portion of code rather than on correct syntax (it should be reasonable, though). Your lines of Pseudocode should also be listed in the same order as they will appear in the ROBOTC Program
21
Pseudocode Sample Pseudocode:
22
Pseudocode Additional Details:
Pseudocode is used to outline a program before translating it into proper syntax. Helps in the initial planning of a program, by creating the logical framework and sequence of the code. An additional benefit is that it can be translated into different programming languages and is therefore somewhat universal.
23
Putting it all Together
Effective Program Planning is essential to writing correct code. Carrying out that plan is equally important! Once you have your plan, don’t try to implement it all at once! Systematically add sections of code, testing at every step!
24
Behavior Based Programming Additional Resources
25
Trainer Notes: Introduce the VEX Cortex Video Trainer – Designed to teach behavior based programming using ROBOTC and the VEX Cortex
26
VEX Cortex Video Trainer (VCVT) (In Development)
45 tutorial videos (60+ planned) teach step-by-step how to program using ROBOTC and the Cortex system 75+ pages of supplementary “helper guides” 40+ programming challenges Freely available at
27
Trainer Notes: This is how you can get to the VEX Cortex Video Trainer
28
Behavior Based Programming
Trainer Notes: These videos can be watched as a group, with speakers, or at individual stations if there are headphones. Do not have the class watch it at individual stations with speakers – too much noise. ROBOTC Rules Part 1 and 2 can also be watched and are valuable for programming information.
29
ROBOTC “Natural Language”
30
ROBOTC Natural Language
New, developed specifically for PLTW Goal is to lower the barrier of entry into syntax-based programming by simplifying the code and using more “natural” command names Lines of code for common robot behaviors are consolidated into single commands forward(); lineTrackforTime(); stop(); untilBump();
31
ROBOTC Natural Language
The Natural Language is an additional Platform Type in ROBOTC:
32
ROBOT Motion Commands that cause the entire robot to perform a behavior
33
Setup Allows you to specify what type of robot configuration you have from pre-specified models (RECBOT, Swervebot)
34
Movement Commands that allow you to control individual motors / servos
35
Special Commands that control the more unique VEX Hardware – LED’s and Flashlights
36
Until Commands that allow you to create behaviors where the robot acts “until” a certain event Button Press Encoder Count Reached
37
Wait Commands that wait for an elapsed amount of time in seconds or milliseconds
38
Sample Programs
39
Moving Forward and Backward
40
PLTW Template
41
PLTW Template Top comment section for students to fill their personal information, as well as program planning work. Section between lines 18 and 21 is designated for the actual program.
42
Testbed Overview
43
GTT Testbed
44
VEX Cortex Microcontroller
VEX Cortex (VEX 2.0) 12 digital ports Touch Sensor, Ultrasonic Rangefinder, Shaft Encoders 8 analog inputs Light Sensors, Line Tracking Sensors, Potentiometers, Accelerometers, Gyroscope 10 motor ports 8 standard 3-wire PWM 2 new 2-wire motor ports Built-In VEXnet Connection Enables Wireless Programming, Wireless Debugging, and Remote Control Two UART Ports (Serial) LCD Screen, Other External Devices One I2C port Will connect to multiple new smart sensors Trainer Notes: Quick overview of the system, for new trainees. Items in BOLD are included in GTT kit.
45
Download Firmware
46
Download Firmware
47
Troubleshooting Computer will not Recognize the Cortex
Was the correct startup sequence followed when connecting the Cortex to the computer? Is the connected battery sufficiently charged? Does the Cortex need to be power cycled? Try another USB port on the computer. Make sure that your computer allows for “new hardware” to be connected. Extremely locked down computers may prohibit new hardware such as the VEX Cortex from being connected.
48
Motors and Sensors Setup
Open the PLTW Template Save the file as “testbed default” Go to Motors and Sensors Setup
49
Motors and Sensors Setup
The Motors and Sensor Setup window allows you to give your motors and sensors custom names. The names, however: Should be descriptive of the sensor or motor they refer to (rightMotor, frontBumper, ect.) Must be all one word made up of letters, numbers, and spaces Must contain no special characters (&, $, /, ect.) Cannot already be a ROBOTC reserved word (task, motor, true)
50
Motors and Sensors Setup
51
Motors and Sensors Setup
52
Motors and Sensors Setup
53
Debugger Window Power on the Cortex.
View motor and sensor debugger windows. Click Robot. Click Compile and Download Program. Click Robot, Debug Windows, then Motors Click Robot, Debug Windows, then Sensors Increase the debugger window area at the bottom Note that this window can be viewed any time by clicking Robot then Debugger.
54
Debugger Window
55
Debugger Window Test the motors and sensors and watch the effect in the debugger window.
56
ROBOTC Basics Part 1 Part 2
57
Basic Programming: Motor and Wait Commands
58
VEX Motors 3 Main Types: Original 3-wire motor Newer 2-wire motor 269 Newer 2-wire motor 393 All motors are programmed the same way in ROBOTC Accept values between 127 (full forward) and -127 (full reverse) GTT kits only contain the 2-wire motor 269
59
Connecting the Motors Two-wire motors can be plugged directly into MOTOR ports 1 & 10 on the Cortex, and 2-9 using the Motor Controller 29 Zip tie wires together to prevent loose connections
60
Let’s write a program! Step 1 – complete project information and pseudocode. Sample Program 1 PLTW 5/22/11 Period 3 Turn on one motor for 5 seconds. Turn right motor on Wait 5 seconds Turn right motor off
61
Motor 2 on for 5 Seconds Displays configuration changes from the Motors and Sensors Setup Defines the “main task” of the robot All commands belonging to task main must be in-between these curly braces
62
Motor 2 on for 5 Seconds Turns the port2 rightMotor on at half power forward
63
Motor 2 on for 5 Seconds Causes the robot to wait here in the program for 5.0 seconds
64
Motor 2 on for 5 Seconds End Result: rightMotor spins for 5.0 seconds.
Trainer Notes: Draw attention to which lines have semicolons at the end, and which don’t. This will be important when we hit while loops and if statements. In general, single commands or statements get semicolons. Things that change the flow or structure of a program do not get semicolons. Stops the port2 rightMotor. End Result: rightMotor spins for 5.0 seconds.
65
Let’s write a program! Sample Program 1 PLTW 5/22/11 Period 3
Turn on one motor for 5 seconds. Turn right motor on Wait 5 seconds Turn right motor off
66
Quick ROBOTC Exercise Create this program yourself and download it to the Robot Using the Program Debug Window Making Changes to a Sample Program Turn on leftMotor – Download and watch result Reverse both motors – Download and watch result Trainer Notes: This slide is meant to be a class activity, for trainees to actually get some guided experience with the ROBOTC interface, ROBOTC Commands, Cortex system, ect. The steps should be: Open ROBOTC Verify the Platform Type is set to Cortex Natural Language Library Create the Program Connect the Cortex to the Computer (via USB or VEXnet) Turn on the Cortex Go to Robot > Compile and Download Program Run the program – Observe the testbed Turn on leftMotor in the program, after rightMotor and before the wait command (left motor should also be turned off after the wait command). Compile and Download the Program Run the Program – observe the testbed Reverse the motor powers for both motors Download and run the program – observe the motors spinning in the other direction.
67
Renaming and Reversing
Robot > Motors and Sensors Setup Optional with Motors (not Sensors) Giving Motors custom names Reversing motor polarity Trainer Notes: Recbot needs to have Port 2 reversed, but Swervebot needs Port 3 reversed. No Reversal needed with Testbed.
68
Motor Exercises Turn the rightMotor on forward at half speed for 5 seconds, then stop. Turn the leftMotor on in reverse at three-fourths speed for 2.5 seconds, then stop. Turn both motors on at full power, and spinning in the same direction, for 7.25 seconds, then stop. Trainer Notes: Recommend that trainees name their finished programs by the title of the slide, including the number and whether it was a group or individual activity. This will help them refer back to the code later.
69
GTT Example Exercise: Robot Drag Race
Task description: Program a robot dragster to travel as fast as possible over 20 feet.
70
Robot Drag Race Notice comments within program
71
VEX LED Plugged into DIGITAL Port 12 Set as “Digital Outs”
Either ON or OFF In the debugger 0 is ON and 1 is OFF Red, Green, and Yellow colors available
72
Basic Programming: Until Commands
Trainer notes: Hardware available to participants will vary some. In general, the LED is interchangeable with the Flashlight, ec.t
73
The Problem with Wait States
Motor Speed is affected by battery power If the battery is fully charged, the motors move quickly If the battery is running low, the motors move slowly Consequently, the robot will not move consistently as the battery power drains Anyone experience these effects? Wouldn’t it be better if we could control how much the robot moves, regardless of how long it took to complete?
74
Sensor Information: Touch Sensors
75
Touch Sensors Touch Sensor Check How they work Two Types Using them
Plugged into Digital 1 & 2 How they work Digital sensor - Pressed or Released 1 = pressed 0 = released Two Types Limit Switches Bumper Switches Using them The SensorValue[] command untilTouch, untilRelease, untilBump NL commands
76
Touch Sensors Other Properties Limitations
Limit Switch arm can be bent to create a more ideal “hit area” Both sensors spring back to “open” position Limitations Watch out for “bouncing”. As the sensor is pressed or released, it may bounce between 0 and 1 very briefly and quickly. A very brief wait can be inserted after touch sensor related commands to reduce the bouncing effect:
77
Bumper Switch Exercise
Example: Wait for the bumper switch to be “bumped” before the right motor turns on at half power for 5 seconds, then stops. Individual: Wait for the bumper switch to be “bumped” before the both motors turn on at half power, until the sensor is bumped again. Both motors should then move in reverse at half power for 3.5 seconds. Trainer Notes: Recommend that trainees name their finished programs by the title of the slide, including the number and whether it was a group or individual activity. This will help them refer back to the code later.
78
Additional Resources
79
Sensor Information: Potentiometer
80
Potentiometers Potentiometer Check How they work Analog Port 2
Analog sensor Measures rotation of a shaft between 0 and ~265 degrees Cortex returns values 0 - ~4095 Using them The SensorValue[] command untilPotentiometerGreaterThan, untilPotentiometerLessThan NL commands
81
Potentiometers Other Properties Limitations
Internal mechanical stops prevent the potentiometer from turning a full revolution. Limitations Caution: Excess torque against the internal mechanical stops (can be caused by hand or by a VEX motor) will cause them to wear away. The potentiometer will continue to function, but will have a “dead zone” where the mechanical stops were, where no new values are sent. Switching the direction the potentiometer is facing will also switch the direction it “counts”. For example: counter-clockwise turns will count 0 to 4095 on one side; on the other counter-clockwise turns will count 4095 – 0.
82
Potentiometer Exercise
Example: Turn on the greenLED until the potentiometer value is greater than Then the greenLED should turn off, and the leftMotor should turn on for 3.5 seconds. Individual: Turn on the greenLED until the potentiometer value is greater than Then the greenLED should turn off, and the leftMotor should turn on until the potentiometer is less than 2048. Trainer Notes: Recommend that trainees name their finished programs by the title of the slide, including the number and whether it was a group or individual activity. This will help them refer back to the code later.
83
Additional Resources
84
Sensor Information Line Tracker
85
Line Tracking “Active” Light Sensor Set of 3 Analog Sensors
Sends out a IR beam, and measure how much is reflected back Each reads values between 0 and 4095 Using them The SensorValue[] command untilDark, untilLight, lineTrackforDistance, lineTrackforTime NL commands
86
Line Tracking Other Properties
The Line Tracker should be kept between ¼ and 1/8 of an inch of what it’s measuring for the best results. Constant, consistent lighting is also very important for achieving repeatable robot behavior. In order to use the Line Tracking sensor(s) you must first calculate a threshold that allows it to distinguish light from dark.
87
Thresholds Overview A Threshold is a value (usually halfway between) two extremes Light and dark (Light sensors) Near and Far (Ultrasonic) Thresholds allow your robot to make decisions via Boolean Comparisons Line Following Kits come with 3 sensors To use all three, you must choose a Threshold that will work with all 3 sensors, or 3 separate Thresholds If you are only using one sensor, then you only need to calculate the Threshold for that sensor
88
Threshold Calculation
Calculate an appropriate Threshold with the aid of the Sensor Debug Window Trainer Notes: The following slides detail the process for determining a threshold.
89
Threshold Calculation
Verify that the Program Debug Window’s Refresh Rate does not display “Continuous”. *Press the “Continuous” button if it does. Trainer Notes: Seeing “Continuous” means that the Sensor debug window will not be seeing continuous updates from the sensors.
90
Threshold Calculation
Add the two values and divide by two. The result is the threshold for that sensor. Light reading + Dark Reading 2 = Threshold
91
Line Tracker Exercise Example: Program the claw to open until the line tracking sensor is covered, then program it to stay open until the sensor is uncovered. Individual: Start with the LED On. Turn LED off when your hand covers line follower. Then turn the LED on for 5 seconds when hand is removed. Trainer Notes: Recommend that trainees name their finished programs by the title of the slide, including the number and whether it was a group or individual activity. This will help them refer back to the code later.
92
Decision Making: while loops and Boolean Logic
93
While Loops A while loop is a structure within ROBOTC which allows a section of code to be repeated as long as a certain condition remains true. There are three main parts to every while loop.
94
1. The word “while” Every while loop begins with the keyword “while”.
95
2. The Condition The condition controls how long or how many times a while loop repeats. While the condition is true, the while loop repeats; when the condition is false, the while loop ends and the robot moves on in the program. The condition is checked every time the loop repeats, before the commands between the curly braces are run.
96
3. Commands to be Repeated
Commands placed between the curly braces will repeat while the (condition) is true when the program checks at the beginning of each pass through the loop.
97
Boolean Logic Decisions robots make must always based on questions which have only two possible answers: yes or no, true or false. Statements that can be only true or false are called Boolean statements, and their true-or-false value is called a truth value.
98
Boolean Logic
100
While Loop Exercise 1 Example: Program the greenLED to repeatedly turn on for 2 seconds, then off for 2 seconds, while the limit switch isn’t pressed. Individual: Expand the previous program to loop only while the the potentiometer reads less than 2048. Trainer Notes: Recommend that trainees name their finished programs by the title of the slide, including the number and whether it was a group or individual activity. This will help them refer back to the code later.
101
GTT Example Exercise: Terry Traffic Tamer
Task description: Install a traffic light that turns a green light on for 5 seconds, then yellow light for 1 second and red light for 5 seconds. When a pushbutton switch is pressed and held the light timing changes so that the red light stays on until emergency vehicle(s) passes through the intersection. When the pushbutton is released the normal light sequence starts over again.
102
Terry the Traffic Tamer
This is a sample solution – make sure heading and pseudocode information is completed. Notice in this solution the system must complete the green-yellow-red light sequence before checking to see if the emergency button is pressed. Is that the best solution???
103
Timers More loop control please? Solution: Timers
Question: Where would the wait statement go if we wanted the loop to repeat for a controlled amount of time? Answer: We need something else. Solution: Timers Can be thought of as internal stopwatches (4 available) Timers should be “cleared” anytime before they are used Watch where you clear them!
104
Timers In the program below, timer T1 is used as the condition for the while loop, which will run for 30 seconds:
105
While Loop Exercise 2 Example: Program the greenLED to repeatedly turn on for 2 seconds, then off for 2 seconds, while less than 20 seconds have elapsed. Individual: Program the greenLED to repeatedly turn on for 2 seconds, then off for 2 seconds, forever. Trainer Notes: Recommend that trainees name their finished programs by the title of the slide, including the number and whether it was a group or individual activity. This will help them refer back to the code later.
106
GTT Example Exercise: Terry Traffic Tamer Bonus
Task description: Install a traffic light that turns a green light on for 5 seconds, then yellow light for 1 second and red light for 5 seconds. When a pushbutton switch is pressed and held the light timing changes immediately so that the red light stays on until emergency vehicle(s) passes through the intersection. When the pushbutton is released the normal light sequence starts over again.
107
Terry the Traffic Tamer Bonus
Notice the emergency button is checked within the time each light is on. This is a sample solution – make sure heading and pseudocode information is completed.
108
Decision Making: if, if-else, and Boolean Logic
109
If Statements When your robot reaches an if Statement in the program, it evaluates the condition contained between the parenthesis. If the condition is true, any commands between the braces are run. If the condition is false, those same commands are ignored. Very similar to how a while loop works, but does not repeat the code!
110
If-else statements The if-else Statement is an expansion of the basic if Statement. The “if” section still checks the condition and runs the appropriate commands when it evaluates to true Using the “else” allows for specific code to be run only when the condition is false. Either the “if” or the “else” branch is always run; no more, no less.
111
If-else Exercise 1 Example: Program the greenLED to turn on if the bumperSwitch is pressed, and off if it’s released. Loop Forever. Individual: Convert the previous program to use an if-else.
112
Multiple If-else Statements
Be careful when using two separate if-else statements, particularly when they are used to control the same mechanism. One branch of each if-else statement is always run, so you may create a scenario where the two sets of “fight” eachother.
113
Multiple If-else Statements
In this example, if one of the touch sensors is pressed, the rightMotor will be turned on in one if-else statement, and immediately turned off in the other.
114
Multiple If-else Statements
This can be corrected by embedding the second if-else within the else branch of the first, so that it only runs if the first condition is false.
115
If-else Shorthand An embedded if-else can also be represented as an else if:
116
Troubleshooting
117
Troubleshooting Questions
Step 1: Identify the problem Step 2: What can we tell about the student’s understanding based on the problem? Step 3: What could we tell the student to address the problem, and their understanding? Just giving the answer to the student teaches dependence! This method teaches!
118
Troubleshooting Student: I want my robot to move forward, then turn. I had it moving forward, and added the turn. Now it’s turning, then moving forward.
119
Troubleshooting Student: My code won’t compile.
120
Troubleshooting Student: I want my robot to move forward, then reverse. I had it moving forward, and added the reverse, but it never actually backs up.
121
Troubleshooting Student: My loop should only be running for 1 minute, but it never stops.
122
Troubleshooting Student: My code compiles, but I get an error when I try to download it to the robot. Check: Is the robot turned on and sufficiently powered? (blinking green light) Is the robot connected to the computer? Is the correct platform type selected in ROBOTC? Is the correct port selected in ROBOTC? Has the driver for the programming cable been installed? Has the firmware been loaded on the VEX? Does the Master Firmware need re-downloaded? Is another ROBOTC window open, using the debugger windows?
123
Questions and Discussion
124
Resources
125
CMU Resources ROBOTC.net: http://www.robotc.net/
The ROBOTC Forum: ROBOTC PLTW Page: ROBOTC Webinars: VEX Cortex Video Trainer Robotics Academy Trainer Notes: It’s recommended that you visit the different pages and show trainees the materials that are there.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.