FRC Robot Add Sensor-11/13/12

advertisement
FRC Robot Framework
Add and Use a Sensor
& Autonomous
For FIRST Robotics
Sensors – Adding Intelligence
and Enabling Automation
Types of sensors:
Limit Switches – on/off
Gyro - provides Robot rotation angle position
Potentiometer – like a volume control – can be used to control
arm rotation
Encoder - measures shaft rotation – robot distance, lift height
Light sensors – detect object breaking beam
Infrared - detect presence of object nearby
Ultrasonic - detects distance to object – such as wall
Camera (Vision) - Direct feed to dashboard, Targeting with
vision processing
Kinect (Camera + Infrared) – For Driver Station or on board
robot?
not used ….. yet…
Session Objectives:
•
Discuss principles and applications for “Gyro” sensor.
•
•
Bicycle wheel demo
Incorporate “Gyro” into Autonomous code:
Control Robot to drive in straight line
•
•
•
Open Gyro in Begin.vi
•
PID control
Get Gyro Angle Tele-op.vi display on Front Panel
Next use Gyro reading as “Feedback” to tell if robot is driving
straight (at angle specified)
FRC Project

Browse to find
your last code



(or open new)
Navigate to the
Robot Main block
diagram
Then select Begin

Go to Block Diagram
Begin .vi Updated for adding Gyro
• Edit vi: Add an accessory
motor:
• Open function palette and
select: WPI Robotics Library
/ Sensors / Gyro
• Add Open Gyro .vi
• Identify where plugged in
• Add Refnum Set.vi
• Give it a name
Open the “Autonomous VI”
 Remove diagram
disable
 Put cursor on edge of
disabled structure, right
click and select
“Remove Diagram
Disable Structure”
 Delete the last 2
while loops
 After noting what the
default code is intended
to do
 A method of
sequencing operations
in autonomous that we
may return to
Set up a While Loop in Autonomous
 In remaining While Loop:
 Enlarge, create space to
add Gyro and PID functions
 Change length of time to
5 seconds
 Each loop is 50 ms, 100
loops = 5 secs.
 Change motor inputs to 0
 For now
Modify Autonomous.VI to Read Gyro

From WPI Robotics Library/ Sensors/ Gyro palette

Bring the Refnum Get and provide name it was given in the Begin.vi

Bring Gyro Get Output vi and connect them

Put cursor on “angle” output, right click, select, create indicator
Indicator shows up on Front Panel
Digital indicator is default but can be replaced with a Dial or Linear Indicator
Modify Front Panel Indicator
for Gyro reading
Put Cursor on indicator, right click
and select “Replace”, then
“Gauge”

Enlarge gauge by dragging
diagonally


Click on the 10 and change to: 180

Click on the 0 and make it: -180

Hover on the 180 until you see the
rotation arrows – then drag the 180
around to the -180.
Test the Code
See if in Autonomous the Gyro is being read
Next: Lets use it for an Autonomous code
With “Feed-back” control
Feed-Back Control
Open Loop:
Controller
Robot
Examples:
In an (older) car: turn heater knob to high
Heater turns on and stays on until the driver gets too hot and
manually turns it down
Robot Harvester(2012): Operator holds button to turn harvester
motor, watches until sees ball move up and then releases
which stops motor
Feed-Back Control
Closed Loop
Controller
Robot
Sensor
Examples:
In a (newer) car: turn heater knob to 70oF
Heater goes on until the thermostat (sensor) reads that it is 70oF , then automatically
turns it off until it gets too cool, then back on, etc.
Robot Harvester: Operator presses button to start harvester motor
Motor goes until on board light sensor “sees” ball – sends signal back to cRio
Labview program then directs motor to stop
Generally using it to see if a process is complete, then stabilize
PID Control
 PID stands for Proportional-Integral-Derivative
 A method of closed loop feedback control
 A way of using what you know from your sensors to
compute an “intelligent” motor output.
 Proportional – P – looks at difference between desired
position and actual and sets motor speed to close gap
proportional to that gap
 Incorporates the idea that you need to slow down as you
get close so you don’t overshoot the target.
The PID Function Block
 Set-point
 Desired value to get to
 Process variable
 Actual value as measured by a
sensor
 Output determined by
magnitude of difference
(error) between setpoint and
process variable
 PID Gains adjust sensitivity
Add: Read Gyro And PID Control Of
Steering Correction
 Get Gyro Refnum, Get
Gyro Angle
 Add PID function block
1. Setpoint – set to 0 to
drive straight forward
2. Connect Gyro output
as Process variable
input to PID
3. Limit output range
4. Set PID gains
5. Connect output to X
input to arcade drive
(Steering)
Suggested method for
determining PID gains
Method for Setting Values
Start with CP small and CI, CD both zero.
Raise CP until the robot is oscillating
consistently around the target.
Once this is accomplished, start increasing
CD until the robot stops oscillating.
Then add CI until the robot stops within a
desired range of the target.
Often we have only used the P, or PD
Next we will see if our code works!
Homework Challenge Slides
• Learn how to modify the Dashboard
• Make an autonomous Drive Sequence
•
Drive a square pattern
• Learn to use the “examples” and be able to
code a variety of sensors – including encoder
Modifying the Dashboard
– Gyro Indicator
a)
Open Dashboard Project, Modify to display Gyro angle on a gage
•
b)
(follow Labview tutorial number 7)
Modify Robot code Tele-op to send data to dashboard (also part of Labview tutorial)
DashboardMain.vi
Front Panel:
Incorporating Sensors – Gyro::
a)
Open Dashboard Project, Modify to display Gyro angle on a gage (follow Labview
tutorial)
b)
Modify Robot code Tele-op to send data to dashboard (also part of Labview
tutorial)
• Follow Tutorials 4-7
• Adds Gyro
• Opens Dashboard
Project
Homework / Challenge # 2
Update the Autonomous code
• Add 3 sequential While loops (like in default
disabled structure)
• Have robot go straight, turn 90 degrees,
• Repeat 3 times to drive in a square.
Homework / Challenge # 3
Add variety of sensors to Begin and Tele-op
Use “Examples” as source to copy correct formats
Begin.VI - Open and name sensors
Tele-op.VI - Get values and display
Download
Related flashcards
Create Flashcards