The final program for the #include AIR robot
Dependencies: Biquad HIDScope QEI angleandposition controlandadjust mbed
Fork of includeair by
Diff: main.cpp
- Revision:
- 22:b29ba919d93e
- Parent:
- 21:6954cc25f2a7
- Child:
- 23:1c4a18799464
--- a/main.cpp Tue Oct 20 13:51:30 2015 +0000 +++ b/main.cpp Tue Oct 20 13:56:29 2015 +0000 @@ -51,6 +51,8 @@ const double Ts_control=1.0/control_frequency; +float error1=0; +float error2=0; float error1_int=0;// storage variables for the errors float error2_int=0; float error1_prev=0; @@ -155,6 +157,8 @@ scope.set(0,desired_position); scope.set(1,desired_angle1); scope.set(2,desired_angle2); + scope.set(3,error1); + scope.set(4,error2); scope.send(); } //read potmeters and adjust the safetyfactor and threshold @@ -244,8 +248,8 @@ desired_angle1=anglepos.positiontoangle1(desired_position,y_during_punch);// calculate desired angles desired_angle2=anglepos.positiontoangle2(desired_position,y_during_punch); - float error1=(desired_angle1-counttorad*encoder1.getPulses());//calculate errors - float error2=(desired_angle2-counttorad*encoder2.getPulses()); + error1=(desired_angle1-counttorad*encoder1.getPulses());//calculate errors + error2=(desired_angle2-counttorad*encoder2.getPulses()); mycontroller.PI(error1,error2,Kp,Ki,Ts_control,error1_int,error2_int);// send errors to controller scopedata();//send data to hidscope WARING lower freqyency than normal @@ -416,8 +420,8 @@ } } if (control_go==true) {// calculate errors and send them to controllers - float error1=(desired_angle1-counttorad*encoder1.getPulses()); - float error2=0; + error1=(desired_angle1-counttorad*encoder1.getPulses()); + error2=0; mycontroller.PI(error1,error2,Kp,Ki,Ts_control,error1_int,error2_int); control_go=false; } @@ -445,8 +449,8 @@ } } if (control_go==true) {// calculate errors and send to controller - float error1=0; - float error2=(desired_angle2-counttorad*encoder2.getPulses()); + error1=0; + error2=(desired_angle2-counttorad*encoder2.getPulses()); mycontroller.PI(error1,error2,Kp,Ki,Ts_control,error1_int,error2_int); control_go=false; } @@ -473,8 +477,8 @@ desired_angle1=anglepos.positiontoangle1(desired_position,y_start); desired_angle2=anglepos.positiontoangle2(desired_position,y_start); - float error1=(desired_angle1-counttorad*encoder1.getPulses()); - float error2=(desired_angle2-counttorad*encoder2.getPulses()); + error1=(desired_angle1-counttorad*encoder1.getPulses()); + error2=(desired_angle2-counttorad*encoder2.getPulses()); mycontroller.PI(error1,error2,Kp,Ki,Ts_control,error1_int,error2_int); control_go=false; }