FIRST Robotics Competition Discussions

cancel
Showing results for 
Search instead for 
Did you mean: 

Simple PID Example

I am a mentor looking to help the students understand a simple PID loop.  The hardware we built is a simple systen - a motor (geared down) driving a "dial" than can go from 9:00 to 3:00 (180 degrees) and connected to that dial is an encoder that reads position -200 to +200

I would like to use a simple PID to 'lock on' to the desired position - set by a number in the software. Now I understand there are 'dynamics' and other variables involved, but can you point me in the right direction (or example) of how to set up and then tune (can I set I and D to zero?) the loop. Are there 'typical' relationships between P I & D?

0 Kudos
Message 1 of 11
(17,041 Views)

Hi Mentor

For PID control you will use the PID.vi located under addons>>PID control>> PID. You will use this same VI for both P, PI and PID control. Simply set the constant to zero for any term which you do not wish to use. The following documentation goes over the PID toolkit indepth:

http://zone.ni.com/devzone/cda/tut/p/id/3782#toc1

Depending on if we are controlling a stepper motor or servo this will drastically change our method of control. Our Setpoint will be the encoder reading of our desired position for both stepper and servo control. For a servo motor your process variable would be the voltage to output to the system. For a stepper motor you would use this to change our PWM to a faster or slower rate (there may be some conversion math also known as compensator required with doing this). The output range will specify the limits for use on the process variable. D(t) will calculate itself if unwired based off the rate the current loop is running. Initially only change P until we are able achieve a value where we oscillate over our setpoint.

For tuning once we have got our control loop up and running, I recommend performing the Nichols Ziegler method shown in the documentation. Basically we will increase P until we find our system begin to oscillate over the set value (180 in our case) once we reach this we divide the value by two to find our Kc. You can then try both the PI and PID commands using the given Kc and this should give you a good start to begin adjustments from.

Control
P
Ti
Td
P
0.5Kc
-
-
PI
0.45Kc
Pc/1.2
-
PID
0.60Kc
0.5Pc
Pc/8

Table 1. Ziegler-Nichols tuning, using the oscillation method.

Below is an image of what a sample PID system would look like in LabVIEW. The output of the control system would be the error.

PID example.JPG

Please let me know if this helps get your system up and running.

Thank You

Eric Reid

Applications Engineer

National Instruments


Thank You
Eric Reid
National Instruments
Motion R&D
0 Kudos
Message 2 of 11
(4,506 Views)

For another PID resource that may help you with tuning, see The Effective Use of PID Control in Robotics Systems

Best Regards,

~Nate

0 Kudos
Message 3 of 11
(4,506 Views)

Thanks Nate thats great documenation on the subject!


Thank You
Eric Reid
National Instruments
Motion R&D
0 Kudos
Message 4 of 11
(4,506 Views)

We are just using a 'plian DC motor' with a gear box 16:1 (not a servo). The output at of the gear box will rotate at 1000RPM, full speed - so to move 180 degrees only takes 1.5 seconds (fast) - but not much control - very dependent on battery voltage, motor temp, etc...

0 Kudos
Message 5 of 11
(4,506 Views)

Hi Mentor

What kind of feedback are you using for the Motor? To use PID we need a linear system so we can calculate our error and feed this back into the PID VI. You will most likely need to open a connection to an encoder you can use the WPI liberary functions to do this, using the encoder as feedback you can further develop your control system. Please let me know if you run into questions.

Thank You

Eric Reid

Applications Engineer


Thank You
Eric Reid
National Instruments
Motion R&D
0 Kudos
Message 6 of 11
(4,506 Views)

The motor in this example is the RS-545;

Calculated Performance*
Motor: RS-545 (Pinion)
Operating v: 4.5v - 12v
Nominal v: 12v
No Load RPM: 988
No Load A: 0.8A
Stall Current: 37A
Stall Torque: 592 oz-in4180 mN-m
Kt: 16 oz-in/A113 mN-m/A
Kv: 82 rpm/v
RPM - Peak Eff: 861
Torque - Peak Eff: 86.4 oz-in610 mN-m
Current - Peak Eff: 5.4A


In the notes above, using the Nichols Ziegler menthod, I understand how to get the constant Kc, but what is Pc?

0 Kudos
Message 7 of 11
(4,506 Views)

Pc is the period of oscillation.  As noted in the PID theory link, in Ziegler-Nichols tuning you adjust the proportional gain (with the I and D components set to 0) until there's a slight, stable oscillation of the output.  In your case that means your motor should just overshoot the target point, then undershoot it, back to overshoot, etc.  The amount of time for one oscillation - from the maximum overshoot to undershoot and back to maximum overshoot - is Pc, the critical period.  Make sure you measure this in the same time units that the PID VI expects; it's either minutes or seconds and should be noted in the documentation (if the tuning doesn't work at first, try the other unit).  You can measure this period either by logging data to disk with timestamps, or by displaying the encoder output on a graph on your front panel and estimating the period of oscillation.

0 Kudos
Message 8 of 11
(4,506 Views)

Thank you for the pointers Nathan.

Another thing you can do to calculate the time is wire the output of dt from the PID VI and monitor the value.


Thank You
Eric Reid
National Instruments
Motion R&D
0 Kudos
Message 9 of 11
(4,506 Views)

Hi Eric - how does the dt output from the PID block help determine the period of oscillation?

Also, on a related note, why do you recommend wiring the dt input whenever possible?  I can't imagine it saves a lot of calculation to avoid a shift register and a subtract, since the same calculation would still need to be done outside the PID VI, but maybe I'm missing something.

0 Kudos
Message 10 of 11
(4,506 Views)