controller/lib/pid/pid.cpp
bool PID::Compute() {
  if (!inAuto)
    return false;
  unsigned long now = Hal.millis();
  unsigned long timeChange = (now - lastTime);
  if (timeChange >= SampleTime) {
    /*Compute all the working error variables*/
    double input = *myInput;
    double error = *mySetpoint - input;
    double dInput = (input - lastInput);
    outputSum += (ki * error);

    /*Add Proportional on Measurement, if P_ON_M is specified*/
    if (!pOnE)
      outputSum -= kp * dInput;

    if (outputSum > outMax)
      outputSum = outMax;
    else if (outputSum < outMin)
      outputSum = outMin;

    /*Add Proportional on Error, if P_ON_E is specified*/
    double output;
    if (pOnE)
      output = kp * error;
    else
      output = 0;

    /*Compute Rest of PID Output*/
    output += outputSum - kd * dInput;

    if (output > outMax)
      output = outMax;
    else if (output < outMin)
      output = outMin;
    *myOutput = output;

    /*Remember some variables for next time*/
    lastInput = input;
    lastTime = now;
    return true;
  } else
    return false;
}
/* Compute()
 *********************************************************************** This,
 *as they say, is where the magic happens.  this function should be called every
 *time "void loop()" executes.  the function will decide for itself whether a
 *new pid Output needs to be computed.  returns true when the output is
 *computed, false when nothing has been done.
 **********************************************************************************/
Compute()
This,
as they say, is where the magic happens.  this function should be called every
time "void loop()" executes.  the function will decide for itself whether a
new pid Output needs to be computed.  returns true when the output is
computed, false when nothing has been done.
Compute () This as they say is where the magic happens . this function should be called every time " void loop () " executes . the function will decide for itself whether a new pid Output needs to be computed . returns true when the output is computed false when nothing has been done .
bool PID::Compute() {
  if (!inAuto)
    return false;
  unsigned long now = Hal.millis();
  unsigned long timeChange = (now - lastTime);
  if (timeChange >= SampleTime) {
    double input = *myInput;
    double error = *mySetpoint - input;
    double dInput = (input - lastInput);
    outputSum += (ki * error);
    if (!pOnE)
      outputSum -= kp * dInput;
    if (outputSum > outMax)
      outputSum = outMax;
    else if (outputSum < outMin)
      outputSum = outMin;
    double output;
    if (pOnE)
      output = kp * error;
    else
      output = 0;
    output += outputSum - kd * dInput;
    if (output > outMax)
      output = outMax;
    else if (output < outMin)
      output = outMin;
    *myOutput = output;
    lastInput = input;
    lastTime = now;
    return true;
  } else
    return false;
}
bool PID :: Compute ( ) { if ( ! inAuto ) return false ; unsigned long now = Hal . millis ( ) ; unsigned long timeChange = ( now - lastTime ) ; if ( timeChange >= SampleTime ) { double input = * myInput ; double error = * mySetpoint - input ; double dInput = ( input - lastInput ) ; outputSum += ( ki * error ) ; if ( ! pOnE ) outputSum -= kp * dInput ; if ( outputSum > outMax ) outputSum = outMax ; else if ( outputSum < outMin ) outputSum = outMin ; double output ; if ( pOnE ) output = kp * error ; else output = 0 ; output += outputSum - kd * dInput ; if ( output > outMax ) output = outMax ; else if ( output < outMin ) output = outMin ; * myOutput = output ; lastInput = input ; lastTime = now ; return true ; } else return false ; }
Compute()
 This,
as they say, is where the magic happens.
Compute () This as they say is where the magic happens .
/*Compute all the working error variables*/ /*Add Proportional on Measurement, if P_ON_M is specified*/ /*Add Proportional on Error, if P_ON_E is specified*/ /*Compute Rest of PID Output*/ /*Remember some variables for next time*/