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.

Slides:



Advertisements
Similar presentations
Full Speed Ahead Introductory Presentation. Opening Activity Choose one of the objects to the right and in ten or more steps explain how it goes from.
Advertisements

While Loops and If-Else Structures
Automation and Robotics
VEX and Robot C Chris Patterson Presented by Modified by J. Andazola.
Developed in collaboration with Introduction to Programming.
Available at: – Program Optical Quad Encoders in Autonomous Mode Program optical quad encoders in autonomous mode.
RobotC Programming for LEGO Mindstorms NXT Carnegie Mellon Dacta Lego Timothy Friez Miha Štajdohar SOURCES:
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.
ROBOTC for VEX Online Professional Development
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
Programming Design ROBOTC Software Principles of Engineering
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.
AUTOMATION WITH ROBOTC Starting to write and troubleshoot computer code.
Find the Mindstorms Icon on the computer.. To start a new program click go.
Vex Robotics Program four: reversing and turning.
The George Washington University Electrical & Computer Engineering Department ECE 002 Dr. S. Ahmadi Class3/Lab 2.
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.
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.
BEGINNER FLL PROGRAMMING WORKSHOP BY DROIDS ROBOTICS & EV3LESSONS.
VEX and Robot C Chris Patterson Frisco ISD CTE Center Presented by.
Deriving Consistency from LEGOs What we have learned in 6 years of FLL by Austin and Travis Schuh © 2005 Austin and Travis Schuh, all rights reserved.
Automation and Robotics.  First you select the platform type so that you can use Natural Language PLTW.
ROBOTC for VEX Online Professional Development. Homework Questions Thoughts? Questions?
Bot Shop Jane Taylor Dee Wallace Robot C For Vex.
Robotics Programming Wall Follow Line tracking for a set amount of time Line tracking for a distance.
Sensor Information: while loops and Boolean Logic.
ROBOTC for CORTEX Teacher Training © 2011 Project Lead The Way, Inc. Automation and Robotics VEX.
Programming Design ROBOTC Software Principles Of Engineering
Introduction to Programming in RobotC
VEX Cortex Video Trainer using ROBOTC
Deriving Consistency from LEGOs
VEX IQ Mix & Match Curriculum
ROBOTC for VEX Online Professional Development
ROBOTC for VEX On-Site Professional Development
Robotics Programming Using Shaft Encoders
ROBOTC for VEX Online Professional Development
Programming Design ROBOTC Software Computer Integrated Manufacturing
Introductory Presentation
Programming - Motion Intro to Robotics.
Movement using Shaft Encoders
Using Encoders to go Straight
Autonomy using Encoders
RobotC Sensors.
Getting Started in RobotC
Automation and Robotics
While Loops and If-Else Structures
An Introduction to VEX IQ Programming with Modkit
Getting Started in RobotC
Auto Straightening using VEX Shaft Encoders
While Loops and If-Else Structures
Programming Design ROBOTC Software Principles Of Engineering
While Loops and If-Else Structures
While Loops and If-Else Structures
While Loops and If-Else Structures
Programming - Buttons Intro to Robotics.
RobotC While loop When and how to use the while loop
if-else Structures Principles of Engineering
Robotics Programming Using Shaft Encoders
Programming - Buttons Intro to Robotics.
Robotics Programming Using Shaft Encoders
While Loops and If-Else Structures
Robotics Programming Using Shaft Encoders
While Loops and If-Else Structures
Programming Design ROBOTC Software Principles of Engineering
While Loops And If-Else Structures
Getting started with LEGO EV3 Mindstorms software
Presentation transcript:

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 timers. We use our new sensor, the ENCODER.

Autonomy/Encoders Forward for Distance In this unit, you will learn to use the encoders to control the distance the robot moves, and to self-correct its steering to counteract the random drift that occurs during movement. This will eventually serve two purposes.

Autonomy/Encoders Forward for Distance First, it will provide you with a new form of Operator Assist that uses the sensors on the robot to drive straighter than a human operator might be capable of doing. Second, it will begin building a base of behaviors that the robot can use on its own during the Autonomous Period that is part of the revised challenge. For 20 seconds at the start of the match, your robot will have a chance to run and score points completely on its own.

The Encoder The Encoder is a sensor that measures rotation. On the Squarebot 3.0, encoders are attached to the wheels of the robot. The encoders measure how far the wheels have turned, and therefore, how far the robot has moved. The distance the robot covers moving forward is equal to the length of the tire tread that spins by.

