Automatic Tuning


#1

This thread is dedicated to the discussion of automated tuning methods for future development.

A few questions to start off (mostly to reinforce my understanding):

  1. Out of curiosity, the current manual tuning method seams very similar to Ziegler-Nichols, is it Ziegler-Nichols or a variant?

  2. Why is the controller utilizing PI and not PID? I assume it has to do with the “stacking” of Voltage/Current/Velocity/Position control, as a change in position is by definition velocity.

  3. Most importantly, what would be the optimal tuning method to achieve said goal? I would say that we would like to minimize the risk of possible damage. I’m thinking along the lines of Cohen-Coon or Relay Method.


#2

Responding to number 2, it is effectively a PD controller, not a PI. It is setup as a cascading PID controller, I assume to make it easier and more intuitive to add feedforward control. For simple tuning (where there is nothing being fed forward and where vel_integrator_gain is 0), this can just be treated as a PD controller. The quantities to change gains by will be slightly different, though, because the position gain is now tied to the velocity gain.

A regular PD controller is setup like this: current = Kp*error + Kd*velocity
This PD controller is setup like this: current = Kd*(Kp*error - velocity)
That is equivalent to: current = Kd*Kp*error - Kd*velocity

So the Kp in a normal PD controller is actually (Kp*Kd)

The I term is just for velocity. So if the velocity I term is used, then it becomes these two equations:
v_err = Kp*error - velocity
current = Kd*(v_err) + Ki*INTEGRAL_OF(v_err)

That integrator term seems to make this very messy, since that encompasses the integral of position error and velocity error.

All of this logic can be found at the very end of Firmware/MotorControl/low_level.c

Also, someone should correct me if I read the code wrong or drew the wrong conclusions from it :grinning:


#3

Yep you got the right understanding!