Please talk my ear off about control theory. There has got to be a better way to get motors to stay put than beating my head against the brick wall that is PID tuning parameters trying to find a value of I that doesn’t make the oscillation progressively worse as time goes on
I wouldn’t use any integral gain. The (transfer function of the linearization of the) DC motor has a pole at zero, i.e. a natural integrator. It already has one; no need to add another one. Adding integral gain could very easily destabilize the system. That’s probably what’s happening.
I built a “toy control system” over the summer to test stuff I read in books, basically an inverted pendulum setup actuated by a standard DC motor. In my most recent attempt to control it, I ended up using just proportional control to keep the pendulum upright. Adding a straight-up derivative will amplify high-frequency noise, and it made my setup unstable. I think that commercial PID controllers have filtered derivative terms that throw out high-frequency crap. Adding integral control also made my setup unstable, including enabling integrator windup protection (saturates the integral term so it doesn’t stay “up” for an obnoxiously long time if there’s an impulsive measurement). My setup ultimately could keep it upright pretty easily, and it could track slowly changing reference angles all the way around to pendulum down, but if I got it into an oscillation it would go unstable.
Proportional control acts like a spring. Remember Hooke’s law: F=kx. k>0 is a “stiffness” constant: the bigger k gets, the stiffer the “spring action” of the controller becomes, the more the controller wants to oppose displacement from its equilibrium. Unlike the real spring, if k is too high, it can absolutely go unstable. You probably will benefit from some proportional control, but it sounds like you have a little too much.
At least for my setup, because I am using an Arduino with an 8-bit motor driver, I only get 2^8 = 256 quantized levels to work with. I think that quantization is too coarse for an inverted pendulum. Quantization is ridiculously nonlinear. If it’s too coarse, PID and other linear control laws won’t like it.
I think that if your moment of inertia is more uniformly radially distributed in space, i.e. if what you’re driving is balanced, it will act more like a “motor” and less like a “pendulum”. So my experience is biased by the fact that my toy control system is deliberately designed to bring out the “worst” of the system, i.e. the nonlinear nature of the actual state equation.
If you need to track a reference input, you can probably get better results for small inputs if you design a full-state feedback controller and state-observer, although for that you’d need a system model. Unfortunately, it’s (extremely) not very robust to model uncertainty. Large inputs will effectively change the system model as it moves through different angles if the load isn’t balanced. On the plus side, despite the intimidating-looking math, what you’ll end up doing is just some boilerplate MATLAB code and maybe some mild linear algebra to implement your control law.
You can definitely get better results using Model Predictive Control, but compared to state-space or classical methods it’s computationally expensive. Basically, you (or probably an already-existing optimization library) would be solving an optimization once every time step to find the optimal control input each time step. Also, you still need a system model.
You can also experiment with multiple feedback loops of PID control. For example, I worked with a “smart” brushless DC motor that had one loop for position control and another for torque control. Both could be controlled and changed simultaneously. For the project I was working on, because it attaches to an actual human, we actually did have some pretty stringent constraints on both torque and position.
I haven’t implemented this myself, but there is some literature about adaptive control including adaptive PID, i.e. you change the PID gains depending on the input signal. I haven’t finished that reading yet, lol.
Please talk my ear off about control theory. There has got to be a better way to get motors to stay put than beating my head against the brick wall that is PID tuning parameters trying to find a value of I that doesn’t make the oscillation progressively worse as time goes on
Can do!
I wouldn’t use any integral gain. The (transfer function of the linearization of the) DC motor has a pole at zero, i.e. a natural integrator. It already has one; no need to add another one. Adding integral gain could very easily destabilize the system. That’s probably what’s happening.
I built a “toy control system” over the summer to test stuff I read in books, basically an inverted pendulum setup actuated by a standard DC motor. In my most recent attempt to control it, I ended up using just proportional control to keep the pendulum upright. Adding a straight-up derivative will amplify high-frequency noise, and it made my setup unstable. I think that commercial PID controllers have filtered derivative terms that throw out high-frequency crap. Adding integral control also made my setup unstable, including enabling integrator windup protection (saturates the integral term so it doesn’t stay “up” for an obnoxiously long time if there’s an impulsive measurement). My setup ultimately could keep it upright pretty easily, and it could track slowly changing reference angles all the way around to pendulum down, but if I got it into an oscillation it would go unstable.
Proportional control acts like a spring. Remember Hooke’s law: F=kx. k>0 is a “stiffness” constant: the bigger k gets, the stiffer the “spring action” of the controller becomes, the more the controller wants to oppose displacement from its equilibrium. Unlike the real spring, if k is too high, it can absolutely go unstable. You probably will benefit from some proportional control, but it sounds like you have a little too much.
At least for my setup, because I am using an Arduino with an 8-bit motor driver, I only get 2^8 = 256 quantized levels to work with. I think that quantization is too coarse for an inverted pendulum. Quantization is ridiculously nonlinear. If it’s too coarse, PID and other linear control laws won’t like it.
I think that if your moment of inertia is more uniformly radially distributed in space, i.e. if what you’re driving is balanced, it will act more like a “motor” and less like a “pendulum”. So my experience is biased by the fact that my toy control system is deliberately designed to bring out the “worst” of the system, i.e. the nonlinear nature of the actual state equation.
If you need to track a reference input, you can probably get better results for small inputs if you design a full-state feedback controller and state-observer, although for that you’d need a system model. Unfortunately, it’s (extremely) not very robust to model uncertainty. Large inputs will effectively change the system model as it moves through different angles if the load isn’t balanced. On the plus side, despite the intimidating-looking math, what you’ll end up doing is just some boilerplate MATLAB code and maybe some mild linear algebra to implement your control law.
You can definitely get better results using Model Predictive Control, but compared to state-space or classical methods it’s computationally expensive. Basically, you (or probably an already-existing optimization library) would be solving an optimization once every time step to find the optimal control input each time step. Also, you still need a system model.
You can also experiment with multiple feedback loops of PID control. For example, I worked with a “smart” brushless DC motor that had one loop for position control and another for torque control. Both could be controlled and changed simultaneously. For the project I was working on, because it attaches to an actual human, we actually did have some pretty stringent constraints on both torque and position.
I haven’t implemented this myself, but there is some literature about adaptive control including adaptive PID, i.e. you change the PID gains depending on the input signal. I haven’t finished that reading yet, lol.
Hope this sparks some inspiration.