Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: HIDScope MODSERIAL QEI biquadFilter mbed
Fork of emg_import by
main.cpp@44:969348be74a5, 2016-11-01 (annotated)
- Committer:
- daniQQue
- Date:
- Tue Nov 01 15:40:43 2016 +0000
- Revision:
- 44:969348be74a5
- Parent:
- 42:7164ccd2aa14
- Child:
- 45:d0e9f586cd03
terug naar werkend script, goede kall (nu in ticker), motors draaien lang door
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| daniQQue | 0:34c739fcc3e0 | 1 | //libraries |
| daniQQue | 0:34c739fcc3e0 | 2 | #include "mbed.h" |
| daniQQue | 0:34c739fcc3e0 | 3 | #include "HIDScope.h" |
| daniQQue | 14:5b17697cf775 | 4 | #include "BiQuad.h" |
| daniQQue | 40:187ef29de53d | 5 | #include "MODSERIAL.h" |
| daniQQue | 0:34c739fcc3e0 | 6 | |
| daniQQue | 0:34c739fcc3e0 | 7 | //Define objects |
| daniQQue | 40:187ef29de53d | 8 | AnalogIn emg_biceps_right_in( A0 ); //analog in to get EMG biceps (r) in to c++ |
| daniQQue | 40:187ef29de53d | 9 | AnalogIn emg_triceps_right_in(A1); //analog in to get EMG triceps (r) in to c++ |
| daniQQue | 40:187ef29de53d | 10 | AnalogIn emg_biceps_left_in (A2); //analog in to get EMG biceps (l) in to c++ |
| daniQQue | 42:7164ccd2aa14 | 11 | |
| daniQQue | 44:969348be74a5 | 12 | DigitalIn button_calibration_biceps (SW3); //button to start calibration biceps |
| daniQQue | 44:969348be74a5 | 13 | DigitalIn button_calibration_triceps (SW2); // button to start calibration tricps |
| daniQQue | 42:7164ccd2aa14 | 14 | |
| daniQQue | 0:34c739fcc3e0 | 15 | Ticker sample_timer; //ticker |
| daniQQue | 40:187ef29de53d | 16 | Ticker switch_function; //ticker |
| daniQQue | 44:969348be74a5 | 17 | Ticker ticker_calibration_biceps; |
| daniQQue | 44:969348be74a5 | 18 | Ticker ticker_calibration_triceps; |
| daniQQue | 40:187ef29de53d | 19 | HIDScope scope(5); //open 3 channels in hidscope |
| daniQQue | 44:969348be74a5 | 20 | |
| daniQQue | 40:187ef29de53d | 21 | MODSERIAL pc(USBTX, USBRX); //pc connection |
| daniQQue | 40:187ef29de53d | 22 | DigitalOut red(LED_RED); |
| daniQQue | 40:187ef29de53d | 23 | DigitalOut green(LED_GREEN); |
| daniQQue | 42:7164ccd2aa14 | 24 | DigitalOut blue(LED_BLUE); |
| daniQQue | 40:187ef29de53d | 25 | //motors |
| daniQQue | 40:187ef29de53d | 26 | DigitalOut richting_motor1(D4); |
| daniQQue | 40:187ef29de53d | 27 | PwmOut pwm_motor1(D5); |
| daniQQue | 40:187ef29de53d | 28 | DigitalOut richting_motor2(D7); |
| daniQQue | 40:187ef29de53d | 29 | PwmOut pwm_motor2(D6); |
| daniQQue | 0:34c739fcc3e0 | 30 | |
| daniQQue | 0:34c739fcc3e0 | 31 | //define variables |
| daniQQue | 40:187ef29de53d | 32 | //other |
| daniQQue | 41:9ea3d5921f07 | 33 | int onoffsignal_biceps=0; // on/off signal: 1; biceps activation, 0: nothing, -1, triceps activation |
| daniQQue | 41:9ea3d5921f07 | 34 | int switch_signal_triceps=0; // switching between motors. |
| daniQQue | 42:7164ccd2aa14 | 35 | volatile double cut_off_value_biceps_right =0.04; //gespecificeerd door floortje |
| daniQQue | 42:7164ccd2aa14 | 36 | volatile double cut_off_value_biceps_left =-0.04; |
| daniQQue | 44:969348be74a5 | 37 | volatile double cut_off_value_triceps=-0.04; //gespecificeerd door floortje |
| daniQQue | 41:9ea3d5921f07 | 38 | double signal_biceps_sum; |
| daniQQue | 44:969348be74a5 | 39 | double bicepstriceps_rightarm; |
| daniQQue | 42:7164ccd2aa14 | 40 | int motorswitch= 0; //start van de teller wordt op nul gesteld |
| daniQQue | 42:7164ccd2aa14 | 41 | |
| daniQQue | 42:7164ccd2aa14 | 42 | //variables and constants for calibration |
| daniQQue | 42:7164ccd2aa14 | 43 | const float percentage_max_triceps=0.3; |
| daniQQue | 42:7164ccd2aa14 | 44 | const float percentage_max_biceps =0.3; |
| daniQQue | 42:7164ccd2aa14 | 45 | double max_biceps; //calibration maximum biceps |
| daniQQue | 42:7164ccd2aa14 | 46 | double max_triceps; //calibration maximum triceps |
| daniQQue | 42:7164ccd2aa14 | 47 | |
| daniQQue | 40:187ef29de53d | 48 | //biceps arm 1, right arm |
| daniQQue | 15:bb4a6c7836d8 | 49 | double emg_biceps_right; |
| daniQQue | 15:bb4a6c7836d8 | 50 | double emg_filtered_high_biceps_right; |
| daniQQue | 15:bb4a6c7836d8 | 51 | double emg_abs_biceps_right; |
| daniQQue | 15:bb4a6c7836d8 | 52 | double emg_filtered_biceps_right; |
| daniQQue | 40:187ef29de53d | 53 | double emg_filtered_high_notch_1_biceps_right; |
| daniQQue | 40:187ef29de53d | 54 | //double emg_filtered_high_notch_1_2_biceps_right; |
| daniQQue | 40:187ef29de53d | 55 | |
| daniQQue | 40:187ef29de53d | 56 | //triceps arm 1, right arm |
| daniQQue | 40:187ef29de53d | 57 | double emg_triceps_right; |
| daniQQue | 40:187ef29de53d | 58 | double emg_filtered_high_triceps_right; |
| daniQQue | 40:187ef29de53d | 59 | double emg_abs_triceps_right; |
| daniQQue | 40:187ef29de53d | 60 | double emg_filtered_triceps_right; |
| daniQQue | 40:187ef29de53d | 61 | double emg_filtered_high_notch_1_triceps_right; |
| daniQQue | 40:187ef29de53d | 62 | |
| daniQQue | 40:187ef29de53d | 63 | //biceps arm 1, left arm |
| daniQQue | 40:187ef29de53d | 64 | double emg_biceps_left; |
| daniQQue | 40:187ef29de53d | 65 | double emg_filtered_high_biceps_left; |
| daniQQue | 40:187ef29de53d | 66 | double emg_abs_biceps_left; |
| daniQQue | 40:187ef29de53d | 67 | double emg_filtered_biceps_left; |
| daniQQue | 40:187ef29de53d | 68 | double emg_filtered_high_notch_1_biceps_left; |
| daniQQue | 40:187ef29de53d | 69 | |
| daniQQue | 40:187ef29de53d | 70 | //before abs filtering |
| daniQQue | 40:187ef29de53d | 71 | |
| daniQQue | 40:187ef29de53d | 72 | //b1 = biceps right arm |
| daniQQue | 40:187ef29de53d | 73 | BiQuad filterhigh_b1(9.5654e-01,-1.9131e+00,9.5654e-01,-1.9112e+00,9.1498e-01); |
| daniQQue | 40:187ef29de53d | 74 | BiQuad filternotch1_b1 (9.9376e-01 , -1.8902e-00, 9.9376e-01 , -1.8902e-00 , 9.875e-01); |
| daniQQue | 40:187ef29de53d | 75 | |
| daniQQue | 40:187ef29de53d | 76 | //t1= triceps right arm |
| daniQQue | 40:187ef29de53d | 77 | BiQuad filterhigh_t1(9.5654e-01,-1.9131e+00,9.5654e-01,-1.9112e+00,9.1498e-01); |
| daniQQue | 40:187ef29de53d | 78 | BiQuad filternotch1_t1 (9.9376e-01 , -1.8902e-00, 9.9376e-01 , -1.8902e-00 , 9.875e-01); |
| daniQQue | 5:688b1b5530d8 | 79 | |
| daniQQue | 40:187ef29de53d | 80 | //b2= biceps left arm |
| daniQQue | 40:187ef29de53d | 81 | BiQuad filterhigh_b2(9.5654e-01,-1.9131e+00,9.5654e-01,-1.9112e+00,9.1498e-01); |
| daniQQue | 40:187ef29de53d | 82 | BiQuad filternotch1_b2 (9.9376e-01 , -1.8902e-00, 9.9376e-01 , -1.8902e-00 , 9.875e-01); |
| daniQQue | 40:187ef29de53d | 83 | |
| daniQQue | 40:187ef29de53d | 84 | //after abs filtering |
| daniQQue | 40:187ef29de53d | 85 | BiQuad filterlow_b1 (6.2942e-06, 1.2588e-05,6.2942e-06,-1.9929e+00,9.9292e-01); |
| daniQQue | 40:187ef29de53d | 86 | BiQuad filterlow_t1 (6.2942e-06, 1.2588e-05,6.2942e-06,-1.9929e+00,9.9292e-01); |
| daniQQue | 40:187ef29de53d | 87 | BiQuad filterlow_b2 (6.2942e-06, 1.2588e-05,6.2942e-06,-1.9929e+00,9.9292e-01); |
| daniQQue | 10:7255b59224cc | 88 | |
| daniQQue | 40:187ef29de53d | 89 | //function teller |
| daniQQue | 40:187ef29de53d | 90 | void SwitchN() { // maakt simpele functie die 1 bij n optelt |
| daniQQue | 41:9ea3d5921f07 | 91 | if(switch_signal_triceps==1) |
| daniQQue | 40:187ef29de53d | 92 | { |
| daniQQue | 42:7164ccd2aa14 | 93 | motorswitch++; |
| daniQQue | 42:7164ccd2aa14 | 94 | |
| daniQQue | 42:7164ccd2aa14 | 95 | if (motorswitch%2==0) |
| daniQQue | 42:7164ccd2aa14 | 96 | {pc.printf("If you contract the right arm, the robot will go right \r\n"); |
| daniQQue | 42:7164ccd2aa14 | 97 | pc.printf("If you contract biceps of the left arm, the robot will go left \r\n"); |
| daniQQue | 42:7164ccd2aa14 | 98 | pc.printf("\r\n"); |
| daniQQue | 42:7164ccd2aa14 | 99 | green=0; |
| daniQQue | 42:7164ccd2aa14 | 100 | red=1; |
| daniQQue | 42:7164ccd2aa14 | 101 | } |
| daniQQue | 42:7164ccd2aa14 | 102 | |
| daniQQue | 42:7164ccd2aa14 | 103 | else |
| daniQQue | 42:7164ccd2aa14 | 104 | {pc.printf("If you contract the biceps of right arm, the robot will go up \r\n"); |
| daniQQue | 41:9ea3d5921f07 | 105 | pc.printf("If you contract the biceps of left arm, the robot will go down \r\n"); |
| daniQQue | 41:9ea3d5921f07 | 106 | pc.printf("\r\n"); |
| daniQQue | 42:7164ccd2aa14 | 107 | green=1; |
| daniQQue | 42:7164ccd2aa14 | 108 | red=0; |
| daniQQue | 42:7164ccd2aa14 | 109 | |
| daniQQue | 40:187ef29de53d | 110 | } |
| daniQQue | 42:7164ccd2aa14 | 111 | |
| daniQQue | 40:187ef29de53d | 112 | } |
| daniQQue | 41:9ea3d5921f07 | 113 | } |
| daniQQue | 40:187ef29de53d | 114 | |
| daniQQue | 40:187ef29de53d | 115 | //functions which are called in ticker to sample the analog signal |
| daniQQue | 40:187ef29de53d | 116 | |
| daniQQue | 42:7164ccd2aa14 | 117 | //callibration |
| daniQQue | 42:7164ccd2aa14 | 118 | void calibration_biceps(){ |
| daniQQue | 44:969348be74a5 | 119 | if (button_calibration_biceps==0){ |
| daniQQue | 42:7164ccd2aa14 | 120 | pc.printf("start of calibration biceps, contract maximal \n"); |
| daniQQue | 42:7164ccd2aa14 | 121 | red=1; |
| daniQQue | 42:7164ccd2aa14 | 122 | green=1; |
| daniQQue | 42:7164ccd2aa14 | 123 | blue=0; |
| daniQQue | 42:7164ccd2aa14 | 124 | |
| daniQQue | 44:969348be74a5 | 125 | for(int n =0; n<1500;n++) //read for 2000 samples as calibration |
| daniQQue | 42:7164ccd2aa14 | 126 | { |
| daniQQue | 42:7164ccd2aa14 | 127 | emg_biceps_right=emg_biceps_right_in.read(); //read the emg value from the elektrodes |
| daniQQue | 42:7164ccd2aa14 | 128 | emg_filtered_high_biceps_right= filterhigh_b1.step(emg_biceps_right); |
| daniQQue | 42:7164ccd2aa14 | 129 | emg_filtered_high_notch_1_biceps_right=filternotch1_b1.step(emg_filtered_high_biceps_right); |
| daniQQue | 42:7164ccd2aa14 | 130 | emg_abs_biceps_right=fabs(emg_filtered_high_notch_1_biceps_right); //fabs because float |
| daniQQue | 42:7164ccd2aa14 | 131 | emg_filtered_biceps_right=filterlow_b1.step(emg_abs_biceps_right); |
| daniQQue | 42:7164ccd2aa14 | 132 | |
| daniQQue | 42:7164ccd2aa14 | 133 | if (emg_filtered_biceps_right > max_biceps) //determine what the highest reachable emg signal is |
| daniQQue | 42:7164ccd2aa14 | 134 | { |
| daniQQue | 42:7164ccd2aa14 | 135 | max_biceps = emg_filtered_biceps_right; |
| daniQQue | 42:7164ccd2aa14 | 136 | |
| daniQQue | 42:7164ccd2aa14 | 137 | } |
| daniQQue | 42:7164ccd2aa14 | 138 | wait(0.001f); //to sample at same freq; 1000Hz |
| daniQQue | 42:7164ccd2aa14 | 139 | } |
| daniQQue | 42:7164ccd2aa14 | 140 | cut_off_value_biceps_right=percentage_max_biceps*max_biceps; |
| daniQQue | 42:7164ccd2aa14 | 141 | cut_off_value_biceps_left=-cut_off_value_biceps_right; |
| daniQQue | 42:7164ccd2aa14 | 142 | //toggle lights |
| daniQQue | 42:7164ccd2aa14 | 143 | blue=!blue; |
| daniQQue | 42:7164ccd2aa14 | 144 | |
| daniQQue | 42:7164ccd2aa14 | 145 | pc.printf(" end of calibration\r\n",cut_off_value_biceps_right ); |
| daniQQue | 42:7164ccd2aa14 | 146 | pc.printf(" change of cv biceps: %f ",cut_off_value_biceps_right ); |
| daniQQue | 42:7164ccd2aa14 | 147 | |
| daniQQue | 44:969348be74a5 | 148 | wait(0.2f); |
| daniQQue | 42:7164ccd2aa14 | 149 | |
| daniQQue | 42:7164ccd2aa14 | 150 | if (motorswitch%2==0) |
| daniQQue | 42:7164ccd2aa14 | 151 | {green=0; |
| daniQQue | 42:7164ccd2aa14 | 152 | red=1;} |
| daniQQue | 42:7164ccd2aa14 | 153 | |
| daniQQue | 42:7164ccd2aa14 | 154 | else {green=1; |
| daniQQue | 42:7164ccd2aa14 | 155 | red=0;} |
| daniQQue | 44:969348be74a5 | 156 | } |
| daniQQue | 42:7164ccd2aa14 | 157 | } |
| daniQQue | 42:7164ccd2aa14 | 158 | |
| daniQQue | 42:7164ccd2aa14 | 159 | void calibration_triceps(){ |
| daniQQue | 44:969348be74a5 | 160 | if(button_calibration_triceps==0){ |
| daniQQue | 42:7164ccd2aa14 | 161 | red=1; |
| daniQQue | 42:7164ccd2aa14 | 162 | green=1; |
| daniQQue | 42:7164ccd2aa14 | 163 | blue=0; |
| daniQQue | 42:7164ccd2aa14 | 164 | |
| daniQQue | 42:7164ccd2aa14 | 165 | pc.printf("start of calibration triceps\r\n"); |
| daniQQue | 42:7164ccd2aa14 | 166 | |
| daniQQue | 44:969348be74a5 | 167 | for(int n =0; n<1500;n++) //read for 2000 samples as calibration |
| daniQQue | 42:7164ccd2aa14 | 168 | { |
| daniQQue | 42:7164ccd2aa14 | 169 | emg_triceps_right=emg_triceps_right_in.read(); //read the emg value from the elektrodes |
| daniQQue | 42:7164ccd2aa14 | 170 | emg_filtered_high_triceps_right= filterhigh_t1.step(emg_triceps_right); |
| daniQQue | 42:7164ccd2aa14 | 171 | emg_filtered_high_notch_1_triceps_right=filternotch1_t1.step(emg_filtered_high_triceps_right); |
| daniQQue | 42:7164ccd2aa14 | 172 | emg_abs_triceps_right=fabs(emg_filtered_high_notch_1_triceps_right); //fabs because float |
| daniQQue | 42:7164ccd2aa14 | 173 | emg_filtered_triceps_right=filterlow_t1.step(emg_abs_triceps_right); |
| daniQQue | 42:7164ccd2aa14 | 174 | |
| daniQQue | 42:7164ccd2aa14 | 175 | if (emg_filtered_triceps_right > max_triceps) //determine what the highest reachable emg signal is |
| daniQQue | 42:7164ccd2aa14 | 176 | { |
| daniQQue | 42:7164ccd2aa14 | 177 | max_triceps = emg_filtered_triceps_right; |
| daniQQue | 42:7164ccd2aa14 | 178 | |
| daniQQue | 42:7164ccd2aa14 | 179 | } |
| daniQQue | 42:7164ccd2aa14 | 180 | wait(0.001f); //to sample at same freq; 1000Hz |
| daniQQue | 42:7164ccd2aa14 | 181 | } |
| daniQQue | 44:969348be74a5 | 182 | cut_off_value_triceps=-percentage_max_triceps*max_triceps; |
| daniQQue | 42:7164ccd2aa14 | 183 | pc.printf(" end of calibration\r\n"); |
| daniQQue | 42:7164ccd2aa14 | 184 | pc.printf(" change of cv triceps: %f ",cut_off_value_triceps ); |
| daniQQue | 42:7164ccd2aa14 | 185 | blue=!blue; |
| daniQQue | 44:969348be74a5 | 186 | wait(0.2f); |
| daniQQue | 42:7164ccd2aa14 | 187 | if (motorswitch%2==0) |
| daniQQue | 42:7164ccd2aa14 | 188 | {green=0; |
| daniQQue | 42:7164ccd2aa14 | 189 | red=1;} |
| daniQQue | 42:7164ccd2aa14 | 190 | |
| daniQQue | 42:7164ccd2aa14 | 191 | else {green=1; |
| daniQQue | 42:7164ccd2aa14 | 192 | red=0;} |
| daniQQue | 44:969348be74a5 | 193 | } |
| daniQQue | 42:7164ccd2aa14 | 194 | } |
| daniQQue | 42:7164ccd2aa14 | 195 | |
| daniQQue | 0:34c739fcc3e0 | 196 | void filter(){ |
| daniQQue | 40:187ef29de53d | 197 | //biceps right arm read+filtering |
| daniQQue | 15:bb4a6c7836d8 | 198 | emg_biceps_right=emg_biceps_right_in.read(); //read the emg value from the elektrodes |
| daniQQue | 40:187ef29de53d | 199 | emg_filtered_high_biceps_right= filterhigh_b1.step(emg_biceps_right); |
| daniQQue | 40:187ef29de53d | 200 | emg_filtered_high_notch_1_biceps_right=filternotch1_b1.step(emg_filtered_high_biceps_right); |
| daniQQue | 44:969348be74a5 | 201 | emg_abs_biceps_right=fabs(emg_filtered_high_notch_1_biceps_right); //fabs because float |
| daniQQue | 40:187ef29de53d | 202 | emg_filtered_biceps_right=filterlow_b1.step(emg_abs_biceps_right); |
| daniQQue | 40:187ef29de53d | 203 | |
| daniQQue | 40:187ef29de53d | 204 | //triceps right arm read+filtering |
| daniQQue | 40:187ef29de53d | 205 | emg_triceps_right=emg_triceps_right_in.read(); //read the emg value from the elektrodes |
| daniQQue | 40:187ef29de53d | 206 | emg_filtered_high_triceps_right= filterhigh_t1.step(emg_triceps_right); |
| daniQQue | 40:187ef29de53d | 207 | emg_filtered_high_notch_1_triceps_right=filternotch1_t1.step(emg_filtered_high_triceps_right); |
| daniQQue | 40:187ef29de53d | 208 | emg_abs_triceps_right=fabs(emg_filtered_high_notch_1_triceps_right); //fabs because float |
| daniQQue | 40:187ef29de53d | 209 | emg_filtered_triceps_right=filterlow_t1.step(emg_abs_triceps_right); |
| daniQQue | 7:42d0e38196f1 | 210 | |
| daniQQue | 40:187ef29de53d | 211 | //biceps left arm read+filtering |
| daniQQue | 40:187ef29de53d | 212 | emg_biceps_left=emg_biceps_left_in.read(); //read the emg value from the elektrodes |
| daniQQue | 40:187ef29de53d | 213 | emg_filtered_high_biceps_left= filterhigh_b2.step(emg_biceps_left); |
| daniQQue | 40:187ef29de53d | 214 | emg_filtered_high_notch_1_biceps_left=filternotch1_b2.step(emg_filtered_high_biceps_left); |
| daniQQue | 40:187ef29de53d | 215 | emg_abs_biceps_left=fabs(emg_filtered_high_notch_1_biceps_left); //fabs because float |
| daniQQue | 40:187ef29de53d | 216 | emg_filtered_biceps_left=filterlow_b2.step(emg_abs_biceps_left); |
| daniQQue | 40:187ef29de53d | 217 | |
| daniQQue | 41:9ea3d5921f07 | 218 | //signal substraction of filter biceps and triceps. right Biceps + left biceps - |
| daniQQue | 41:9ea3d5921f07 | 219 | signal_biceps_sum=emg_filtered_biceps_right-emg_filtered_biceps_left; |
| daniQQue | 44:969348be74a5 | 220 | bicepstriceps_rightarm=emg_filtered_biceps_right-emg_filtered_triceps_right; |
| daniQQue | 40:187ef29de53d | 221 | //creating of on/off signal with the created on/off signals, with if statement for right arm! |
| daniQQue | 41:9ea3d5921f07 | 222 | if (signal_biceps_sum>cut_off_value_biceps_right) |
| daniQQue | 41:9ea3d5921f07 | 223 | {onoffsignal_biceps=1;} |
| daniQQue | 7:42d0e38196f1 | 224 | |
| daniQQue | 41:9ea3d5921f07 | 225 | else if (signal_biceps_sum<cut_off_value_biceps_left) |
| daniQQue | 40:187ef29de53d | 226 | { |
| daniQQue | 41:9ea3d5921f07 | 227 | onoffsignal_biceps=-1; |
| daniQQue | 40:187ef29de53d | 228 | } |
| daniQQue | 40:187ef29de53d | 229 | |
| daniQQue | 40:187ef29de53d | 230 | else |
| daniQQue | 41:9ea3d5921f07 | 231 | {onoffsignal_biceps=0;} |
| daniQQue | 7:42d0e38196f1 | 232 | |
| daniQQue | 40:187ef29de53d | 233 | //creating on/off signal for switch (left arm) |
| daniQQue | 40:187ef29de53d | 234 | |
| daniQQue | 44:969348be74a5 | 235 | if (bicepstriceps_rightarm<cut_off_value_triceps) |
| daniQQue | 40:187ef29de53d | 236 | { |
| daniQQue | 41:9ea3d5921f07 | 237 | switch_signal_triceps=1; |
| daniQQue | 40:187ef29de53d | 238 | } |
| daniQQue | 40:187ef29de53d | 239 | |
| daniQQue | 40:187ef29de53d | 240 | else |
| daniQQue | 40:187ef29de53d | 241 | { |
| daniQQue | 41:9ea3d5921f07 | 242 | switch_signal_triceps=0; |
| daniQQue | 40:187ef29de53d | 243 | } |
| daniQQue | 40:187ef29de53d | 244 | |
| daniQQue | 0:34c739fcc3e0 | 245 | //send signals to scope |
| daniQQue | 40:187ef29de53d | 246 | scope.set(0, emg_filtered_biceps_right); //set emg signal to scope in channel 0 |
| daniQQue | 40:187ef29de53d | 247 | scope.set(1, emg_filtered_triceps_right); // set emg signal to scope in channel 1 |
| daniQQue | 40:187ef29de53d | 248 | scope.set(2, emg_filtered_biceps_left); // set emg signal to scope in channel 2 |
| daniQQue | 44:969348be74a5 | 249 | scope.set(3, onoffsignal_biceps); |
| daniQQue | 40:187ef29de53d | 250 | |
| daniQQue | 40:187ef29de53d | 251 | scope.send(); //send all the signals to the scope |
| daniQQue | 0:34c739fcc3e0 | 252 | } |
| daniQQue | 0:34c739fcc3e0 | 253 | |
| daniQQue | 0:34c739fcc3e0 | 254 | //program |
| daniQQue | 0:34c739fcc3e0 | 255 | |
| daniQQue | 0:34c739fcc3e0 | 256 | int main() |
| daniQQue | 0:34c739fcc3e0 | 257 | { |
| daniQQue | 42:7164ccd2aa14 | 258 | pc.baud(115200); //connect with pc with baudrate 115200 |
| daniQQue | 42:7164ccd2aa14 | 259 | |
| daniQQue | 42:7164ccd2aa14 | 260 | sample_timer.attach(&filter, 0.001); //continously execute the EMG reader and filter, it ensures that filter and sampling is executed every 1/frequency seconds |
| daniQQue | 42:7164ccd2aa14 | 261 | switch_function.attach(&SwitchN,1.0); //switch is every second available |
| daniQQue | 44:969348be74a5 | 262 | ticker_calibration_biceps.attach (&calibration_biceps,2.0); //to call calibration biceps, stop everything else |
| daniQQue | 44:969348be74a5 | 263 | ticker_calibration_triceps.attach(&calibration_triceps,2.0); //to call calibration triceps, stop everything else |
| daniQQue | 40:187ef29de53d | 264 | |
| daniQQue | 44:969348be74a5 | 265 | if (motorswitch%2==0) { |
| daniQQue | 44:969348be74a5 | 266 | pc.printf("If you contract the right arm, the robot will go right \r\n"); |
| daniQQue | 42:7164ccd2aa14 | 267 | pc.printf("If you contract biceps of the left arm, the robot will go left \r\n"); |
| daniQQue | 42:7164ccd2aa14 | 268 | pc.printf("\r\n"); |
| daniQQue | 44:969348be74a5 | 269 | green=0; |
| daniQQue | 44:969348be74a5 | 270 | red=1; |
| daniQQue | 44:969348be74a5 | 271 | blue=1; |
| daniQQue | 42:7164ccd2aa14 | 272 | } |
| daniQQue | 42:7164ccd2aa14 | 273 | |
| daniQQue | 42:7164ccd2aa14 | 274 | else |
| daniQQue | 42:7164ccd2aa14 | 275 | {pc.printf("If you contract the biceps of right arm, the robot will go up \r\n"); |
| daniQQue | 42:7164ccd2aa14 | 276 | pc.printf("If you contract the biceps of left arm, the robot will go down \r\n"); |
| daniQQue | 42:7164ccd2aa14 | 277 | pc.printf("\r\n"); |
| daniQQue | 42:7164ccd2aa14 | 278 | green=1; |
| daniQQue | 42:7164ccd2aa14 | 279 | red=0; |
| daniQQue | 42:7164ccd2aa14 | 280 | blue=1; |
| daniQQue | 42:7164ccd2aa14 | 281 | |
| daniQQue | 42:7164ccd2aa14 | 282 | } |
| daniQQue | 0:34c739fcc3e0 | 283 | //endless loop |
| daniQQue | 0:34c739fcc3e0 | 284 | |
| daniQQue | 40:187ef29de53d | 285 | |
| daniQQue | 40:187ef29de53d | 286 | while (true) { // zorgt er voor dat de code oneindig doorgelopen wordt |
| daniQQue | 40:187ef29de53d | 287 | |
| daniQQue | 8:cd0cb71b69f2 | 288 | |
| daniQQue | 41:9ea3d5921f07 | 289 | if (onoffsignal_biceps==-1) // als s ingedrukt wordt gebeurd het volgende |
| daniQQue | 40:187ef29de53d | 290 | { |
| daniQQue | 42:7164ccd2aa14 | 291 | if (motorswitch%2==0) // als s ingedrukt wordt en het getal is even gebeurd het onderstaande |
| daniQQue | 40:187ef29de53d | 292 | { |
| daniQQue | 40:187ef29de53d | 293 | richting_motor1 = 1; |
| daniQQue | 44:969348be74a5 | 294 | pwm_motor1 = 0.5; |
| daniQQue | 44:969348be74a5 | 295 | pc.printf("ccw m1\r\n"); |
| daniQQue | 42:7164ccd2aa14 | 296 | |
| daniQQue | 40:187ef29de53d | 297 | |
| daniQQue | 40:187ef29de53d | 298 | } |
| daniQQue | 40:187ef29de53d | 299 | |
| daniQQue | 40:187ef29de53d | 300 | else // als s is ingedrukt maar het getal is niet even (dus oneven) gebeurdt het onderstaande |
| daniQQue | 40:187ef29de53d | 301 | { |
| daniQQue | 40:187ef29de53d | 302 | richting_motor2 = 1; |
| daniQQue | 40:187ef29de53d | 303 | pwm_motor2 = 1; |
| daniQQue | 42:7164ccd2aa14 | 304 | |
| daniQQue | 40:187ef29de53d | 305 | } |
| daniQQue | 40:187ef29de53d | 306 | |
| daniQQue | 8:cd0cb71b69f2 | 307 | } |
| daniQQue | 41:9ea3d5921f07 | 308 | else if (onoffsignal_biceps==1) // als d ingedrukt wordt gebeurd het volgende |
| daniQQue | 40:187ef29de53d | 309 | { |
| daniQQue | 42:7164ccd2aa14 | 310 | if (motorswitch%2==0) // als d is ingedrukt en n is even dan gebeurd het volgende |
| daniQQue | 40:187ef29de53d | 311 | { |
| daniQQue | 40:187ef29de53d | 312 | richting_motor1 = 0; |
| daniQQue | 44:969348be74a5 | 313 | pwm_motor1 = 0.5; |
| daniQQue | 44:969348be74a5 | 314 | pc.printf("cw 1 aan\r\n"); |
| daniQQue | 40:187ef29de53d | 315 | |
| daniQQue | 42:7164ccd2aa14 | 316 | |
| daniQQue | 40:187ef29de53d | 317 | } |
| daniQQue | 40:187ef29de53d | 318 | else // als d is ingedrukt maar het getal is niet even (dus oneven) gebeurt het onderstaande |
| daniQQue | 40:187ef29de53d | 319 | { |
| daniQQue | 40:187ef29de53d | 320 | richting_motor2 = 0; |
| daniQQue | 40:187ef29de53d | 321 | pwm_motor2 = 1; |
| daniQQue | 42:7164ccd2aa14 | 322 | |
| daniQQue | 40:187ef29de53d | 323 | |
| daniQQue | 40:187ef29de53d | 324 | } |
| daniQQue | 40:187ef29de53d | 325 | } |
| daniQQue | 40:187ef29de53d | 326 | else{ |
| daniQQue | 40:187ef29de53d | 327 | |
| daniQQue | 40:187ef29de53d | 328 | pwm_motor2=0; |
| daniQQue | 40:187ef29de53d | 329 | pwm_motor1=0; |
| daniQQue | 40:187ef29de53d | 330 | } |
| daniQQue | 40:187ef29de53d | 331 | |
| daniQQue | 40:187ef29de53d | 332 | } |
| daniQQue | 44:969348be74a5 | 333 | } |
