mike-matera / FastPID

A fast, integer based PID controller suitable for Arduino.
GNU Lesser General Public License v2.1
139 stars 44 forks source link

Hello my friend #2

Closed SkyNet26 closed 6 years ago

SkyNet26 commented 6 years ago

Help with the FastPID library. When the feedback changes, the output changes between 0 and 1.

mike-matera commented 6 years ago

Can you provide example code?

SkyNet26 commented 6 years ago

include

define PIN_INPUT A1

define PIN_OUTPUT 10

double Kp=0, Ki=0, Kd=1; uint16_t deadband = 0; int output_bits = 1; bool output_signed = false;

FastPID myPID(Kp, Ki, Kd, deadband, output_bits, output_signed);

void setup() { Serial.begin(9600); }

void loop() { int setpoint = 500; int feedback = analogRead(PIN_INPUT); int output = myPID.step(setpoint, feedback); analogWrite(PIN_OUTPUT, 255 - output); Serial.print("sp: "); Serial.print(setpoint); Serial.print(" fb: "); Serial.print(feedback); Serial.print(" out: "); Serial.println(output); delay(100); }

SkyNet26 commented 6 years ago

sp: 500 fb: 256 out: 0 sp: 500 fb: 258 out: 0 sp: 500 fb: 260 out: 0 sp: 500 fb: 275 out: 0 sp: 500 fb: 327 out: 0 sp: 500 fb: 361 out: 0 sp: 500 fb: 379 out: 0 sp: 500 fb: 297 out: 1 sp: 500 fb: 276 out: 1 sp: 500 fb: 261 out: 1 sp: 500 fb: 253 out: 1 sp: 500 fb: 251 out: 1 sp: 500 fb: 224 out: 1 sp: 500 fb: 199 out: 1 sp: 500 fb: 149 out: 1 sp: 500 fb: 111 out: 1 sp: 500 fb: 124 out: 0 sp: 500 fb: 133 out: 0 sp: 500 fb: 145 out: 0 sp: 500 fb: 159 out: 0

SkyNet26 commented 6 years ago

Please tell me why the library does not work, values do not increase more than 1.

mike-matera commented 6 years ago

Hi, It's a bug in the example code! Sorry! There's a new version of the example that works with the latest release. The example you have will work if you change this line:

int output_bits = 1;

to this:

int output_bits = 8;

Sorry for the confusion!

SkyNet26 commented 6 years ago

Thank you!

сб, 21 апр. 2018 г., 19:24 Mike Matera notifications@github.com:

Hi, It's a bug in the example code! Sorry! There's a new version of the example that works with the latest release. The example you have will work if you change this line:

int output_bits = 1;

to this:

int output_bits = 8;

Sorry for the confusion!

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/mike-matera/FastPID/issues/2#issuecomment-383310398, or mute the thread https://github.com/notifications/unsubscribe-auth/AR1vNETWBYguwU7irdOeCIvMWXYP4_Cyks5tq11BgaJpZM4TcicD .