PPT

advertisement
Program optical quad encoders
in autonomous mode
Available at: www.etcurr.com
Lesson 3.2 – Program Optical Quad Encoders in Autonomous Mode
Program optical quad encoders
in autonomous mode






Performance Objective: Given the components of a
VEX robotics design system program optical quad
encoders in autonomous mode to have the robot
travel in a two foot square.
Enabling Objectives:
explain the purpose of an optical quad encoder
explain how an optical quad encoder operates
draw a flow chart for using an optical quad encoder
program an optical quad encoder
Available at: www.etcurr.com
Lesson 3.2 – Program Optical Quad Encoders in Autonomous Mode
Optical Quad Encoder



An encoder is a digital sensor whose signals can be
used to measure and define rotational movement
A quad encoder has two outputs, typically called
the A Channel and B Channel.
These outputs are out of phase with one another
and are used to determine direction of rotation
(CW or CCW)
Available at: www.etcurr.com
Lesson 3.2 – Program Optical Quad Encoders in Autonomous Mode
How does it work?



The encoder works by shining light onto the edge of a disk
outfitted with evenly spaced slots around the circumference
As the disk spins, light passes through the slots and is
blocked by the opaque spaces between the slots
As the disk rotates, the encoder detects and counts the
number of slots light has passed through (pulses)
determining distance traveled and direction of rotation
Available at: www.etcurr.com
Lesson 3.2 – Program Optical Quad Encoders in Autonomous Mode
Optical Quad Encoder



The encoder counts pulses and keeps
track of the number in the variable name
that you set for the encoder
1 full revolution of the encoder is 90
pulses
If you program a motor to turn for 90
pulses of an encoder, it will turn one
revolution
Available at: www.etcurr.com
Lesson 3.2 – Program Optical Quad Encoders in Autonomous Mode
Encoder Resolution




The number of pulses per revolution of the encoder is its
resolution
If the encoder is turning faster than the motor, the
resolution will be increased, if the encoder revolves twice
(180 pulses) for one wheel revolution, you can be more
accurate with the encoder
The resolution can be increased by putting the encoder on
a shaft that is spinning faster than the shaft on the motor
(gearing up)
The optical VEX quad encoder can detect up to 1,700 pulses
per second, which corresponds to 18.9 revolutions per
second
Available at: www.etcurr.com
Lesson 3.2 – Program Optical Quad Encoders in Autonomous Mode
Optical Quad Encoder

When you drag an Optical
Quad Encoder block into the
Programming Window, the
Optical Quad Encoder dialog
box appears, allowing you to
choose one of four
commands for the encoder
function to process:
Available at: www.etcurr.com
Lesson 3.2 – Program Optical Quad Encoders in Autonomous Mode
Programming a Quad
Encoder





The Start option tells the
encoders to start counting
encoder pulses
The Preset option allows you to
set the encoder to a fixed value or
to the value of a variable
The Get option allows you to store
the feedback from the encoder
into a variable
The Stop option tells the encoders
to stop counting encoder pulses.
It is important to stop your
encoders when they are not in
use to keep from overloading your
system
Available at: www.etcurr.com
Lesson 3.2 – Program Optical Quad Encoders in Autonomous Mode
Programming a Quad
Encoder



Select the Interrupt Port
number for the A channel
that corresponds with the
port on the Vex controller
Select the Input Port
number for the B Channel
that corresponds to the
port on the Vex controller
Use Invert Direction to
reverse the positive
direction of rotation
Available at: www.etcurr.com
Lesson 3.2 – Program Optical Quad Encoders in Autonomous Mode
Flow Chart a Quad Encoder


Draw a flow chart for a program that will
turn two encoders on, set preset value
to 1, and begin to count the pulses
If the encoders are less than a certain
value, then turn the motors on, once the
encoders reach that value, the motors
should shut off
Available at: www.etcurr.com
Lesson 3.2 – Program Optical Quad Encoders in Autonomous Mode
Flow Chart for Quad
Encoder
Start
Encoders
Drive
Forward
No
If encoders < X
Yes
Stop
Motors
End
Available at: www.etcurr.com
Lesson 3.2 – Program Optical Quad Encoders in Autonomous Mode
Program the robot using
the quad encoders






