Proportional, integral, derivative controller example.

Dependencies:   mbed PID

main.cpp

Committer:
aberk
Date:
2010-08-03
Revision:
0:85367d3ee779
Child:
1:c48bef0d5d3c

File content as of revision 0:85367d3ee779:

#include "PID.h"

#define RATE 0.1

//Kc, Ti, Td, interval
PID controller(1.0, 0.0, 0.0, RATE);
AnalogIn pv(p15);
PwmOut   co(p26);

int main(){

  //Analog input from 0.0 to 3.3V
  controller.setInputLimits(0.0, 3.3);
  //Pwm output from 0.0 to 1.0
  controller.setOutputLimits(0.0, 1.0);
  //If there's a bias.
  controller.setBias(0.3);
  controller.setMode(AUTO_MODE);
  //We want the process variable to be 1.7V
  controller.setSetPoint(1.7);

  while(1){
    //Update the process variable.
    controller.setProcessValue(pv.read());
    //Set the new output.
    co = controller.getRealOutput();
    //Wait for another loop calculation.
    wait(RATE);
  }

}