PID control pt. 2: Why PID is really PD

This was inspired by this post.

It should be important to know that PID in Roblox is redundant because of the physic instances.

PID is a set of algorithms used to calculate an input for an unknown equation to get a known output. Seems stupid right? Cause it is stupid for game development pretty much 100% of the time. You can just set the value directly.

It is useful however for real-world applications, specifically ones which act on things that change over time. Examples are temperature regulators like your oven, motors trying to remain at a set RPM, etc. You could also use PID for root-finding but proper root-finding algorithms like newton’s method are much MUCH better.

In PID you tune the algorithm, that is you change how much each set of algorithms affects the output by multiplying the output of each one by some constant (called a gain, sometimes marked in code with a k prefix) and then adding them all together.

For example, if my gains were (0.4,0.2,0.1) then my output would be 0.4*proportionalAlgorithm(errorFromDesiredOutput) + 0.2*integralAlgorithm(errorFromDesiredOutput) + 0.1*derivativeAlgorithm(errorFromDesiredOutput)

Now your gains are in terms of your output, so if my output was in terms of degrees per second then setting my proportional gain to say 40 with an error of 50 degrees would mean I would set my degree velocity to 2000 degrees per second :flushed:

Never reaching the setpoint means your output gain may not have enough output effort to reach it given the stresses on the system. The biggest factor in your system will be your proportional part. Then the derivative component and the integral component.

The derivative part determines your acceleration in a velocity context, where proportional control your output gain directly, the derivative is the derivative to your proportional value.

Your integral gain determines how long you have been away from the setpoint relative to the error you are currently at.

Here’s the problem with integral gains from my personal experience, windup can occur where your system can’t apply any more effort however that error causes this negative feedback loop, making your system go out of control.

For example, if I had a plane and I wanted to apply a PID system to the pitch to keep it level if my algorithm is telling me to rotate the plane 90 degrees but I have added soft limits to it to only rotate by 45 degrees (to prevent stalling) then that would create windup which would cause my control system to fail. See this.

The solution is to model your system as accurately as possible, this is known as system identification. If I know I need to apply 14 volts to my oven when it is closed to get to about 300 Celcius then I could simply add that to my output. Now instead of the system being 300 degrees away from my target, I can limit my space to the tolerance of my oven, that is I measured it to vary between ±30 Celcius under load so I can base my gains to be within that range to prevent overshooting.

There is no need for PID in Roblox or any computer program where you can directly control the output. Even if you wanted to simulate physics you still don’t need PID as you can follow the equations which govern them, maybe even applying noise to them if you are not satisfied and want to “simulate” entropy for some weird reason. You’re making a game, not a rocket simulation.

Keynotes:

  • PID is useless because of physics constraints
  • Learn to problem-solve with the tools you got, want to make a bike? If you want it to stay up just use a bodygyro
  • Integral gains are not the best way to eliminate steady-state error, even in positional systems it’s better to use a profiled model
  • Your derivative gain controls how much dampening your system has
  • Your proportional gain controls how quickly your system reacts as well
5 Likes