frc robot programming 1.pid continued 2.downloading and deploying code 3.program a 2012 robot from...

23
FRC Robot Programming 1. PID Continued 2. Downloading and Deploying Code 3. Program a 2012 Robot from Spec Basic code For FIRST Robotics

Upload: melvyn-pearson

Post on 13-Jan-2016

235 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: FRC Robot Programming 1.PID Continued 2.Downloading and Deploying Code 3.Program a 2012 Robot from Spec Basic code For FIRST Robotics

FRC Robot Programming

1. PID Continued2. Downloading and Deploying Code3. Program a 2012 Robot from Spec

• Basic code

For FIRST Robotics

Page 2: FRC Robot Programming 1.PID Continued 2.Downloading and Deploying Code 3.Program a 2012 Robot from Spec Basic code For FIRST Robotics

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

Page 3: FRC Robot Programming 1.PID Continued 2.Downloading and Deploying Code 3.Program a 2012 Robot from Spec Basic code For FIRST Robotics

Where We Left Off:Read Gyro And PID Control Of Steering Correction

In Autonomous Get Gyro Refnum, Get

Gyro Angle Set Timer of loop (30ms

used here)

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 gains5.Connect output to X

input to arcade drive (Steering)

Page 4: FRC Robot Programming 1.PID Continued 2.Downloading and Deploying Code 3.Program a 2012 Robot from Spec Basic code For FIRST Robotics

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

Page 5: FRC Robot Programming 1.PID Continued 2.Downloading and Deploying Code 3.Program a 2012 Robot from Spec Basic code For FIRST Robotics

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

Page 6: FRC Robot Programming 1.PID Continued 2.Downloading and Deploying Code 3.Program a 2012 Robot from Spec Basic code For FIRST Robotics

Tuning the PID

Hands on example of trial and error

Page 7: FRC Robot Programming 1.PID Continued 2.Downloading and Deploying Code 3.Program a 2012 Robot from Spec Basic code For FIRST Robotics

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.

Page 8: FRC Robot Programming 1.PID Continued 2.Downloading and Deploying Code 3.Program a 2012 Robot from Spec Basic code For FIRST Robotics

• 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:

1. On Project Explorer, right click on: “Build specifications” and select: New / Real Time Application

2. 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”

3. Once Build is complete – right click on this latest “Real Time Application” and select “Run at Start-up”

1. This deploys the compiled code onto the cRio, The robot should be connected by Ethernet cable for this step.

2. If you get a “Conflict Resolution” message – it is ok it means you will be replacing the existing code loaded on the cR io.

3. If you get a message that you cannot say ok to - you probably need to reboot the robot and try again.

4. Once deployed it will ask to reboot the robot – say yes.

1. Once rebooted it will be running your code on the cRio.

Deploying the Code to the Robot

Page 9: FRC Robot Programming 1.PID Continued 2.Downloading and Deploying Code 3.Program a 2012 Robot from Spec Basic code For FIRST Robotics

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

Page 10: FRC Robot Programming 1.PID Continued 2.Downloading and Deploying Code 3.Program a 2012 Robot from Spec Basic code For FIRST Robotics

Modifying the Dashboard – Gyro Indicator

a) Open Dashboard Project, Modify to display Gyro angle on a gage • (follow Labview tutorial number 7)

b) Modify Robot code Tele-op to send data to dashboard (also part of Labview tutorial)

DashboardMain.vi

Front Panel:

Page 11: FRC Robot Programming 1.PID Continued 2.Downloading and Deploying Code 3.Program a 2012 Robot from Spec Basic code For FIRST Robotics

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 (7)

Page 12: FRC Robot Programming 1.PID Continued 2.Downloading and Deploying Code 3.Program a 2012 Robot from Spec Basic code For FIRST Robotics

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.

Page 13: FRC Robot Programming 1.PID Continued 2.Downloading and Deploying Code 3.Program a 2012 Robot from Spec Basic code For FIRST Robotics

