Something basic I do not understand about PID. All of the lecture seems to be about the internals of PID. But only the examples include the rapping. Unfortunately, most or the examples are un-runnable by me. PID is based on error. So, in the null hypothesis, the value (Set-point SP) let's say should be zero. The error is determined, and then PID gives f(e). So, then f(e) is applied as the new input. However, if the desired value is 100, the error could be the same and f(e) could be the same. So, the new input should be 100 +f(e). Is that correct? But the literature does not express this point. Have I formulated the wrong conclusion?

My specific problem is that my nunchuck has values of one byte (0-255). I want my PID to output (-255) to (255). Actually, a max speed of (-8) to (8). But I think what I am seeing is that the input and output range should be the same. But the PID tunings (kp, ki, kd) have not been chosen yet. Wouldn't they handle the conversion?

However it might be simpler to convert your 0-255 to -128 and +127 before feeding it to the PID logic.

I suspect I am misunderstanding this

The error is determined, and then PID gives f(e). So, then f(e) is applied as the new input. However, if the desired value is 100, the error could be the same and f(e) could be the same. So, the new input should be 100 +f(e).

My take on it is that the I value is calculated as the previous I value plus the Error * Kfactor and the P value is calculated as Error * Pfactor.

When I am controlling the speed of a motor the I value represents the PWM value that is necessary to keep the motor running at the chosen speed and the P value will then be 0 (because the error is zero).

However, it might be simpler to convert your 0-255 to -128 and +127 before feeding it to the PID logic.

That’s the easy part. At least I understand that math.

There is an Arduino library by Brett Beauregard. I have to understand this process to use it properly.

What gets lost in the explanation and math is the introduction. The (Setpoint -output) is the error and is what is sent to the PID. So, a PID controller never sees the Setpoint but only the error and must figure out what the setpoint is. (Strange) The tuning parameters have the ability to hide all kinds of magic. Such as unit conversions and biases. All three tuning parameters would have to have the same unit conversions. (Undefined) Any bias would have to be taken care of by the integral term. When the Setpoint is changed (say from 0 to 1), after steady state is reached, error goes to zero, proportional goes to zero and rate of change goes to zero. So, the Integral term has to remember (I AM IN THE CORRECT PLACE). So, coming out of a PID and adding the Setpoint to the Output is NOT what the PID is expecting.

This brings me back to the (0-255) (-128 - 127) issue. Would a PID be that smart?

Brett uses only one set of min-max parameters. That could be (0 to 255) or (-128 to 127) or (-255 to 255) or (-8 to 8) (Minus eight to eight). But again, he only uses one range. So, what is it?

This brings me to the conclusion that there is no preset correct value set for the parameters.

So, a PID controller never sees the Setpoint but only the error and must figure out what the setpoint is.

That is not a good way to look at it.

In the simplest case, (P only) the controller does the following:

If the error is zero, do nothing.
If the error is positive, decrease output.
If the error is negative, increase output.

Note that the sign of the error term is not treated consistently in the literature, hence the REVERSE parameter in the Arduino library code, which swaps the action for positive and negative error.

CLplaneguy:
There is an Arduino library by Brett Beauregard. I have to understand this process to use it properly.

What gets lost in the explanation and math is the introduction.

Yeah. The whole thing seems to go out of its way to make some simple calculations complicated.

The simple parts, and the only important parts, are the ones I mentioned in Reply #1. Many control processes do not need the D term, but if yours does it is equally straightforward.

If you know the code to convert 0-255 to -128 to +127 then you should have no trouble converting the output of your PID calculation to any range you need.

You guys really know this stuff. It is just that I had been studying the details of the math so much, that I had to take a step back and look at the big picture.