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- mbed-dsp mbed
Project_main.cpp@39:0328b1f16a5a, 2014-10-08 (annotated)
- Committer:
- Hooglugt
- Date:
- Wed Oct 08 12:26:56 2014 +0000
- Revision:
- 39:0328b1f16a5a
- Parent:
- 38:277ba1c0693c
- Child:
- 40:7e93c2f1c1e9
alleen nog floats van emg signaal (bi+tri), error qua lampje kleurtjes zijn verdwenen
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| Hooglugt | 23:8d9a623dd713 | 1 | #include "mbed.h" |
| Hooglugt | 23:8d9a623dd713 | 2 | #include "MODSERIAL.h" |
| Hooglugt | 23:8d9a623dd713 | 3 | #include "HIDScope.h" |
| Hooglugt | 29:7523e4a8e000 | 4 | |
| Hooglugt | 39:0328b1f16a5a | 5 | #define TIMEB4NEXTCHOICE 1 // sec keuzelampje blijft aan |
| Hooglugt | 39:0328b1f16a5a | 6 | #define TIMEBETWEENBLINK 20 // sec voor volgende blink |
| Hooglugt | 23:8d9a623dd713 | 7 | |
| Hooglugt | 23:8d9a623dd713 | 8 | //Define objects |
| Hooglugt | 29:7523e4a8e000 | 9 | AnalogIn emg0(PTB1); //Analog input biceps |
| Hooglugt | 39:0328b1f16a5a | 10 | float emg_bifloat; //Float voor EMG-waarde biceps |
| Hooglugt | 38:277ba1c0693c | 11 | |
| Hooglugt | 29:7523e4a8e000 | 12 | AnalogIn emg1(PTB2); //Analog input triceps |
| Hooglugt | 38:277ba1c0693c | 13 | float emg_trifloat; //Float voor EMG-waarde triceps |
| Hooglugt | 29:7523e4a8e000 | 14 | |
| Hooglugt | 38:277ba1c0693c | 15 | Ticker log_timer; |
| Hooglugt | 38:277ba1c0693c | 16 | Ticker reset_timer; |
| Hooglugt | 38:277ba1c0693c | 17 | MODSERIAL pc(USBTX,USBRX); |
| Hooglugt | 39:0328b1f16a5a | 18 | HIDScope scope(2); |
| Hooglugt | 29:7523e4a8e000 | 19 | |
| Hooglugt | 29:7523e4a8e000 | 20 | PwmOut red(LED_RED); |
| Hooglugt | 23:8d9a623dd713 | 21 | PwmOut green(LED_GREEN); |
| Hooglugt | 23:8d9a623dd713 | 22 | PwmOut blue(LED_BLUE); |
| Hooglugt | 29:7523e4a8e000 | 23 | |
| Hooglugt | 35:c3182df00ec8 | 24 | int direction = 0; |
| Hooglugt | 35:c3182df00ec8 | 25 | int force = 0; |
| Hooglugt | 23:8d9a623dd713 | 26 | |
| Hooglugt | 39:0328b1f16a5a | 27 | void looper() |
| Hooglugt | 23:8d9a623dd713 | 28 | { |
| Hooglugt | 39:0328b1f16a5a | 29 | //put raw emg value of biceps and triceps in emg_bifloat and emg_trifloat, respectively |
| Hooglugt | 38:277ba1c0693c | 30 | emg_bifloat = emg0.read(); // read float value (0..1 = 0..3.3V) biceps |
| Hooglugt | 38:277ba1c0693c | 31 | emg_trifloat = emg1.read(); // read float value (0..1 = 0..3.3V) triceps |
| Hooglugt | 29:7523e4a8e000 | 32 | |
| Hooglugt | 31:d8eaf0ce8517 | 33 | /*send value to PC. Line below is used to prevent buffer overrun */ |
| Hooglugt | 30:5e5098b0cca6 | 34 | if(pc.rxBufferGetSize(0)-pc.rxBufferGetCount() > 30) { //VRAAG: praktisch nut hiervan? print emg value wanneer buffercount groter dan 30 is |
| Hooglugt | 30:5e5098b0cca6 | 35 | //pc.printf("%u\n",emg_bivalue); |
| Hooglugt | 29:7523e4a8e000 | 36 | } |
| Hooglugt | 36:af949aaaba01 | 37 | |
| Hooglugt | 34:e166187e62ce | 38 | /* EMG-singaal van biceps en triceps worden hier gefilterd*/ |
| Hooglugt | 36:af949aaaba01 | 39 | |
| Hooglugt | 39:0328b1f16a5a | 40 | scope.set(0,emg_bifloat); |
| Hooglugt | 39:0328b1f16a5a | 41 | scope.set(1,emg_trifloat); |
| Hooglugt | 23:8d9a623dd713 | 42 | scope.send(); |
| Hooglugt | 23:8d9a623dd713 | 43 | } |
| Hooglugt | 23:8d9a623dd713 | 44 | |
| Hooglugt | 34:e166187e62ce | 45 | /* |
| Hooglugt | 32:aaf01b1bf05d | 46 | void resetlooper() // VRAAG: wat gebeurt er wanneer en resetlooper en looper tegelijkertijd gecalled worden?! |
| Hooglugt | 31:d8eaf0ce8517 | 47 | { |
| Hooglugt | 30:5e5098b0cca6 | 48 | if(emg_trifloat.read()>0.8 && direction != 0) { //dit is alleen mogelijk wanneer directionchoice is gemaakt |
| Hooglugt | 30:5e5098b0cca6 | 49 | direction = 0; |
| Hooglugt | 30:5e5098b0cca6 | 50 | force = 0; // WEGHALEN, wanneer in uiteindelijke script na force keuzen niet meer gereset kan worden (voor nu wel handig) |
| Hooglugt | 31:d8eaf0ce8517 | 51 | pc.printf("reset "); |
| Hooglugt | 31:d8eaf0ce8517 | 52 | } |
| Hooglugt | 30:5e5098b0cca6 | 53 | } |
| Hooglugt | 35:c3182df00ec8 | 54 | CONSTANTE RESETS DOOR BEWEGINGSARTEFACTEN */ |
| Hooglugt | 31:d8eaf0ce8517 | 55 | |
| Hooglugt | 23:8d9a623dd713 | 56 | int main() |
| Hooglugt | 23:8d9a623dd713 | 57 | { |
| Hooglugt | 25:ec41b972b250 | 58 | pc.baud(115200); //baudrate instellen |
| Hooglugt | 25:ec41b972b250 | 59 | log_timer.attach(looper, 0.001); // The looper() function will be called every 0.001 seconds (with the ticker object) |
| Hooglugt | 34:e166187e62ce | 60 | // reset_timer.attach(resetlooper, 0.1); // |
| Hooglugt | 32:aaf01b1bf05d | 61 | |
| Hooglugt | 37:2d248e64b745 | 62 | goto directionchoice; // goes to first while(1) for the deciding the direction |
| Hooglugt | 37:2d248e64b745 | 63 | |
| Hooglugt | 37:2d248e64b745 | 64 | while(1) { //Loop keuze DIRECTION |
| Hooglugt | 37:2d248e64b745 | 65 | directionchoice: |
| Hooglugt | 23:8d9a623dd713 | 66 | for(int i=1; i<4; i++) { |
| Hooglugt | 23:8d9a623dd713 | 67 | if(i==1) { //red |
| Hooglugt | 23:8d9a623dd713 | 68 | red=0; |
| Hooglugt | 23:8d9a623dd713 | 69 | green=1; |
| Hooglugt | 23:8d9a623dd713 | 70 | blue=1; |
| Hooglugt | 37:2d248e64b745 | 71 | for (int lag=0; lag<TIMEBETWEENBLINK; lag++) { |
| Hooglugt | 38:277ba1c0693c | 72 | if(emg_bifloat>0.8) { // 0.8 klopt niet als grenswaarde. #nofilter |
| Hooglugt | 25:ec41b972b250 | 73 | direction = 1; |
| Hooglugt | 37:2d248e64b745 | 74 | red=1; |
| Hooglugt | 37:2d248e64b745 | 75 | green = 0; |
| Hooglugt | 36:af949aaaba01 | 76 | blue = 0; |
| Hooglugt | 37:2d248e64b745 | 77 | pc.printf("links "); |
| Hooglugt | 37:2d248e64b745 | 78 | wait(TIMEB4NEXTCHOICE); // Tijdelijke wait om cyaan lampje aan te zetten ter controle selectie |
| Hooglugt | 37:2d248e64b745 | 79 | goto forcechoice; // goes to second while(1) for the deciding the force |
| Hooglugt | 23:8d9a623dd713 | 80 | } else { |
| Hooglugt | 23:8d9a623dd713 | 81 | wait(0.1); |
| Hooglugt | 23:8d9a623dd713 | 82 | } |
| Hooglugt | 23:8d9a623dd713 | 83 | } |
| Hooglugt | 23:8d9a623dd713 | 84 | } |
| Hooglugt | 23:8d9a623dd713 | 85 | if(i==2) { //green |
| Hooglugt | 23:8d9a623dd713 | 86 | red =1; |
| Hooglugt | 23:8d9a623dd713 | 87 | green=0; |
| Hooglugt | 23:8d9a623dd713 | 88 | blue=1; |
| Hooglugt | 37:2d248e64b745 | 89 | for (int lag=0; lag<TIMEBETWEENBLINK; lag++) { |
| Hooglugt | 38:277ba1c0693c | 90 | if(emg_bifloat>0.8) { //0.8 klopt niet als grenswaarde. #nofilter |
| Hooglugt | 25:ec41b972b250 | 91 | direction = 2; |
| Hooglugt | 37:2d248e64b745 | 92 | red=0; |
| Hooglugt | 29:7523e4a8e000 | 93 | green = 1; |
| Hooglugt | 37:2d248e64b745 | 94 | blue = 0; |
| Hooglugt | 37:2d248e64b745 | 95 | pc.printf("mid "); |
| Hooglugt | 37:2d248e64b745 | 96 | wait(TIMEB4NEXTCHOICE); // Tijdelijke wait om paars lampje aan te zetten ter controle selectie |
| Hooglugt | 23:8d9a623dd713 | 97 | goto forcechoice; |
| Hooglugt | 23:8d9a623dd713 | 98 | } else { |
| Hooglugt | 23:8d9a623dd713 | 99 | wait(0.1); |
| Hooglugt | 23:8d9a623dd713 | 100 | } |
| Hooglugt | 23:8d9a623dd713 | 101 | } |
| Hooglugt | 23:8d9a623dd713 | 102 | } |
| Hooglugt | 23:8d9a623dd713 | 103 | if(i==3) { //blue |
| Hooglugt | 23:8d9a623dd713 | 104 | red=1; |
| Hooglugt | 23:8d9a623dd713 | 105 | green=1; |
| Hooglugt | 23:8d9a623dd713 | 106 | blue=0; |
| Hooglugt | 37:2d248e64b745 | 107 | for (int lag=0; lag<TIMEBETWEENBLINK; lag++) { |
| Hooglugt | 38:277ba1c0693c | 108 | if(emg_bifloat>0.8) { //0.8 klopt niet als grenswaarde. #nofilter |
| Hooglugt | 23:8d9a623dd713 | 109 | direction = 3; |
| Hooglugt | 37:2d248e64b745 | 110 | red=0; |
| Hooglugt | 29:7523e4a8e000 | 111 | green = 0; |
| Hooglugt | 37:2d248e64b745 | 112 | blue = 1; |
| Hooglugt | 37:2d248e64b745 | 113 | pc.printf("rechts "); |
| Hooglugt | 37:2d248e64b745 | 114 | wait(TIMEB4NEXTCHOICE); // Tijdelijke wait om oranje lampje aan te zetten ter controle selectie |
| Hooglugt | 23:8d9a623dd713 | 115 | goto forcechoice; |
| Hooglugt | 23:8d9a623dd713 | 116 | } else { |
| Hooglugt | 23:8d9a623dd713 | 117 | wait(0.1); |
| Hooglugt | 23:8d9a623dd713 | 118 | } |
| Hooglugt | 23:8d9a623dd713 | 119 | } |
| Hooglugt | 23:8d9a623dd713 | 120 | } |
| Hooglugt | 25:ec41b972b250 | 121 | } |
| Hooglugt | 23:8d9a623dd713 | 122 | } |
| Hooglugt | 37:2d248e64b745 | 123 | while(1) { //Loop keuze FORCE |
| Hooglugt | 25:ec41b972b250 | 124 | forcechoice: |
| Hooglugt | 37:2d248e64b745 | 125 | for(int j=1; j<4; j++) { |
| Hooglugt | 37:2d248e64b745 | 126 | if(j==1) { //red |
| Hooglugt | 37:2d248e64b745 | 127 | red=0; |
| Hooglugt | 37:2d248e64b745 | 128 | green=1; |
| Hooglugt | 37:2d248e64b745 | 129 | blue=1; |
| Hooglugt | 37:2d248e64b745 | 130 | if(direction==0) { //if statement die controleert of direction 0 is (dus of triceps gereset is) |
| Hooglugt | 37:2d248e64b745 | 131 | goto directionchoice; |
| Hooglugt | 37:2d248e64b745 | 132 | } |
| Hooglugt | 37:2d248e64b745 | 133 | for (int lag=0; lag<TIMEBETWEENBLINK; lag++) { |
| Hooglugt | 38:277ba1c0693c | 134 | if(emg_bifloat>0.8) { // 0.8 klopt niet als grenswaarde. #nofilter |
| Hooglugt | 37:2d248e64b745 | 135 | force = 1; |
| Hooglugt | 37:2d248e64b745 | 136 | red=1; |
| Hooglugt | 37:2d248e64b745 | 137 | green = 0; |
| Hooglugt | 37:2d248e64b745 | 138 | blue = 0; |
| Hooglugt | 37:2d248e64b745 | 139 | pc.printf("zwak "); |
| Hooglugt | 37:2d248e64b745 | 140 | wait(TIMEB4NEXTCHOICE); // Tijdelijke wait om cyaan lampje aan te zetten ter controle selectie |
| Hooglugt | 37:2d248e64b745 | 141 | goto choicesmade; |
| Hooglugt | 37:2d248e64b745 | 142 | } else { |
| Hooglugt | 37:2d248e64b745 | 143 | wait(0.1); |
| Hooglugt | 23:8d9a623dd713 | 144 | } |
| Hooglugt | 23:8d9a623dd713 | 145 | } |
| Hooglugt | 37:2d248e64b745 | 146 | } |
| Hooglugt | 37:2d248e64b745 | 147 | if(j==2) { //green |
| Hooglugt | 37:2d248e64b745 | 148 | red =1; |
| Hooglugt | 37:2d248e64b745 | 149 | green=0; |
| Hooglugt | 37:2d248e64b745 | 150 | blue=1; |
| Hooglugt | 37:2d248e64b745 | 151 | if(direction==0) { //if statement die controleert of direction 0 is (dus of triceps gereset is) |
| Hooglugt | 37:2d248e64b745 | 152 | goto directionchoice; |
| Hooglugt | 37:2d248e64b745 | 153 | } |
| Hooglugt | 37:2d248e64b745 | 154 | for (int lag=0; lag<TIMEBETWEENBLINK; lag++) { |
| Hooglugt | 38:277ba1c0693c | 155 | if(emg_bifloat>0.8) { //0.8 klopt niet als grenswaarde. #nofilter |
| Hooglugt | 37:2d248e64b745 | 156 | force = 2; |
| Hooglugt | 37:2d248e64b745 | 157 | red=0; |
| Hooglugt | 37:2d248e64b745 | 158 | green = 1; |
| Hooglugt | 37:2d248e64b745 | 159 | blue = 0; |
| Hooglugt | 37:2d248e64b745 | 160 | pc.printf("normaal "); |
| Hooglugt | 37:2d248e64b745 | 161 | wait(TIMEB4NEXTCHOICE); // Tijdelijke wait om paars lampje aan te zetten ter controle selectie |
| Hooglugt | 37:2d248e64b745 | 162 | goto choicesmade; |
| Hooglugt | 37:2d248e64b745 | 163 | } else { |
| Hooglugt | 37:2d248e64b745 | 164 | wait(0.1); |
| Hooglugt | 23:8d9a623dd713 | 165 | } |
| Hooglugt | 23:8d9a623dd713 | 166 | } |
| Hooglugt | 37:2d248e64b745 | 167 | } |
| Hooglugt | 37:2d248e64b745 | 168 | if(j==3) { //blue |
| Hooglugt | 37:2d248e64b745 | 169 | red=1; |
| Hooglugt | 37:2d248e64b745 | 170 | green=1; |
| Hooglugt | 37:2d248e64b745 | 171 | blue=0; |
| Hooglugt | 37:2d248e64b745 | 172 | if(direction==0) { //if statement die controleert of direction 0 is (dus of triceps gereset is) |
| Hooglugt | 37:2d248e64b745 | 173 | goto directionchoice; |
| Hooglugt | 37:2d248e64b745 | 174 | } |
| Hooglugt | 37:2d248e64b745 | 175 | for (int lag=0; lag<TIMEBETWEENBLINK; lag++) { |
| Hooglugt | 38:277ba1c0693c | 176 | if(emg_bifloat>0.8) { //0.8 klopt niet als grenswaarde. #nofilter |
| Hooglugt | 37:2d248e64b745 | 177 | force = 3; |
| Hooglugt | 37:2d248e64b745 | 178 | red=0; |
| Hooglugt | 37:2d248e64b745 | 179 | green = 0; |
| Hooglugt | 37:2d248e64b745 | 180 | blue = 1; |
| Hooglugt | 37:2d248e64b745 | 181 | pc.printf("sterk "); |
| Hooglugt | 37:2d248e64b745 | 182 | wait(TIMEB4NEXTCHOICE); // Tijdelijke wait om oranje lampje aan te zetten ter controle selectie |
| Hooglugt | 37:2d248e64b745 | 183 | goto choicesmade; |
| Hooglugt | 37:2d248e64b745 | 184 | } else { |
| Hooglugt | 37:2d248e64b745 | 185 | wait(0.1); |
| Hooglugt | 23:8d9a623dd713 | 186 | } |
| Hooglugt | 23:8d9a623dd713 | 187 | } |
| Hooglugt | 23:8d9a623dd713 | 188 | } |
| Hooglugt | 23:8d9a623dd713 | 189 | } |
| Hooglugt | 37:2d248e64b745 | 190 | } |
| Hooglugt | 37:2d248e64b745 | 191 | choicesmade: |
| Hooglugt | 33:a78ec776dfd5 | 192 | |
| Hooglugt | 37:2d248e64b745 | 193 | /* Vanaf hier komt de aansturing van de motor (inclusief de controller)*/ |
| Hooglugt | 37:2d248e64b745 | 194 | |
| Hooglugt | 33:a78ec776dfd5 | 195 | |
| Hooglugt | 25:ec41b972b250 | 196 | if(direction == 1 && force == 1) { // links zwak |
| Hooglugt | 39:0328b1f16a5a | 197 | pc.printf("links zwak "); |
| Hooglugt | 25:ec41b972b250 | 198 | } |
| Hooglugt | 25:ec41b972b250 | 199 | if(direction == 1 && force == 2) { // links normaal |
| Hooglugt | 39:0328b1f16a5a | 200 | pc.printf("links normaal "); |
| Hooglugt | 25:ec41b972b250 | 201 | } |
| Hooglugt | 25:ec41b972b250 | 202 | if(direction == 1 && force == 3) { // links sterk |
| Hooglugt | 39:0328b1f16a5a | 203 | pc.printf("links sterk "); |
| Hooglugt | 25:ec41b972b250 | 204 | } |
| Hooglugt | 25:ec41b972b250 | 205 | if(direction == 2 && force == 1) { // mid zwak |
| Hooglugt | 39:0328b1f16a5a | 206 | pc.printf("mid zwak "); |
| Hooglugt | 25:ec41b972b250 | 207 | } |
| Hooglugt | 25:ec41b972b250 | 208 | if(direction == 2 && force == 2) { // mid normaal |
| Hooglugt | 39:0328b1f16a5a | 209 | pc.printf("mid normaal "); |
| Hooglugt | 25:ec41b972b250 | 210 | } |
| Hooglugt | 25:ec41b972b250 | 211 | if(direction == 2 && force == 3) { // mid sterk |
| Hooglugt | 39:0328b1f16a5a | 212 | pc.printf("mid sterk "); |
| Hooglugt | 25:ec41b972b250 | 213 | } |
| Hooglugt | 25:ec41b972b250 | 214 | if(direction == 3 && force == 1) { // rechts zwak |
| Hooglugt | 39:0328b1f16a5a | 215 | pc.printf("rechts zwak "); |
| Hooglugt | 25:ec41b972b250 | 216 | } |
| Hooglugt | 25:ec41b972b250 | 217 | if(direction == 3 && force == 2) { // rechts normaal |
| Hooglugt | 39:0328b1f16a5a | 218 | pc.printf("rechts normaal "); |
| Hooglugt | 25:ec41b972b250 | 219 | } |
| Hooglugt | 25:ec41b972b250 | 220 | if(direction == 3 && force == 3) { // rechts sterk |
| Hooglugt | 39:0328b1f16a5a | 221 | pc.printf("rechts sterk "); |
| Hooglugt | 25:ec41b972b250 | 222 | } |
| Hooglugt | 33:a78ec776dfd5 | 223 | if(direction == 0 || force == 0) { // wanneer de triceps in de korte tijd is aangespannen nadat beide keuzes zijn gemaakt |
| Hooglugt | 39:0328b1f16a5a | 224 | pc.printf("error "); |
| Hooglugt | 33:a78ec776dfd5 | 225 | // mogelijkheid om een goto te maken naar directionchoice (opzich wel handig) |
| Hooglugt | 32:aaf01b1bf05d | 226 | } |
| Hooglugt | 33:a78ec776dfd5 | 227 | |
| Hooglugt | 32:aaf01b1bf05d | 228 | red = 0; |
| Hooglugt | 32:aaf01b1bf05d | 229 | green = 0; |
| Hooglugt | 37:2d248e64b745 | 230 | blue = 0; // wit lampje |
| Hooglugt | 25:ec41b972b250 | 231 | } |