Proportional, integral, derivative controller example.

Dependencies:   mbed PID

Files at this revision

API Documentation at this revision

Comitter:
aberk
Date:
Tue Aug 03 09:09:03 2010 +0000
Child:
1:c48bef0d5d3c
Commit message:
Version 1.0

Changed in this revision

PID_lib.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/PID_lib.lib	Tue Aug 03 09:09:03 2010 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/aberk/programs/PID_lib/latest
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Tue Aug 03 09:09:03 2010 +0000
@@ -0,0 +1,31 @@
+#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);
+  }
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Tue Aug 03 09:09:03 2010 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/9114680c05da