Presentation is loading. Please wait.

Presentation is loading. Please wait.

ROBOTC for VEX On-Site Professional Development. Lab Procedures Logging onto computers –Log in with: teachers / teachers1 VEX Robots/chargers –Make sure.

Similar presentations

Presentation on theme: "ROBOTC for VEX On-Site Professional Development. Lab Procedures Logging onto computers –Log in with: teachers / teachers1 VEX Robots/chargers –Make sure."— Presentation transcript:

1 ROBOTC for VEX On-Site Professional Development

2 Lab Procedures Logging onto computers –Log in with: teachers / teachers1 VEX Robots/chargers –Make sure during breaks, lunches and end of day to charge your robot Headsets –Each workstation has two headsets to allow both partners to watch the videos at the same time Teacher folders and journals

3 ROBOTC this Week There are several versions of ROBOTC on your desktops This class we will use ROBOTC 3.0 Beta as much as possible

4 Discussion What is a robot? What can you teach with a robot? Journaling

5 VEX 0.5 PIC System Overview

6 VEX 0.5 PIC Testbed Features: –VEX PIC –2 Motors –Servo Motor –Ultrasonic Rangefinder –Potentiometer –Ambient Light Sensor –Line Tracking Sensor –Limit Switch –Bumper Switch –RF Receiver –LED

7 VEX 0.5 PIC Overview Coordinates the flow of information and power on the robot All electronic components interface with the microcontroller 8 Motor Ports 16 Analog/Digital Ports for Sensors Rx1 and Rx2 Ports for Radio Control

8 ROBOTC Overview

9 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 Approved for VEX Robotics, BEST, TSA and RoboFest Competitions! 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

10 Industry Standard Coding Students that learn ROBOTC Programming are also learning key components of Industry Standard Programming Languages...

11 Industry Standard IDE Students programming in the ROBOTC IDE are also learning how to use features in Industry Standard IDE’s...

12 Visual Studio IDE and Code

13 ROBOTC IDE and Code

14 ROBOTC Features

15 Platform Type Allows you to toggle ROBOTC’s programming mode between the VEX PIC and VEX Cortex, will enable features and commands for the system

16 ROBOTC Start Page Displays the latest ROBOTC news, version of ROBOTC, and ROBOTC Resources

17 Sample Programs Over 75 Included ROBOTC Sample programs, organized by robot behavior

18 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

19 ROBOTC Help In-depth explanations about the ROBOTC interface, commands, debugger, etc

20 Function Library Lists the available functions, with a description. List of available functions will expand or shrink depending on the “Menu Level”

21 Menu Level Customizes the ROBOTC interface and Function Library based on the user’s experience level

22 Motors and Sensor Setup One central place to configure and name all of the motors and sensors attached to your Cortex

23 Teaching ROBOTC for IFI VEX Robots


25 Teaching ROBOTC for IFI VEX Robots (TRC4V) 40 tutorial videos 275 pages of printable guides aligned to the videos 50 pages of supplementary “helper guides” 35 programming challenges Freely available at

26 Student-Paced Instruction Everyone learns different things at different paces Everyone MUST move at a different pace –Going too fast results in failure and frustration –Going too slow results in loss of attention (i.e. future failure) TRC4V can be used as a teaching aid –One instructor can’t teach at 20 different paces simultaneously –One instructor plus 20 computers can

27 System Configuration

28 Downloading Firmware What is Firmware? Step 1: Download Master Firmware Step 2: Download ROBOTC Firmware Step 3: Power-cycle the VEX

29 ROBOTC “Natural Language”

30 ROBOTC Natural Language 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 Basic Programming: Motor and Wait Commands

41 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)

42 Motor 2 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

43 Motor 2 for 5 Seconds Turns the port2 rightMotor on at half power forward

44 Motor 2 for 5 Seconds Causes the robot to wait here in the program for 5.0 seconds

45 Motor 2 for 5 Seconds Stops the port2 rightMotor. End Result: rightMotor spins for 5.0 seconds.

46 Quick ROBOTC Exercise Create this program yourself and download it to the Robot –Using the Program Debug Window

47 Renaming and Reversing Robot > Motors and Sensors Setup –Optional with Motors (not Sensors) –Giving Motors custom names –Reversing motor polarity

