Presentation is loading. Please wait.

Presentation is loading. Please wait.

ROBOTC for VEX Online Professional Development Jesse Flot

Similar presentations


Presentation on theme: "ROBOTC for VEX Online Professional Development Jesse Flot"— Presentation transcript:

1 ROBOTC for VEX Online Professional Development Jesse Flot

2 PID Control

3 PID Control A Proportional-Integral-Derivative controller is a control loop feedback mechanism widely used in control systems. Calculates an error value as the difference between a measured value and a desired value Can be used with any sensor that provides a range of values

4 PID Formula Source:

5 PID Closed Loop

6 PID Closed Loop

7 PID Closed Loop

8 PID Closed Loop

9 PID Closed Loop

10 PID Closed Loop 52

11 PID Control in ROBOTC Enable-able in Motors and Sensors Setup with Integrated Motor Encoders

12 PID Notes PID algorithms must have ‘wiggle room’ to work properly
Setting the motor speed too high (>100 power) may not give the algorithm enough room for adjustments PID algorithms allow for very low motor speeds

13 Variables

14 Presentation Name Course Name Unit # – Lesson #.# – Lesson Name 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

15 Variable Types Data Type Description Example Code Integer
Positive 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, float Boolean True or false – Useful for expressing the outcomes of comparisons true, false bool Character Individual characters, placed in single quotes ‘L’, ‘f’, ‘8’ char String Strings of characters, such as words and sentences placed in double quotes “Hello World!”, “asdf” string

16 Creating a Variable To create a variable you must give it a:
Type for type of data it will hold 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”

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

18 Common Variable Uses Variables are useful for keeping track of results from complicated equations

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

20 Variables Continued

21 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 to Long Integer (long) – Memory Usage: 32 bits / 4 bytes Ranges in value from to Floating Point (float) – Memory Usage: 32 bits / 4 bytes Integer or Decimal Numbers Variable precision, maximum of 4 digits after decimal

22 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 Ranges in value from 0 to +255 Boolean Value (bool) – Memory Usage 4 bits / .5 bytes True (1) or False (0) values only.

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

24 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

25 The M in STEM

26 The M in STEM Current method for moving the robot: Do it smarter!
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 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? Diameter of the wheel = 2.75 inches

27 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 deg X deg Solved mechanically using cross-multiplication Solved algebraically as a Linear Equation of One Variable

28 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!)

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

30 Functions

31 Functions 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)

32 Function Definition

33 Function Call

34 Function Practice Create Functions to: Review VCVT Videos
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

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

36 Advanced Function Definition

37 Advanced Function Call

38 Advanced Function Practice
Expand your previous functions : Point Turn x Degrees Right Point Turn x Degrees Left Reverse for x Rotations Review VCVT Videos

39 Remote Control

40 VEXnet Joysticks An out-of-box VEX Cortex comes with basic built-in Remote Control functionality The VEXnet Joysticks do not have settings like the older Radio Control Transmitters ROBOTC enables full customization of how the VEXnet Joystick signals controls the Cortex If the Cortex and VEXnet Joystick are linked over VEXnet, there is no extra code to enable remote control – they’re already linked!

41 VEXnet Joysticks The VEXnet Joysticks and Cortex (when linked) continually send data back and forth Two Joysticks with two “Channels” each Values range from -127 to 127 12 Buttons A Pressed button = 1, released = 0 Built in Accelerometer X and Y values No crystal or chance of interference, Cortex and VEXnet Joysticks create their own wireless network over VEXnet

42 Wireless Programming and Debugging
The connection between the VEXnet Joysticks and Cortex can be used to wirelessly download the ROBOTC Firmware, ROBOTC Programs, and debugger data! Even when you’re not actively “using” the VEXnet Joysticks, it’s transmitting and the batteries are draining. Batteries last ~2 hours; use it wisely!

43 VEXnet Configuration Switch your VEX Cortex Download Method to Download using VEXnet or USB Remember that you will need to download a program and power-cycle the Cortex for the setting to take effect.

44 VEXnet Configuration 2. Connect the VEXnet Joysticks to the computer and update its firmware

45 VEXnet Configuration 3. Establish a VEXnet Link between the Cortex and Remote Control