Sequence While Loops After Each OtherSet Time (= # Iterations) For Each Step

In this case each is 100 iterations or 3 seconds.

Page 14: FRC Robot Programming 1.PID Continued 2.Downloading and Deploying Code 3.Program a 2012 Robot from Spec Basic code For FIRST Robotics

Homework / Challenge # 3Add variety of sensors to Begin and Tele-op

Use “Examples” as source to copy correct formats

Page 15: FRC Robot Programming 1.PID Continued 2.Downloading and Deploying Code 3.Program a 2012 Robot from Spec Basic code For FIRST Robotics

Begin.VI - Open and name sensors

Page 16: FRC Robot Programming 1.PID Continued 2.Downloading and Deploying Code 3.Program a 2012 Robot from Spec Basic code For FIRST Robotics

Tele-op.VI - Get values and display

Page 17: FRC Robot Programming 1.PID Continued 2.Downloading and Deploying Code 3.Program a 2012 Robot from Spec Basic code For FIRST Robotics

Program a Robot From its Functional Spec

Start with a list of components and how connected Apple Pi Robot: Mantis

2012

Robot Control System Data Connection Spreadsheet

I/O Type

Actuator/Sensor

AIO DIO PWM

Relay Pneumatic

I/O Port

If Actuator, controlled by : If Sensor, used to control:

Left rear drive motor PWM 1 Joy1 axes 1&2

Right rear drive motor PWM 2 Joy1 axes 1&2

Right Front drive motor PWM 1 Joy1 axes 1&2

Left Front drive motor PWM 2 Joy1 axes 1&2

Lower Harvester Motor PWM 3 Joy2 button 7

Upper Harvester Motor PWM 4 Joy2 button 8

Shooter Motor1 PWM 5 Joy2 button 1

Shooter Motor2 PWM 5 Joy2 button 1

Ramp Knockdown Device Motor PWM 6 Joy2 Axes 2

Encoder Left drive 1 DIO 1 Auton Drive

Encoder Left drive 2 DIO 2 Auton Drive

Encoder Right drive 1 DIO 3 Auton Drive

Encoder Right drive 2 DIO 4 Auton Drive

Upper Limit switch DIO 5 Knockdown Device

Lower Limit switch DIO 6 Knockdown Device

Upper Harvester IR Sensor AIO 1 Harvester motors

Middle Harvester IR Sensor AIO 2 Harvester motors

Lower Harvester IR Sensor AIO 3 Harvester motors

Tech Tigers Robot: Tiogar

2012

Robot Control System Data Connection Spreadsheet

I/O Type

Actuator/Sensor

AIO DIO PWM

Relay Pneumatic

I/O PortIf Actuator, controlled by : If Sensor, used to control:

Left rear drive motor PWM 1 Joy1 axes 1&2

Right rear drive motor PWM 2 Joy1 axes 1&2

Right Front drive motor PWM 1 Joy1 axes 1&2

Left Front drive motor PWM 2 Joy1 axes 1&2

Accessory Motor 1 PWM 3 Joy2 button ?

Accessory Motor 2 PWM 4 Joy2 button ?

Upper Limit switch DIO 1

Lower Limit switch DIO 2

Pressure Switch DIO 3

Compressor Spike Relay 1

Solenoid 1 Pneum 1

Solenoid 2 Pneum 2

Solenoid 3 Pneum 3

Page 18: FRC Robot Programming 1.PID Continued 2.Downloading and Deploying Code 3.Program a 2012 Robot from Spec Basic code For FIRST Robotics

Program a Robot From its Functional Spec

Start with Drive FunctionalityBase 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

Page 19: FRC Robot Programming 1.PID Continued 2.Downloading and Deploying Code 3.Program a 2012 Robot from Spec Basic code For FIRST Robotics

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

Page 20: FRC Robot Programming 1.PID Continued 2.Downloading and Deploying Code 3.Program a 2012 Robot from Spec Basic code For FIRST Robotics

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

Page 21: FRC Robot Programming 1.PID Continued 2.Downloading and Deploying Code 3.Program a 2012 Robot from Spec Basic code For FIRST Robotics

Program a Robot From Its Functional Spec

Look for Pneumatic Examples

Page 22: FRC Robot Programming 1.PID Continued 2.Downloading and Deploying Code 3.Program a 2012 Robot from Spec Basic code For FIRST Robotics

Program a Robot From Its Functional Spec

Automate the Harvester:1. Two harvester rollers – can be

independently turned on and off

2. 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. Three IR sensors

used to detect presence of Ball

1

2

3

Page 23: FRC Robot Programming 1.PID Continued 2.Downloading and Deploying Code 3.Program a 2012 Robot from Spec Basic code For FIRST Robotics

Automation Truth Table sets up a “State Machine”

Truth Table for Mantis Auto Harvester

Desired behavior is that when Auto harvester engaged - it will collect 3 balls and have them ready for shooting.

Lower IR Sensor Middle IR Sensor Upper IR Sensor Lower Harvester Motor Upper Harvester Motor

0 0 0    

1 0 0    

0 1 0    

0 0 1    

1 1 0    

1 0 1    

0 1 1    

1 1 1    

This table tells us how we want the harvester to behave in response to the sensor readings.