Do you have some special method to do this?
The question applies to gains relevant to Motion Magic, path following, and other gains and constants, too.
I’ve found PID without a PHD and Christopher Gerth’s blog posts, especially those on tuning PID gains and PID controller theory to be particularly helpful.
I haven’t done Motion Magic but one really simple way of tuning PID is:
- Set the P, I and D constants to 0.
- Slowly increase P until the system oscillates around the target. You can start with 1/the error.
- Slowly increase D until the system smoothly goes to the target.
I also find simulator sites like these to be useful. I find the best way to learn to tune a PID is with a quick overview of the terms and their effects, and then practice tuning different types of systems (an elevator/lift will behave differently that an arm) until you’re comfortable with what you need to tune. After that, you could always try to write code for your own PID controller to better understand the inner workings if that is what you’re interested in.
Following along with this - something I never understood - what are the max units for setting PID gains in a CTRE product? Is 1 the max number it will take? What happens if I have a P value of 100? Does it truncate to 1 like PercentVBUS?
I believe the max value is the integer limit. Generally the constants stay below 1, but that isnt always true.
Disclaimer: I’m a mechanical lead.
Took these links from a previous thread. If you’re familiar with motors and hardware, start on chapter 4. If you’re really impatient, go to chapter 9. Personally, I find 4-9 interesting.
Disclaimer: I’m the dude running the camera.
- Chapter One, Motors (46:03)
- Chapter Two, Talon SRX (52:35)
- Chapter Three, Talon Encoders and Sensors (16:34)
- Chapter Four, Control Loops (47:47)
- Chapter Five, Live Tuning Examples part 1 (53:13)
- Chapter Six, Live Tuning Examples part 2 (55:02)
- Chapter Seven, Live Tuning Examples part 3 (38:59)
- Chapter Eight, Live Tuning Examples part 4 (56:37)
- Chapter Nine, Quick Start Tuning Guide and Q&A (38:00)
The units of your PID gains are related (same, integral of, and derivative of, respectively) the units of your process variable/setpoint.
Last year for our elevator, we used the Phoenix controller for live PID tuning.
Start with a value that makes sense. Our elevator range was 0 - 70,000 ticks. The motor output was 0.0-1.0.
At an error of 70,000 (The elevator is at 0 and needs to go to the top) you want the motor moving at full speed (most likely)
So you set your initial value to 1/70,000. You slowly increase it until you start approaching your target too fast. Introduce some D into it (just enough to start noticing it), then some I in come cases. I like to view I as “Inertia” rather than “Integral” because heavier loads need more I (at least in what I’ve used it for)
Is this true? Aren’t the gains multiplied by the error function (and its derivative, and its integral) to produce motor power? Doesn’t that mean that for the P value, the units are in (percent Vbus)/(setpoint units), and the same concept would follow for the I and D values?
Those are the process variables, which is what Rahul was saying.
Ha, I read that as process variable or setpoint, rather than as a division symbol. Ignore my comment.
There are great links in the answers above on how to set the pid values … So I will focus my answer on a very important thing related to pid setting, and this is that you want to reduce the error to a minimum before the pid corrects the final remaining error.
Some things that we do for that -
1 set correct “nominal” value (the power required to start moving the mechanism
2 use arbitrary feed forward that is changed as the power to start moving the mechanism changes (e.g. Cosine of the angle of a rotating arm, or different values for staged lift)
3 use relatively physical motion profile, such as motion magic, or path finder
4 calibrate and test the feed forward (f value) of the control algorithm)
If you have done all of this right… The system will follow the desired motion plan with pid coefficients equal to 0.
Now… When the pid needs only to compensate for small unknowns in real time (changing friction, weight lifted or so…), we calibrate the P and D as suggested above. Almost never use I.
When you first take care of everything else… The pid calibration takes 5 minutes and is smooth and crisp
We just completed a presentation at Jumpstart SCSU. The videos will be posted hopefully soon. @SMSLittle Meanwhile here is a link to the slides.
Slides have links to our work sheets calculator that helps you with finding the feed forward, P, I, D values. The tutorial walks through the CTRE sample and as a bonus the worksheet links to the relative chapter in the CTRE documents.
The oscillation won’t necessarily be around the target value!
Also, a nice tool to experiment with gain values is simulink. This is a great tool for visualizations and provides a good medium for exploratory learning of control systems.
The links you provided are exactly my techniques, which I learned from an engineer who did engine dynamometer tuning for a living.
this has some useful info
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.