Presentation on theme: "Add and Use a Sensor & Autonomous For FIRST Robotics"— Presentation transcript:
1 Add and Use a Sensor & Autonomous For FIRST Robotics FRC Robot FrameworkAdd and Use a Sensor& AutonomousFor FIRST Robotics
2 Sensors – Adding Intelligence and Enabling Automation Types of sensors:Limit Switches – on/offGyro - provides Robot rotation angle positionPotentiometer – like a volume control – can be used to control arm rotationEncoder - measures shaft rotation – robot distance, lift heightLight sensors – detect object breaking beamInfrared - detect presence of object nearbyUltrasonic - detects distance to object – such as wallCamera (Vision) - Direct feed to dashboard, Targeting with vision processingKinect (Camera + Infrared) – For Driver Station or on board robot?not used ….. yet…
3 Session Objectives:Discuss principles and applications for “Gyro” sensor.Bicycle wheel demoIncorporate “Gyro” into Autonomous code: Control Robot to drive in straight lineOpen Gyro in Begin.viGet Gyro Angle Tele-op.vi display on Front PanelNext use Gyro reading as “Feedback” to tell if robot is driving straight (at angle specified)PID control
4 FRC Project Browse to find your last code (or open new)Navigate to the Robot Main block diagramThen select BeginGo to Block Diagram
5 Begin .vi Updated for adding Gyro Edit vi: Add an accessory motor:Open function palette and select: WPI Robotics Library / Sensors / GyroAdd Open Gyro .viIdentify where plugged inAdd Refnum Set.viGive it a name
6 Open the “Autonomous VI” Remove diagram disablePut cursor on edge of disabled structure, right click and select “Remove Diagram Disable Structure”Delete the last 2 while loopsAfter noting what the default code is intended to doA method of sequencing operations in autonomous that we may return to
7 Set up a While Loop in Autonomous In remaining While Loop:Enlarge, create space to add Gyro and PID functionsChange length of time to 5 secondsEach loop is 50 ms, 100 loops = 5 secs.Change motor inputs to 0For now
8 Modify Autonomous.VI to Read Gyro From WPI Robotics Library/ Sensors/ Gyro paletteBring the Refnum Get and provide name it was given in the Begin.viBring Gyro Get Output vi and connect themPut cursor on “angle” output, right click, select, create indicatorIndicator shows up on Front PanelDigital indicator is default but can be replaced with a Dial or Linear Indicator
9 Modify Front Panel Indicator for Gyro reading Put Cursor on indicator, right click and select “Replace”, then “Gauge”Enlarge gauge by dragging diagonallyClick on the 10 and change to: 180Click on the 0 and make it: -180Hover on the 180 until you see the rotation arrows – then drag the 180 around to the -180.
10 Test the Code See if in Autonomous the Gyro is being read Next: Lets use it for an Autonomous codeWith “Feed-back” control
11 Feed-Back Control Open Loop: Examples: In an (older) car: turn heater knob to highHeater turns on and stays on until the driver gets too hot and manually turns it downRobot Harvester(2012): Operator holds button to turn harvester motor, watches until sees ball move up and then releases which stops motorControllerRobot
12 Feed-Back Control Closed Loop Examples: In a (newer) car: turn heater knob to 70oFHeater 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 motorMotor goes until on board light sensor “sees” ball – sends signal back to cRioLabview program then directs motor to stopControllerRobotSensorGenerally using it to see if a process is complete, then stabilize
13 PID Control PID stands for Proportional-Integral-Derivative A method of closed loop feedback controlA 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 gapIncorporates the idea that you need to slow down as you get close so you don’t overshoot the target.
14 The PID Function Block Set-point Process variable Desired value to get toProcess variableActual value as measured by a sensorOutput determined by magnitude of difference (error) between setpoint and process variablePID Gains adjust sensitivity
15 Add: Read Gyro And PID Control Of Steering Correction Get Gyro Refnum, Get Gyro AngleAdd PID function blockSetpoint – set to 0 to drive straight forwardConnect Gyro output as Process variable input to PIDLimit output rangeSet PID gainsConnect output to X input to arcade drive (Steering)
16 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
18 Homework Challenge Slides Learn how to modify the DashboardMake an autonomous Drive SequenceDrive a square patternLearn to use the “examples” and be able to code a variety of sensors – including encoder
19 Modifying the Dashboard – Gyro Indicator Open Dashboard Project, Modify to display Gyro angle on a gage(follow Labview tutorial number 7)Modify Robot code Tele-op to send data to dashboard (also part of Labview tutorial)DashboardMain.viFront Panel:
20 Incorporating Sensors – Gyro:: Open Dashboard Project, Modify to display Gyro angle on a gage (follow Labview tutorial)Modify Robot code Tele-op to send data to dashboard (also part of Labview tutorial)Follow Tutorials 4-7Adds GyroOpens Dashboard Project
21 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.
22 Homework / Challenge # 3Add variety of sensors to Begin and Tele-op Use “Examples” as source to copy correct formats