Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Programming (http://www.chiefdelphi.com/forums/forumdisplay.php?f=51)
-   -   Tuning PID Constants Over a Range (http://www.chiefdelphi.com/forums/showthread.php?t=151541)

AustinSchuh 28-09-2016 00:16

Re: Tuning PID Constants Over a Range
 
Quote:

Originally Posted by Paul Copioli (Post 1609174)
We have found that motion profile + feedforward gain + PID work for all of our telemetry navigation needs, whether it be for driving or moving a ridiculously complicated arm.

Austin and his crew use state space, but I am too simplistic for all that awesomeness so I stick with profile + FF + PID.

Agreed! profiles + Feed Forward + PID is good enough for FRC. Everything in FRC can be worked down to a second order system, which means that PID is a good control strategy.

I love playing with control systems, and like pushing the limits. That being said, I don't recommend using the controllers we use unless you have a strong math background and time to learn what is going on.

The Talon SRXs have good support for all of this as well.

kylestach1678 28-09-2016 00:33

Re: Tuning PID Constants Over a Range
 
1 Attachment(s)
Wesley did a great job of summarizing our process for tuning, but I'd like to add a few things, especially with respect to the trapezoidal motion component:
Quote:

Originally Posted by wesleyac (Post 1609205)
I would agree that motion profiling + feed forward will help a lot. 254 and 971 did a great video on this at champs in 2015 (https://www.youtube.com/watch?v=8319J1BEHwM).

The process that we used for tuning our turning went something like this:

1.) Write and test motion profile code (graph it to make sure that it is actually doing what it is supposed to).
2.) Find motion profile parameters. We used trapezoidal motion.
2a.) You can find the maximum velocity by sending 12v to both motors and looking at the maximum slope of the line.
2b.) From the same plot of the velocity, you can run a regression to get the acceleration.
2c.) You should set you FF parameters to something slightly lower than the actual values - as the season wears on, your robot will get less efficient, and you don't want to ask your robot to follow a profile that it's incapable of following.

3.) Find FF parameters
3a.) You can use the dynamics of the system to calculate what these should be, but we found that for turning, they ended up being fairly inaccurate (probably wheel scrub + static friction were a lot of that. pneumatic wheels can be a pain :P) We started with calculated values, and tuned them by hand until they largely matched the motion profile. Again, having plots of angle over time as well as target angle over time on the same axes helps hugely here. If you don't have some system to graph variables over time, make one! it will save time in the long run. Test every change with multiple values.
4.) Start tuning PID. There are many different strategies for this. The one that you are using looks fine. Test every change for a range of values (90deg, 25deg, 10deg, 5deg, 2deg, etc. This also applies to tuning the FF values.) Again, graph everything. You can very easily see the effects of changing PID parameters from the graphs.

Another thing to consider it when you want to terminate the loop. If you don't need to be very accurate (for example, in an initial turn before starting vision), then don't have strict termination conditions. Also, if you have problems with the robot continuing to turn after the profile is over, consider adding a minimum derivative as a termination condition.

If you have any questions, feel free to ask.

(emphasis mine)

2b) The regression that Wesley is referring to is an exponential regression against the solution to the second-order differential equation that the drivetrain (theoretically) should follow: x'' = ax' + bu where x is distance (or angle - we controlled angle and distance with two separate controllers) and u is voltage, assumed to be constant at 12V. You basically just collect a bunch of data and then do a regression on that to find the constants a and b. You can also not bother with this part for acceleration and just try to manually tune constants, which can work just as well or better in some cases but can require more time.

2c) You definitely need to set the motion profile's acceleration and velocity parameters to lower than the maximum, but not only because of wear/tear/battery voltage/other pesky things that happen in the real world. If you set the velocity to the maximum the robot can possibly go, you will not be able to actually control it when it is going that speed - to properly control a system, you should not be saturating its inputs or the system and controller will respond in a pretty strange manner (nonlinearities are unlikely to play well with PID controllers), being "less responsive" when moving at full speed than when accelerating or decelerating. In addition, the end of the acceleration period will get cut off and will not act nicely (the middle plot is velocity and the bottom plot is voltage):
Attachment 21083

3a) I don't have anything to add on this point, but I just wanted to emphasize how important it is to have some way to visualize everything that's happening on your robot. Not only for tuning purposes, but for debugging as well - log everything you can in some way; it will serve you well when you are tearing your hair out over some strange bug.

Brian Selle 28-09-2016 13:01

Re: Tuning PID Constants Over a Range
 
One more idea is to use PID alone for small movements (like < 5 deg) and motion profile (w/ PID position control) for larger turns. If you tune your controller for using motion profile the gains will be relatively high and should work well for small angle corrections.

Jared Russell 28-09-2016 14:32

Re: Tuning PID Constants Over a Range
 
I agree that a motion profile + feedforward to overcome static friction can solve this problem adequately for FRC purposes. However, the Talon SRX makes precise 1KHz velocity control stupidly easy to achieve; hiding the stiction nonlinearity behind a Talon and using plain old position PID is just as workable a solution these days. (But is still improved by using a motion profile of course)

Andrew Schreiber 28-09-2016 14:45

Re: Tuning PID Constants Over a Range
 
Quote:

Originally Posted by Jared Russell (Post 1609298)
I agree that a motion profile + feedforward to overcome static friction can solve this problem adequately for FRC purposes. However, the Talon SRX makes precise 1KHz velocity control stupidly easy to achieve; hiding the stiction nonlinearity behind a Talon and using plain old position PID is just as workable a solution these days. (But is still improved by using a motion profile of course)

Are you saying for heading changes, let's assume turn in place, you'd suggest figuring out how far the wheels need to turn and then just position PID them (with or without motion profile) ?

