Robotics Programming Using Shaft Encoders

Slides:



Advertisements
Similar presentations
ROBOTC for CORTEX While Loops Part 1
Advertisements

Variables and Functions ROBOTC Software. Variables A variable is a space in your robots memory where data can be stored, including whole numbers, decimal.
While Loops and If-Else Structures
Automation and Robotics
VEX and Robot C Chris Patterson Presented by Modified by J. Andazola.
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.
Available at: – Program Optical Quad Encoders in Autonomous Mode Program optical quad encoders in autonomous mode.
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 Software Introduction. ROBOTC Software ROBOTC developed specifically for classrooms and competitions Complete programming solution for VEX Cortex.
ROBOTC for VEX On-Site Professional Development
Variables and Functions. Open your Encoder program Let’s begin by opening the “Labyrinth Auto Straight” code. Save this file as Labyrinth with variables.
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.
Getting Started in RobotC // Comment task main() motor[] {} wait1Msec() ; = Header Code Compile Download Run Take out your notes.
Variables and Functions ROBOTC Software © 2012 Project Lead The Way, Inc.Principles of Engineering.
While and If-Else Loops ROBOTC Software. While Loops While loop is a structure within ROBOTC Allows a section of code to be repeated as long as a certain.
RobotC Remote Control. Learning Objectives: Focusing on Virtual World with Physical Examples Understand Real-Time Joystick Mapping Understand how to use.
Programming - Motion Intro to Robotics. Motors and Sensors Setup The first thing we need to do is tell ROBOTC that we have motors on our robot. Choose.
Programming your Robot
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.
Vex Robotics program three: using motors and sensors together.
ROBOTC for VEX Online Professional Development. Homework Questions Thoughts? Questions?
Bot Shop Jane Taylor Dee Wallace Robot C For Vex.
ROBOTC for VEX Online Professional Development. Homework Questions Thoughts? Questions? Concerns? Homework Policy: All homework is due Friday, August.
Decision Making: while loops and Boolean Logic. While Loops A while loop is a structure within ROBOTC which allows a section of code to be repeated as.
Sensor Information: while loops and Boolean Logic.
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
VEX Cortex Video Trainer using ROBOTC
Variables and Functions
Variables and Functions
ROBOTC for VEX Online Professional Development
ROBOTC for VEX On-Site Professional Development
Robotics Programming Using Shaft Encoders
ROBOTC for VEX Online Professional Development
Automation and Robotics
Variables and Functions
RobotC Sensors.
Movement using Shaft Encoders
Using Encoders to go Straight
Autonomy using Encoders
Variables and Functions
RobotC Sensors.
Getting Started in RobotC
Variables and Functions
Variables and Functions
Using variables, for..loop and functions to help organize your code
Automation and Robotics
While Loops and If-Else Structures
Basketball Drill Programming Alternatives
Variables and Functions
Getting Started in RobotC
Auto Straightening using VEX Shaft Encoders
While Loops and If-Else Structures
While Loops and If-Else Structures
While Loops and If-Else Structures
While Loops and If-Else Structures
RobotC While loop When and how to use the while loop
Robotics Programming Using Shaft Encoders
Remote Control For this activity we will use the Squarebot
While Loops and If-Else Structures
Robotics Programming Using Shaft Encoders
While Loops and If-Else Structures
While Loops And If-Else Structures
Is there an alternative to copy-paste for repeating code?
Presentation transcript:

Robotics Programming Using Shaft Encoders

Learning Objectives Be able to use Shaft Encoders to control the robot driving for a distance Motors and Sensors setup Using the while loop Using the debugger window to watch the sensor values change Online time Be able to use Shaft Encoders to help the robot drive straight If If..else

Movement using Shaft Encoders Configure (Motors and Sensors Setup) We will look at the following in this section SensorValue[] while Conditions (<, >, <=, >=, !=, ==)

Getting Started/ Review Open RobotC Start a new program Set up a Squarebot rightMotor: port2 leftMotor: port3 Add code to make it go forward for 1 second and test in the Labyrinth Challenge Virtual World. Make sure you select ‘VEX Squarebot’ from the ‘ROBOTS’ menu in the virtual world. Make sure the robot moves forward and not just spins.

Quadrature/Shaft/Rotation Encoder 360 Ticks per revolution Counts up going forward, down going backwards Takes two digital input ports on the Cortex If the wires are plugged in in reverse order, then the counter will count backwards.

