One Issue for Turning PID using voltage

We implemented our PID for turning:

Out voltage = min_vol + kp*(target degree- current degree)

where min_vol is the voltage below which the chassis will stop turning.

One problem we have is that the drivetrain completely stops turning before reaching the target degree. One “solution” is to increase the min_vol, which however increases the overshooting on the other hand.

is there any better solution? Thanks.

Two things:

  1. you implemented minimum voltage incorrectly. It should look more like this pseudo code
output = kp*error;
if(output < min_volts) {
    output = min_volts;
}
  1. what you have right now is not a full PID control loop, it is just a P loop. If you are experiencing overshooting the target, You should add the D term and make a PD loop. You can then tune your kp and kd constants by setting both to 0, then increasing kp until you overshoot, then slowly raise kd until you stop overshooting.
5 Likes

One solution is to make the turn PID exit when the current angle is within a certain value(accuracy of the target). Another solution is to detect the speed and exit when the speed is low.

Add the I(integral) part of the PID. when the error gets low, kp doesn’t help, but I can.

//Basic Fix
integral += error
output = kp*error + ki*integral

yes, that is what we do, for example, abs(error) < 0.5. However, as we linearly decrease the voltage based on the P-control, the robot stops completely before reaching target degree - 0.5, and gets stuck in the loop.

If we exit early when detecting 0 speed, it undershoots more than usual. But, we can try. Thanks.

Yes, this is a good idea, but one issue is that the robot will stay still for a few seconds until the error accumulates to a certain level. Thanks.

I would think

output = max(kp*error, min_volt)

works similarly to

output = min_volt + kp*error, min_volt

and certainly, it will have the same issue as we are experiencing now. Our main issue is that the min_volt below which the robot does turn depends on the degree to turn and the power level.

I thought P-loop should be good enough for turning PID. We will try adding kd and Ki, tuning Kp and then Kd. Thanks!

Raising ki would solve that problem. Also adding a error accumulation conditions would make sure that ki doesn’t effect the main part of the drive.

PID_Compensation_Animated

Here is this excellent PID animation. You can see in the beginning with only P control they stop between 60% and 80% of the way to the target. Then you can see how adding I and D affects the system.

15 Likes

Thanks a lot. This is very interesting. We will verify t hat.

Just added ki and it works perfectly without too much lag so far. We will further improve by fine tuning kp, kd and ki. Thank you everyone for great suggestions!

1 Like

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.