Using the prepared robot, plug the two quad encoders
into appropriate ports on the microcontroller
Begin a new competition project in easyC
Configure the project microcontroller accordingly
Define two global variables for the two quad encoders
Program the robot in a driving mode of your choice in
the Operator Control tab
Go to the Autonomous tab to being programming the
quad encoders
Available at: www.etcurr.com
Lesson 3.2 – Program Optical Quad Encoders in Autonomous Mode
Program the robot using
the quad encoders


Insert a start block
for each of the
encoders
Insert a preset
block for each
encoder,
presetting each
encoder to 1
Available at: www.etcurr.com
Lesson 3.2 – Program Optical Quad Encoders in Autonomous Mode
Program the robot using
the quad encoders


Insert a while loop
for 1==1
Inside the while loop
insert a block to get
the value for each
variable defined for
the quad encoders
Available at: www.etcurr.com
Lesson 3.2 – Program Optical Quad Encoders in Autonomous Mode
Program the robot using
the quad encoders





Insert an If statement
The If statement should
read “encoder1 &&
encoder2 <= 90”
“Encoder1 and encoder2”
are the variable name for
each encoder
“&&” means “and”, both
variables must be less or
equal to 90
Insert two motor modules
to make the move forward
Available at: www.etcurr.com
Lesson 3.2 – Program Optical Quad Encoders in Autonomous Mode
Program the robot using
the quad encoders

Insert an Else
statement that
stops the motors
once the value in
the if statement
has been reached
Available at: www.etcurr.com
Lesson 3.2 – Program Optical Quad Encoders in Autonomous Mode
Download the code





Build and download the code to the microcontroller
Use the Competition Switch Simulator to test the
program
The robot should turn the motors/wheels one
revolution and then stop
If your code works show your instructor before
proceeding to the next slide
If your code does not work, go back through the lesson
and see if you can determine the cause
Available at: www.etcurr.com
Lesson 3.2 – Program Optical Quad Encoders in Autonomous Mode
Move the robot 5 feet



With the quad encoders you can
program the robot to move a
predetermined distance
This can be done by adjusting the
number of pulses the motors move
How many pulses will make the robot
move 5 feet?
Available at: www.etcurr.com
Lesson 3.2 – Program Optical Quad Encoders in Autonomous Mode
Travel Distance




Recall the 90 pulses equals one
revolution
We can determine how far the robot
moves with one revolution of the wheels
The wheel moves the distance of its
circumference for each revolution
What is the circumference of the
wheels?
Available at: www.etcurr.com
Lesson 3.2 – Program Optical Quad Encoders in Autonomous Mode
Calculating Circumference





Circumference(C) equals the diameter(d) of
the wheel times(x) pi(3.14)
C = d x 3.14
Measure the diameter of the a wheel on the
robot
Multiply that measurement by 3.14
You now have the circumference of the wheel
Available at: www.etcurr.com
Lesson 3.2 – Program Optical Quad Encoders in Autonomous Mode
How many pulses?



If a wheel is 5 inches in diameter, its circumference is
15.7 inches
If I wanted to move forward 15 feet (180 inches) I
would divide 180 inches by 15.7 inches (the
circumference) to calculate the number of revolutions
required, 11.46
180” / 15.7” = 11.46 rev
Then multiply 11.46 times 90 (number of pulses in one
revolution) to calculate the number of pulses, 1031.84
11.46 rev X 90 pulses = 1031.84 pulses
Available at: www.etcurr.com
Lesson 3.2 – Program Optical Quad Encoders in Autonomous Mode
You Calculate


If you wanted the robot with the
encoders to travel 5 feet, how many
pulses should it go?
Modify your program code to have you
robot move forward 5 feet
Available at: www.etcurr.com
Lesson 3.2 – Program Optical Quad Encoders in Autonomous Mode
Finished!



If your robot moves forward 5 feet and
then stopped, your done!
Show your instructor your success
For more technical data on the optical quad encoder, visit:
http://www.vexforum.com/wiki/index.php/Optical_Shaft_Encoder
Available at: www.etcurr.com
Lesson 3.2 – Program Optical Quad Encoders in Autonomous Mode
Challenge




Now that you know how to program the optical
quad encoders . . .
Draw a flow chart that utilizes optical quad
encoders to have the robot travel in a two foot
square
Program the robot to travel in a two foot square
When you have completed this challenge, have
your instructor check this activity off on the
performance evaluation
Available at: www.etcurr.com
Lesson 3.2 – Program Optical Quad Encoders in Autonomous Mode
Download