# PID position control when setpoint does not require continuous force

I'm struggling with the practical application of a PID control algorithm when the set point does not require any external force to stay in position.

For example, I have a geared electric motor that has a mass attached perpendicular to the motor's shaft. The mass is fixed to the shaft so it will rotate with the shaft without slipping. There is a sensor on the mass that knows its angle relative to horizontal (an accelerometer in my case), which is used for error feedback. The control system attempts to drive the motor such that the mass is always balanced vertically above the shaft, as pictured below. The motor itself is attached to a robotic arm that may rotate around arbitrarily, so the motor will work to keep the mass vertical at all times. The key thing to note here is that once the motor has achieved the set point (the mass is vertical above the shaft), it does not require any more work from the motor. No additional force is required to hold it there. In fact, there's enough back-drive friction in the gearing that even if the mass is, say, 10 degrees from vertical, it'll still stay put.

My question is in regards to correctly implementing a PID control loop for this kind of system. Here's the situation that has me confused:

Let's say the mass has come to rest deflected 5 degrees from vertical. In the PID loop, the P component is very small because the error is very small. So the integrator winds up to do most of the work of removing this steady-state error. It does its job and adds just enough power into the motor to drive the mass to the vertical position. Once the vertical position is achieved, no additional force is required to hold it there. But that integrator component still has a non-zero value and will keep driving the motor, making it push the mass passed the set point and to the other side. An inevitable oscillation about the set point will then occur.

Are there special considerations in a PID algorithm for this case? Or am I just fundamentally misunderstanding how a standard PID algorithm will react to the system I described above?

EDIT:
My original question was misusing the word "stable". Thank you to Carl Witthoft for pointing that out. The focus of my question, however, is how to properly implement a PID loop when the system requires that the control forces drop to zero as the position error approaches zero.

• Positioners are typically PD controllers. Aug 29 '16 at 20:40
• Just for informational purpose that might help you : Proportional = Force, Integral = How fast, Derivative = I resist both.
– Ken
Nov 4 '18 at 13:54

You are correct about the effect of the Proportional and Integral terms in your controller, but don't forget the Derivative part! While the Integral term tends to add energy to a system, the Derivative term subtracts energy by trying to slow down the rate of change of error. It acts like friction or damping in the system. Derivative terms are usually necessary for systems which don't have much physical damping, otherwise they would oscillate a lot before coming to a stop. This is why generally speaking you will see PD and PID controllers, but rarely just P and never (to my knowledge) I control.

How do you fix your problem? Well you have two options.

The first option is to increase the derivative gain. This will reduce oscillations but it will also slow the response of your system.

The second option is to limit the integral windup. This will prevent the integral term from getting too large, meaning your torque will stop increasing after a certain point. This way you can use a smaller derivative gain since the integral term will not get so large. I would start with a saturation function that causes $K_I \int e(t)dt \leq m g l$ (where $K_I$ is the integral gain, $e$ is the error, $m$ is the mass, $g$ is acceleration due to gravity, and $l$ is the length of the arm on which the mass is attached). This is a worst-case estimate of how large your integral term would have to be. Start from there and try decreasing it until you get the performance you want.

You will probably need to use a combination of option one and two to achieve the best performance.

• In a system where 0 speed and 0 torque causes no change movement (e.g. a motor without a load, or a winch moving something laterally), can you achieve precise positioning with just PI? Even with Integral limit, what's to stop the motor from ever resting, as the Integral component will always be non-zero when the motor reaches the setpoint? Apr 8 '20 at 20:02
• @19172281 In theory, the integral term will only truly be zero after an infinite amount of time. In practice, after the integral term gets very small the motor will effectively be off. How soon that happens depends on the amount of friction in the system and the values of the other control gains Apr 8 '20 at 20:47
• The Integral may get very small, causing the motor to stop, but wouldn't it then rise up again after some time, depending on Ki? Apr 8 '20 at 21:06
• You could see a buildup in error over time if the static friction is bad, resulting in movement after it builds up enough, but once you get your error below your sensor resolution it will stop accumulating Apr 8 '20 at 21:11
• Ahhh, I see. However with a high resolution encoder, wouldn't this take some time, or not happen at all? Are you saying that we would need to be under 1 count away from thee setpoint? Does Derivative gain help with this? Apr 8 '20 at 21:15

You are confusing the definition of "stable," I suspect. Yes, the weight will remain vertical in the absence of applied forces, but no, that is not the stability you're looking for (with apologies to Obi-Wan). This is known as an "unstable equilibrium" because any force, or if you want to get fancy, quantum fluctuations as described by the Heisenberg Uncertainty Principle(1) , will cause the system to leave equilibrium.
By comparison, if the weight is hanging vertically below the rod, that's a "stable equilibrium" because any minor displacement will be counteracted by gravitational force, returning the system to the equilibrium point.

So, yes, you'll need some sort of controller to keep the weight pointing up.

 Yes, Heisenberg is silly in this context but there are plenty of physics students who are given macro problems like this just to demonstrate the magnitude of the effect.

• Carl, thank you, I feel rather silly for misusing the word stable. I'm going to edit my question and reword it. But that aside, my question still stands. The core of what I was asking is regarding the behavior of the integrator term when the mass is near the set point. Aug 18 '16 at 16:57

"Let's say the mass has come to rest deflected 5 degrees from vertical"

How did the mass come to rest with the PID controller enabled?

"The P component is very small because the error is very small."

The proportional error is very small, but the proportional gain make the "P component" be however large you want it to be.

"Once the vertical position is achieved, no additional force is required to hold it there."

The mass must have moved into position. Having mass and a speed (with which it attained the correct position) means that it has inertia. The inertia then requires that either a force is applied to remove the speed or that the mass must pass vertical.

"An inevitable oscillation about the set point will then occur."

To be more blunt than CarlWitthoft, could you put the mass in position with such precision that it would stay there forever? The answer is no, for the reason he mentioned: such a position is inherently unstable. Given enough time, it will fall over.

"Am I just fundamentally misunderstanding how a standard PID algorithm will react to the system I described above?"

I don't think you're misunderstanding the PID controller, I think you're beginning to see some of the drawbacks of PID control. The same integral error that prevents "droop" if you were trying to control the reference position to be 90 degrees (parallel to ground) causes you to overshoot when you try to control the load to be vertical.

It's possible to overcome the shortcoming in this (relatively simple) case by adding a "feed-forward" term. That is, you could calculate the anticipated load torque, based on load angle, mass, and the length of the arm to which the mass is attached.

The load torque you are calculating is the static torque required to hold the load in a position. It does not provide any torque to move the load to a new position, or any control to maintain the position, if you had any modelling errors (error measuring mass, effective moment arm, etc.).

By "seeding" the motor with the rough current (torque) it needs to maintain the load at any angle, the PID controller could then be tuned to a set of "universal" gains that should then behave the same at any angle.

So, to summarize:

PID control is most effective when the underlying system isn't changing. When the system changes (the required torques change, for example), then either the control gains need to change or the performance degrades.

You can use a compensatory controller (feed-forward control, for example) to "normalize" the underlying system, promoting a more versatile "robust" PID controller.

For the record, I hate the word robust.