dror balbul
/
pidtaurd
taurd for noam
main.cpp@0:85367d3ee779, 2010-08-03 (annotated)
- Committer:
- aberk
- Date:
- Tue Aug 03 09:09:03 2010 +0000
- Revision:
- 0:85367d3ee779
- Child:
- 1:c48bef0d5d3c
Version 1.0
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
aberk | 0:85367d3ee779 | 1 | #include "PID.h" |
aberk | 0:85367d3ee779 | 2 | |
aberk | 0:85367d3ee779 | 3 | #define RATE 0.1 |
aberk | 0:85367d3ee779 | 4 | |
aberk | 0:85367d3ee779 | 5 | //Kc, Ti, Td, interval |
aberk | 0:85367d3ee779 | 6 | PID controller(1.0, 0.0, 0.0, RATE); |
aberk | 0:85367d3ee779 | 7 | AnalogIn pv(p15); |
aberk | 0:85367d3ee779 | 8 | PwmOut co(p26); |
aberk | 0:85367d3ee779 | 9 | |
aberk | 0:85367d3ee779 | 10 | int main(){ |
aberk | 0:85367d3ee779 | 11 | |
aberk | 0:85367d3ee779 | 12 | //Analog input from 0.0 to 3.3V |
aberk | 0:85367d3ee779 | 13 | controller.setInputLimits(0.0, 3.3); |
aberk | 0:85367d3ee779 | 14 | //Pwm output from 0.0 to 1.0 |
aberk | 0:85367d3ee779 | 15 | controller.setOutputLimits(0.0, 1.0); |
aberk | 0:85367d3ee779 | 16 | //If there's a bias. |
aberk | 0:85367d3ee779 | 17 | controller.setBias(0.3); |
aberk | 0:85367d3ee779 | 18 | controller.setMode(AUTO_MODE); |
aberk | 0:85367d3ee779 | 19 | //We want the process variable to be 1.7V |
aberk | 0:85367d3ee779 | 20 | controller.setSetPoint(1.7); |
aberk | 0:85367d3ee779 | 21 | |
aberk | 0:85367d3ee779 | 22 | while(1){ |
aberk | 0:85367d3ee779 | 23 | //Update the process variable. |
aberk | 0:85367d3ee779 | 24 | controller.setProcessValue(pv.read()); |
aberk | 0:85367d3ee779 | 25 | //Set the new output. |
aberk | 0:85367d3ee779 | 26 | co = controller.getRealOutput(); |
aberk | 0:85367d3ee779 | 27 | //Wait for another loop calculation. |
aberk | 0:85367d3ee779 | 28 | wait(RATE); |
aberk | 0:85367d3ee779 | 29 | } |
aberk | 0:85367d3ee779 | 30 | |
aberk | 0:85367d3ee779 | 31 | } |