The Encoder We will be able to make reasonably accurate predictions about exactly how far the robot will move after every full turn of the wheels. The encoder measures in 4-degree increments, and so will register 90 counts for a full 360-degree rotation. For this lesson, the important part is simply that the number of encoder counts is directly linked to the amount that the wheels turn, and therefore, to the distance that the robot travels. Being able to directly measure the turning of the wheels allows us to dictate the motion of the robot in terms of distances rather than simply defining a period of time that the robot should move. This is a much more reliable method, because it is unaffected by factors like speed or battery power. Using the encoder-based distance to determine movement, therefore, will result in much better consistency of movement. This is exactly what your robot needs to do its job well, with or without human supervision!

Open a sample program Save in the UCF folder as Encoder Test

Motors & Sensors Setup Notice that the encoders are a DIGITAL sensor and that we named them “rightEncoder” and “leftEncoder”. Each encoder is plugged into TWO ports on the Cortex.

Let’s inspect our code The “SensorValue” command is used for ALL sensors and can be used to clear any digital value stored in the sensor. Each command must specify which sensor it is referring to by its NAME. In this case, we are setting each encoder to ZERO. This clears out the encoder so that it can measure out distance. This MUST be done each time you travel a distance or make a turn.

Let’s inspect our code This is a special type of CONTROL STRUCTURE, called a WHILE LOOP.

while ( ) When the program reaches most commands, it runs them and then moves on. When the program reaches a while ( ) loop, however, it steps INSIDE the loop, and stays there as long as the while ( ) loops decides that it should. The commands repeat over and over.

Let’s inspect our code The CONDITION inside the parenthesis states that the encoder values need to be LESS than As long as the counts are less than 1800 the COMMANDS(simple statements) inside the curly braces will loop over and over. As soon as the count goes OVER 1800, the loop will END and the next line of code will begin.

Modifying our Labyrinth Code Checkpoint Your robot should begin executing the first behavior two seconds after it is turned on. The robot will start moving — and keep moving! If you pick it up and let it run for a while, you will notice that it eventually stops, but nowhere near the right distance. The guess we used for the number of encoder counts was off is far too many counts for the distance that the robot needs to move.

Encoder count off? Change this value until you reach the turn in the labyrinth. Compile and download each time until the robot reaches the correct position.

Test the Encoder count

Making turns with the Encoder You must ZERO the left encoder before using it for a different leg of the labyrinth. We use a NEW COUNT for the right turn and also make sure we reverse the right motor to make the turn correctly. All of this is done inside a second WHILE loop.

Rule of thumb

Finish the program

Test & make changes to encoder counts Save the program as MAZE using encoders. Complete the maze using encoder counts. Use comments in the code as well.

Motor power changes?

Motor Power Changes

What happened?

Encoder usefulness

Automated Straightening Earlier in the course, we tweaked the power motor values to get the robot to go straight even though the task was tedious.

Automated Straightening

The “If” statement The “IF” statement is similar to a while loop in that it is a CONTROL STRUCTURE. But it is very different in that it only runs the commands ONCE instead of looping. Just like the while loop, the “IF” statement has a CONDITION that robotC checks to see if it is true. If the condition is true, it runs the commands inside the curly braces. If it is false, it exits and runs the next line of code. Save your code from before as LABYRINTH AUTO STRAIGHT.

Using the “RIGHT” Encoder Since BOTH encoders will be used to monitor whether the robot moves straight it is important to make sure you ZERO out each encoder before each turn.

Using the “IF” statements Locate your FIRST while loop and inside set up the framework for the THREE “IF” statements.

If the LEFT is greater than the RIGHT This says, if the counts on the left encoder are greater than the counts on the right encoder then lessen the power on the left motor and increase the power on the right

If the RIGHT is greater than the LEFT

If the RIGHT is equal to the LEFT The WHILE loop still makes sure the distance is set at the correct # of counts while the “IF” statements make sure the robot moves straight over this distance.

Using /* comments */ to test program Note: Make sure the last */ - comment tag is BEFORE your last “task main” punctuation pair. “Commenting out your code” is a great way to go back and test out individual parts of the code as you work on changes. Comment out your MAZE code and test just the first leg of the STRAIGHT program.

Test!

Finish the changes! Now change the REST of the code for the OTHER behaviors which require the robot to go straight. Be sure to RESET the encoder values to zero before each while loop.

Boolean Logic The programming we just did is called Boolean logic which is simply based on whether the condition is TRUE or FASLE.

Boolean Logic – Comparison Operator A comparison operator is one where the condition is either YES(true) or NO(false).

Boolean Logic – Logical Operator A logical operator takes TWO conditions and makes ONE truth statement.

Test the Labyrinth Save your code and make sure it has comments!