48 Naming Rules 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 underscores –Must contain no special characters (&, $, /, ect.) –Cannot already be a ROBOTC reserved word (task, motor, true)

49 Quick ROBOTC Exercise Make Changes to the Program 1.Turn on leftMotor Download and watch result 2.Reverse both motors Download and watch result

50 Motor Exercises 1.Turn the rightMotor on forward at full speed for 6 seconds, then stop. 2.Turn the leftMotor on in reverse at three- fourths speed for 2.5 seconds, then stop. 3.Turn both motors on at half power for 3 seconds, stop for two seconds, reverse at half power for 3 seconds, then stop.


52 Servo Motors Very similar in appearance to the normal 3-wire motor Very different in operation –Rotates between 0 and ~120 degrees –Where the motor is set to a “power value” the servo is set to a “position value” –-127 = 0 degrees, 0 = 60 degrees, 127 = 120 degrees, etc –Servo motors can be programmed exactly the same way as normal motors in ROBOTC, so the programmer must know the hardware and intent –setServo() Natural Language command

53 Servo Exercises Example: Program the servo to go to position -127 for 2 seconds, position 0 for 2 seconds, and position 127 for 2 seconds. Individual: Program the servo to go to position -127 for 2 seconds, position -63 for 3 seconds, position 0 for 2 seconds, position 63 for 3 seconds, and position 127 for 2 seconds.

54 VEX LED Plugged into A/D Port 16 Set as “VEX LED” –Either ON or OFF 1 ON and 0 is OFF Red, Green, and Yellow colors available turnLEDOff(), turnLEDOn NL commands

55 Program Planning

56 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

57 The Labyrinth Challenge


59 Programming Discussion The Challenge: The Labyrinth The Solution: ??? The Programmer’s (your) Role –Understanding Program Flow and Behavior Based Programming –Plan out the robot’s path / actions - Pseudocoding –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!

60 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

61 Pseudocode Sample Pseudocode:

62 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.

63 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!


65 ROBOTC Rules/Syntax What does every program have to have? –task main() –Set of "Curly Braces“ {} In what order does ROBOTC run a program? –Sequentially – Top to Bottom What is whitespace? –Space in a program to make it easier for a human to read. Simple Robot Commands (statements) always end with a…? –Semicolon ;

66 ROBOTC Rules/Syntax Paired Punctuation –Some functions have "square brackets“ [], other have "parenthesis“ () –How do I keep them straight? Memorization Functions Library Control Structures –Just like task main, they have a set of curly braces defining their beginning and end. {} –Example? Comments –//Necessary Evil –Get into the habit now, or you won't do it ever –Your students learn their habits from you…

67 ROBOTC Rules/Syntax Syntax is the cause of 80% of programming errors… Most important thing to do when troubleshooting: Check Syntax –Missing Semicolons –Incorrect Braces on Structures –Misspelled words –Improper ‘case’ – motor vs. MoToR ROBOTC is friendly about most of these errors... but can’t catch everything.


69 Basic Programming: Until Commands

70 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?

71 Sensor Information: Touch Sensors

72 Touch Sensors Touch Sensor Check –Plugged into A/D 14 & 15 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

73 Touch Sensors Other Properties –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 as part of the untilBump() command, or after the untilTouch() and untilRelease() commands to reduce the bouncing effect:

74 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 both motors turn on at half power, and stay on until the sensor is bumped again. Both motors should then move in reverse at half power for 3.5 seconds.


76 Sensor Information: Potentiometer

77 Potentiometers Potentiometer Check –A/D Port 3 How they work –Analog sensor –Measures rotation of a shaft between 0 and ~265 degrees –PIC returns values 0 - ~1023 –Cortex returns values 0 - ~4095 Using them –The SensorValue[] command –untilPotentiometerGreaterThan, untilPotentiometerLessThan NL commands

78 Potentiometers Other Properties –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 1023on one side; on the other counter- clockwise turns will count 1023– 0.

