With this program the buttons on the biorobotics shield can be used to move the arms. both buttons pressed means shoot. Also SW3 can be pressed to adjust controller constants via Serial connection
Dependencies: HIDScope QEI controlandadjust mbed
Diff: main.cpp
- Revision:
- 5:be9f9dcbd9b0
- Parent:
- 4:5243e66b1fea
- Child:
- 6:2d67144f217b
- Child:
- 7:8482ea098a37
--- a/main.cpp Wed Oct 14 15:22:49 2015 +0000 +++ b/main.cpp Thu Oct 15 09:51:08 2015 +0000 @@ -30,9 +30,9 @@ // controller values and errors controlandadjust mycontroller;//the value between () is the maximum value of the PWM signal send to the motors -const float Kp=0.5; -const float Ki=0.01; -const float Kd=0.001; + float Kp=0.5; + float Ki=0.01; + float Kd=0.001; const float Ts_control=1.0/control_frequency; float error1=0; float error2=0; @@ -97,7 +97,7 @@ schiettimer.start(); float pass=0; while(schiettimer.read()<=schiettijd) { - // errors berekenen en naar de controller passen +// errors berekenen en naar de controller passen error1=(desiredangle[0]-counttorad*encoder1.getPulses()); error2=(desiredangle[1]-counttorad*encoder2.getPulses()); mycontroller.PI(error1, error2, Kp, Ki, Ts_control, error1_int, error2_int); @@ -112,6 +112,19 @@ desiredangle[1]-=schiethoek; } +void changecontrollervalues() +{ + mycontroller.STOP(); + + pc.printf("KP is now %f, enter new value\n",Kp); + pc.scanf("%f", &Kp); + + pc.printf("KI is now %f, enter new value\n",Ki); + pc.scanf("%f", &Ki); + + pc.printf("KD is now %f, enter new value\n",Kd); + pc.scanf("%f", &Kd); +} //////////////////////////////////////////////////MAIN/////////////////////////////////// int main() { @@ -159,17 +172,7 @@ scopedata_go=false; } //unit om controllervalues aan te passen - if (changecontrollervaluesbutton.read()==0) { - mycontroller.STOP(); - pc.printf("KP is now %f, enter new value\n",Kp); - pc.scanf("%f", &Kp); - - pc.printf("KI is now %f, enter new value\n",Ki); - pc.scanf("%f", &Ki); - - pc.printf("KD is now %f, enter new value\n",Kd); - pc.scanf("%f", &Kd); - } + changecontrollervaluesbutton.fall(&changecontrollervalues); } return 0; }