46 VEXnet Configuration 4. Insert VEXnet Keys and Test!

47 vexRT[] Command The vexRT[] Command allows you to access any of the values from the VEXnet Joysticks The values from the joystick axis are identified by the the letters “Ch” + the number closest to them Channel variable names: Ch1 - X-Axis - Right Joystick Ch2 - Y-Axis - Right Joystick Ch3 - Y-Axis - Left Joystick Ch4 - X-Axis - Left Joystick

48 vexRT[] Command The buttons are identified by the letters “Btn” + the number closest to it + the letter etched into it Button variable names: Btn5U - Button group 5 - "U" (up) Btn5D - Button group 5 - "D" (down) Btn6U - Button group 6 - "U" (up) Btn6D - Button group 6 - "D" (down) Btn7U - Button group 7 - "U" (up) Btn7D - Button group 7 - "D" (down) Btn7L - Button group 7 - "L" (left) Btn7R - Button group 7 - "R" (right) Btn8U - Button group 8 - "U" (up) Btn8D - Button group 8 - "D" (down) Btn8L - Button group 8 - "L" (left) Btn8R - Button group 8 - "R" (right)

49 Joystick Value Mapping
Direct Value Mapping Values from the remote control are directly used to control the motors (1:1 ratio)

50 Joystick Value Mapping
Indirect Value Mapping Values from the remote control 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

51 Remote Control (with virtual robots)

52 Remote Control - Names The VEXnet Joystick does not share its values with the PC so it cannot be used with RVW The USB port provides power, not joystick data ROBOTC allows almost any USB Controller to be used The Logitech F310 is supported by default A Joystick Configurator can be used to ensure non-default joysticks work Like the VEXnet Joystick, all the buttons and joysticks can be used in your program

53 Joystick Control – Tank Control

54 Joystick Control – Arcade Control
X1 Y1

55 Joystick Control – Arm Control

56 Advanced Remote Control

57 USB Remote Control Code

58 Advanced Remote Control
More loop control please? Is remote controlling the robot forever always appropriate? Next Challenge: Mine Removal Challenge Question: Where would the wait statement go if we wanted the robot to be remote controlled 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!

59 Timers

60 Advanced Remote Control
Wasting Time? The time it takes to turn on the VEX and get situated could be used to score points, but is wasted. Could we make the robot wait to start it’s timer until we were ready? Any ideas? Wait for a Remote Control Button press The robot won’t start the timer until we say so The robot also can’t move until we says so Program Flow Trace Could this idea also be used to make a “more friendly” start button on a non-radio controlled robot? Other ideas of how to improve remote control? Use the buttons to initiate common actions Turn 90 degrees, move straight forward, ect

61 Advanced Remote Control
Use the buttons to control the arm The VEXnet Remote Control buttons send values of 0 or 1

62 Really Advanced Remote Control

63 Accelerometer Control
A built-in Accelerometer provides X-Y tilt values Allows you to control an arm or drive system by changing the orientation of the controller

64 Accelerometer Control
Open the Accelerometer Control Sample Program in the Remote Control folder Review how it works Try it out!

65 Troubleshooting

66 Troubleshooting Student: My loop should only be running for 1 minute, but it never stops.

67 Troubleshooting I enabled Remote Control for 30 seconds, but my robot just sits there.

68 Sensing

69 Sensor Information: Touch Sensors

70 Touch Sensors Touch Sensor Check How they work Setting them up
Limit Switch plugged into Digital Port 6 Bumper Switch plugged into Digital Port 11 How they work Digital sensor - Pressed or Released Watch out for “bouncing” Setting them up ROBOTC Motors and Sensors Setup window Using them The SensorValue[] command

71 Move Forward until Pressed

72 Touch Sensors Start Button
Remember how we used the Remote Control button to start the timer portion of the program. How would we implement the same thing with the bumper switch?

73 Sensor Information: Potentiometer

74 Potentiometers Potentiometer Check How they work Setting them up
Plugged into Analog Port 3 How they work Analog sensor Measures absolute rotation of a shaft between 0 and ~265 degrees Returns values 0 – ~4095 Internal mechanical stops Setting them up ROBOTC Motors and Sensors Setup window Using Analog and Digital Sensors Using them The SensorValue[] command