79 Potentiometer Exercise Example: Turn on the LED until the potentiometer value is greater than 512. Then the LED should turn off, and the leftMotor should turn on for 3.5 seconds. Individual: Turn on the LED until the potentiometer value is greater than 512. Then the LED should turn off, and the leftMotor should turn on until the potentiometer is less than 512.

80 Sensor Information: Shaft Encoders

81 Quadrature Shaft Encoders How they work –Digital counting sensor –As the inner shaft spins, the encoder “counts” Capabilities and Resolution –360 “counts” per revolution of the inner shaft –Counts Up and down –Allows you to control the distance a robot moves, by monitoring how much the wheels spin. Using them –The SensorValue[] command –untilEncoderCounts, untilRotations, moveStraightforTime, moveStraightforRotations NL commands

82 Shaft Encoders Other Properties –Switching which wire is in the A/D port vs. the INTERRUPT port will reverse the polarity of the encoder (whether it counts up or down for CW turns). –There is an older single-wire version of the encoder, which only counts 90 degrees per revolution of the encoder. –The Natural Language commands automatically clear the encoder for you. Otherwise, clearing the encoders before using them to track rotations is recommended for consistency.

83 Shaft Encoder Exercise Example: Turn on both motors forward until the encoder has counted 480 degrees. Individual: Turn on both motors forward until the encoder has counted 480 degrees. Then turn on both motors in reverse until another 3.5 rotations of the encoder have passed.


85 Sensor Information Ultrasonic Rangefinder

86 Ultrasonic Rangefinder Ultrasonic Rangefinder Check –Output wire plugged into INTERRUPT Port 1 (Input is always first) –Input wire plugged into A/D Port 10 How they work –Similar to how bats and submarines work –Digital sensor – but returns distance values between 0 & 255 inches (Can also return values of -1 or -2 if used improperly) –Cortex resolution can be in inches, cm, or even mm Using them –The untilNear and untilFar NL commands

87 Ultrasonic Rangefinder Other Properties –The Ultrasonic Rangefinder is able to detect objects in a “cone” field of view. As objects get further away, the sensor is able to detect them further away from the center of the sensor. –The sensor bases distance calculations off of sound waves, which means that some objects may not be detectable: soft objects that absorb sound, sharp objects that deflect sound, etc. –Do not use the ultrasonic sensor as the very first command in your code. Until the first sound echo returns to the sensor, it will have a value of -1. A simple delay at the beginning of your program solves this.

88 Ultrasonic Exercise Example: Turn on both motors until an object is within 10 inches of the sensor, then turn the motors off, and turn the LED on for 6.25 seconds. Individual: Wait until an object is detected within 15 inches to turn the motors on. Then wait for the object to move more than 20 inches away before turning the motors off.


90 Sensor Information Line Tracker

91 Line Tracking “Active” Light Sensor Set of 3 Analog Sensors Sends out a IR beam, and measure how much is reflected back VEX Cortex returns values between 0 and 4095 VEX PIC returns values between 0 to 1023 Using them –The SensorValue[] command –untilDark, untilLight, lineTrackforDistance, lineTrackforTime NL commands

92 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.

93 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 The Testbed has only one sensor –You only need to calculate the Threshold for that sensor

94 Threshold Calculation Calculate an appropriate Threshold with the aid of the Sensor Debug Window 1.In ROBOTC, create a program that configures your Line Following sensor.

95 Threshold Calculation 2. Download the Program to the Robot 3. Open the Sensor Debug Window

96 Threshold Calculation 4. Verify that the Program Debug Window’s Refresh Rate does not display “Continuous” and press the Start button. *Press the “Continuous” button if it does.

97 Threshold Calculation 5. Place a light colored object (or no object) above the line tracking sensor. 6. Record the value for the sensor displayed in the Sensors Debug Window. Only record the value for Analog Port 1 “in1”. *values displayed will vary from your values

98 Threshold Calculation 7. Place a dark object above the line tracking sensor (or completely block it). 8. Record the value for the sensor displayed in the Sensors Debug Window. *values displayed will vary from your values

99 Threshold Calculation 9. Add the two values and divide by two. The result is the threshold for that sensor. Light reading + Dark Reading 2 = Threshold 10. Use the threshold(s) in your program