AustinSchuh 29-09-2016 01:57

Re: Tuning PID Constants Over a Range
 
Quote:

Originally Posted by Andrew Schreiber (Post 1609301)
Are you saying for heading changes, let's assume turn in place, you'd suggest figuring out how far the wheels need to turn and then just position PID them (with or without motion profile) ?

Yes, but he's proposing that the output of the position PID and (maybe) profile would be a velocity to feed to the velocity PID running on the talon.

Andrew Schreiber 29-09-2016 09:52

Re: Tuning PID Constants Over a Range
 
Quote:

Originally Posted by AustinSchuh (Post 1609396)
Yes, but he's proposing that the output of the position PID and (maybe) profile would be a velocity to feed to the velocity PID running on the talon.

So run a traditional PID control loop with the Gyro as the input and a fake output that sends a target velocity to the velocity PID on the talons?

Jared Russell 29-09-2016 11:51

Re: Tuning PID Constants Over a Range
 
Quote:

Originally Posted by Andrew Schreiber (Post 1609412)
So run a traditional PID control loop with the Gyro as the input and a fake output that sends a target velocity to the velocity PID on the talons?

Yeah, use one controller with gyro angle as the process variable to track a desired heading profile. The output of this loop is a desired angular velocity. You can then use an inverse kinematics equation* to map angular velocity to drive motor velocities, and use these as velocity setpoints for the Talon SRX.

* For differentially steered robots, this equation looks something like:
Code:

drive_wheel_linear_velocity = wheelbase_width_meters * desired_turning_rate_rads_per_second / 2
left_motor_desired_linear_velocity = -drive_wheel_linear_velocity
right_motor_desired_linear_velocity = +drive_wheel_linear_velocity

(you can also multiply the right side of the equation above by a corrective factor that you tune to account for losses due to skidding; ours was ~2 with 8 low pressure pneumatic wheels this year. You don't have to be super precise on this, as the gyro PID controller will correct for error, but better to be more accurate than not)

To tune this, start with the Talon SRX velocity loop and work backwards. Make sure you can accurately track a variety of speeds (both fast and slow) in straight line, turn in place, and arcing motions. We were able to find that one set of gains did a good job in all of these cases, but YMMV. Once you can accurately track your velocity commands, tune your kinematics by adjusting the equation's corrective factor while turning in place (ex. command each side of the drive to go +/- a couple feet per second and measure the actual turning rate with the gyro...repeat and find the best fit for your model). Finally, you can then tune the gyro PID loop (which will be really easy, likely P-only, because of the fast velocity loop underneath).

Ether 29-09-2016 13:37

Re: Tuning PID Constants Over a Range
 
Quote:

Originally Posted by Jared Russell (Post 1609425)
drive_wheel_linear_velocity = wheelbase_width_meters * desired_turning_rate_rads_per_second / 2

For a robot with center of mass located at center of rectangle formed by the 4 wheels, I think that should be:

S = (1+f2)(W/2)ω

S is drive wheel linear speed
W is trackwidth
ω is desired turning rate in radians per second
f the the ratio L/W, where L is wheelbase



Andrew Schreiber 29-09-2016 13:42

Re: Tuning PID Constants Over a Range
 
Quote:

Originally Posted by Ether (Post 1609444)
For a robot with center of mass located at center of rectangle formed by the 4 wheels, I think that should be:

S = (1+f2)(W/2)ω

S is drive wheel linear speed
W is trackwidth
ω is desired turning rate in radians per second
f the the ratio L/W, where L is wheelbase



And by L (wheelbase) you mean contact patch (I think that's the terminology Hibner used)? So, for most teams it would be either the distance between the inner 2 sets of wheels (4/8wd) or the distance between the sets of wheels that the CoM is between (6/10wd). I'm going to ignore the option of a moving CoM because it's going to make my head hurt.

Ether 29-09-2016 13:58

Re: Tuning PID Constants Over a Range
 
2 Attachment(s)
...

Andrew Schreiber 29-09-2016 14:04

Re: Tuning PID Constants Over a Range
 
Quote:

Originally Posted by Ether (Post 1609446)
...

Yes, I know the traditional definitions. Perhaps a better question would be, do I measure wheel base as the distance from the front wheel to the back wheel or do I measure it from the front wheel that touches to the back wheel that touches for drop center drive systems?

Ether 29-09-2016 14:14

Re: Tuning PID Constants Over a Range
 

for 6WD drop-center skidsteer with most of the weight over the center wheels "f" is essentially zero so it reduces to Jared's formula.



Jared Russell 29-09-2016 15:26

Re: Tuning PID Constants Over a Range
 
Quote:

Originally Posted by Ether (Post 1609444)
For a robot with center of mass located at center of rectangle formed by the 4 wheels, I think that should be:

S = (1+f2)(W/2)ω

S is drive wheel linear speed
W is trackwidth
ω is desired turning rate in radians per second
f the the ratio L/W, where L is wheelbase



Yep, and this is the equation we actually used as our starting point (using the track width and wheelbase length of our inner four wheels). Our CoG was within an inch or two of the geometric center (ignoring dynamics). We found that even with this correction, we were ~50% off of the true value (a bit unsurprising since even though our outside wheels were raised, they still bore some weight because of deflection of our 15-20 PSI inner wheels).

Oblarg 30-09-2016 15:36

Re: Tuning PID Constants Over a Range
 
If all you're doing is tuning a turn-to-angle loop, though, do you really need to take the extra step to figure out the proper scaling factor for turning rate? You could just "absorb" that constant (whatever it is) into the value of p.


All times are GMT -5. The time now is 05:36.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi