Making PID have a smooth startup

Good evening everyone. I was just wondering if there is a way to make the starting up of the PID smoother. When the PID starts the Error value is at whatever the target is since the sensor value is at zero so the power shoots up to max acceleration which causes our robot to jerk upward. I wanted to know a way to have the power gradually increase at startup similar to a motion profile.

Pure PID has this issue. If you just set the end goal as your value, you also start saturating your I term. Think about what trajectory your robot would follow going from A to B. Would you go from 0% to 100% on your motor? Would you accelerate? One solution is to map out a profile and set your desired locations to the profile. Another might be to predict the motor drive required to ho where you want (feed forward) and use PID to correct errors as you follow this.

A practical solution might just be to use PID on your entire move and limit startup jerk with a limited acceleration. If your code doesn’t already do this, zero out I until you’re close to arriving.

My team does this with what’s called a slew rate controller. You can make a very simple one by just storing the PID output from the last tick of your loop, and find out how much it changed by on this tick. If the change in speed is too much, then limit the change in speed to a certain amount. This makes the speeding up of the drive a lot smoother, but may also mess up the slowing down depending on how you have it tuned. I’d recommend messing with the maximum acceleration value a bit, and maybe have different max accelerations for increasing and decreasing speed to get the best result.

1 Like

Alright thank you I got it fixed