PID Continued Downloading and Deploying Code Program a 2012 Robot from Spec Basic code For FIRST Robotics FRC Robot Programming
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
Where We Left Off:Read Gyro And PID Control Of Steering CorrectionIn Autonomous • Get Gyro Refnum, Get Gyro Angle • Set Timer of loop (30ms used here) • Add PID function block • Setpoint – set to 0 to drive straight forward • Connect Gyro output as Process variable input to PID • Limit output range • Set PID gains • Connect output to X input to arcade drive (Steering)
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
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. (or one bounce?) 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
Tuning the PID Hands on example of trial and error
Downloading Vs. Deploying Code • When developing code it is convenient to run the code right from the lap top by pressing the single arrow in the top left of the Robot Main Front Panel VI and “downloading” it from the laptop. • You must first be connected to the robot through the driver station (Prior session) • f you get a ‘Conflict Resolution” message – it is ok – it only means that you will be overriding the code previously deployed to run at the start-up of the robot. • Sometimes you get another warning that will require you to reboot the robot and try again.
Deploying the Code to the Robot • Once code is developed it is then desirable to Deploy it to the cRio to run onboard the robot. This is required for competition. • To Deploy: • On Project Explorer, right click on: “Build specifications” and select: New / Real Time Application • On source selection screen, Select Source Files, Then select Robot Main, and by clicking arrow add it to the “Startup .Vi’s” , then press “Build” • Once Build is complete – right click on this latest “Real Time Application” and select “Run at Start-up” • This deploys the compiled code onto the cRio, The robot should be connected by Ethernet cable for this step. • If you get a “Conflict Resolution” message – it is ok it means you will be replacing the existing code loaded on the cR io. • If you get a message that you cannot say ok to - you probably need to reboot the robot and try again. • Once deployed it will ask to reboot the robot – say yes. • Once rebooted it will be running your code on the cRio.
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
DashboardMain.vi 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) Front Panel:
Incorporating Sensors – Gyro:: • Follow Tutorials 4-7 • Adds Gyro • Opens Dashboard Project (7) 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)
Homework / Challenge # 2 Update the Autonomous code • Add multiple sequential While loops (like in default disabled structure) • Have robot go straight, turn 90 degrees, • Repeat 4-5 times to drive in a square.
Sequence While Loops After Each OtherSet Time (= # Iterations) For Each StepIn this case each is 100 iterations or 3 seconds.
Homework / Challenge # 3 • Add variety of sensors to Begin and Tele-op • Use “Examples” as source to copy correct formats
Program a Robot From its Functional SpecStart with a list of components and how connected
Program a Robot From its Functional Spec Start with Drive Functionality Base code may have most of this – may need to replace 2 motor with 4 motor • In Begin • Open 2w Drive or 4w Drive, set Refnum, set correct PWM #’s • Open Joystick, Set Refnum • In Tele-op • Get Refnum, Get Joystick Axes • Get Refnum, Set Arcade Drive • Connect X & Y axes to the Arcade drive inputs • Test & Debug this portion
Program a Robot From Its Functional Spec Next what do the other motors do, and how are they controlled? • In Begin • Open motors, set Refnum, set correct PWM #’s • Open 2nd Joystick (?), set refnum • In Tele-op • Get Refnum, Get Joystick2 Axes and/or Buttons • Get Refnum, Set motor • If using Buttons, need to add a case structure changing motor input from 0 if False to “Value” if On • Test & Debug this portion
Program a Robot From Its Functional Spec Next Incorporate the Limit switches to their functions.? • In Begin • Open DIO(s), set Refnum, set correct PWM #’s • In Tele-op • Get Refnum, Get DIOs: read true (on) or False (off) • Set up case structure(s) to set motor(s) to zero if limit switch is true • Test & Debug this portion
Program a Robot From Its Functional Spec Look for Pneumatic Examples
Program a Robot From Its Functional Spec Automate the Harvester: • Two harvester rollers – can be independently turned on and off • 3 IR Sensors can detect if ball is in front of them (On or Off = True or False) Set up a “truth table” • Determine what you want the rollers to do based on what the sensors see. 3 2 Three IR sensors used to detect presence of Ball 1
Automation • Truth Table sets up a “State Machine”