Alle subfiles samengevoegd

Dependencies:   HIDScope biquadFilter mbed MODSERIAL FastPWM QEI

Committer:
s1600907
Date:
Thu Oct 20 11:15:59 2016 +0000
Revision:
0:c96cf9760185
Child:
1:e1267e72ade8
De filter en het berekenen van de motorhoek gecombineerd

Who changed what in which revision?

UserRevisionLine numberNew contents of line
s1600907 0:c96cf9760185 1 #include "mbed.h"
s1600907 0:c96cf9760185 2 #include "HIDScope.h"
s1600907 0:c96cf9760185 3 #include "BiQuad.h"
s1600907 0:c96cf9760185 4 #include "math.h"
s1600907 0:c96cf9760185 5 #include "iostream"
s1600907 0:c96cf9760185 6 #define SERIAL_BAUD 115200
s1600907 0:c96cf9760185 7
s1600907 0:c96cf9760185 8 Serial pc(USBTX,USBRX);
s1600907 0:c96cf9760185 9 //EMG aansluitingen
s1600907 0:c96cf9760185 10 AnalogIn emg0( A0 ); //Biceps Rechts
s1600907 0:c96cf9760185 11 AnalogIn emg1( A1 ); //Bicpes Links
s1600907 0:c96cf9760185 12 AnalogIn emg2( A2 ); //Upper leg
s1600907 0:c96cf9760185 13 //Leds
s1600907 0:c96cf9760185 14 DigitalOut led(LED1); // lampje om te zien dat het programma werkt
s1600907 0:c96cf9760185 15 DigitalOut led2(LED2);
s1600907 0:c96cf9760185 16 DigitalOut led3(LED3);
s1600907 0:c96cf9760185 17 //HIDScope
s1600907 0:c96cf9760185 18 HIDScope scope( 6 ); // aantal channels op de HIDscope
s1600907 0:c96cf9760185 19 //Button om Calibratie te beëindigen
s1600907 0:c96cf9760185 20 InterruptIn Button1(PTC6); // DIT WORDT EEN ANDERE BUTTON
s1600907 0:c96cf9760185 21
s1600907 0:c96cf9760185 22 // Tickers
s1600907 0:c96cf9760185 23 Ticker sample_timer;
s1600907 0:c96cf9760185 24 Ticker TickerCalculationsForTheta;
s1600907 0:c96cf9760185 25
s1600907 0:c96cf9760185 26 //BiQuad
s1600907 0:c96cf9760185 27 // making the biquads and chains; imported from matlab
s1600907 0:c96cf9760185 28 BiQuadChain bqc; //Chain for right biceps
s1600907 0:c96cf9760185 29 BiQuadChain bqc2; //Chain for left biceps
s1600907 0:c96cf9760185 30 BiQuadChain bqc3; //Chain for Upper leg
s1600907 0:c96cf9760185 31 // 1 to 3 are for right biceps
s1600907 0:c96cf9760185 32 BiQuad bq1( 9.14969e-01, -1.82994e+00, 9.14969e-01, -1.82269e+00, 8.37182e-01 );
s1600907 0:c96cf9760185 33 BiQuad bq2( 9.91104e-01, -1.60364e+00, 9.91104e-01, -1.60364e+00, 9.82207e-01 );
s1600907 0:c96cf9760185 34 BiQuad bq3( 8.76555e-05, 1.75311e-04, 8.76555e-05, -1.97334e+00, 9.73695e-01 );
s1600907 0:c96cf9760185 35 // 4 to 6 are for left biceps
s1600907 0:c96cf9760185 36 BiQuad bq4( 9.14969e-01, -1.82994e+00, 9.14969e-01, -1.82269e+00, 8.37182e-01 );
s1600907 0:c96cf9760185 37 BiQuad bq5( 9.91104e-01, -1.60364e+00, 9.91104e-01, -1.60364e+00, 9.82207e-01 );
s1600907 0:c96cf9760185 38 BiQuad bq6( 8.76555e-05, 1.75311e-04, 8.76555e-05, -1.97334e+00, 9.73695e-01 );
s1600907 0:c96cf9760185 39 // 7 to 9 are for upper leg
s1600907 0:c96cf9760185 40 BiQuad bq7( 9.14969e-01, -1.82994e+00, 9.14969e-01, -1.82269e+00, 8.37182e-01 );
s1600907 0:c96cf9760185 41 BiQuad bq8( 9.91104e-01, -1.60364e+00, 9.91104e-01, -1.60364e+00, 9.82207e-01 );
s1600907 0:c96cf9760185 42 BiQuad bq9( 3.91302e-05, 7.82604e-05, 3.91302e-05, -1.98223e+00, 9.82385e-01 );
s1600907 0:c96cf9760185 43
s1600907 0:c96cf9760185 44 // Variabelen voor filter
s1600907 0:c96cf9760185 45 // spier EMG niet boven treshhold
s1600907 0:c96cf9760185 46 volatile bool BicepsLeft = false;
s1600907 0:c96cf9760185 47 volatile bool BicepsRight = false;
s1600907 0:c96cf9760185 48 volatile bool Leg = false;
s1600907 0:c96cf9760185 49 // filtergo uit zetten, zodat deze niet fout gaat.
s1600907 0:c96cf9760185 50 volatile bool filtergo = false;
s1600907 0:c96cf9760185 51
s1600907 0:c96cf9760185 52 // Variabelen voor MotorHoekBerekenen
s1600907 0:c96cf9760185 53 double x = 0.0; // beginpositie x en y
s1600907 0:c96cf9760185 54 double y = 305.5;
s1600907 0:c96cf9760185 55 volatile const double pi = 3.14159265359;
s1600907 0:c96cf9760185 56 double Theta1Gear = 1.0/3.0*pi; // Beginpositie op 60 graden
s1600907 0:c96cf9760185 57 double Theta2Gear = 1.0/3.0*pi;
s1600907 0:c96cf9760185 58 double Theta1 = Theta1Gear*42/12; // Beginpositie van MotorHoek
s1600907 0:c96cf9760185 59 double Theta2 = Theta2Gear*42/12;
s1600907 0:c96cf9760185 60 double Fr_Speed_Theta = 100.0; // frequentie in Hz waarmee theta wordt uigerekend
s1600907 0:c96cf9760185 61 bool Calibration = true; // beginnen met calibreren
s1600907 0:c96cf9760185 62 volatile bool Stepper_State = false; // false = we zijn niet bezig met flippen
s1600907 0:c96cf9760185 63
s1600907 0:c96cf9760185 64 /////////////////////// functies voor filters /////////////////////////////////////////////
s1600907 0:c96cf9760185 65 void sample()
s1600907 0:c96cf9760185 66 {
s1600907 0:c96cf9760185 67 /* Sample function
s1600907 0:c96cf9760185 68 samples the emg0 (of the rightBiceps)
s1600907 0:c96cf9760185 69 samples the emg1 (of the leftBiceps)
s1600907 0:c96cf9760185 70 samples the emg2 (of the Upper leg)
s1600907 0:c96cf9760185 71 filter the singals
s1600907 0:c96cf9760185 72 sends it to HIDScope
s1600907 0:c96cf9760185 73 */
s1600907 0:c96cf9760185 74
s1600907 0:c96cf9760185 75 // Rechts Biceps
s1600907 0:c96cf9760185 76 double inRechts = emg0.read(); // EMG signal
s1600907 0:c96cf9760185 77 double FilterRechts = bqc.step(inRechts); // High pass + Notch (50 HZ)
s1600907 0:c96cf9760185 78 double RectifyRechts = fabs(FilterRechts); // Rectify
s1600907 0:c96cf9760185 79 double outRechts = bq3.step(RectifyRechts); // Low pass
s1600907 0:c96cf9760185 80
s1600907 0:c96cf9760185 81 // Links Biceps
s1600907 0:c96cf9760185 82 double inLinks = emg1.read(); // EMG signal
s1600907 0:c96cf9760185 83 double FilterLinks = bqc2.step(inLinks); // High pass + Notch (50 HZ)
s1600907 0:c96cf9760185 84 double RectifyLinks = fabs(FilterLinks); // Rectify
s1600907 0:c96cf9760185 85 double outLinks = bq6.step(RectifyLinks); // Low pass
s1600907 0:c96cf9760185 86
s1600907 0:c96cf9760185 87 // Upper leg
s1600907 0:c96cf9760185 88 double inBeen = emg2.read(); // EMG signal
s1600907 0:c96cf9760185 89 double FilterBeen = bqc3.step(inBeen); // High pass + Notch (50 HZ)
s1600907 0:c96cf9760185 90 double RectifyBeen = fabs(FilterBeen); // Rectify
s1600907 0:c96cf9760185 91 double outBeen = bq9.step(RectifyBeen); // Low pass
s1600907 0:c96cf9760185 92
s1600907 0:c96cf9760185 93
s1600907 0:c96cf9760185 94
s1600907 0:c96cf9760185 95 /* EMG signal in channel 0 (the first channel)
s1600907 0:c96cf9760185 96 and the filtered EMG signal in channel 1 (the second channel)
s1600907 0:c96cf9760185 97 of the HIDscope */
s1600907 0:c96cf9760185 98 scope.set(0,inRechts);
s1600907 0:c96cf9760185 99 scope.set(1,outRechts);
s1600907 0:c96cf9760185 100 scope.set(2,inLinks);
s1600907 0:c96cf9760185 101 scope.set(3,outLinks);
s1600907 0:c96cf9760185 102 scope.set(4,inBeen);
s1600907 0:c96cf9760185 103 scope.set(5,outBeen);
s1600907 0:c96cf9760185 104
s1600907 0:c96cf9760185 105 // send all channels to the PC at once
s1600907 0:c96cf9760185 106 scope.send();
s1600907 0:c96cf9760185 107
s1600907 0:c96cf9760185 108 // To indicate that the function is working, the LED is on
s1600907 0:c96cf9760185 109 if (outRechts >= 0.015){
s1600907 0:c96cf9760185 110 led2 = 0;
s1600907 0:c96cf9760185 111 led = 1;
s1600907 0:c96cf9760185 112 BicepsRight = true;
s1600907 0:c96cf9760185 113 }
s1600907 0:c96cf9760185 114 else{
s1600907 0:c96cf9760185 115 led2 = 1;
s1600907 0:c96cf9760185 116 led = 0;
s1600907 0:c96cf9760185 117 BicepsRight = false;
s1600907 0:c96cf9760185 118 }
s1600907 0:c96cf9760185 119
s1600907 0:c96cf9760185 120 // If Biceps links is actuated then:
s1600907 0:c96cf9760185 121 if (outLinks >= 0.015){
s1600907 0:c96cf9760185 122 led3 = 0;
s1600907 0:c96cf9760185 123 led = 1;
s1600907 0:c96cf9760185 124 BicepsLeft = true;
s1600907 0:c96cf9760185 125 }
s1600907 0:c96cf9760185 126 else{
s1600907 0:c96cf9760185 127 led3 = 1;
s1600907 0:c96cf9760185 128 led = 0;
s1600907 0:c96cf9760185 129 BicepsLeft = false;
s1600907 0:c96cf9760185 130 }
s1600907 0:c96cf9760185 131 // If upper leg is actuated then:
s1600907 0:c96cf9760185 132 if (outBeen >= 0.01){
s1600907 0:c96cf9760185 133 led3 = 0;
s1600907 0:c96cf9760185 134 led2 = 0;
s1600907 0:c96cf9760185 135 led = 1;
s1600907 0:c96cf9760185 136 Leg = true;
s1600907 0:c96cf9760185 137 }
s1600907 0:c96cf9760185 138 else{
s1600907 0:c96cf9760185 139 led3 = 1;
s1600907 0:c96cf9760185 140 led2 = 1;
s1600907 0:c96cf9760185 141 led = 0;
s1600907 0:c96cf9760185 142 Leg = false;
s1600907 0:c96cf9760185 143 }
s1600907 0:c96cf9760185 144 filtergo = false;
s1600907 0:c96cf9760185 145 }
s1600907 0:c96cf9760185 146
s1600907 0:c96cf9760185 147 // zet de filter aan
s1600907 0:c96cf9760185 148 void filter()
s1600907 0:c96cf9760185 149 {
s1600907 0:c96cf9760185 150 filtergo=true;
s1600907 0:c96cf9760185 151 }
s1600907 0:c96cf9760185 152
s1600907 0:c96cf9760185 153 ///////////////////// functies voor motorhoekberekenen //////////////////////////
s1600907 0:c96cf9760185 154 // vorige x berekenen
s1600907 0:c96cf9760185 155 double Calc_Prev_x () {
s1600907 0:c96cf9760185 156 double Prev_x = x;
s1600907 0:c96cf9760185 157 //pc.printf("prev x = %f\r\n", Prev_x);
s1600907 0:c96cf9760185 158 return Prev_x;
s1600907 0:c96cf9760185 159 }
s1600907 0:c96cf9760185 160
s1600907 0:c96cf9760185 161 // vorige y berekenen
s1600907 0:c96cf9760185 162 double Calc_Prev_y () {
s1600907 0:c96cf9760185 163 double Prev_y = y;
s1600907 0:c96cf9760185 164 //pc.printf("prev y = %f\r\n", Prev_y);
s1600907 0:c96cf9760185 165 return Prev_y;
s1600907 0:c96cf9760185 166 }
s1600907 0:c96cf9760185 167
s1600907 0:c96cf9760185 168 // berekenen van de nieuwe x en y waardes
s1600907 0:c96cf9760185 169 bool CalcXY (bool BicepsLeft, bool BicepsRight, bool Leg, bool Stepper_State) {
s1600907 0:c96cf9760185 170 double Step = 10/Fr_Speed_Theta ; //10 mm per seconde afleggen
s1600907 0:c96cf9760185 171
s1600907 0:c96cf9760185 172 if (BicepsLeft==true && BicepsRight==true && Leg==true && Stepper_State==false) {
s1600907 0:c96cf9760185 173 Stepper_State = true; // we zijn aan het flipper dus geen andere dingen doen
s1600907 0:c96cf9760185 174 // flipper functie aanroepen
s1600907 0:c96cf9760185 175 }
s1600907 0:c96cf9760185 176 else if (BicepsLeft==true && BicepsRight==false && Leg==false && Stepper_State==false) {
s1600907 0:c96cf9760185 177 x = x - Step;
s1600907 0:c96cf9760185 178 }
s1600907 0:c96cf9760185 179 else if (BicepsLeft==false && BicepsRight==true && Leg==false && Stepper_State==false) {
s1600907 0:c96cf9760185 180 x = x + Step; // naar Right bewegen
s1600907 0:c96cf9760185 181 }
s1600907 0:c96cf9760185 182 else if (BicepsLeft==true && BicepsRight==true && Leg==false && Stepper_State==false) {
s1600907 0:c96cf9760185 183 y = y + Step; // naar voren bewegen
s1600907 0:c96cf9760185 184 }
s1600907 0:c96cf9760185 185 else if (BicepsLeft==false && BicepsRight==true && Leg==true && Stepper_State==false) {
s1600907 0:c96cf9760185 186 y = y - Step; // naar achter bewegen
s1600907 0:c96cf9760185 187 }
s1600907 0:c96cf9760185 188 else if (BicepsLeft==false && BicepsRight==false && Leg==false || Stepper_State==true) {
s1600907 0:c96cf9760185 189 }
s1600907 0:c96cf9760185 190
s1600907 0:c96cf9760185 191 // Grenswaardes LET OP: ARMEN MISSCHIEN GEBLOKKEERD DOOR BALK AAN DE BINNENKANT
s1600907 0:c96cf9760185 192 if (x > 200) {
s1600907 0:c96cf9760185 193 x = 200;
s1600907 0:c96cf9760185 194 }
s1600907 0:c96cf9760185 195 else if (x < -200) {
s1600907 0:c96cf9760185 196 x = -200;
s1600907 0:c96cf9760185 197 }
s1600907 0:c96cf9760185 198 if (y > 306) {
s1600907 0:c96cf9760185 199 y = 306;
s1600907 0:c96cf9760185 200 }
s1600907 0:c96cf9760185 201 else if (y < 50) {
s1600907 0:c96cf9760185 202 y = 50; // GOKJE, UITPROBEREN
s1600907 0:c96cf9760185 203 }
s1600907 0:c96cf9760185 204 pc.printf("x = %f, y = %f\r\n", x, y);
s1600907 0:c96cf9760185 205
s1600907 0:c96cf9760185 206 return Stepper_State;
s1600907 0:c96cf9760185 207 }
s1600907 0:c96cf9760185 208
s1600907 0:c96cf9760185 209 // diagonaal berekenen voor linker arm
s1600907 0:c96cf9760185 210 double CalcDia1 (double x, double y) {
s1600907 0:c96cf9760185 211 double a = 50.0; // de afstand van gekozen assenstelsel tot de armas (assenstelsel precies in het midden) KEERTJE NAMETEN
s1600907 0:c96cf9760185 212 double BV1 = sqrt(pow((a+x),2) + pow(y,2)); // diagonaal (afstand van armas tot locatie) berekenen
s1600907 0:c96cf9760185 213 double Dia1 = pow(BV1,2)/(2*BV1); // berekenen van de afstand oorsprong tot diagonaal
s1600907 0:c96cf9760185 214
s1600907 0:c96cf9760185 215 //pc.printf("dia = %f, x = %f, y= %f\r\n", Dia1, x, y);
s1600907 0:c96cf9760185 216 return Dia1;
s1600907 0:c96cf9760185 217 }
s1600907 0:c96cf9760185 218
s1600907 0:c96cf9760185 219 // diagonaal berekenen voor rechter arm
s1600907 0:c96cf9760185 220 double CalcDia2 (double x, double y) {
s1600907 0:c96cf9760185 221 double a = 50.0;
s1600907 0:c96cf9760185 222 double BV2 = sqrt(pow((x-a),2) + pow(y,2)); // zelfde nog een keer doen maar nu voor de rechter arm
s1600907 0:c96cf9760185 223 double Dia2 = pow(BV2,2)/(2*BV2);
s1600907 0:c96cf9760185 224
s1600907 0:c96cf9760185 225 //pc.printf("dia = %f, x = %f, y= %f\r\n", Dia2, x, y);
s1600907 0:c96cf9760185 226 return Dia2;
s1600907 0:c96cf9760185 227 }
s1600907 0:c96cf9760185 228
s1600907 0:c96cf9760185 229 // calculate Theta1
s1600907 0:c96cf9760185 230 void CalcTheta1 (double Dia1, double Prev_x, double Prev_y) {
s1600907 0:c96cf9760185 231 double a = 50.0;
s1600907 0:c96cf9760185 232 double Bar = 200.0; // lengte van de armen
s1600907 0:c96cf9760185 233 double Prev_Theta1_Gear = Theta1Gear;
s1600907 0:c96cf9760185 234 double MaxThetaGear = pi - 30.0*pi/180.0; // de hoek voordat arm het opstakel raakt (max hoek is 24.9 tussen arm en opstakel)
s1600907 0:c96cf9760185 235
s1600907 0:c96cf9760185 236 // Hoek berekenen van het grote tandwiel (gear)
s1600907 0:c96cf9760185 237 if (x > -a) {
s1600907 0:c96cf9760185 238 Theta1Gear = pi - atan(y/(x+a)) - acos(Dia1/Bar);
s1600907 0:c96cf9760185 239 }
s1600907 0:c96cf9760185 240 else if (x > -a) {
s1600907 0:c96cf9760185 241 Theta1Gear = pi - (pi + atan(y/(x+a))) - acos(Dia1/Bar);
s1600907 0:c96cf9760185 242 }
s1600907 0:c96cf9760185 243 else { // als x=-a
s1600907 0:c96cf9760185 244 Theta1Gear = 0.5*pi - acos(Dia1/Bar);
s1600907 0:c96cf9760185 245 }
s1600907 0:c96cf9760185 246
s1600907 0:c96cf9760185 247 // limiten (als de hoek te groot wordt, reset dan de hoek en de x en y waardes)
s1600907 0:c96cf9760185 248 if (Theta1Gear >= MaxThetaGear) { // is de maximale hoek in radialen
s1600907 0:c96cf9760185 249 Theta1Gear = Prev_Theta1_Gear;
s1600907 0:c96cf9760185 250 x = Prev_x;
s1600907 0:c96cf9760185 251 y = Prev_y;
s1600907 0:c96cf9760185 252 }
s1600907 0:c96cf9760185 253
s1600907 0:c96cf9760185 254 // omrekenen van grote tandwiel naar motortandwiel
s1600907 0:c96cf9760185 255 Theta1 = Theta1Gear*42.0/12.0; // grote tandwiel heeft 42 tanden. Motortandwiel heeft er 12.
s1600907 0:c96cf9760185 256
s1600907 0:c96cf9760185 257 pc.printf("thetaMotor = %f, thetaGear = %f, Prev_Gear = %f\r\n", Theta1, Theta1Gear, Prev_Theta1_Gear);
s1600907 0:c96cf9760185 258 }
s1600907 0:c96cf9760185 259
s1600907 0:c96cf9760185 260 void CalcTheta2 (double Dia2, double Prev_x, double Prev_y) {
s1600907 0:c96cf9760185 261 double a = 50.0;
s1600907 0:c96cf9760185 262 double Bar = 200.0; // lengte van de armen
s1600907 0:c96cf9760185 263 double Prev_Theta2_Gear = Theta2Gear;
s1600907 0:c96cf9760185 264 double MaxThetaGear = pi - 30.0*pi/180.0; // de hoek voordat arm het opstakel raakt (max hoek is 24.9 tussen arm en opstakel)
s1600907 0:c96cf9760185 265
s1600907 0:c96cf9760185 266 // Hoek berekenen van het grote tandwiel (gear)
s1600907 0:c96cf9760185 267 if (x < a) {
s1600907 0:c96cf9760185 268 Theta2Gear = pi + atan(y/(x-a)) - acos(Dia2/Bar);
s1600907 0:c96cf9760185 269 }
s1600907 0:c96cf9760185 270 else if (x > a) {
s1600907 0:c96cf9760185 271 Theta2Gear = pi - (pi - atan(y/(x-a))) - acos(Dia2/Bar);
s1600907 0:c96cf9760185 272 }
s1600907 0:c96cf9760185 273 else { // als x=a
s1600907 0:c96cf9760185 274 Theta2Gear = 0.5*pi - acos(Dia2/Bar);
s1600907 0:c96cf9760185 275 }
s1600907 0:c96cf9760185 276
s1600907 0:c96cf9760185 277 // limiten (als de hoek te groot wordt, reset dan de hoek en de x en y waardes)
s1600907 0:c96cf9760185 278 if (Theta2Gear >= MaxThetaGear) {
s1600907 0:c96cf9760185 279 Theta2Gear = Prev_Theta2_Gear;
s1600907 0:c96cf9760185 280 x = Prev_x;
s1600907 0:c96cf9760185 281 y = Prev_y;
s1600907 0:c96cf9760185 282 }
s1600907 0:c96cf9760185 283
s1600907 0:c96cf9760185 284 // omrekenen van grote tandwiel naar motortandwiel
s1600907 0:c96cf9760185 285 Theta2 = Theta2Gear*42.0/12.0; // grote tandwiel heeft 42 tanden. Motortandwiel heeft er 12.
s1600907 0:c96cf9760185 286
s1600907 0:c96cf9760185 287 pc.printf("thetaMotor = %f, thetaGear = %f, Prev_Gear = %f\r\n", Theta2, Theta2Gear, Prev_Theta2_Gear);
s1600907 0:c96cf9760185 288 }
s1600907 0:c96cf9760185 289
s1600907 0:c96cf9760185 290 void CalculationsForTheta () {
s1600907 0:c96cf9760185 291 double Prev_x = Calc_Prev_x ();
s1600907 0:c96cf9760185 292 double Prev_y = Calc_Prev_y ();
s1600907 0:c96cf9760185 293 bool Stepper_State = CalcXY (BicepsLeft, BicepsRight, Leg, Stepper_State);
s1600907 0:c96cf9760185 294 double Dia1 = CalcDia1 (x, y);
s1600907 0:c96cf9760185 295 double Dia2 = CalcDia2 (x, y);
s1600907 0:c96cf9760185 296 CalcTheta1 (Dia1, Prev_x, Prev_y);
s1600907 0:c96cf9760185 297 CalcTheta2 (Dia2, Prev_x, Prev_y);
s1600907 0:c96cf9760185 298 }
s1600907 0:c96cf9760185 299
s1600907 0:c96cf9760185 300 // als de button ingedrukt wordt dan stoppen we met calibreren
s1600907 0:c96cf9760185 301 void EndCalibration () {
s1600907 0:c96cf9760185 302 Calibration = false;
s1600907 0:c96cf9760185 303 }
s1600907 0:c96cf9760185 304
s1600907 0:c96cf9760185 305 //////////////// functies voor aansturing motoren ///////////////////////////////
s1600907 0:c96cf9760185 306
s1600907 0:c96cf9760185 307
s1600907 0:c96cf9760185 308
s1600907 0:c96cf9760185 309 ////////////////////////// main loop ////////////////////////////////////////////
s1600907 0:c96cf9760185 310 int main()
s1600907 0:c96cf9760185 311 {
s1600907 0:c96cf9760185 312 pc.baud(SERIAL_BAUD);
s1600907 0:c96cf9760185 313 pc.printf("\r\n Nieuwe code uitproberen :) \r\n");
s1600907 0:c96cf9760185 314
s1600907 0:c96cf9760185 315 /* making the biquad chain for filtering the emg
s1600907 0:c96cf9760185 316 notch and high pass */
s1600907 0:c96cf9760185 317 bqc.add( &bq1 ).add( &bq2 );
s1600907 0:c96cf9760185 318 bqc2.add( &bq4 ).add( &bq5 );
s1600907 0:c96cf9760185 319 bqc3.add( &bq7 ).add( &bq8 );
s1600907 0:c96cf9760185 320
s1600907 0:c96cf9760185 321 // Calibreren
s1600907 0:c96cf9760185 322 while (Calibration == true) {
s1600907 0:c96cf9760185 323 // potmeter dingen aanpassen
s1600907 0:c96cf9760185 324
s1600907 0:c96cf9760185 325 pc.printf("calibreren is bezig\r\n");
s1600907 0:c96cf9760185 326 Button1.fall(&EndCalibration);
s1600907 0:c96cf9760185 327 }
s1600907 0:c96cf9760185 328
s1600907 0:c96cf9760185 329 /**Attach the 'sample' function to the timer 'sample_timer'.
s1600907 0:c96cf9760185 330 * this ensures that 'sample' is executed every 0.002 seconds = 500 Hz
s1600907 0:c96cf9760185 331 */
s1600907 0:c96cf9760185 332 sample_timer.attach(&filter, 0.002);
s1600907 0:c96cf9760185 333
s1600907 0:c96cf9760185 334 // extra stap, zodat er geen op onthoudt komt.
s1600907 0:c96cf9760185 335 while (filtergo == true)
s1600907 0:c96cf9760185 336 {
s1600907 0:c96cf9760185 337 sample();
s1600907 0:c96cf9760185 338 }
s1600907 0:c96cf9760185 339
s1600907 0:c96cf9760185 340 // ticker voor hoek berekenen aanzetten
s1600907 0:c96cf9760185 341 TickerCalculationsForTheta.attach(&CalculationsForTheta,2); ///Fr_Speed_Theta
s1600907 0:c96cf9760185 342
s1600907 0:c96cf9760185 343
s1600907 0:c96cf9760185 344 //empty loop, sample() is executed periodically
s1600907 0:c96cf9760185 345 while(1) {}
s1600907 0:c96cf9760185 346 }