100 Line Tracker Exercise Example: Move the servo to position 127 until a light object is detected, then have the servo move to position -127. Individual: Move the servo to position 127 until a dark object is detected, then have the servo move to position -127.

101 Sensor Information Ambient Light Sensor

102 Ambient Light Sensor “Passive” Light Sensor Measures the amount of ambient light in its environment Cortex returns values between 0 and 4095 PIC returns values between 0 and 1023 Range is 0 – 6 feet from the sensor Using them –The SensorValue[] command –untilDark, untilLight, NL commands

103 Light Sensor Exercise Example: Program the LED to turn on for 5 seconds when the room lights go out Individual: Program the LED to turn on when the lights go out, and back off when the lights turn back on.

104 Decision Making: while loops and Boolean Logic

105 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.

106 1. The word “while” Every while loop begins with the keyword “while”.

107 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.

108 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.

109 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.

110 Boolean Logic


112 While Loop Exercise 1 Example: Using the Ambient Light Sensor, program the LED to turn on when the lights in the room go out (or the sensor is blocked), and turn back off when the lights are turned back on, forever. Individual: Expand the previous program to loop only while the limit switch isn’t pressed.

113 Timers More loop control please? –Question: Where would the wait statement go if we wanted the loop to repeat for a controlled amount of time? –Answer: Nowhere! We need something else. Solution: Timers –Can be thought of as internal stopwatches (4 available) –Like encoders, timers should be “cleared” anytime before they are used Watch where you clear them!

114 Timers In the program below, timer T1 is used as the condition for the while loop, which will run for 30 seconds:

115 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 servo to go to position 127 for 3 seconds, then position -127 for 3 seconds, while less than 30 seconds have elapsted.

116 Decision Making: if, if-else, and Boolean Logic

117 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!

118 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.

119 If-else Exercise 1 Example: Program the LED 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.

120 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.

121 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.

122 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.

123 If-else Shorthand An embedded if-else can also be represented as an else if:

124 Closing Thoughts Downloading Firmware ROBOTC Natural Language Behavior Based Programming Pseudocode and Program Flow Basic Motor Commands and Wait States Until Statements with VEX Sensors Decision Making

125 Remote Control

126 An out-of-box VEX Microcontroller comes with basic built-in Radio Control functionality –The Radio Control Transmitter can be configured to allow some customization of that built-in functionality –Still very limited customizability and usefulness! The ROBOTC firmware enables full customization of how the Radio Control Transmitter signals controls the VEX –By default ROBOTC turns off reception from the transmitter to save battery life during autonomous programming –One line of code turns it back on

127 Remote Control One Transmitter continuously sends out 6 separate values over 6 separate channels –Values range from -127 to 127 –Doesn’t something else have values that range from -127 to 127? The “crystal” number must match on the transmitter and receiver –The crystal is what controls the frequency of the transmission –One transmitter can control multiple robots, so be careful in your classrooms –13 different crystals/frequencies are available

128 Radio Control Reset Since the Radio Control Transmitter can be configured, there’s the possibility that it’s configured inappropriately for our purposes. –Watch the Radio Control Setup and Values and Axes (Part 1) Videos in TRC4V, found in Radio Control > Control Mapping –Be sure to follow along with the Radio Control Setup Video!

129 Radio Control Signals

130 Remote Control Exercise 1 Example: Implement Basic Remote Control with a while loop. Individual: Expand the previous program to only run for 30 seconds.

131 Remote Control Direct Value Mapping –Values from the transmitter are directly used to control the motors (1:1 ratio) Program Flow Tracing –Radio Control with Wait States –Radio Control with a Loop (real-time control) Indirect Value Mapping –Values from the transmitter are modified before being used to control motors –Can make the robot easier to control –Appropriate in situations that require more “delicate” movements –Notice: the robot reads the right side of the equal sign first

132 Remote Control Exercise 2 Example: Add button control to the basic remote control program so that the servo moves to position 127 when the top Ch5 button is pressed. Individual: Expand the previous program so that the servo spins to -127 when the bottom button is pressed.

Download ppt "ROBOTC for VEX On-Site Professional Development. Lab Procedures Logging onto computers –Log in with: teachers / teachers1 VEX Robots/chargers –Make sure."

Similar presentations

Ads by Google