Dlloydev / QuickPID

A fast PID controller with multiple options. Various Integral anti-windup, Proportional, Derivative and timer control modes.
MIT License
195 stars 50 forks source link

Negative inputs don't work with QuickPID #47

Closed mmcgraw74 closed 2 years ago

mmcgraw74 commented 2 years ago

I'm trying to use QuickPID to control a servo.

The servo signal is a float with a range of +90.0 degrees to -90.0 degrees.

I observe that the QuickPID output doesn't go negative with negative input and negative setpoint.

QuickPID output does go positive with positive input values and positive setpoint, and when the input and setpoint are the same value the output is 0.0 - which is what I expect.

Am I doing something wrong?

mmcgraw74 commented 2 years ago

An additional observation on QuickPID.

If the positive setpoint is less than the positive input - QuickPID output does not go negative, which would be required to get to the servo position to the lower setpoint.

Dlloydev commented 2 years ago

I haven't worked with servo's yet but was wondering if you've set the output limits with something like myPID.SetOutputLimits(-255, 255);

Is there a similar issue when using the Arduino PID library? #include <PID_v1.h>

mmcgraw74 commented 2 years ago

I just set the PID OutputLimits - that solved my issue! now with that range the PID output is able to track the setpoint whether positive or negative within that range!