EE192 Team 4
/
EE192_PID
first draft
Fork of EE192_PID by
Revision 1:5c1051bb7958, committed 2016-03-15
- Comitter:
- openg
- Date:
- Tue Mar 15 21:44:34 2016 +0000
- Parent:
- 0:87a63b2d26ef
- Commit message:
- first draft;
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r 87a63b2d26ef -r 5c1051bb7958 main.cpp --- a/main.cpp Tue Mar 15 21:18:47 2016 +0000 +++ b/main.cpp Tue Mar 15 21:44:34 2016 +0000 @@ -13,19 +13,21 @@ int PW = period/2; int outPeriod = period; //assume period always is the same -int outPW; +int outPW = outPeriod/2; float Ki = 0; //adjust float Kp = 30; //adjust Ticker Controller; +int flag = 0; void Control(){ error = ref - Sensor.read()*adjustmentFactor; totalError += error; - outPW = Kp*error + Ki*(totalError); + outPW = Kp*error + Ki*totalError; Output.period_us(outPeriod); - Output.pulsewidth_us(outPW); + Output.pulsewidth_us(int(outPW)); + flag = 1; } int main() { @@ -34,4 +36,11 @@ 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 + while(1) { + if (flag) { + pc.printf("PW: %d \n\r",outPW); + flag = 0; + } + } + }