Problem on the PID output all the time receives the value 0

Hello everyone,
I have a question, namely I am trying to set up a PID loop on imaginary data. That is, I have a difference in the direction between what is and should be, let's say 59.5 degrees, which will be my input_heading.
I define myself a PID loop and set the setPoint value to 0.
And I want to see the output value which is output_heading.
but no matter what i change i.e. Kp, Ki, Kd or input_heading i have 0 value at the output all the time. Can anyone help me what am I doing wrong??
The reasoning behind this is that if I give Kp=2 the remainder Kii Kd to 0, I should get 59.5x2 at the output on the first loop. Am I wrong?

Wokwi:

And code:

#include <PID_v1.h> 

double setPoint_heading = 0; 
double input_heading = 59.5; 
double output_heading;
PID pid_heading(&input_heading, &output_heading, &setPoint_heading, 2, 1, 1, DIRECT);



void setup() {


   

  // put your setup code here, to run once:
  Serial.begin(115200);


 
}

void loop() {
  input_heading = input_heading+1;

  output_heading = pid_heading.Compute();
  
  Serial.println(output_heading,8);
  // put your main code here, to run repeatedly:
  delay(1000); // this speeds up the simulation
}


I will answer myself, I forgot to set setmode in the setup section :wink:

The .Compute() function does not return the Output value. It returns 'true' if it actually did anything. It returns false (0) if it is too early to compute a new interval. The Output value is returned in the global variable passed when the PID object was created.

Note: The Output is NOT a 'heading'. It is a unitless control signal applied to the system to try to move the Input closer to the Setpoint.

1 Like

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