The final program for the #include AIR robot

Dependencies:   Biquad HIDScope QEI angleandposition controlandadjust mbed

Fork of includeair by BioRobotics

Committer:
Gerth
Date:
Wed Oct 14 15:14:59 2015 +0000
Revision:
10:9e96d14d7034
Parent:
9:4ee354663560
Child:
11:c10651055871
Added stop when switching modes;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Gerth 0:dd66fff537d7 1 #include "mbed.h"
Gerth 1:917c07a4f3ec 2 #include "QEI.h"
Gerth 1:917c07a4f3ec 3 #include "HIDScope.h"
Gerth 1:917c07a4f3ec 4 #include "Biquad.h"
Gerth 1:917c07a4f3ec 5 #include "controlandadjust.h"
Gerth 1:917c07a4f3ec 6
Gerth 1:917c07a4f3ec 7 //info out
Gerth 10:9e96d14d7034 8 HIDScope scope(6);
Gerth 1:917c07a4f3ec 9 Ticker scope_ticker;
Gerth 3:48438eea184e 10 const double scope_frequency=500;
Gerth 1:917c07a4f3ec 11 Serial pc(USBTX,USBRX);
Gerth 1:917c07a4f3ec 12
Gerth 1:917c07a4f3ec 13 ////////////////ENCODERS
Gerth 9:4ee354663560 14 const float cpr_sensor=32;
Gerth 9:4ee354663560 15 const float cpr_shaft=cpr_sensor*131;
Gerth 9:4ee354663560 16 QEI encoder1(D12,D13,NC,cpr_sensor);/// maybe use Encoder in stead of QEI, because Encoder had setposition
Gerth 9:4ee354663560 17 QEI encoder2(D10,D11,NC,cpr_sensor);
Gerth 9:4ee354663560 18 const double PIE=3.14159265359;
Gerth 9:4ee354663560 19 const float counttorad=((2*PIE)/cpr_shaft);
Gerth 1:917c07a4f3ec 20
Gerth 6:37c94a5e205f 21 /////////////////////////////////CALIBRATION (MODE)
Gerth 8:54a7da09ccad 22 int modecounter=1;
Gerth 6:37c94a5e205f 23 DigitalIn changemodebutton(PTA4);
Gerth 6:37c94a5e205f 24
Gerth 7:7fbb2c028778 25 Ticker readbuttoncalibrate_ticker;
Gerth 7:7fbb2c028778 26 const double readbuttoncalibrate_frequency=10;
Gerth 7:7fbb2c028778 27
Gerth 9:4ee354663560 28 const double radpersec_calibrate=0.1*PIE;
Gerth 8:54a7da09ccad 29
Gerth 8:54a7da09ccad 30 DigitalIn buttonR(D2);
Gerth 8:54a7da09ccad 31 DigitalIn buttonL(D3);
Gerth 8:54a7da09ccad 32
Gerth 1:917c07a4f3ec 33 //////////////////////////////////CONTROLLER
Gerth 1:917c07a4f3ec 34 controlandadjust mycontroller; // make a controller
Gerth 1:917c07a4f3ec 35 //controller constants
Gerth 1:917c07a4f3ec 36 float Kp=0.5;
Gerth 9:4ee354663560 37 float Ki=0.01;
Gerth 1:917c07a4f3ec 38 float Kd=0.001;
Gerth 1:917c07a4f3ec 39 Ticker control_ticker;
Gerth 9:4ee354663560 40 const double control_frequency=25;
Gerth 7:7fbb2c028778 41 const double Ts_control=1.0/control_frequency;
Gerth 1:917c07a4f3ec 42
Gerth 7:7fbb2c028778 43 float error1_int=0;// storage variables for the errors
Gerth 7:7fbb2c028778 44 float error2_int=0;
Gerth 7:7fbb2c028778 45 float error1_prev=0;
Gerth 7:7fbb2c028778 46 float error2_prev=0;
Gerth 1:917c07a4f3ec 47
Gerth 1:917c07a4f3ec 48 InterruptIn valuechangebutton(PTC6);//button to change controller constants
Gerth 1:917c07a4f3ec 49
Gerth 1:917c07a4f3ec 50 //safetyandthreshold
Gerth 3:48438eea184e 51 AnalogIn safety_pot(A3);//pot 2, used for the safety cutoff value for the pwm
Gerth 3:48438eea184e 52 AnalogIn threshold_pot(A2);//pot1, used to adjust threshold if signal differs per person
Gerth 1:917c07a4f3ec 53
Gerth 1:917c07a4f3ec 54 Ticker safetyandthreshold_ticker; // ticker to read potmeters
Gerth 3:48438eea184e 55 const double safetyandthreshold_frequency=1; // frequency for the ticker
Gerth 3:48438eea184e 56
Gerth 4:bf7765b0f612 57 float threshold_value=1;//initial threshold value
Gerth 1:917c07a4f3ec 58
Gerth 1:917c07a4f3ec 59 ////////////////////////////////FILTER
Gerth 1:917c07a4f3ec 60 #include "filtervalues.h"
Gerth 1:917c07a4f3ec 61 Ticker filter_ticker;
Gerth 3:48438eea184e 62 const double filter_frequency=500;
Gerth 1:917c07a4f3ec 63 Biquad myfilter1;
Gerth 1:917c07a4f3ec 64 Biquad myfilter2;
Gerth 1:917c07a4f3ec 65
Gerth 1:917c07a4f3ec 66 AnalogIn emg1_input(A0);
Gerth 1:917c07a4f3ec 67 AnalogIn emg2_input(A1);
Gerth 1:917c07a4f3ec 68
Gerth 1:917c07a4f3ec 69 double filteredsignal1=0;
Gerth 1:917c07a4f3ec 70 double filteredsignal2=0;
Gerth 5:8ac5d0651e4d 71 float filter_extragain=1;
Gerth 1:917c07a4f3ec 72
Gerth 3:48438eea184e 73 /////////////////READSIGNAL
Gerth 3:48438eea184e 74 Ticker readsignal_ticker;
Gerth 3:48438eea184e 75 const double readsignal_frequency=25;
Gerth 3:48438eea184e 76
Gerth 4:bf7765b0f612 77 DigitalOut led1(D8);
Gerth 4:bf7765b0f612 78 DigitalOut led2(D9);
Gerth 4:bf7765b0f612 79
Gerth 4:bf7765b0f612 80 //////////////////////////////// POSITION AND ANGLE SHIZZLE
Gerth 4:bf7765b0f612 81 float desired_position=0;
Gerth 4:bf7765b0f612 82 float desired_angle[]= {0,0};
Gerth 3:48438eea184e 83
Gerth 1:917c07a4f3ec 84 //////////////////////GO FLAGS AND ACTIVATION FUNCTIONS
Gerth 1:917c07a4f3ec 85 volatile bool scopedata_go=false,
Gerth 1:917c07a4f3ec 86 control_go=false,
Gerth 1:917c07a4f3ec 87 filter_go=false,
Gerth 3:48438eea184e 88 safetyandthreshold_go=false,
Gerth 6:37c94a5e205f 89 readsignal_go=false,
Gerth 8:54a7da09ccad 90 switchedmode=true,
Gerth 7:7fbb2c028778 91 readbuttoncalibrate_go=false;
Gerth 1:917c07a4f3ec 92
Gerth 1:917c07a4f3ec 93 void scopedata_activate()
Gerth 1:917c07a4f3ec 94 {
Gerth 1:917c07a4f3ec 95 scopedata_go=true;
Gerth 1:917c07a4f3ec 96 }
Gerth 1:917c07a4f3ec 97 void control_activate()
Gerth 1:917c07a4f3ec 98 {
Gerth 1:917c07a4f3ec 99 control_go=true;
Gerth 1:917c07a4f3ec 100 }
Gerth 1:917c07a4f3ec 101 void filter_activate()
Gerth 1:917c07a4f3ec 102 {
Gerth 1:917c07a4f3ec 103 filter_go=true;
Gerth 1:917c07a4f3ec 104 }
Gerth 1:917c07a4f3ec 105 void safetyandthreshold_activate()
Gerth 1:917c07a4f3ec 106 {
Gerth 1:917c07a4f3ec 107 safetyandthreshold_go=true;
Gerth 1:917c07a4f3ec 108 }
Gerth 3:48438eea184e 109 void readsignal_activate()
Gerth 3:48438eea184e 110 {
Gerth 3:48438eea184e 111 readsignal_go=true;
Gerth 3:48438eea184e 112 }
Gerth 7:7fbb2c028778 113 void readbuttoncalibrate_activate()
Gerth 7:7fbb2c028778 114 {
Gerth 7:7fbb2c028778 115 readbuttoncalibrate_go=true;
Gerth 7:7fbb2c028778 116 }
Gerth 1:917c07a4f3ec 117
Gerth 1:917c07a4f3ec 118 ////////////////////////FUNCTIONS
Gerth 1:917c07a4f3ec 119 //gather data and send to scope
Gerth 1:917c07a4f3ec 120 void scopedata()
Gerth 1:917c07a4f3ec 121 {
Gerth 10:9e96d14d7034 122 scope.set(0,desired_angle[0]);
Gerth 10:9e96d14d7034 123 scope.set(1,counttorad*encoder1.getPulses());
Gerth 10:9e96d14d7034 124 scope.set(2,mycontroller.motor1pwm());
Gerth 10:9e96d14d7034 125 scope.set(3,desired_angle[1]);
Gerth 10:9e96d14d7034 126 scope.set(4,counttorad*encoder2.getPulses());
Gerth 10:9e96d14d7034 127 scope.set(5,mycontroller.motor2pwm());
Gerth 3:48438eea184e 128 scope.send();
Gerth 4:bf7765b0f612 129 }
Gerth 1:917c07a4f3ec 130 //read potmeters and adjust the safetyfactor and threshold
Gerth 1:917c07a4f3ec 131 void safetyandthreshold()
Gerth 1:917c07a4f3ec 132 {
Gerth 3:48438eea184e 133 mycontroller.cutoff((ceil (10*safety_pot.read()) )/10); // adjust the safetyfactor value between 0 and 1 rounded to 1 decimal
Gerth 3:48438eea184e 134 threshold_value=((ceil (10*threshold_pot.read()) )/10); // adjust the threshold value between 0 and 1 rounded to 1 decimal
Gerth 1:917c07a4f3ec 135 }
Gerth 1:917c07a4f3ec 136 /////filter
Gerth 1:917c07a4f3ec 137 void filtereverything()
Gerth 1:917c07a4f3ec 138 {
Gerth 1:917c07a4f3ec 139 //filter_timer.reset();
Gerth 1:917c07a4f3ec 140 // filter_timer.start();
Gerth 1:917c07a4f3ec 141 //pass1 so f1
Gerth 2:c7707856d137 142 double pass1_emg1 = myfilter1.filter(emg1_input.read(), v1_f1_emg1 , v2_f1_emg1 , a1_f1 , a2_f1 , b0_f1 , b1_f1 , b2_f1);
Gerth 2:c7707856d137 143 double pass1_emg2 = myfilter2.filter(emg2_input.read(), v1_f1_emg2 , v2_f1_emg2 , a1_f1 , a2_f1 , b0_f1 , b1_f1 , b2_f1);
Gerth 1:917c07a4f3ec 144
Gerth 1:917c07a4f3ec 145 //pass2 so f2
Gerth 2:c7707856d137 146 double pass2_emg1 = myfilter1.filter(pass1_emg1, v1_f2_emg1 , v2_f2_emg1 , a1_f2 , a2_f2 , b0_f2 , b1_f2 , b2_f2);
Gerth 2:c7707856d137 147 double pass2_emg2 = myfilter2.filter(pass1_emg2, v1_f2_emg2 , v2_f2_emg2 , a1_f2 , a2_f2 , b0_f2 , b1_f2 , b2_f2);
Gerth 1:917c07a4f3ec 148
Gerth 1:917c07a4f3ec 149 //pass3 so f3
Gerth 2:c7707856d137 150 double pass3_emg1 = myfilter1.filter(pass2_emg1, v1_f3_emg1 , v2_f3_emg1 , a1_f3 , a2_f3 , b0_f3 , b1_f3 , b2_f3);
Gerth 2:c7707856d137 151 double pass3_emg2 = myfilter2.filter(pass2_emg2, v1_f3_emg2 , v2_f3_emg2 , a1_f3 , a2_f3 , b0_f3 , b1_f3 , b2_f3);
Gerth 1:917c07a4f3ec 152
Gerth 1:917c07a4f3ec 153 //pass4 so f4
Gerth 2:c7707856d137 154 double pass4_emg1 = myfilter1.filter(pass3_emg1, v1_f4_emg1 , v2_f4_emg1 , a1_f4 , a2_f4 , b0_f4 , b1_f4 , b2_f4);
Gerth 2:c7707856d137 155 double pass4_emg2 = myfilter2.filter(pass3_emg2, v1_f4_emg2 , v2_f4_emg2 , a1_f4 , a2_f4 , b0_f4 , b1_f4 , b2_f4);
Gerth 1:917c07a4f3ec 156
Gerth 1:917c07a4f3ec 157 //pass5 so f5
Gerth 2:c7707856d137 158 double pass5_emg1 = myfilter1.filter(pass4_emg1, v1_f5_emg1 , v2_f5_emg1 , a1_f5 , a2_f5 , b0_f5 , b1_f5 , b2_f5);
Gerth 2:c7707856d137 159 double pass5_emg2 = myfilter2.filter(pass4_emg2, v1_f5_emg2 , v2_f5_emg2 , a1_f5 , a2_f5 , b0_f5 , b1_f5 , b2_f5);
Gerth 1:917c07a4f3ec 160
Gerth 1:917c07a4f3ec 161 ///// take absolute value
Gerth 2:c7707856d137 162 double pass5_emg1_abs=(fabs(pass5_emg1));
Gerth 2:c7707856d137 163 double pass5_emg2_abs=(fabs(pass5_emg2));
Gerth 1:917c07a4f3ec 164
Gerth 1:917c07a4f3ec 165 //pass6 so f6
Gerth 2:c7707856d137 166 double pass6_emg1 = myfilter1.filter(pass5_emg1_abs, v1_f6_emg1 , v2_f6_emg1 , a1_f6 , a2_f6 , b0_f6 , b1_f6 , b2_f6);
Gerth 2:c7707856d137 167 double pass6_emg2 = myfilter2.filter(pass5_emg2_abs, v1_f6_emg2 , v2_f6_emg2 , a1_f6 , a2_f6 , b0_f6 , b1_f6 , b2_f6);
Gerth 1:917c07a4f3ec 168
Gerth 1:917c07a4f3ec 169
Gerth 1:917c07a4f3ec 170 //pass7 so f7
Gerth 2:c7707856d137 171 double pass7_emg1 = myfilter1.filter(pass6_emg1, v1_f7_emg1 , v2_f7_emg1 , a1_f7 , a2_f7 , b0_f7 , b1_f7 , b2_f7);
Gerth 2:c7707856d137 172 double pass7_emg2 = myfilter2.filter(pass6_emg2, v1_f7_emg2 , v2_f7_emg2 , a1_f7 , a2_f7 , b0_f7 , b1_f7 , b2_f7);
Gerth 1:917c07a4f3ec 173
Gerth 2:c7707856d137 174 filteredsignal1=(pass7_emg1*9e11*filter_extragain);
Gerth 2:c7707856d137 175 filteredsignal2=(pass7_emg2*9e11*filter_extragain);
Gerth 1:917c07a4f3ec 176
Gerth 1:917c07a4f3ec 177 //filter_timer.stop();
Gerth 1:917c07a4f3ec 178 }
Gerth 1:917c07a4f3ec 179
Gerth 7:7fbb2c028778 180
Gerth 1:917c07a4f3ec 181
Gerth 1:917c07a4f3ec 182 //adjust controller values when sw2 is pressed
Gerth 1:917c07a4f3ec 183 void valuechange()
Gerth 1:917c07a4f3ec 184 {
Gerth 3:48438eea184e 185 mycontroller.STOP();
Gerth 5:8ac5d0651e4d 186 pc.printf("KP is now %f, enter new value\n",Kp);
Gerth 1:917c07a4f3ec 187 pc.scanf("%f", &Kp);
Gerth 1:917c07a4f3ec 188
Gerth 1:917c07a4f3ec 189 pc.printf("KI is now %f, enter new value\n",Ki);
Gerth 1:917c07a4f3ec 190 pc.scanf("%f", &Ki);
Gerth 1:917c07a4f3ec 191
Gerth 1:917c07a4f3ec 192 pc.printf("KD is now %f, enter new value\n",Kd);
Gerth 5:8ac5d0651e4d 193 pc.scanf("%f", &Kd);
Gerth 3:48438eea184e 194
Gerth 3:48438eea184e 195 pc.printf("Extra gain is now %f, enter new value\n",filter_extragain);
Gerth 5:8ac5d0651e4d 196 pc.scanf("%f", &filter_extragain);
Gerth 1:917c07a4f3ec 197 }
Gerth 3:48438eea184e 198 void readsignal()
Gerth 3:48438eea184e 199 {
Gerth 4:bf7765b0f612 200 if (filteredsignal1>=threshold_value && filteredsignal2>=threshold_value) {
Gerth 4:bf7765b0f612 201 led1=led2=1;
Gerth 4:bf7765b0f612 202 } else if (filteredsignal1>=threshold_value && filteredsignal2<=threshold_value) {
Gerth 4:bf7765b0f612 203 led1=1;
Gerth 4:bf7765b0f612 204 led2=0;
Gerth 4:bf7765b0f612 205 } else if (filteredsignal1<=threshold_value && filteredsignal2>=threshold_value) {
Gerth 4:bf7765b0f612 206 led1=0;
Gerth 4:bf7765b0f612 207 led2=1;
Gerth 3:48438eea184e 208 } else {
Gerth 4:bf7765b0f612 209 led1=led2=0;
Gerth 3:48438eea184e 210 }
Gerth 3:48438eea184e 211 }
Gerth 3:48438eea184e 212
Gerth 6:37c94a5e205f 213 void changemode()
Gerth 6:37c94a5e205f 214 {
Gerth 10:9e96d14d7034 215 mycontroller.STOP();
Gerth 6:37c94a5e205f 216 switchedmode=true;
Gerth 6:37c94a5e205f 217 modecounter++;
Gerth 6:37c94a5e205f 218 if (modecounter==3) {
Gerth 6:37c94a5e205f 219 modecounter=0;
Gerth 6:37c94a5e205f 220 } else {
Gerth 6:37c94a5e205f 221 modecounter=modecounter;
Gerth 6:37c94a5e205f 222 }
Gerth 6:37c94a5e205f 223 wait(1);
Gerth 6:37c94a5e205f 224 }
Gerth 0:dd66fff537d7 225
Gerth 7:7fbb2c028778 226
Gerth 7:7fbb2c028778 227
Gerth 0:dd66fff537d7 228 int main()
Gerth 0:dd66fff537d7 229 {
Gerth 1:917c07a4f3ec 230 //tickers
Gerth 1:917c07a4f3ec 231 safetyandthreshold_ticker.attach(&safetyandthreshold_activate,1.0/safetyandthreshold_frequency);
Gerth 1:917c07a4f3ec 232 filter_ticker.attach(&filter_activate,1.0/filter_frequency);
Gerth 1:917c07a4f3ec 233 control_ticker.attach(&control_activate,1.0/control_frequency);
Gerth 1:917c07a4f3ec 234 scope_ticker.attach(&scopedata_activate,1.0/scope_frequency);
Gerth 3:48438eea184e 235 readsignal_ticker.attach(&readsignal_activate, 1.0/readsignal_frequency);
Gerth 7:7fbb2c028778 236 readbuttoncalibrate_ticker.attach(&readbuttoncalibrate_activate, 1.0/readbuttoncalibrate_frequency);
Gerth 1:917c07a4f3ec 237
Gerth 1:917c07a4f3ec 238 while(1) {
Gerth 6:37c94a5e205f 239 if (changemodebutton==0) {
Gerth 6:37c94a5e205f 240 changemode();
Gerth 1:917c07a4f3ec 241 }
Gerth 9:4ee354663560 242 if (scopedata_go==true) {
Gerth 9:4ee354663560 243 scopedata();
Gerth 9:4ee354663560 244 scopedata_go=false;
Gerth 9:4ee354663560 245 }
Gerth 9:4ee354663560 246 if (safetyandthreshold_go==true) {
Gerth 9:4ee354663560 247 safetyandthreshold();
Gerth 9:4ee354663560 248 safetyandthreshold_go=false;
Gerth 9:4ee354663560 249 }
Gerth 7:7fbb2c028778 250 ///////////////////////////////////////////NORMAL RUNNING MODE
Gerth 7:7fbb2c028778 251 if(modecounter==0) {
Gerth 6:37c94a5e205f 252 if (switchedmode==true) {
Gerth 6:37c94a5e205f 253 encoder1.reset();
Gerth 6:37c94a5e205f 254 encoder2.reset();
Gerth 6:37c94a5e205f 255 pc.printf("Program running\n");//
Gerth 6:37c94a5e205f 256 switchedmode=false;
Gerth 6:37c94a5e205f 257 }
Gerth 9:4ee354663560 258
Gerth 6:37c94a5e205f 259 if (filter_go==true) {
Gerth 6:37c94a5e205f 260 filtereverything();
Gerth 6:37c94a5e205f 261 filter_go=false;
Gerth 6:37c94a5e205f 262 }
Gerth 6:37c94a5e205f 263 if (control_go==true) {
Gerth 7:7fbb2c028778 264 float error1=0;
Gerth 7:7fbb2c028778 265 float error2=0;
Gerth 7:7fbb2c028778 266 mycontroller.PI(error1,error2,Kp,Ki,Ts_control,error1_int,error2_int);
Gerth 6:37c94a5e205f 267 control_go=false;
Gerth 6:37c94a5e205f 268 }
Gerth 6:37c94a5e205f 269 if (readsignal_go==true) {
Gerth 6:37c94a5e205f 270 readsignal();
Gerth 6:37c94a5e205f 271 readsignal_go=false;
Gerth 6:37c94a5e205f 272 }
Gerth 6:37c94a5e205f 273 valuechangebutton.fall(&valuechange);
Gerth 1:917c07a4f3ec 274 }
Gerth 7:7fbb2c028778 275 ////////////////////////////////////////////////////CALIBRATE RIGHT ARM
Gerth 6:37c94a5e205f 276 if (modecounter==1) {
Gerth 6:37c94a5e205f 277 if(switchedmode==true) {
Gerth 6:37c94a5e205f 278 pc.printf("Calibration mode! Use buttons to move rigth arm to 0 degrees\n");
Gerth 6:37c94a5e205f 279 switchedmode=false;
Gerth 6:37c94a5e205f 280 }
Gerth 7:7fbb2c028778 281 if (control_go==true) {
Gerth 9:4ee354663560 282 float error1=(desired_angle[0]-counttorad*encoder1.getPulses());;
Gerth 9:4ee354663560 283 float error2=0;// this is the error you want to use
Gerth 7:7fbb2c028778 284 mycontroller.PI(error1,error2,Kp,Ki,Ts_control,error1_int,error2_int);
Gerth 7:7fbb2c028778 285 control_go=false;
Gerth 7:7fbb2c028778 286 }
Gerth 9:4ee354663560 287 if (readbuttoncalibrate_go==true) {
Gerth 9:4ee354663560 288 if (buttonR.read()==0 && buttonL.read()==1) {
Gerth 9:4ee354663560 289 desired_angle[0] += (radpersec_calibrate/readbuttoncalibrate_frequency);
Gerth 9:4ee354663560 290 readbuttoncalibrate_go=false;
Gerth 9:4ee354663560 291 }
Gerth 9:4ee354663560 292 if (buttonR.read()==1 && buttonL.read()==0) {
Gerth 9:4ee354663560 293 desired_angle[0] -= (radpersec_calibrate/readbuttoncalibrate_frequency);
Gerth 9:4ee354663560 294 readbuttoncalibrate_go=false;
Gerth 9:4ee354663560 295 }
Gerth 9:4ee354663560 296 }
Gerth 8:54a7da09ccad 297 }
Gerth 8:54a7da09ccad 298 ////////////////////////////////////////////CALIBRATE LEFT ARM
Gerth 8:54a7da09ccad 299 if (modecounter==2) {
Gerth 8:54a7da09ccad 300 if(switchedmode==true) {
Gerth 8:54a7da09ccad 301 pc.printf("Calibration mode! Use buttons to move left arm to 0 degrees\n");
Gerth 8:54a7da09ccad 302 switchedmode=false;
Gerth 8:54a7da09ccad 303 }
Gerth 8:54a7da09ccad 304 if (control_go==true) {
Gerth 8:54a7da09ccad 305 float error1=0;
Gerth 8:54a7da09ccad 306 float error2=(desired_angle[1]-counttorad*encoder2.getPulses());// this is the error you want to use
Gerth 8:54a7da09ccad 307 mycontroller.PI(error1,error2,Kp,Ki,Ts_control,error1_int,error2_int);
Gerth 8:54a7da09ccad 308 control_go=false;
Gerth 8:54a7da09ccad 309 }
Gerth 8:54a7da09ccad 310 if (readbuttoncalibrate_go==true) {
Gerth 8:54a7da09ccad 311 if (buttonR.read()==0 && buttonL.read()==1) {
Gerth 8:54a7da09ccad 312 desired_angle[1] += (radpersec_calibrate/readbuttoncalibrate_frequency);
Gerth 8:54a7da09ccad 313 readbuttoncalibrate_go=false;
Gerth 7:7fbb2c028778 314 }
Gerth 8:54a7da09ccad 315 if (buttonR.read()==1 && buttonL.read()==0) {
Gerth 8:54a7da09ccad 316 desired_angle[1] -= (radpersec_calibrate/readbuttoncalibrate_frequency);
Gerth 8:54a7da09ccad 317 readbuttoncalibrate_go=false;
Gerth 7:7fbb2c028778 318 }
Gerth 6:37c94a5e205f 319 }
Gerth 3:48438eea184e 320 }
Gerth 0:dd66fff537d7 321 }
Gerth 8:54a7da09ccad 322 }