75 Potentiometers

76 Potentiometers Fine-tuned Arm Control Part 2
Use the potentiometer to tell the robot when it has reached its maximum point

77 Sensor Challenges Example: Variable Speed Program
Use the rotation of the potentiometer to control how fast the robots motors spin Class activity: Quick-tap Challenge Incorporating Sensors, Variables, Loops, If Statements, Timers, Boolean Logic, Pseudocoding, and FUN all into one activity

78 Sensor Information Ultrasonic Rangefinder

79 The Ultrasonic Rangefinder
Ultrasonic Rangefinder Check Input wire plugged into Digital Port 8 Output wire plugged into Digital Port 9 How they work Similar to how bats and submarines work Digital sensor – but returns distance values in inches, centimeters, or millimeters on the Cortex Setting them up ROBOTC Motors and Sensors Setup window Using them Be careful not to use them immediately as your program starts – they take time to initialize and will return negative values The SensorValue[] command

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

81 Forward until Near

82 Ultrasonic Rangefinder
Forward until Near

83 The Ultrasonic Rangefinder
Forward until Near Move forward until the robot is “near” an object, then stop Automatic Pick-up Straight Forward until Near + picking up the mine Optional: Assign to a button on the Remote Control

84 VEX Robotics Competition Programming

85 VEX Robotics Competitions
Official VEX Competitions utilize special Field Control Hardware to enable and disable robots

86 Competition Templates
ROBOTC is fully legal in VEX Competitions You must program using the built-in templates Competition Template Driver Skills Template

87 Competition Template Pre-autonomous code goes here – clear encoders, ect Autonomous code goes here Remote Control code goes here

88 Testing Competition Code
The ROBOTC Competition Control Debug Window simulates the Field Control Hardware, so you can test your code

89 Competition Resources

90 Additional Sensors

91 Ambient Light Sensor

92 Ambient Light Sensor Plugged into Analog Port 4 “Passive” Light Sensor
Measures the amount of ambient light in its environment Returns values between 0 and 4095 Range is 0 – 6 feet from the sensor Using them The SensorValue[] command

93 Different Types of Threshold
No Threshold Touch Sensors (Only 1 or 0) Chosen Threshold Ultrasonic Rangefinder (You choose the distance) Shaft Encoders (When guessing and checking) Measured Threshold Potentiometer (Viewed in the Sensor Debug Window) Calculated Threshold Shaft Encoders (When using a mathematical method) Measured and Calculated Threshold Line Following Sensor (Measurements taken, mean calculated) Light Sensor (Measurements taken, mean calculated)

94 Light Sensor Activities
Lights On / Lights Off Graphing Data to Debug Stream

95 Accelerometers

96 Accelerometers Electromechanical device that measures acceleration forces in three axis simultaneously. Connects to the Cortex using up to 3 Analog Ports ANALOG Ports 6, 7, and 8 Selectable sensitivity via jumper: ±2g and ±6g. 0-5V analog output (one for each axis). LED indicated power and proper connection. Mounts directly to VEX.

97 Accelerometers How they work: Additional Information:
“Piezoelectric Effect” – accelerometers contain microscopic crystal structures that get stressed by accelerative forces, which causes a voltage (and consequently an Analog sensor value) to be generated. Additional Information: Gravity is indistinguishable from upward acceleration, so the sensor will detect a constant 1.0G while at rest. If the board is mounted horizontally, gravity will effect only the Z axis. If the sensor is tilted away from the horizontal, the gravity reading on the Z axis will diminish, and the readings on the other axis will change depending on which way you are tilting it. Accelerometers are sensitive to heat, fluctuations in voltage, ect., so some filtering on the Sensor Data is necessary.

98 Accelerometer Activities
Wait for Acceleration Robot waits for you to tap it before performing its task Other Uses: Detecting when your autonomous robot crashes Keeping an arm level, going up a ramp

99 Sensor Activities Finish the Automatic Pickup Behavior
Add code to automatically score the ball Quick-Tap Challenge Review Sensing Videos With a Virtual Robot: Sensing > Robocci Sensing > Speed of Sound Sensing Robo-Dunk 2


Download ppt "ROBOTC for VEX Online Professional Development Jesse Flot"

Similar presentations


Ads by Google