Configuring the Encoders Configure the encoders on your warm-up code. Robot -> Motors and Sensors Setup

Name and Select 1) Select the VEX Cortex Digital Sensors 1-12 tab. 3) Select the Sensor Type. Quadrature Encoder in this case. 2) Name the encoder. (Start with a letter, no spaces, no punctuation, no reserved words, descriptive.) 4) Click ‘Apply’ and ‘OK’ Note: On the Cortex the quadrature encoder cables must be plugged in next to each other.

pragma Statements Created

Now that it is set up, we want to use the encoder to control the distance a robot travels The sensor will return 360 ticks per revolution or 1 tick per degree. The squarebot has 2.75” diameter wheels. How many ticks for the robot to travel 3.6 feet? Pseudocode While the robot has not travelled 1800 ticks, keep ongoing. 3.6 feet 12 inches 1 revolution 360 ticks = 1800 ticks 1 foot Pi * 2.75 inches Use the wheel diameter to match your robot.

Initializes both encoder values to 0. From Math to Code SensorValue[rightEncoder] is used to initialize (set to 0 in this case) and read encoder values. Initializes both encoder values to 0. While the value of the left encoder is less than 1800 it will go through the loop again. while (condition) { }

Breaking Down 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.

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

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.

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.

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.

Boolean Logic Conditions: True or False Conditions: Compare two items and return a true or a false value examples while (SensorValue[leftEncoder] < 2000) { } while (SensorValue[leftEncoder] > -2000) while (SensorValue[leftEncoder] <= 2000) RobotC Comparison Operations < Is less than > Is greater than <= Is less than or equal to >= Is greater than or equal to == Is equal to != Is not equal to

Back to the Encoder Example SensorValue[rightEncoder] is used to initialize (set to 0 in this case) and read encoder values. Initializes both encoder values to 0. While the value of the left encoder is less than 1800 it will go through the loop again. while (condition) { } What happens if you add a wait1Msec(12000); command inside the while loop? Test this code in the Virtual World.

Debugging: Watching the Sensor Values Open Debugger window for Sensors Robot->Degugger Windows -> Sensors Note: If the ‘Debugger Window’ option is not available, then compile and download the program to your robot and try again.

Watch the Values Run the program in the Virtual World Watch the sensor values change Sensor Values

Online Time Motor Encoder Movement Challenges using only encoders, no timing. Basketball Drills Turning Investigation Labyrinth Challenge

Auto Straightening using VEX Shaft Encoders

Learning Objectives Understand how the strategy for using shaft encoders to help the robot drive straight. Be able to program the robot to go straight using shaft encoders Be able to use the while loop, if and variables.

Pseudo Code (What we are trying to get the robot to do) While the robot has not reached the destination If the left motor has gone farther, slow the left motor and have right motor go at speed If the right motor has gone farther, slow the right motor and have the left motor go at speed If the motors are the same, have both motors go at speed

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!

Going Straight: Translating to Code Pseudo Code While the robot has not reached the destination If the left motor has gone farther, slow the left motor and have right motor go at speed If the right motor has gone farther, slow the right motor and have the left motor go at speed If the motors are the same, have both motors go at speed

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.

Code this and test it on the Huge Table. Implementing if..else Code this and test it on the Huge Table.

But… If the motors are not close in their Power to Speed then the difference between 50 and 63 might not be sufficient. So it will take some tweaking. Rather than changing the 63 to another value when modifying the ‘at speed’ needed, you can use variables.

RobotC Variables Review int Stores integer values: 5, 0, -100 float Stores floating point (real) values: 3.01, -5.21, 0 string Stores words: “Hello World” char Stores single characters: “A”, “@” bool Stores Boolean (true, false) values

Code After Using Variables for Speed Values These variables are setup as local variables in task main(). Declaring the variables. type name; Initialize the variables. You can change the values of the variables. fullSpeed = fullSpeed + 5; Modify your going straight code to incorporate variables. Try modifying the fullSpeed and slowerSpeed values to see how if changes the robot behavior.

Summary motor[] SensorValue[] wait1Msec() while if if..else Conditions Conjunctions Motors and Sensor Quadrature Encoder Strategies on going straight Timing vs. distance

Driving Straight Activity Driving Straight II using encoders Bull in the Ring: Using a while or an if Robo-Slalom I: Using a while or an if