Download presentation
Presentation is loading. Please wait.
Published byTracy Lamb Modified over 9 years ago
1
ROBOTC for VEX Online Professional Development
2
Warm-up Activity Review/Watch videos from VCVT –Especially the ones from the Fundamentals and Movement sections Work on: –Labyrinth Challenge with obstacles with real robot –Movement > Sentry Challenge or Utility > Robotics Academy Challenge with virtual robot
3
Warm-up Questions What is Firmware? What are valid motor power levels on the VEX? All commands that we want the robot to follow must be within _________? Each command must end with a(n) _________? What VEX sensors are Analog? Digital? What distinguishes them?
4
Standard ROBOTC: Basic Movement
5
Platform Type 1.Choose ROBOTC for VEX Robotics 4.X (not graphical) 2.Choose VEX 2.0 Cortex 3.Deselect Natural Language if needed
6
Get Your Motors Running Motor Check –Right Motor is plugged into MOTORS 2 –Left Motor is plugged into MOTORS 3 Open Sample Program –File > Open Sample Program > Training Samples > Motor Port 3 Forward
7
Motor Port 3 Forward Defines the “main task” of the robot All commands belonging to task main must be in-between these curly braces
8
Motor Port 3 Forward Turns the port3 motor on at full power forward
9
Motor Port 3 Forward Robot stays here in the program for 3000 milliseconds End Result: robot spins one motor for 3 seconds Try it out!
10
Basic Movements Forward / Reverse
11
Basic Movements Point Turns
12
Basic Movements Swing Turns
13
Basic Movements Manual Adjustments
14
Movement Challenges VCVT Videos (recommended) –Watch videos in the Movement > Moving Forward Section –Watch videos in the Movement > Speed and Direction Section The Labyrinth –Remember to Pseudocode –Remember to Journal –The two are not mutually exclusive!
15
Troubleshooting
16
Troubleshooting Method 1.Identify the problem. Don't tell me how to fix the problem. Just tell me what it is. 2.What can we tell about the student because of the problem? What do they know? What don't they know? 3.What can we tell the student to fix their understanding AND the problem? Just giving the answer to the student teaches dependence! This method teaches!
17
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.
18
Troubleshooting Student: My code won’t compile.
19
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.
20
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 lights) –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 ROBOTC firmware been loaded on the VEX? –Does the Master Firmware need re-downloaded? –Is another ROBOTC window open, using the debugger windows?
21
The Problem with Wait States Motor Speed is affected by battery power –If the battery is fully charged, the robot moves quickly –If the battery is running low, the robot moves slowly –Consequently, the robot will not move consistently as the battery power drains –Makes completing the Labyrinth tricky Anyone experience these effects? Wouldn’t it be better if we could control the distance the robot moves, regardless of how long it took to complete?
22
Better Movement: Integrated Motor Encoders
23
Integrated Motor Encoders How they work –“I2C” Smart Sensor –Replaces the back plate of 269 and 393 Motors –As inner striped wheel spins, internal light sensor detects and counts Capabilities and Resolution –627 Counts Per Revolution in High Torque Configuration –392 Counts Per Revolution in High Speed Configuration –Up to 8 encoders “daisy chained” in a row –Counts Up and down –Allows you to control the distance a robot moves, by monitoring how much the wheels spin –Due to “closed-loop” configuration, “PID” control is possible
24
Motors and Sensors Setup Enabled and configured on the Motors tab Motor “Type” is important, as their resolution is not uniform
25
Testing your Encoder Setup You can try to follow the wires from the sensors to the I2C and Motor ports… …or use the Motor Debug Window!
26
Better Movement with Encoders Forward and Backward for Distance
27
Better Movement with Encoders Turning Right and Left
28
PID Control Proportional-Integral-Derivative With the integrated motor encoders, we have what is called a “closed-loop” system –The Cortex knows exactly how fast the motors should be spinning versus how fast they are actually spinning and can make rapid adjustments to compensate for the difference
29
Variables A variable is a space in your robots memory where data can be stored, including whole numbers, decimal numbers, and words Variable names follow the same rules as custom motor and sensor names: capitalization, spelling, availability Variables can improve the readability and expandability of your programs
30
Variable Types Data TypeDescriptionExampleCode IntegerPositive and negative whole numbers, as well as zero -35, -1, 0, 33, 100 int Floating Point Number Numeric values with decimal points (even if the decimal part is zero) -.123, 0.56, 3.0, 1000.07 float BooleanTrue or false – Useful for expressing the outcomes of comparisons true, false bool CharacterIndividual characters, placed in single quotes ‘L’, ‘f’, ‘8’ char StringStrings of characters, such as words and sentences placed in double quotes “Hello World!”, “asdf” string
31
Creating a Variable To create a variable you must give it a: 1.Type for type of data it will hold 2.Name by which variable can be referenced Variables can be set to different values throughout program Naming variables follows the same rules as naming your Motors and Sensors Giving a variable an initial value is called “initializing the variable”
32
Common Variable Uses Variables are useful for keeping track of loop iterations The following code lets the loop run 10x Note that the side on the right of the equal sign is evaluated first, then set to the variable on the left. This is always the case.
33
Common Variable Uses Variables are useful for keeping track of sensor or timer values at different parts of the program
34
Common Variable Uses Variables are useful for keeping track of results from complicated equations
35
Variable Exercises Create and initialize the following variables in your Labyrinth Program: –int motorSpeed –int encoderCount1 –int encoderCount2 –int encoderCount3 –int encoderCount4 Replace the corresponding values in your program with variables. –Download and run. What happens? –Try increasing and decreasing the speed of your robot only by adjusting the variable.
36
Variables Continued
37
More Data Types There are 8 different types of variables in ROBOTC –Integer (int) – Memory Usage: 16 bits / 2 bytes Integer Numbers Only Ranges in value from -32768 to +32767 –Long Integer (long) – Memory Usage: 32 bits / 4 bytes Integer Numbers Only Ranges in value from -2147483648 to +2147483647 –Floating Point (float) – Memory Usage: 32 bits / 4 bytes Integer or Decimal Numbers Variable precision, maximum of 4 digits after decimal
38
More Data Types There are 8 different types of variables in ROBOTC –Single Byte Integer (byte) – Memory Usage: 8 bits/1 byte Integer Numbers Only Ranges in value from -128 to +127 –Unsigned Single Byte Integer (ubyte) – Memory Usage: 8 bits / 1 byte Integer Numbers Only Ranges in value from 0 to +255 –Boolean Value (bool) – Memory Usage 4 bits /.5 bytes True (1) or False (0) values only.
39
More Data Types There are 8 different types of variables in ROBOTC –Single Character (char) - Memory Usage: 8 bits / 1 byte Single ASCII Character only Declared with apostrophe – ‘A’ –String of Character (string) - Memory Usage: 160 bits / 20 bytes Multiple ASCII Characters Declared with quotations – “ROBOTC” 19 characters maximum per string (NXT Screen limit)
40
Constants Some additional notes –Adding “const” in front of a variable will make that variable a constant. This will prevent the variable from being changed by the program –Constants do not take up any memory on the VEX IQ –The VEX IQ has room for 7500 bytes of variables
41
The M in STEM
42
Current method for moving the robot: –Guess-and-check - true for wait states and encoder rotations Do it smarter! –We can measure the distance for the robot to travel –We can measure the circumference of the wheel –We know 627 encoder counts = 1 wheel rotation –Spend 10 - 15 minutes working out a solution Use your idea to move forward and reverse –Discuss how well your ideas worked Now Consider Turning –Is having the robot turn 90 degrees the same as having the encoder turn 90 counts? Why or why not?
43
The M in STEM How did you solve the math problem? Some common methods: –Scale Factor (“Scaling” multiples of a known quantity) –Rate: Unit Ratio (# of X in a single Y, times the number of Y’s) “Rate” relationship Find #degrees/1in, then multiply that rate by the total What about #degrees per floor-line? –Rate: Raw Ratio (# of X per # of Y, times the number of Y’s) Find 360degrees/8.6in, then multiply that rate by the total –Direct Proportion (Traditional “ratio” equation) 8.6 in = 24 in 627 deg X deg Solved mechanically using cross-multiplication Solved algebraically as a Linear Equation of One Variable
44
Everyone is a Math Teacher How did you solve the math problem? Many STEM teachers will not be teaching in Math class, yet Math is clearly what they are teaching –Make the math explicit; don’t waste the opportunity! –Embrace multiple methods of solving the same problem; students need more tools at their disposal, not conflicting information about which ones are “better” than others (none are, use what works!)
45
Exercise: Precise Turning Now that you know how to calculate the encoder counts for any forward movement, can you apply that to point turns and swing turns? Figure it out! Keep in mind what “distance” the wheels are traversing to accomplish the turn. Be prepared to share your findings!
46
Programming Discussion The behaviors we are using work, but imagine using them to solve the Labyrinth. –Moving Forward or Turning with Encoders = ~8 lines –7 movements needed for the Labyrinth –7 x ~8 = ~56 Lines of code! Notice that the behaviors are mostly comprised of the same exact code, over and over. –What if there were a way to reuse the same set of code? –There is: Functions!
47
Functions
48
Functions are used to group together several lines of code, which can then be referenced many times in task main, or even other functions. Convenient uses in the Labyrinth –Moving Forward –Turning 90 Degrees Left –Turning 90 Degrees Right Creating Functions –Example: Moving Forward –Function Header (Part1 – The name of the function) –Function Definition (Part 2 – The code that goes with the function) Using Functions –Function Call (Part 3 – Where you want the function code to run)
49
Function Definition
50
Function Call
51
Function Practice Create Functions to: –Point Turn 90 Degrees Right –Point Turn 90 Degrees Left –Reverse for 2 Rotations Review VCVT Videos – Note: The code is different, but the process is the same
52
Advanced Functions What about the very similar lines of code that go with the automatically moving straight code? Is there a way to include those lines in the function? –What’s different each time we use the code? The number of degrees for the distance of the straight movement! What programming tool do we have that lets us store numbers in our code? Variables! Functions allow use for a special kind of variable, called a Parameter. Parameters allow you to pass values into functions to account for small differences, like the number of degrees to move forward.
53
Advanced Function Definition
54
Advanced Function Call
55
Advanced Function Practice Expand your previous functions : –Point Turn x Degrees Right –Point Turn x Degrees Left –Reverse for x Rotations Review VCVT Videos
56
Homework! Homework assignments can always be found and turned-in on CS2NLearn You’ll also be expected to watch a series of videos for review Optional practice quizzes will prepare you for the certification exam at the end
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.