PID_v2 dynamic setpoint

Hi,
I want to use PID_v2 library for my project which is too large to post it here, so let's stay with the example from the library (below). In a nutshell, I want to remotely control winch. Arduino that controls the winch receives desired % value of the preset winching force and the PID loop should control the motor throttle to maintain the resultant winching force. It worked with the AutoPID library, but caused a lot of problems and I want to use the PID_v2 library, which has some nice features. The thing is, the example has a fixed setpoint and I don't know how to update the setpoint in a loop. AutoPID worked with pointers, but in PID_v2 it fails... Could somebody help me and clarify how to do that here ?

#include <PID_v2.h>

#define PIN_INPUT 0
#define PIN_OUTPUT 3

// Specify the links and initial tuning parameters
double Kp = 2, Ki = 5, Kd = 1;
PID_v2 myPID(Kp, Ki, Kd, PID::Direct);

void setup() {
  myPID.Start(analogRead(PIN_INPUT),  // input
              0,                      // current output
              100);                   // setpoint
}

void loop() {
  const double input = analogRead(PIN_INPUT);
  const double output = myPID.Run(input);
  analogWrite(PIN_OUTPUT, output);
}

Change the setpoint with
myPID.Setpoint(newSetpoint);
Get the current setpoint with:
currentSetpoint = myPID.GetSetpoint();

See the PID_v2 library GitHub page.

Thanks! I don;t know how I could overlook it

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.