Hey guys, I am currently learning about the PID controller. I’m wondering if you guys actually use it for your robot or some other kind of controller?
PID is widely used in FRC. From swerve module rotation and driving, flywheel speed control, arm joints, elevators, and more.
Its used plenty in industry as well, like for PC fans.
PID is the closed loop controller we use, but I will say many times you only need a P or maybe a PD controller. Very rarely do we use I given how fast paced control is for our team.
Yeah, in most cases the integral term is more trouble than its worth, and a PD or just P controller is good enough. Comes in handy at times for flywheels I find.
But I meant more as an overall concept, PID is very widely used.
Oh interesting! How come “I” isn’t used? I thought that without the “I” the P might undershoot since the error gets so small that it will just not be able to reach the setpoint.
Makes sense, I’ll make sure we consider I for our shooter prototypes.
There isn’t much steady state error that can’t be addressed with feed forward. In regards to over shoot we use D to control that. P gets you there fast. D and internal resistance make you stop at your spot.
Additionally I can take time to build up. When you only give a sec at a position good luck having it do anything at small values and not taking over at medium ones.
Its important to keep it very small, since its easy for the integral term to dominate. There are also options in CTRE (and maybe REV) to only apply the I term when the error is within a certain range, and reset the I term when outside that range, so you don’t get integral windup.
Check out these interactive PID pages.
You can see that even without feed-forward, a simple PD controller can achieve a pretty good tune. Of course, using feed-forward is desirable, especially for things like a flywheel. And the steady state error for most mechanisms is usually so small that it doesn’t matter, so you don’t bother adding I.
https://trickingrockstothink.com/blog_posts/2019/10/19/tuning_pid.html
https://trickingrockstothink.com/blog_posts/2019/10/26/controls_supp_arm.html
Long story short, everything goes back to PID, but not just PID.
As you keep researching, you’ll probably find mention of PIDF, or PID with feedforward. The feedforward term is effectively a prediction of what voltage should be applied at a given time, and if it’s tuned well, it means the PID’s voltage contribution isn’t necessarily as aggressive.
You’ll also see motion profiling, which gives PID a setpoint that smoothly approaches your actual target, leading to smoother mechanism control. Both of these methods still rely on proportional control though.
There are more advanced controllers such as cascading PIDs (position-velocity or potion-velocity-current) and/or motion profiling with feedforwards can give much better results for high-inertia systems. They preform better because they can be tuned to slam the motor in full reverse when the system needs to decelerate. In contrast, the D term of PID will only slowly tell the motor to go in reverse and will decelerate the system much slower than what it is capable of doing, resulting in a longer setting time.
Both the methods come with the downside of taking significantly longer to tune due to needing to run multiple tests to determine the constants, and both cascade control and velo/accel feedforwards at the same with the additional downside of needing to model the system to tune the controller.
I have not found that to be quite far from the truth in my experience. I gains aren’t difficult to tune if you use an integral cap and if you tune them first (or comment out the other gains while tuning I).
Set an appropriate I cap so significant windup is impossible, and then set kI such that the buildup is at a reasonable rate, and then the integral controller will never misbehave. Some systems can further benefit by completely wiping out the integral buildup when the system overshoots. A correctly tuned I gain and cap allows a potion controller to be over or critically-damped without significant increasing the settling time compared to an underdamped PD controller and has mattered in my expereince.
Yeah applying motion profiling on top of regular PID control can help you achieve a very smooth motion, as it can control the acceleration and velocity of your mechanism. In WPILib there is a class to help you do this, ProfiledPIDController
.
But with most mechanisms in reality, you can achieve a very good tune without I, and the steady state error is going to be so small that it doesn’t matter anyway. Like for an arm or elevator. And the marginal benefit of adding I after you’ve already achieved a tune that gets you 98% of the way there IMO isn’t worth it a lot of the time.
In my experience, many mechanisms do not achieve a very good tune without I when running position PID. What happens is even with correctly-tuned P and D gains on a single mechanism, the system will inconsistently get steady-state error and a PD controller fails to correct it. Sure, there “better” ways to eliminate steady-state error, but they all take significantly longer to tune than tuning an integral gain. It doesn’t take that long to correctly tune the I gain and cap, being able to run a slightly overdamped system without any steady-state error is worth the small amount of time it takes to tune it.
More aggressive P gains have fixed that issue for me. Motion profiles can also help avoid steady-state error accruing in the first place (i.e., only changing the setpoint as fast as the system can keep up with; see ProfiledPIDController).
I would recommend watching ALL 9 of these videos. It might help answer some of the other questions you’ve been asking also.
They’re a bit dated but the science of PID hasn’t changed.
better
All good questions so far. To extend the line of thinking… it’s important to know for yourself what “better” implies. Possible components of “better”:
- Easy/fast to write code for
- Easy to understand the underlying concepts
- Well documented
- Goes to the setpoint smoothly
- Goes to the setpoint quickly
- Doesn’t go past the setpoint much
- Goes to the setpoint efficiently
- Teaches you something new
- Applicable to other areas (IE, used in industry or research)
Note some of these are conflicting - there isn’t an “all of the above” checkbox.
So definitely look into PID, and look into “next steps”. But keep in mind, there isn’t a single, global ranking for better/worse control algorithms. Given a specific definition of “better”, one could then come up with a ranking.
For FRCFIRST Robotics Competition and for someone just learning, my opinion is “Start with PID, see some limitations, then look into feed-forward”. I think that’s within the grasp of almost any high schooler in their four years on a team, and will produce phenomenal, concrete results on a robot.
ReCalc feedforward gains work out of the box for most mechanisms, no tuning involved.
Integral gain is a really crude strategy; it never decays, which is terrible for system stability and determinism. You can hack around this or use something more-complicated like input error estimation, but for the vast majority of mechanisms you don’t have to.
For certain mechanisms, like a flywheel, where you have high inertia, significant load, and no delay in your plant (so where control input has nearly immediate effect on output) then you typically want to increase the P gain really high. If you take that to an extreme, people sometimes call that a bang-bang controller. It’s called this because it changes to “full on” when the process variable goes below the setpoint and goes to “full off” when the process variable reaches the setpoint.
I do wanna note that technically speaking, lots of teams use something that is better than a pure PID controller. It’s good practice to characterize the mechanism you’re using, model its behavior, and use feedforward terms to get you very close to what you’re trying to do; PID (or commonly just PD) just corrects the difference from there.
Academically, this is pretty different from what you’d find if you just Google PID, as the PID controller is typically doing all the work in the examples you read.