|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools | Rate Thread | Display Modes |
|
|
|
#1
|
|||
|
|||
|
Tuning PID Constants Over a Range
Our team is trying to impliment PID for autonomous driving/turning, however we are struggling on tuning the constants. We have been using 1114's suggested method of tuning kP, kD, then kI, and we have been successful for tuning a single value.
For example we can tune gyroTurn(5) to turn 5 degrees, but those constants don't work for gyroTurn(25). Are we doing something wrong? or are we supposed to create different sets of constants for ranges of the angle? |
|
#2
|
|||
|
|||
|
I am by no means an expert with PIDs, but in this I would suggest turn down the I constant. I ramps up over time, so with the greater degree of movement, it takes longer for the PID controller to get to the target value. Therefore, the I constant may get too high.
Sent from my SM-N920G using Tapatalk |
|
#3
|
|||
|
|||
|
Re: Tuning PID Constants Over a Range
Could you clarify what you mean by "didn't work"?
Was the response not fast enough or did it never reach the intended goal value? |
|
#4
|
|||
|
|||
|
Re: Tuning PID Constants Over a Range
If we tuned the turn for 5 degrees, then the robot would be too slow and never make it to 25 degrees. If we tune the turn for 25 degrees, the robot would overshoot the 5 degrees.
|
|
#5
|
||||
|
||||
|
Re: Tuning PID Constants Over a Range
Quote:
|
|
#6
|
|||
|
|||
|
Re: Tuning PID Constants Over a Range
We clip our motor power at 0.7, but this would not be slow enough for smaller angles and if we clip the power lower, the larger turns would be slower than desired.
|
|
#7
|
||||
|
||||
|
Re: Tuning PID Constants Over a Range
Quote:
While we're at it, the following information would be helpful: What type of drivetrain do you have? How many/which drive motors power the drivetrain? What is the minimum throttle value which allows the robot to turn in place? What is the maximum achievable angular velocity of the robot? |
|
#8
|
|||
|
|||
|
Re: Tuning PID Constants Over a Range
This is likely a static friction problem, and the easiest solution I've found to deal with it is to implement a "minimum output" parameter that roughly corresponds to the smallest motor voltage which will result in actual movement. Then, you change your PID response so that the magnitude of the output is never less than that value, e.g. you can just add the value (with the proper sign) to any output, or you can simply set any output that is too small to the minimum value (again, with the proper sign). I think the former behaves somewhat better, but both work.
You can also implement cascading control, where the output of your angle PID is fed to a velocity PID for the wheels instead of directly to the motors. Thus, the internal PID loop will account for the problem automatically (provided it is tuned correctly). You also really should not need an I or D term for a turn-to-angle loop. Last edited by Oblarg : 26-09-2016 at 11:00. |
|
#9
|
||||
|
||||
|
Re: Tuning PID Constants Over a Range
Something that also helps in making small turns is to move forward slightly while turning to the set degree.
|
|
#10
|
|||
|
|||
|
Re: Tuning PID Constants Over a Range
Quote:
I don't think you need to go to cascading control here. That sounds more complicated than needed. We run statespace controllers, but the only real difference between a SS controller and a PID loop is the improved filtering on the velocity term. Our heading controller works very well. The first thing I tell people who ask me about tuning controllers like this is to start plotting things. With time as the X axis, plot left power, right power, right - left position, and gyro heading. You'll learn a lot from those plots. Feel free to post them as well if you want some more feedback. Backlash in your drivetrain is also important. If you have too much backlash, you will hunt around the goal. A small move will stabilize because you don't get moving fast enough to need to flip to the other side of the backlash in order to slow down. What frequency are you running your control loops at? Are you using the WPILib PID loop or your own? Too slow a loop time, or running the controller in the joystick code can cause a lot of problems. Consider also adding in a motion profile. You can do a constant velocity profile, or try a trapezoidal profile. This will give your controller a bunch of small moves in a (more) feasible path which will be a lot easier to follow. We do trapezoidal motion profiles for all of our movements. OP: From your profile, it looks like you are in the Bay Area. If the timing works out, 971 would be happy to chat in person with you guys, and take a look. |
|
#11
|
|||
|
|||
|
Re: Tuning PID Constants Over a Range
We ran a cascading P loop last year, and it worked beautifully. It's really not any extra work (or complexity) to run cascading control if you're already using velocity control for your drive - you just output to the existing PID controller instead of to the motors.
|
|
#12
|
||||||
|
||||||
|
Re: Tuning PID Constants Over a Range
Quote:
While your statement is true, we have found that simply putting a motion profile on your input will eliminate the need for cascading control. To me, the motion profile (whichever you choose .. we use trapezoidal acceleration) is a more pure way to do it. We all know that if you give a step input to a motor it really doesn't behave that way so why not give it an input it really can perform. 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. Paul |
|
#13
|
||||
|
||||
|
Re: Tuning PID Constants Over a Range
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 ) 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. Last edited by wesleyac : 27-09-2016 at 18:40. Reason: Pushed submit too early :o |
|
#14
|
||||
|
||||
|
Re: Tuning PID Constants Over a Range
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:
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): 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. |
|
#15
|
||||
|
||||
|
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.
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|