Aaron Berk
/
PID_HelloWorld
Proportional, integral, derivative controller example.
Embed:
(wiki syntax)
Show/hide line numbers
main.cpp
00001 #include "PID.h" 00002 00003 #define RATE 0.1 00004 00005 //Kc, Ti, Td, interval 00006 PID controller(1.0, 0.0, 0.0, RATE); 00007 AnalogIn pv(p15); 00008 PwmOut co(p26); 00009 00010 int main(){ 00011 00012 //Analog input from 0.0 to 3.3V 00013 controller.setInputLimits(0.0, 3.3); 00014 //Pwm output from 0.0 to 1.0 00015 controller.setOutputLimits(0.0, 1.0); 00016 //If there's a bias. 00017 controller.setBias(0.3); 00018 controller.setMode(AUTO_MODE); 00019 //We want the process variable to be 1.7V 00020 controller.setSetPoint(1.7); 00021 00022 while(1){ 00023 //Update the process variable. 00024 controller.setProcessValue(pv.read()); 00025 //Set the new output. 00026 co = controller.compute(); 00027 //Wait for another loop calculation. 00028 wait(RATE); 00029 } 00030 00031 }
Generated on Fri Jul 15 2022 07:23:17 by 1.7.2