Ollie Peng
/
EE192_PID
first draft
Revision 0:87a63b2d26ef, committed 2016-03-15
- Comitter:
- openg
- Date:
- Tue Mar 15 21:18:47 2016 +0000
- Commit message:
- first draft;
Changed in this revision
diff -r 000000000000 -r 87a63b2d26ef PID.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PID.lib Tue Mar 15 21:18:47 2016 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/aberk/code/PID/#6e12a3e5af19
diff -r 000000000000 -r 87a63b2d26ef main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Tue Mar 15 21:18:47 2016 +0000 @@ -0,0 +1,37 @@ +#include "mbed.h" + +Serial pc(USBTX, USBRX); // tx, rx +PwmOut Clock(PTD4); +PwmOut Output(////); +AnalogIn Sensor(////); + +float adjustmentFactor = 1.0; //change so that sensor data is calibrated +float ref = 3.0; +float error = 0.0; +float totalError = 0.0; +int period = 1000; +int PW = period/2; + +int outPeriod = period; //assume period always is the same +int outPW; + +float Ki = 0; //adjust +float Kp = 30; //adjust + +Ticker Controller; + +void Control(){ + error = ref - Sensor.read()*adjustmentFactor; + totalError += error; + outPW = Kp*error + Ki*(totalError); + Output.period_us(outPeriod); + Output.pulsewidth_us(outPW); + } + +int main() { + Clock.period_us(period); + Clock.pulsewidth_us(PW); + Controller.attach_us(Control,period*128); //assumed that we should wait 128 clock cycles before activating controller + //because line camera requires 128 cycles. should verify + +}
diff -r 000000000000 -r 87a63b2d26ef mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Tue Mar 15 21:18:47 2016 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/87f2f5183dfb \ No newline at end of file