|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools | Rate Thread | Display Modes |
|
|
|
#1
|
|||
|
|||
|
Re: Velocity PID(F) Best Practices - To Integrate, or Not To Integrate?
Quote:
|
|
#2
|
||||
|
||||
|
Re: Velocity PID(F) Best Practices - To Integrate, or Not To Integrate?
Quote:
Similar thread for those interested: https://www.chiefdelphi.com/forums/s...d.php?t=152106 Just curious, did your team attempt a velocity servo and wasn't successful? |
|
#3
|
|||
|
|||
|
Re: Velocity PID(F) Best Practices - To Integrate, or Not To Integrate?
Quote:
This preseason we are experimenting with doing PID control on the talons, and so the main question is whether we should tune around 'p' or 'i'. We're also still wrestling with technical issues, so we haven't experimented with either on the Talon quite yet. |
|
#4
|
|||
|
|||
|
Re: Velocity PID(F) Best Practices - To Integrate, or Not To Integrate?
Just thought I'd report back - we just got a flywheel working with a PF loop, basically exactly as described above. Indeed, there is plenty of headroom to make the P term big enough that the steady-state error is negligible (plus or minus ~.2 RPS) without the system becoming unstable. We'll see about tuning our drive this way next, though we need a few more talons to do that.
Just a note about PID control on the talons: god, the handling of the units in the java WPILib code is terrible. "Native units" (which are noted to be either per 10ms or per 100ms depending on which source you check; they are actually the latter) are used everywhere *except* for the set and getsetpoint functions, which use RPM. The comments helpfully mention that the latter function returns a value in "appropriate units." Also, the output scaling for F gain is -1023 to 1023, which is a sort of odd choice. On the plus side, the loop works great. I hope, before too long, to try tuning a variety of systems using both strategies and actually compare the performance. |
|
#5
|
|||||
|
|||||
|
Re: Velocity PID(F) Best Practices - To Integrate, or Not To Integrate?
Quote:
|
|
#6
|
|||
|
|||
|
Re: Velocity PID(F) Best Practices - To Integrate, or Not To Integrate?
So, here's a graph of our flywheel velocity error (units in RPS) versus time during a shooting test. The negative spikes are slowdown while the flywheel is in contact with the ball. The velocity setpoint was 50 RPS.
![]() As we can see, consistent with the above discussion, there is steady-state error, but it is very small. We are wondering if teams bother to introduce any integral gain to eliminate the steady-state error, and if this performance is consistent with what other people have seen using similar methods. |
|
#7
|
||||
|
||||
|
Re: Velocity PID(F) Best Practices - To Integrate, or Not To Integrate?
Quote:
How long did you wait between shots? How much was the steady state error effected when you changed the set point. How much time, or how many iterations did you spend tuning the Kf value? How about Kp? Thanks again. Last edited by Bryce2471 : 07-12-2016 at 19:01. |
|
#8
|
|||
|
|||
|
Re: Velocity PID(F) Best Practices - To Integrate, or Not To Integrate?
Quote:
2) We haven't rigorously tested this yet, will report back once we have data 3) We tested our flywheel speed at max voltage, and then simply naively set Kf to (max output)/(max speed). We did not test across multiple battery voltages or setpoints - if anyone has suggestions for a good systematic way to do this, it'd be appreciated. 4) We started Kp pretty small and then doubled it until we started to see oscillations, at which point we set it to halfway between that and the previous value. There were a couple more iterations after that, I think, but I don't recall exactly how many. All in all, it was a pretty "rough" tuning procedure - we were mostly interested in getting it working, with the understanding that we can fine-tune it later. Quote:
Hopefully we'll find some time to sit down and really play with different tuning schemes, and record the data. Last edited by Oblarg : 07-12-2016 at 19:25. |
|
#9
|
||||
|
||||
|
Re: Velocity PID(F) Best Practices - To Integrate, or Not To Integrate?
I'm the person who implemented the velocity PID controller in WPILib last summer. If I understand correctly, an integrator is necessary and sufficient to eliminate steady-state error in controlling a DC motor with a velocity PID controller in all cases. Here's some math:
I'll be using the model for a DC motor from http://ctms.engin.umich.edu/CTMS/ind...stemModelin g, which has the following transfer function from voltage (V) to angular velocity (theta_dot): P(s) = theta_dot(s)/V(s)=K/((Js+b)(Ls+R)+K^2) First, we'll try controlling it with a P controller defined as: C(s) = Kp When these are in unity feedback, the transfer function from the input voltage to the error is: E(s)/V(s) = 1/(1+C(s)P(s)) E(s) = 1/(1+C(s)P(s))*V(s) = 1/(1+Kp*K/((Js+b)(Ls+R)+K^2))*V(s) (See http://ctms.engin.umich.edu/CTMS/Con...motorBlock.png for a diagram. I'm assuming that theta_dot_ref maps to the input voltage with a constant gain and that the measured signal is used as-is in the error calculation, so H(s) = 1). In this case, we'll apply a step input, so V(s) = 1/s. E(s) = 1/(1+Kp*K/((Js+b)(Ls+R)+K^2))*1/s To find the steady-state value of a transfer function, we can apply the formula: e_ss = lim_s->0 s*E(s) e_ss = lim_s->0 s*1/(1+Kp*K/((Js+b)(Ls+R)+K^2))*1/s = lim_s->0 1/(1+Kp*K/((Js+b)(Ls+R)+K^2)) = 1/(1+Kp*K/((0+b)(0+R)+K^2)) = 1/(1+Kp*K/(bR+K^2)) Notice that the steady-state error is non-zero. To fix this, an integrator must be included in the controller: C(s) = Kp+Ki/s Same steady-state calculations as before with the new controller: E(s) = 1/(1+C(s)P(s))*V(s) = 1/(1+(Kp+Ki/s)*K/((Js+b)(Ls+R)+K^2))*1/s e_ss = lim_s->0 s(1/(1+(Kp+Ki/s)*K/((Js+b)(Ls+R)+K^2))*1/s) = lim_s->0 1/(1+(Kp+Ki/s)*K/((Js+b)(Ls+R)+K^2)) multiplying by s/s: = lim_s->0 s/(s+(Kp*s+Ki)*K/((Js+b)(Ls+R)+K^2)) = 0/(0+(0+Ki)*K/((0+b)(0+R)+K^2)) = 0/(Ki*K/(bR+K^2)) the denominator is non-zero, so e_ss = 0. So mathematically speaking, an integrator is required to eliminate steady-state error in all cases for this model. If you don't want to use one, a feedforward can eliminate most if not all of the error if chosen carefully. Given that, there is always uncertainty, hence why feedback control exists. Oblarg is correct that the behavior of the velocity PID tuning constants doesn't match the displacement PID. I tried to get something with close enough dynamics that teams could use a similar tuning procedure for both (except in the velocity case, there's no steady-state error so I made Ki not do anything). |
|
#10
|
|||||
|
|||||
|
Re: Velocity PID(F) Best Practices - To Integrate, or Not To Integrate?
Quote:
If the system inertia is large enough compared to the motor power and the control frequency high enough you'll get high frequency oscillations of low magnitude around the setpoint (as Jared and Oblarg detailed above). So, you need an integrator to eliminate steady state error in a theoretical sense, but not necessarily in a practical sense depending on the system. Last edited by AdamHeard : 08-12-2016 at 01:19. |
|
#11
|
|||||
|
|||||
|
Re: Velocity PID(F) Best Practices - To Integrate, or Not To Integrate?
Quote:
e_ss approaches zero as Kp approaches infinity, and the closed-loop transfer function is stable for all positive values of Kp. Last edited by Jared Russell : 08-12-2016 at 01:58. |
|
#12
|
|||
|
|||
|
Re: Velocity PID(F) Best Practices - To Integrate, or Not To Integrate?
Quote:
I'd like, when I find the time, to run some actual tests and find out what the practical difference in performance is between the two approaches in FRC contexts. I know the WPILib implementation runs in its own thread and the loop frequency can be set manually - do you know what the fastest speed it can run is? Last edited by Oblarg : 08-12-2016 at 02:04. |
|
#13
|
|||
|
|||
|
Re: Velocity PID(F) Best Practices - To Integrate, or Not To Integrate?
Quote:
As you get faster and faster, you'll start to see noise show up in the velocity measurement due to the discrete differentiation. When that starts to happen, you'll need to add complexity to filter it out. |
|
#14
|
|||
|
|||
|
Re: Velocity PID(F) Best Practices - To Integrate, or Not To Integrate?
What kind of filtering do people typically use? Would exponential smoothing suffice?
|
|
#15
|
|||||
|
|||||
|
Re: Velocity PID(F) Best Practices - To Integrate, or Not To Integrate?
Quote:
https://github.com/Team254/FRC-2016-...ants.java#L152 (Talons were in coast mode as well) We allowed firing whenever our flywheel was within 100rpm (1.67rps) of our setpoint because we found it made no practical difference to our shot trajectory. In practice, most shots we took were within 20rpm of our setpoint. If you are within .1rps (6rpm) steady-state, I'd say you're already in good shape. |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|