Thanks that helps a lot.
I've been working on the velocity version of PID and here are some results so far.

Deriving the velocity PID equations from the position PID equations.
I used Maxima (download Maxima and open PID.wxm)
Download Maxima from: http://maxima.sourceforge.net/
Starting at the top line, use the mouse to select the bracket on the left and press control-enter. This will make the line evaluate. Use the down arrow to go to the next line and repeat.
The file PIDobj3.js is the code to do the velocity PID.
Test were conducted using and R-C filter between the analog output and the analog input. R=100k, C=10uF
Input, output and setpoint are scaled to be in the range 0.0 to 1.0.
To make the velocity form work there has to be integral gain in order to get a setpoint change into the math.
The initial setpoint is 0.5 and is changed to 0.6 at some point to test the response.
The ZZZn.csv files contain several combinations of PID tunings.
Adding proportional gain improves the response but introduces “droop” error. It doesn’t hit the setpoint. Tradition is to add integral gain to remove the droop.
Puzzling over this I noticed that if the setpoint is zero the “droop” error disappears.
My first attempt was to modify the PID internals to operate between -0.5 an 0.5. This showed some improvement. Then it occurred to me to shift the PID internals so that the internal setpoint is always zero so that “droop” is eliminated.
Caution beyond this point there be dragons!
PIDobj6.js contains the code.
YYY3.csv contains the output for P=1.0, I=0.1 D=0.0 and
YYY4.csv for P=1.0, I=0.0, D=0.0.

Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.

ClearMemory041063Thanks that helps a lot.

I've been working on the velocity version of PID and here are some results so far.

Deriving the velocity PID equations from the position PID equations.

I used Maxima (download Maxima and open PID.wxm)

Download Maxima from:

http://maxima.sourceforge.net/

Starting at the top line, use the mouse to select the bracket on the left and press control-enter. This will make the line evaluate. Use the down arrow to go to the next line and repeat.

The file PIDobj3.js is the code to do the velocity PID.

Test were conducted using and R-C filter between the analog output and the analog input. R=100k, C=10uF

Input, output and setpoint are scaled to be in the range 0.0 to 1.0.

To make the velocity form work there has to be integral gain in order to get a setpoint change into the math.

The initial setpoint is 0.5 and is changed to 0.6 at some point to test the response.

The ZZZn.csv files contain several combinations of PID tunings.

Adding proportional gain improves the response but introduces “droop” error. It doesn’t hit the setpoint. Tradition is to add integral gain to remove the droop.

Puzzling over this I noticed that if the setpoint is zero the “droop” error disappears.

My first attempt was to modify the PID internals to operate between -0.5 an 0.5. This showed some improvement. Then it occurred to me to shift the PID internals so that the internal setpoint is always zero so that “droop” is eliminated.

Caution beyond this point there be dragons!

PIDobj6.js contains the code.

YYY3.csv contains the output for P=1.0, I=0.1 D=0.0 and

YYY4.csv for P=1.0, I=0.0, D=0.0.

8 Attachments