ROBOTC for VEX Online Professional Development Jesse Flot

Slides:



Advertisements
Similar presentations
Variables and Functions ROBOTC Software. Variables A variable is a space in your robots memory where data can be stored, including whole numbers, decimal.
Advertisements

Jason Howard. Agenda I. How to download robotc II. What is tele-op used for? III. How to build a basic tele-op program IV. Getting the robot to drive.
Add and Use a Sensor & Autonomous For FIRST Robotics
Automation and Robotics
VEX Robotics Platform and ROBOTC Software Introduction.
VEX Robotics Platform and ROBOTC Software
V EX C OACHES ' T RAINING October 12, Agenda for Today 9 – 10 AM : Tina Reeves and the Engineering Notebook 10 – Noon : Finish Building, Basic Robot.
Autonomy using Encoders Intro to Robotics. Goal Our new task is to navigate a labyrinth. But this time we will NOT use motor commands in conjunction with.
Programing Concept Ken Youssefi/Ping HsuIntroduction to Engineering – E10 1 ENGR 10 Introduction to Engineering (Part A)
Available at: – Program Optical Quad Encoders in Autonomous Mode Program optical quad encoders in autonomous mode.
IR SENSORS AND ENCODERS. LCDs Timothy Friez Class # 2.
Programming – Touch Sensors Intro to Robotics. The Limit Switch When designing robotic arms there is always the chance the arm will move too far up or.
Testbed: Exercises.
What is RobotC?!?! Team 2425 Hydra. Overview What is RobotC What is RobotC used for What you need to program a robot How a robot program works Framework.
ROBOTC for VEX Online Professional Development
VEX Robotics Platform and ROBOTC Software
ROBOTC Software Introduction. ROBOTC Software ROBOTC developed specifically for classrooms and competitions Complete programming solution for VEX Cortex.
Program ultrasonic range sensor in autonomous mode
ROBOTC for VEX On-Site Professional Development
Weston Schreiber & Joshua Gabrielse Robotics Summer Training Programming #1: EasyC Basics.
Programming Concepts (Part B) ENGR 10 Introduction to Engineering 1 Hsu/Youssefi.
Introduction to the VEX ® Robotics Platform and ROBOTC Software © 2012 Project Lead The Way, Inc.Principles of Engineering.
Programing Concept Ken Youssefi/Ping HsuIntroduction to Engineering – E10 1 ENGR 10 Introduction to Engineering (Part A)
Autonomy using Encoders Intro to Robotics. Autonomy/Encoders Forward for Distance In this unit, you will learn to use the encoders to control the distance.
ROBOTC for VEX Online Professional Development. Warm-up Activity Review/Watch videos from VCVT –Especially the ones from the Fundamentals and Movement.
Session 12 Sensors and Timers. 3 Main Types of Robot Projects Command-Based Robot A more complicated project for more complicated robots Iterative Robot.
Variables and Functions ROBOTC Software © 2012 Project Lead The Way, Inc.Principles of Engineering.
Variables and Functions ROBOTC Software. Variables A variable is a space in your robots memory where data can be stored, including whole numbers, decimal.
VEX and Robot C Chris Patterson Frisco ISD CTE Center Presented by.
Automation and Robotics.  First you select the platform type so that you can use Natural Language PLTW.
Casne.ncl.ac.uk Taking care of the CrumbleBot Please do NOT stress the robot's motors 1.Do NOT push the robot 2.Do NOT hold the.
ROBOTC for Testbed © 2011 Project Lead The Way, Inc.Automation and Robotics VEX.
ROBOTC for VEX Online Professional Development. Homework Questions Thoughts? Questions?
Introduction to VEX® components
Programming Design ROBOTC Software. Behavior-Based Programming A behavior is anything your robot does –Turning on a single motor or servo Three main types.
Basic Programming: Until Commands. The Problem with Wait States Motor Speed is affected by battery power. –If the battery is fully charged, the motors.
Robotics Programming Wall Follow Line tracking for a set amount of time Line tracking for a distance.
ROBOTC for VEX Online Professional Development. Homework Questions Thoughts? Questions? Concerns? Homework Policy: All homework is due Friday, August.
ROBOTC for VEX Online Professional Development Jesse Flot.
Variables. A variable is a space in your robot’s memory where you can store data, such as whole numbers, decimal numbers, and words. Variable names follow.
ROBOTC for CORTEX Teacher Training © 2011 Project Lead The Way, Inc. Automation and Robotics VEX.
Introduction to Programming in RobotC
Variables and Functions
ROBOTC for VEX Online Professional Development
Variables and Functions
Variables and Functions
ROBOTC for VEX Professional Development
ROBOTC for VEX Online Professional Development
ROBOTC for VEX Online Professional Development
VEX Robotics Platform and ROBOTC Software
ROBOTC for VEX On-Site Professional Development
Robotics Programming Using Shaft Encoders
ROBOTC for VEX Online Professional Development
ROBOTC for VEX Online Professional Development
Programming Concepts (Part B) ENGR 10 Introduction to Engineering
Variables and Functions
RobotC Sensors.
Movement using Shaft Encoders
Variables and Functions
RobotC Sensors.
Variables and Functions
Variables and Functions
Variables and Functions
Automation and Robotics
TECH 1 BAMS Technology Education
Variables and Functions
Robotics Programming Using Shaft Encoders
Robotics Programming Using Shaft Encoders
Robotics Programming Using Shaft Encoders
Programming Concepts (Part B) ENGR 10 Introduction to Engineering
Presentation transcript:

ROBOTC for VEX Online Professional Development Jesse Flot

PID Control

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

PID Formula Source: http://en.wikipedia.org/wiki/PID_control

PID Closed Loop

PID Closed Loop

PID Closed Loop

PID Closed Loop

PID Closed Loop

PID Closed Loop 52

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

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

Variables

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

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, 1000.07 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

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”

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.

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

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.

Variables Continued

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

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.

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)

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

The M in STEM

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 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? Diameter of the wheel = 2.75 inches

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

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

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!

Functions

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)

Function Definition

Function Call

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

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.

Advanced Function Definition

Advanced Function Call

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

Remote Control

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!

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

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!

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.

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

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

VEXnet Configuration 4. Insert VEXnet Keys and Test!

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

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)

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

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

Remote Control (with virtual robots)

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

Joystick Control – Tank Control

Joystick Control – Arcade Control X1 Y1

Joystick Control – Arm Control

Advanced Remote Control

USB Remote Control Code

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!

Timers

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

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

Really Advanced Remote Control

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

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

Troubleshooting

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

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

Sensing

Sensor Information: Touch Sensors

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

Move Forward until Pressed

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?

Sensor Information: Potentiometer

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

Potentiometers

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

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

Sensor Information Ultrasonic Rangefinder

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

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.

Forward until Near

Ultrasonic Rangefinder Forward until Near

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

VEX Robotics Competition Programming

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

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

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

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

Competition Resources

Additional Sensors

Ambient Light Sensor

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

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)

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

Accelerometers

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.

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.

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

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