Robotcontrol groep 2
Dependencies: Encoder MODSERIAL mbed HIDScope
main.cpp@9:80693874f9ce, 2014-11-03 (annotated)
- Committer:
- wiesdat
- Date:
- Mon Nov 03 21:50:42 2014 +0000
- Revision:
- 9:80693874f9ce
- Parent:
- 8:83115293e84d
- Child:
- 10:e628a87d18aa
KLAAR!!! (hoop ik)
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
wiesdat | 4:c22f3095b130 | 1 | //ROBOTCONTROL BMT M9 - GROEP 2 |
wiesdat | 4:c22f3095b130 | 2 | //Alex Overbeek |
wiesdat | 4:c22f3095b130 | 3 | //Tom Baumeister |
wiesdat | 4:c22f3095b130 | 4 | //Bas van Buuren |
wiesdat | 4:c22f3095b130 | 5 | //Bas Mattern |
wiesdat | 4:c22f3095b130 | 6 | //Thijs ruikes |
wiesdat | 4:c22f3095b130 | 7 | |
wiesdat | 4:c22f3095b130 | 8 | /*Het script bestaat uit drie delen: INCLUDE AND DEFINE, FUNCTIONS, MAINSCRIPT. Per gedeelte wordt uitgelegd wat gedaan wordt. |
wiesdat | 4:c22f3095b130 | 9 | We laten de beweging in fases lopen. Fase 1 werkt in dit script. Voor fase 2 kan de positie al worden ingesteld, de slagbeweging |
wiesdat | 5:36df561f3ac1 | 10 | moet nog gemaakt worden. Dit gaan we doen met een PID regelaar die naar een snelheid toe regelt. |
wiesdat | 4:c22f3095b130 | 11 | */ |
wiesdat | 4:c22f3095b130 | 12 | |
wiesdat | 4:c22f3095b130 | 13 | //INCLUDE AND DEFINE ALL |
wiesdat | 0:25a2e7ea29f3 | 14 | #include "mbed.h" |
wiesdat | 0:25a2e7ea29f3 | 15 | #include "MODSERIAL.h" |
wiesdat | 4:c22f3095b130 | 16 | #include <iostream> |
wiesdat | 4:c22f3095b130 | 17 | #include "encoder.h" |
wiesdat | 5:36df561f3ac1 | 18 | #include "HIDScope.h" |
wiesdat | 1:a010e434a360 | 19 | |
wiesdat | 5:36df561f3ac1 | 20 | #define THRESHOLD 0.04 |
wiesdat | 5:36df561f3ac1 | 21 | #define NOSAMPL 500 |
wiesdat | 0:25a2e7ea29f3 | 22 | |
wiesdat | 7:2e4eb23700b0 | 23 | #define TSAMP1 0.01 |
wiesdat | 3:611fd72c9d46 | 24 | #define K_P1 (0.004) |
wiesdat | 3:611fd72c9d46 | 25 | #define K_I1 (0.00001*TSAMP1) |
wiesdat | 3:611fd72c9d46 | 26 | #define K_D1 (0.0001/TSAMP1) |
wiesdat | 3:611fd72c9d46 | 27 | #define I_LIMIT1 1. |
wiesdat | 7:2e4eb23700b0 | 28 | |
wiesdat | 7:2e4eb23700b0 | 29 | //KPID voor slagfunctie |
wiesdat | 7:2e4eb23700b0 | 30 | #define KSLA_P (0.05) |
wiesdat | 7:2e4eb23700b0 | 31 | #define KSLA_I (0.000001 *TSAMP1) |
wiesdat | 7:2e4eb23700b0 | 32 | #define KSLA_D (0.0005 /TSAMP1) |
wiesdat | 7:2e4eb23700b0 | 33 | |
wiesdat | 8:83115293e84d | 34 | #define MAXPOS 700 |
wiesdat | 8:83115293e84d | 35 | |
wiesdat | 4:c22f3095b130 | 36 | // Constantes voor de filters definiëren: |
wiesdat | 0:25a2e7ea29f3 | 37 | // Constantes voor de Low Pass filter |
wiesdat | 0:25a2e7ea29f3 | 38 | #define A1LP 0.018180963222803 |
wiesdat | 0:25a2e7ea29f3 | 39 | #define A0LP 0.016544013176248 |
wiesdat | 0:25a2e7ea29f3 | 40 | #define B1LP -1.718913340044714 |
wiesdat | 0:25a2e7ea29f3 | 41 | #define B0LP 0.753638316443765 |
wiesdat | 0:25a2e7ea29f3 | 42 | // Constantes voor de High Pass Filter |
wiesdat | 0:25a2e7ea29f3 | 43 | #define A1HP -1.999801878951505 |
wiesdat | 0:25a2e7ea29f3 | 44 | #define A0HP 0.999801878951505 |
wiesdat | 0:25a2e7ea29f3 | 45 | #define B1HP -1.971717601075000 |
wiesdat | 0:25a2e7ea29f3 | 46 | #define B0HP 0.972111984032897 |
wiesdat | 0:25a2e7ea29f3 | 47 | // Constantes voor het Notch Filter |
wiesdat | 0:25a2e7ea29f3 | 48 | #define A0N 0.99436777112 |
wiesdat | 0:25a2e7ea29f3 | 49 | #define A1N -1.89139989664 |
wiesdat | 0:25a2e7ea29f3 | 50 | #define A2N 0.99436777112 |
wiesdat | 0:25a2e7ea29f3 | 51 | #define B1N 1.89070035439 |
wiesdat | 0:25a2e7ea29f3 | 52 | #define B2N -0.988036 |
wiesdat | 0:25a2e7ea29f3 | 53 | |
wiesdat | 0:25a2e7ea29f3 | 54 | // Sample Time |
wiesdat | 0:25a2e7ea29f3 | 55 | #define TSAMP 0.001 |
wiesdat | 4:c22f3095b130 | 56 | |
wiesdat | 3:611fd72c9d46 | 57 | // Outputs van de motor |
wiesdat | 3:611fd72c9d46 | 58 | Encoder encoderA(PTD5,PTA13); |
wiesdat | 3:611fd72c9d46 | 59 | Encoder encoder1(PTD0,PTD2); |
wiesdat | 0:25a2e7ea29f3 | 60 | |
wiesdat | 3:611fd72c9d46 | 61 | // Outputs naar de motor |
wiesdat | 3:611fd72c9d46 | 62 | PwmOut pwm(PTC8); |
wiesdat | 3:611fd72c9d46 | 63 | DigitalOut dir(PTC9); |
wiesdat | 3:611fd72c9d46 | 64 | PwmOut pwm1(PTA5); |
wiesdat | 3:611fd72c9d46 | 65 | DigitalOut dir1(PTA4); |
wiesdat | 3:611fd72c9d46 | 66 | |
wiesdat | 3:611fd72c9d46 | 67 | //lampjes |
wiesdat | 3:611fd72c9d46 | 68 | DigitalOut rood(LED1); |
wiesdat | 3:611fd72c9d46 | 69 | DigitalOut blauw(LED3); |
wiesdat | 3:611fd72c9d46 | 70 | DigitalOut groen(LED2); |
wiesdat | 0:25a2e7ea29f3 | 71 | AnalogIn emg1(PTB1); |
wiesdat | 0:25a2e7ea29f3 | 72 | AnalogIn emg2(PTB2); |
wiesdat | 0:25a2e7ea29f3 | 73 | |
wiesdat | 0:25a2e7ea29f3 | 74 | // PC communicatie |
wiesdat | 0:25a2e7ea29f3 | 75 | MODSERIAL pc(USBTX,USBRX); |
wiesdat | 3:611fd72c9d46 | 76 | |
wiesdat | 0:25a2e7ea29f3 | 77 | // Ticker voor de meetgegevens |
wiesdat | 0:25a2e7ea29f3 | 78 | Ticker timer; |
wiesdat | 0:25a2e7ea29f3 | 79 | volatile bool looptimerflag; |
wiesdat | 0:25a2e7ea29f3 | 80 | |
wiesdat | 0:25a2e7ea29f3 | 81 | // Waardes voor de filters reserveren en als float vaststellen |
wiesdat | 3:611fd72c9d46 | 82 | float emg_value2, ylp2, yhp2, yn2,ysum1 = 0, yave1=0; |
wiesdat | 3:611fd72c9d46 | 83 | float emg_value1, ylp1, yhp1, yn1,ysum2 = 0, yave2=0 ; |
wiesdat | 3:611fd72c9d46 | 84 | |
wiesdat | 3:611fd72c9d46 | 85 | //variabvelen voor positie motor1 |
wiesdat | 4:c22f3095b130 | 86 | float v1=0,out_i1 = 0; //out_i1 globaal gedef om reset |
wiesdat | 0:25a2e7ea29f3 | 87 | |
wiesdat | 0:25a2e7ea29f3 | 88 | // 0 of 1 waardes gedefinieerd uit het EMG, met 0 is te lage activiteit, 1 is hoog genoeg, voor de zekerheid toch als int. |
wiesdat | 0:25a2e7ea29f3 | 89 | uint8_t y1, y2; |
wiesdat | 0:25a2e7ea29f3 | 90 | int check = 0; |
wiesdat | 0:25a2e7ea29f3 | 91 | |
wiesdat | 0:25a2e7ea29f3 | 92 | // integers reserveren voor het deel van het regelsysteem als we de boolean emg waardes hebben: hoek van het badje (0,1, of 2) en de gewenste snelheid (0,1, of 2) |
wiesdat | 3:611fd72c9d46 | 93 | int badjestand, badjes=1,badjedone=0,speeding,armstand=0,armspeed=0; |
wiesdat | 0:25a2e7ea29f3 | 94 | bool speeddone=0; |
wiesdat | 3:611fd72c9d46 | 95 | |
wiesdat | 0:25a2e7ea29f3 | 96 | // Teller voor hoeveel metingen er zijn gedaan |
wiesdat | 0:25a2e7ea29f3 | 97 | uint16_t teller=0; |
wiesdat | 0:25a2e7ea29f3 | 98 | |
wiesdat | 8:83115293e84d | 99 | //Definieer alle functies |
wiesdat | 8:83115293e84d | 100 | void clamp(float * in, float min, float max); |
wiesdat | 8:83115293e84d | 101 | void clampint(int * in, int min, int max); |
wiesdat | 8:83115293e84d | 102 | void setlooptimerflag(void); |
wiesdat | 8:83115293e84d | 103 | float readEMG1(); |
wiesdat | 8:83115293e84d | 104 | float readEMG2(); |
wiesdat | 8:83115293e84d | 105 | float notchfilter1(float ylp1); |
wiesdat | 8:83115293e84d | 106 | float notchfilter2(float ylp2); |
wiesdat | 8:83115293e84d | 107 | float hpfilter1(float yn1); |
wiesdat | 8:83115293e84d | 108 | float hpfilter2(float yn2); |
wiesdat | 8:83115293e84d | 109 | float lpfilter1(float yhp1); |
wiesdat | 8:83115293e84d | 110 | float lpfilter2(float yhp2); |
wiesdat | 8:83115293e84d | 111 | float filter1(float emg_value1); |
wiesdat | 8:83115293e84d | 112 | float filter2(float emg_value2); |
wiesdat | 8:83115293e84d | 113 | float threshold1 (float yave1); |
wiesdat | 8:83115293e84d | 114 | float threshold2 (float yave2); |
wiesdat | 8:83115293e84d | 115 | float getv(float delta_t); |
wiesdat | 8:83115293e84d | 116 | float resetarm(); |
wiesdat | 8:83115293e84d | 117 | uint8_t badje (uint8_t y1, uint8_t y2); |
wiesdat | 8:83115293e84d | 118 | void batposition(int y); |
wiesdat | 8:83115293e84d | 119 | void sla(int k); |
wiesdat | 8:83115293e84d | 120 | float pidposition(float setpoint, float measurement); |
wiesdat | 8:83115293e84d | 121 | float pidarm(float rev_value, float mea_value); |
wiesdat | 8:83115293e84d | 122 | uint8_t armposition (uint8_t y1, uint8_t y2); |
wiesdat | 4:c22f3095b130 | 123 | |
wiesdat | 4:c22f3095b130 | 124 | /*FUNCTIES |
wiesdat | 4:c22f3095b130 | 125 | In deze sectie worden de functie geprogrammeerd, hieronder een uitleg per functie. De functies zijn verdeeld in drie groepen. In het script |
wiesdat | 4:c22f3095b130 | 126 | staat achter enkele functies een 1 of een 2. Er worden 2 signalen bewerkt, dus sommige functies staan dubbel in het script. Signaal 1 wordt |
wiesdat | 4:c22f3095b130 | 127 | door de functies met 1, en signaal 2 wordt door de functie met 2, bewerkt. |
wiesdat | 4:c22f3095b130 | 128 | |
wiesdat | 4:c22f3095b130 | 129 | GLOBAL FUNCTIONS |
wiesdat | 4:c22f3095b130 | 130 | Clamp - "clampt" een waarde binnen grenzen, als de geclampte variabele over de grens heen gaat krijgt de variabele de grenswaarde. |
wiesdat | 4:c22f3095b130 | 131 | setLooptimerflag - Hiermee wordt de ticker aangeroepen. |
wiesdat | 0:25a2e7ea29f3 | 132 | |
wiesdat | 4:c22f3095b130 | 133 | EMG FUNCTIONS |
wiesdat | 4:c22f3095b130 | 134 | readEMG - Leest het voltage af van de geselecteerde pin, in ons geval een EMG waarde. |
wiesdat | 4:c22f3095b130 | 135 | (notch/lp/hp)filter -Er worden drie filters gebruikt: lowpass, highpass en notchfilter. De funtie krijgt een input en geeft dan een gefilterde output. |
wiesdat | 4:c22f3095b130 | 136 | filter - Voert de notch,lp,hp filters achter elkaar uit op een input en geeft het gemiddelde van 500 meetpunten als output. |
wiesdat | 4:c22f3095b130 | 137 | threshold - Vergelijkt de input met een treshold, als de waarde boven de treshold komt (zodra een spier wordt aangespannen) wordt de output 1, anders 0. |
wiesdat | 4:c22f3095b130 | 138 | |
wiesdat | 4:c22f3095b130 | 139 | MOTORCONTROLFUNCTIONS |
wiesdat | 4:c22f3095b130 | 140 | resetarm - Brengt arm terug naar de nul positie, zet de encoder op 0. |
wiesdat | 4:c22f3095b130 | 141 | getv(delta_t) - Geeft de huidige draaisnelheid van motor1, delta_t is het tijdsinterval waarover gemeten wordt |
wiesdat | 4:c22f3095b130 | 142 | badje - Vergelijkt met dubbele input, y1 en y2. Er zijn vier situaties, beide = 0, y1=1, y2=1, beide =1. |
wiesdat | 4:c22f3095b130 | 143 | badposition - Leest de output van badje, laat het badje links, recht, niet draaien. |
wiesdat | 4:c22f3095b130 | 144 | pid... - Pid regelaar, de k waardes wordenin de define sectie gedefineerd. |
wiesdat | 4:c22f3095b130 | 145 | armposition - Op basis van de emgsignalen wordt hier een positie ingesteld. |
wiesdat | 4:c22f3095b130 | 146 | armtopos - Regelt de arm naar de opgegeven positie toe. |
wiesdat | 4:c22f3095b130 | 147 | */ |
wiesdat | 5:36df561f3ac1 | 148 | //HIDScope scope(5); |
wiesdat | 4:c22f3095b130 | 149 | //GLOBAL FUNCTIOMS |
wiesdat | 5:36df561f3ac1 | 150 | /*void viewer(){ |
wiesdat | 5:36df561f3ac1 | 151 | scope.set(0,yave1); |
wiesdat | 5:36df561f3ac1 | 152 | scope.set(1,y1); |
wiesdat | 5:36df561f3ac1 | 153 | scope.set(2,yave2); |
wiesdat | 5:36df561f3ac1 | 154 | scope.set(3,y2); |
wiesdat | 5:36df561f3ac1 | 155 | scope.send(); |
wiesdat | 5:36df561f3ac1 | 156 | }*/ |
wiesdat | 5:36df561f3ac1 | 157 | |
wiesdat | 3:611fd72c9d46 | 158 | void clamp(float * in, float min, float max) |
wiesdat | 0:25a2e7ea29f3 | 159 | { |
wiesdat | 3:611fd72c9d46 | 160 | *in > min ? *in < max? : *in = max: *in = min; |
wiesdat | 0:25a2e7ea29f3 | 161 | } |
wiesdat | 0:25a2e7ea29f3 | 162 | |
wiesdat | 5:36df561f3ac1 | 163 | void clampint(int * in, int min, int max) |
wiesdat | 5:36df561f3ac1 | 164 | { |
wiesdat | 5:36df561f3ac1 | 165 | *in > min ? *in < max? : *in = max: *in = min; |
wiesdat | 5:36df561f3ac1 | 166 | } |
wiesdat | 5:36df561f3ac1 | 167 | |
wiesdat | 4:c22f3095b130 | 168 | void setlooptimerflag(void) |
wiesdat | 4:c22f3095b130 | 169 | { |
wiesdat | 4:c22f3095b130 | 170 | looptimerflag = true; |
wiesdat | 4:c22f3095b130 | 171 | } |
wiesdat | 3:611fd72c9d46 | 172 | |
wiesdat | 4:c22f3095b130 | 173 | //EMG FUNCTIONS |
wiesdat | 0:25a2e7ea29f3 | 174 | float readEMG1() |
wiesdat | 0:25a2e7ea29f3 | 175 | { |
wiesdat | 0:25a2e7ea29f3 | 176 | emg_value1=emg1.read(); |
wiesdat | 0:25a2e7ea29f3 | 177 | return emg_value1; |
wiesdat | 0:25a2e7ea29f3 | 178 | } |
wiesdat | 0:25a2e7ea29f3 | 179 | |
wiesdat | 0:25a2e7ea29f3 | 180 | float readEMG2() |
wiesdat | 0:25a2e7ea29f3 | 181 | { |
wiesdat | 0:25a2e7ea29f3 | 182 | emg_value2=emg2.read(); |
wiesdat | 0:25a2e7ea29f3 | 183 | return emg_value2; |
wiesdat | 0:25a2e7ea29f3 | 184 | } |
wiesdat | 0:25a2e7ea29f3 | 185 | |
wiesdat | 0:25a2e7ea29f3 | 186 | float notchfilter1(float ylp1) |
wiesdat | 0:25a2e7ea29f3 | 187 | { |
wiesdat | 0:25a2e7ea29f3 | 188 | static float yn1,x1=0,x2=0,y1=0,y2=0,x; |
wiesdat | 0:25a2e7ea29f3 | 189 | x = ylp1; |
wiesdat | 0:25a2e7ea29f3 | 190 | yn1 = A0N*x + A1N*x1+A2N*x2+B1N*y1+B2N*y2; |
wiesdat | 0:25a2e7ea29f3 | 191 | x2 = x1; |
wiesdat | 0:25a2e7ea29f3 | 192 | x1 = x; |
wiesdat | 0:25a2e7ea29f3 | 193 | y2 = y1; |
wiesdat | 0:25a2e7ea29f3 | 194 | y1 = yn1; |
wiesdat | 0:25a2e7ea29f3 | 195 | return yn1; |
wiesdat | 0:25a2e7ea29f3 | 196 | } |
wiesdat | 0:25a2e7ea29f3 | 197 | |
wiesdat | 0:25a2e7ea29f3 | 198 | float notchfilter2(float ylp2) |
wiesdat | 0:25a2e7ea29f3 | 199 | { |
wiesdat | 0:25a2e7ea29f3 | 200 | static float x1=0,x2=0,y1=0,y2=0,x; |
wiesdat | 0:25a2e7ea29f3 | 201 | x = ylp2; |
wiesdat | 0:25a2e7ea29f3 | 202 | yn2 = A0N*x + A1N*x1+A2N*x2+B1N*y1+B2N*y2; |
wiesdat | 0:25a2e7ea29f3 | 203 | x2 = x1; |
wiesdat | 0:25a2e7ea29f3 | 204 | x1 = x; |
wiesdat | 0:25a2e7ea29f3 | 205 | y2 = y1; |
wiesdat | 0:25a2e7ea29f3 | 206 | y1 = yn2; |
wiesdat | 0:25a2e7ea29f3 | 207 | return yn2; |
wiesdat | 0:25a2e7ea29f3 | 208 | } |
wiesdat | 0:25a2e7ea29f3 | 209 | |
wiesdat | 0:25a2e7ea29f3 | 210 | float hpfilter1(float yn1) |
wiesdat | 0:25a2e7ea29f3 | 211 | { |
wiesdat | 0:25a2e7ea29f3 | 212 | static float x1=0,y1=0,x2=0, y2=0,x; |
wiesdat | 0:25a2e7ea29f3 | 213 | x = yn1; |
wiesdat | 0:25a2e7ea29f3 | 214 | yhp1 = x + A1HP*x1 + A0HP*x2 - B1HP*y1 - B0HP*y2; |
wiesdat | 0:25a2e7ea29f3 | 215 | x2 = x1; |
wiesdat | 0:25a2e7ea29f3 | 216 | x1 = x; |
wiesdat | 0:25a2e7ea29f3 | 217 | y2 = y1; |
wiesdat | 0:25a2e7ea29f3 | 218 | y1 = yhp1; |
wiesdat | 0:25a2e7ea29f3 | 219 | return yhp1; |
wiesdat | 0:25a2e7ea29f3 | 220 | } |
wiesdat | 0:25a2e7ea29f3 | 221 | |
wiesdat | 0:25a2e7ea29f3 | 222 | float hpfilter2(float yn2) |
wiesdat | 0:25a2e7ea29f3 | 223 | { |
wiesdat | 0:25a2e7ea29f3 | 224 | static float x1=0,y1=0,x2=0, y2=0,x; |
wiesdat | 0:25a2e7ea29f3 | 225 | x = yn2; |
wiesdat | 0:25a2e7ea29f3 | 226 | yhp2 = x + A1HP*x1 + A0HP*x2 - B1HP*y1 - B0HP*y2; |
wiesdat | 0:25a2e7ea29f3 | 227 | x2 = x1; |
wiesdat | 0:25a2e7ea29f3 | 228 | x1 = x; |
wiesdat | 0:25a2e7ea29f3 | 229 | y2 = y1; |
wiesdat | 0:25a2e7ea29f3 | 230 | y1 = yhp2; |
wiesdat | 0:25a2e7ea29f3 | 231 | return yhp2; |
wiesdat | 0:25a2e7ea29f3 | 232 | } |
wiesdat | 0:25a2e7ea29f3 | 233 | |
wiesdat | 0:25a2e7ea29f3 | 234 | float lpfilter1(float yhp1) |
wiesdat | 0:25a2e7ea29f3 | 235 | { |
wiesdat | 0:25a2e7ea29f3 | 236 | static float x1=0,y1=0,x2=0, y2=0,x; |
wiesdat | 0:25a2e7ea29f3 | 237 | x = yhp1; |
wiesdat | 0:25a2e7ea29f3 | 238 | ylp1 = A1LP*x1-B1LP*y1+A0LP*x2-B0LP*y2; |
wiesdat | 0:25a2e7ea29f3 | 239 | x2 = x1; |
wiesdat | 0:25a2e7ea29f3 | 240 | x1 = x; |
wiesdat | 0:25a2e7ea29f3 | 241 | y2 = y1; |
wiesdat | 0:25a2e7ea29f3 | 242 | y1 = ylp1; |
wiesdat | 0:25a2e7ea29f3 | 243 | return ylp1; |
wiesdat | 0:25a2e7ea29f3 | 244 | } |
wiesdat | 0:25a2e7ea29f3 | 245 | |
wiesdat | 0:25a2e7ea29f3 | 246 | float lpfilter2(float yhp2) |
wiesdat | 0:25a2e7ea29f3 | 247 | { |
wiesdat | 0:25a2e7ea29f3 | 248 | static float x1=0,y1=0,x2=0, y2=0,x; |
wiesdat | 0:25a2e7ea29f3 | 249 | x = yhp2; |
wiesdat | 0:25a2e7ea29f3 | 250 | ylp2 = A1LP*x1-B1LP*y1+A0LP*x2-B0LP*y2; |
wiesdat | 0:25a2e7ea29f3 | 251 | x2 = x1; |
wiesdat | 0:25a2e7ea29f3 | 252 | x1 = x; |
wiesdat | 0:25a2e7ea29f3 | 253 | y2 = y1; |
wiesdat | 0:25a2e7ea29f3 | 254 | y1 = ylp2; |
wiesdat | 0:25a2e7ea29f3 | 255 | return ylp2; |
wiesdat | 0:25a2e7ea29f3 | 256 | } |
wiesdat | 0:25a2e7ea29f3 | 257 | |
wiesdat | 0:25a2e7ea29f3 | 258 | float filter1(float emg_value1) |
wiesdat | 0:25a2e7ea29f3 | 259 | { |
wiesdat | 0:25a2e7ea29f3 | 260 | static uint16_t n; |
wiesdat | 0:25a2e7ea29f3 | 261 | yn1 = notchfilter1(emg_value1); |
wiesdat | 0:25a2e7ea29f3 | 262 | yhp1 = hpfilter1(yn1); |
wiesdat | 0:25a2e7ea29f3 | 263 | ylp1 = lpfilter1(yhp1); |
wiesdat | 0:25a2e7ea29f3 | 264 | ylp1 = fabs(ylp1); |
wiesdat | 0:25a2e7ea29f3 | 265 | ysum1 = ysum1+ylp1; |
wiesdat | 0:25a2e7ea29f3 | 266 | n++; |
wiesdat | 0:25a2e7ea29f3 | 267 | if(n==500) { |
wiesdat | 0:25a2e7ea29f3 | 268 | yave1 = ysum1/500; |
wiesdat | 0:25a2e7ea29f3 | 269 | ysum1 = 0; |
wiesdat | 0:25a2e7ea29f3 | 270 | n = 0; |
wiesdat | 0:25a2e7ea29f3 | 271 | } |
wiesdat | 0:25a2e7ea29f3 | 272 | return yave1; |
wiesdat | 0:25a2e7ea29f3 | 273 | } |
wiesdat | 0:25a2e7ea29f3 | 274 | |
wiesdat | 0:25a2e7ea29f3 | 275 | float filter2(float emg_value2) |
wiesdat | 0:25a2e7ea29f3 | 276 | { |
wiesdat | 0:25a2e7ea29f3 | 277 | static uint16_t n; |
wiesdat | 0:25a2e7ea29f3 | 278 | yn2 = notchfilter2(emg_value2); |
wiesdat | 0:25a2e7ea29f3 | 279 | yhp2 = hpfilter2(yn2); |
wiesdat | 0:25a2e7ea29f3 | 280 | ylp2 = lpfilter2(yhp2); |
wiesdat | 0:25a2e7ea29f3 | 281 | ylp2 = fabs(ylp2); |
wiesdat | 0:25a2e7ea29f3 | 282 | ysum2 = ysum2 + ylp2; |
wiesdat | 0:25a2e7ea29f3 | 283 | n++; |
wiesdat | 0:25a2e7ea29f3 | 284 | |
wiesdat | 5:36df561f3ac1 | 285 | if(n==NOSAMPL) { |
wiesdat | 5:36df561f3ac1 | 286 | yave2 = ysum2/NOSAMPL; |
wiesdat | 0:25a2e7ea29f3 | 287 | ysum2 = 0; |
wiesdat | 0:25a2e7ea29f3 | 288 | n = 0; |
wiesdat | 0:25a2e7ea29f3 | 289 | } |
wiesdat | 0:25a2e7ea29f3 | 290 | return yave2; |
wiesdat | 0:25a2e7ea29f3 | 291 | } |
wiesdat | 0:25a2e7ea29f3 | 292 | |
wiesdat | 0:25a2e7ea29f3 | 293 | float threshold1 (float yave1) |
wiesdat | 0:25a2e7ea29f3 | 294 | { |
wiesdat | 0:25a2e7ea29f3 | 295 | if(yave1>THRESHOLD) { |
wiesdat | 0:25a2e7ea29f3 | 296 | y1 = 1; |
wiesdat | 0:25a2e7ea29f3 | 297 | } else { |
wiesdat | 0:25a2e7ea29f3 | 298 | y1 = 0; |
wiesdat | 0:25a2e7ea29f3 | 299 | } |
wiesdat | 0:25a2e7ea29f3 | 300 | return y1; |
wiesdat | 0:25a2e7ea29f3 | 301 | } |
wiesdat | 0:25a2e7ea29f3 | 302 | |
wiesdat | 0:25a2e7ea29f3 | 303 | float threshold2 (float yave2) |
wiesdat | 0:25a2e7ea29f3 | 304 | { |
wiesdat | 0:25a2e7ea29f3 | 305 | if(yave2>THRESHOLD) { |
wiesdat | 0:25a2e7ea29f3 | 306 | y2 = 1; |
wiesdat | 0:25a2e7ea29f3 | 307 | } else { |
wiesdat | 0:25a2e7ea29f3 | 308 | y2 = 0; |
wiesdat | 0:25a2e7ea29f3 | 309 | } |
wiesdat | 0:25a2e7ea29f3 | 310 | return y2; |
wiesdat | 0:25a2e7ea29f3 | 311 | } |
wiesdat | 0:25a2e7ea29f3 | 312 | |
wiesdat | 4:c22f3095b130 | 313 | //MOTORCONTROL FUNCTIONS |
wiesdat | 4:c22f3095b130 | 314 | float getv(float delta_t) |
wiesdat | 0:25a2e7ea29f3 | 315 | { |
wiesdat | 4:c22f3095b130 | 316 | int enca1=0,enca2=0,counts=0; |
wiesdat | 3:611fd72c9d46 | 317 | float v; |
wiesdat | 2:f3e8a27d376c | 318 | int n =0 ; |
wiesdat | 2:f3e8a27d376c | 319 | while(n<3) { |
wiesdat | 2:f3e8a27d376c | 320 | wait(delta_t); |
wiesdat | 2:f3e8a27d376c | 321 | enca2 = enca1; |
wiesdat | 4:c22f3095b130 | 322 | enca1 = encoder1.getPosition(); |
wiesdat | 2:f3e8a27d376c | 323 | n++; |
wiesdat | 2:f3e8a27d376c | 324 | } |
wiesdat | 2:f3e8a27d376c | 325 | counts = (enca1 - enca2)/delta_t; |
wiesdat | 4:c22f3095b130 | 326 | v = (counts)*((2*3.14159265359)/1550)*0.5; |
wiesdat | 2:f3e8a27d376c | 327 | return v; |
wiesdat | 2:f3e8a27d376c | 328 | } |
wiesdat | 4:c22f3095b130 | 329 | |
wiesdat | 4:c22f3095b130 | 330 | float resetarm() |
wiesdat | 3:611fd72c9d46 | 331 | { |
wiesdat | 3:611fd72c9d46 | 332 | v1 = 1; |
wiesdat | 3:611fd72c9d46 | 333 | while(v1 !=0) { |
wiesdat | 3:611fd72c9d46 | 334 | dir1 = 0; |
wiesdat | 3:611fd72c9d46 | 335 | pwm1.write(0.1); |
wiesdat | 4:c22f3095b130 | 336 | v1 =getv(0.1); |
wiesdat | 3:611fd72c9d46 | 337 | } |
wiesdat | 3:611fd72c9d46 | 338 | pwm1 = 0; |
wiesdat | 3:611fd72c9d46 | 339 | dir1 =1; |
wiesdat | 3:611fd72c9d46 | 340 | encoder1.setPosition(0); |
wiesdat | 3:611fd72c9d46 | 341 | return pwm1; |
wiesdat | 3:611fd72c9d46 | 342 | } |
wiesdat | 3:611fd72c9d46 | 343 | uint8_t badje (uint8_t y1, uint8_t y2) |
wiesdat | 3:611fd72c9d46 | 344 | { |
wiesdat | 3:611fd72c9d46 | 345 | if (y1>0 && y2>0 && check>0) { |
wiesdat | 3:611fd72c9d46 | 346 | badjedone=1; |
wiesdat | 3:611fd72c9d46 | 347 | check=0; |
wiesdat | 3:611fd72c9d46 | 348 | rood = 1; |
wiesdat | 3:611fd72c9d46 | 349 | groen = 0; |
wiesdat | 3:611fd72c9d46 | 350 | cout<<"ga naar mode 2"<<endl; |
wiesdat | 5:36df561f3ac1 | 351 | wait(0.2); |
wiesdat | 3:611fd72c9d46 | 352 | } else if (y1>0 && y2>0) { |
wiesdat | 3:611fd72c9d46 | 353 | check=1; |
wiesdat | 3:611fd72c9d46 | 354 | } else if (y1>0) { |
wiesdat | 3:611fd72c9d46 | 355 | badjes=0; |
wiesdat | 3:611fd72c9d46 | 356 | check=0; |
wiesdat | 3:611fd72c9d46 | 357 | } else if (y2>0 ) { |
wiesdat | 3:611fd72c9d46 | 358 | badjes=1; |
wiesdat | 3:611fd72c9d46 | 359 | check=0; |
wiesdat | 4:c22f3095b130 | 360 | } else { |
wiesdat | 3:611fd72c9d46 | 361 | check=0; |
wiesdat | 3:611fd72c9d46 | 362 | badjes = 2; |
wiesdat | 3:611fd72c9d46 | 363 | } |
wiesdat | 3:611fd72c9d46 | 364 | return badjes; |
wiesdat | 3:611fd72c9d46 | 365 | } |
wiesdat | 3:611fd72c9d46 | 366 | |
wiesdat | 4:c22f3095b130 | 367 | void batposition(int y) |
wiesdat | 4:c22f3095b130 | 368 | { |
wiesdat | 4:c22f3095b130 | 369 | switch(y) { |
wiesdat | 4:c22f3095b130 | 370 | case 0: |
wiesdat | 4:c22f3095b130 | 371 | |
wiesdat | 4:c22f3095b130 | 372 | dir = 1; |
wiesdat | 4:c22f3095b130 | 373 | pwm.write(0.4); |
wiesdat | 4:c22f3095b130 | 374 | wait(0.04); |
wiesdat | 4:c22f3095b130 | 375 | pwm.write(0); |
wiesdat | 5:36df561f3ac1 | 376 | cout<<"links"<<endl; |
wiesdat | 4:c22f3095b130 | 377 | break; |
wiesdat | 4:c22f3095b130 | 378 | case 1: |
wiesdat | 4:c22f3095b130 | 379 | dir = 0; |
wiesdat | 4:c22f3095b130 | 380 | pwm.write(0.4); |
wiesdat | 4:c22f3095b130 | 381 | wait(0.04); |
wiesdat | 4:c22f3095b130 | 382 | pwm.write(0); |
wiesdat | 5:36df561f3ac1 | 383 | cout<<"rechts"<<endl; |
wiesdat | 4:c22f3095b130 | 384 | break; |
wiesdat | 4:c22f3095b130 | 385 | case 2: |
wiesdat | 4:c22f3095b130 | 386 | pwm.write(0); |
wiesdat | 4:c22f3095b130 | 387 | break; |
wiesdat | 4:c22f3095b130 | 388 | |
wiesdat | 4:c22f3095b130 | 389 | } |
wiesdat | 4:c22f3095b130 | 390 | |
wiesdat | 4:c22f3095b130 | 391 | } |
wiesdat | 4:c22f3095b130 | 392 | |
wiesdat | 8:83115293e84d | 393 | void sla(int k) |
wiesdat | 8:83115293e84d | 394 | { |
wiesdat | 8:83115293e84d | 395 | float maxpwm; |
wiesdat | 8:83115293e84d | 396 | float new_pwm; |
wiesdat | 8:83115293e84d | 397 | switch(k) |
wiesdat | 8:83115293e84d | 398 | { |
wiesdat | 8:83115293e84d | 399 | case 1: |
wiesdat | 8:83115293e84d | 400 | maxpwm=0.2; |
wiesdat | 8:83115293e84d | 401 | break; |
wiesdat | 8:83115293e84d | 402 | case 2: |
wiesdat | 8:83115293e84d | 403 | maxpwm=0.5; |
wiesdat | 8:83115293e84d | 404 | break; |
wiesdat | 8:83115293e84d | 405 | case 3: |
wiesdat | 8:83115293e84d | 406 | maxpwm=0.8; |
wiesdat | 8:83115293e84d | 407 | break; |
wiesdat | 8:83115293e84d | 408 | case 4: |
wiesdat | 8:83115293e84d | 409 | maxpwm=1; |
wiesdat | 8:83115293e84d | 410 | break; |
wiesdat | 8:83115293e84d | 411 | default: |
wiesdat | 8:83115293e84d | 412 | maxpwm=0; |
wiesdat | 8:83115293e84d | 413 | break; |
wiesdat | 8:83115293e84d | 414 | } |
wiesdat | 8:83115293e84d | 415 | while((encoder1.getPosition()<MAXPOS)||getv(0.01)>0.1) |
wiesdat | 8:83115293e84d | 416 | { |
wiesdat | 8:83115293e84d | 417 | new_pwm=pidarm(MAXPOS,encoder1.getPosition()); |
wiesdat | 8:83115293e84d | 418 | clamp(&new_pwm,-maxpwm,maxpwm); |
wiesdat | 8:83115293e84d | 419 | if (new_pwm>0) |
wiesdat | 8:83115293e84d | 420 | { |
wiesdat | 8:83115293e84d | 421 | dir1=1; |
wiesdat | 8:83115293e84d | 422 | } |
wiesdat | 8:83115293e84d | 423 | else if (new_pwm<0) |
wiesdat | 8:83115293e84d | 424 | { |
wiesdat | 8:83115293e84d | 425 | dir1=0; |
wiesdat | 8:83115293e84d | 426 | } |
wiesdat | 8:83115293e84d | 427 | pwm1.write(fabs(new_pwm)); |
wiesdat | 8:83115293e84d | 428 | cout<<"pwm1: "<<new_pwm<<endl; |
wiesdat | 8:83115293e84d | 429 | cout<<"pos: "<<encoder1.getPosition()<<endl; |
wiesdat | 8:83115293e84d | 430 | } |
wiesdat | 8:83115293e84d | 431 | |
wiesdat | 8:83115293e84d | 432 | pwm1.write(0); |
wiesdat | 8:83115293e84d | 433 | wait(2); |
wiesdat | 8:83115293e84d | 434 | //cout<< encoder1.getPosition()<<endl; |
wiesdat | 8:83115293e84d | 435 | } |
wiesdat | 8:83115293e84d | 436 | |
wiesdat | 4:c22f3095b130 | 437 | float pidposition(float setpoint, float measurement) |
wiesdat | 3:611fd72c9d46 | 438 | { |
wiesdat | 4:c22f3095b130 | 439 | float error, out, out_p=0,out_d=0; |
wiesdat | 4:c22f3095b130 | 440 | static float prev_error = 0; |
wiesdat | 4:c22f3095b130 | 441 | error = setpoint-measurement; |
wiesdat | 4:c22f3095b130 | 442 | out_p = error*K_P1; |
wiesdat | 4:c22f3095b130 | 443 | out_i1 += error*K_I1; |
wiesdat | 4:c22f3095b130 | 444 | out_d = (error-prev_error)*K_D1; |
wiesdat | 4:c22f3095b130 | 445 | clamp(&out_i1,-I_LIMIT1,I_LIMIT1); |
wiesdat | 4:c22f3095b130 | 446 | prev_error = error; |
wiesdat | 4:c22f3095b130 | 447 | out = out_i1+out_p+out_d; |
wiesdat | 5:36df561f3ac1 | 448 | cout<<"out: "<<out<<endl; |
wiesdat | 4:c22f3095b130 | 449 | return out; |
wiesdat | 4:c22f3095b130 | 450 | } |
wiesdat | 4:c22f3095b130 | 451 | |
wiesdat | 8:83115293e84d | 452 | float pidarm(float rev_value, float mea_value) |
wiesdat | 8:83115293e84d | 453 | { |
wiesdat | 8:83115293e84d | 454 | float error; |
wiesdat | 8:83115293e84d | 455 | static float prev_error = 0; |
wiesdat | 8:83115293e84d | 456 | float p_out = 0; |
wiesdat | 8:83115293e84d | 457 | static float i_out = 0; |
wiesdat | 8:83115293e84d | 458 | float d_out = 0; |
wiesdat | 8:83115293e84d | 459 | error = rev_value - mea_value; |
wiesdat | 8:83115293e84d | 460 | p_out = error * KSLA_P; |
wiesdat | 8:83115293e84d | 461 | i_out += error * KSLA_I; |
wiesdat | 8:83115293e84d | 462 | d_out = (error - prev_error) * KSLA_D; |
wiesdat | 8:83115293e84d | 463 | clamp(&i_out,-I_LIMIT1,I_LIMIT1); |
wiesdat | 8:83115293e84d | 464 | prev_error=error; |
wiesdat | 8:83115293e84d | 465 | return p_out + i_out + d_out; |
wiesdat | 8:83115293e84d | 466 | } |
wiesdat | 4:c22f3095b130 | 467 | |
wiesdat | 5:36df561f3ac1 | 468 | |
wiesdat | 4:c22f3095b130 | 469 | uint8_t armposition (uint8_t y1, uint8_t y2) |
wiesdat | 4:c22f3095b130 | 470 | { |
wiesdat | 4:c22f3095b130 | 471 | static int stand=0; |
wiesdat | 4:c22f3095b130 | 472 | if (y1>0 && y2>0 && check>0) { |
wiesdat | 5:36df561f3ac1 | 473 | badjedone=2; |
wiesdat | 4:c22f3095b130 | 474 | check=0; |
wiesdat | 4:c22f3095b130 | 475 | rood = 0; |
wiesdat | 4:c22f3095b130 | 476 | groen = 1; |
wiesdat | 4:c22f3095b130 | 477 | cout<<"ga naar mode 1"<<endl; |
wiesdat | 4:c22f3095b130 | 478 | } else if (y1>0 && y2>0) { |
wiesdat | 4:c22f3095b130 | 479 | check=1; |
wiesdat | 5:36df561f3ac1 | 480 | cout<<"zo naar mode 1"<<endl; |
wiesdat | 4:c22f3095b130 | 481 | } else if (y1>0) { |
wiesdat | 4:c22f3095b130 | 482 | stand=stand+1; |
wiesdat | 4:c22f3095b130 | 483 | check=0; |
wiesdat | 4:c22f3095b130 | 484 | cout<<"stand "<<stand<<endl; |
wiesdat | 4:c22f3095b130 | 485 | } else if (y2>0 ) { |
wiesdat | 4:c22f3095b130 | 486 | stand=stand-1; |
wiesdat | 4:c22f3095b130 | 487 | check=0; |
wiesdat | 4:c22f3095b130 | 488 | cout<<"stand "<<stand<<endl; |
wiesdat | 4:c22f3095b130 | 489 | } else { |
wiesdat | 5:36df561f3ac1 | 490 | |
wiesdat | 4:c22f3095b130 | 491 | check =0; |
wiesdat | 4:c22f3095b130 | 492 | } |
wiesdat | 6:b69b9597d4fc | 493 | clampint(&stand,1,3); |
wiesdat | 4:c22f3095b130 | 494 | return stand; |
wiesdat | 4:c22f3095b130 | 495 | } |
wiesdat | 4:c22f3095b130 | 496 | |
wiesdat | 6:b69b9597d4fc | 497 | float gotopos(int pos) |
wiesdat | 4:c22f3095b130 | 498 | { |
wiesdat | 6:b69b9597d4fc | 499 | float out1; |
wiesdat | 6:b69b9597d4fc | 500 | |
wiesdat | 6:b69b9597d4fc | 501 | switch(pos) { |
wiesdat | 2:f3e8a27d376c | 502 | case 1: |
wiesdat | 6:b69b9597d4fc | 503 | pos = 100; |
wiesdat | 2:f3e8a27d376c | 504 | break; |
wiesdat | 2:f3e8a27d376c | 505 | |
wiesdat | 2:f3e8a27d376c | 506 | case 2: |
wiesdat | 6:b69b9597d4fc | 507 | pos = 200; |
wiesdat | 2:f3e8a27d376c | 508 | break; |
wiesdat | 2:f3e8a27d376c | 509 | |
wiesdat | 2:f3e8a27d376c | 510 | case 3: |
wiesdat | 6:b69b9597d4fc | 511 | pos = 250; |
wiesdat | 2:f3e8a27d376c | 512 | break; |
wiesdat | 2:f3e8a27d376c | 513 | } |
wiesdat | 6:b69b9597d4fc | 514 | |
wiesdat | 6:b69b9597d4fc | 515 | while((abs(pos-encoder1.getPosition()) >6)|| (v1!= 0)) { |
wiesdat | 2:f3e8a27d376c | 516 | |
wiesdat | 2:f3e8a27d376c | 517 | while(!looptimerflag); |
wiesdat | 2:f3e8a27d376c | 518 | looptimerflag = false; |
wiesdat | 6:b69b9597d4fc | 519 | out1 = pidposition(pos,encoder1.getPosition()); |
wiesdat | 2:f3e8a27d376c | 520 | |
wiesdat | 6:b69b9597d4fc | 521 | if(out1>0) { |
wiesdat | 2:f3e8a27d376c | 522 | dir1 = 1; |
wiesdat | 2:f3e8a27d376c | 523 | |
wiesdat | 6:b69b9597d4fc | 524 | } else if(out1<0) { |
wiesdat | 2:f3e8a27d376c | 525 | dir1 = 0; |
wiesdat | 2:f3e8a27d376c | 526 | } |
wiesdat | 6:b69b9597d4fc | 527 | pwm1 = fabs(out1); |
wiesdat | 4:c22f3095b130 | 528 | v1 = getv(0.001); |
wiesdat | 2:f3e8a27d376c | 529 | } |
wiesdat | 2:f3e8a27d376c | 530 | pwm1 =0; |
wiesdat | 2:f3e8a27d376c | 531 | |
wiesdat | 6:b69b9597d4fc | 532 | return pwm1; |
wiesdat | 2:f3e8a27d376c | 533 | } |
wiesdat | 2:f3e8a27d376c | 534 | |
wiesdat | 4:c22f3095b130 | 535 | // MAIN SCRIPT |
wiesdat | 0:25a2e7ea29f3 | 536 | int main() |
wiesdat | 0:25a2e7ea29f3 | 537 | { |
wiesdat | 1:a010e434a360 | 538 | rood = 0; |
wiesdat | 1:a010e434a360 | 539 | blauw = 1; |
wiesdat | 1:a010e434a360 | 540 | groen = 1; |
wiesdat | 4:c22f3095b130 | 541 | resetarm(); |
wiesdat | 0:25a2e7ea29f3 | 542 | pc.baud(115200); |
wiesdat | 0:25a2e7ea29f3 | 543 | timer.attach(setlooptimerflag,TSAMP); |
wiesdat | 0:25a2e7ea29f3 | 544 | wait(2); |
wiesdat | 5:36df561f3ac1 | 545 | cout<<"Begin programma"<<endl; |
wiesdat | 0:25a2e7ea29f3 | 546 | while(1) { |
wiesdat | 4:c22f3095b130 | 547 | //Per TSAMP word EMG uitgelzen, gefilterd en gemiddeld |
wiesdat | 0:25a2e7ea29f3 | 548 | while(!looptimerflag); |
wiesdat | 0:25a2e7ea29f3 | 549 | looptimerflag = false; |
wiesdat | 0:25a2e7ea29f3 | 550 | emg_value1 = readEMG1(); |
wiesdat | 0:25a2e7ea29f3 | 551 | emg_value2 = readEMG2(); |
wiesdat | 0:25a2e7ea29f3 | 552 | yave1 = filter1(emg_value1); |
wiesdat | 0:25a2e7ea29f3 | 553 | yave2 = filter2(emg_value2); |
wiesdat | 0:25a2e7ea29f3 | 554 | y1=threshold1(yave1); |
wiesdat | 0:25a2e7ea29f3 | 555 | y2=threshold2(yave2); |
wiesdat | 0:25a2e7ea29f3 | 556 | teller++; |
wiesdat | 0:25a2e7ea29f3 | 557 | |
wiesdat | 4:c22f3095b130 | 558 | /*Dit gedeelte voert de bewegingen uit. In de eerste fase kan met de linker spier het batje naar links gedraaid worden, |
wiesdat | 4:c22f3095b130 | 559 | en met de rechter spier het batje naar recht. Als het badje in de juiste positie staat kunnen beide spieren tegelijk |
wiesdat | 4:c22f3095b130 | 560 | aangespannen worden om naar de volgende fase te gaan. In fase 2 wordt de armpositie ingesteld. Hoe groter de afstand van de |
wiesdat | 4:c22f3095b130 | 561 | arm met de bal, hoe harder de arm gaat slaan. Zodra de arm in de goede positie staat kan door beide spieren aan te spannen worden |
wiesdat | 4:c22f3095b130 | 562 | doorgegaan naar fase 3. In fase 3 slaat de arm de bal. De snelheid die ingesteld wordt waarmee de arm gaat slaan wordt bepaald aan de |
wiesdat | 4:c22f3095b130 | 563 | hand van de positie waarin de arm in fase 2 is gezet. Zodra de arm de bal geslagen heeft moet de arm gereset worden en terug gaan naar |
wiesdat | 4:c22f3095b130 | 564 | fase 1.*/ |
wiesdat | 0:25a2e7ea29f3 | 565 | |
wiesdat | 5:36df561f3ac1 | 566 | if (teller==NOSAMPL) { |
wiesdat | 0:25a2e7ea29f3 | 567 | teller=0; |
wiesdat | 5:36df561f3ac1 | 568 | switch(badjedone) { |
wiesdat | 5:36df561f3ac1 | 569 | case 0: |
wiesdat | 5:36df561f3ac1 | 570 | cout<<"fase1"<<endl; |
wiesdat | 5:36df561f3ac1 | 571 | badjestand=badje(y1,y2); |
wiesdat | 5:36df561f3ac1 | 572 | batposition(badjestand); |
wiesdat | 5:36df561f3ac1 | 573 | break; |
wiesdat | 5:36df561f3ac1 | 574 | |
wiesdat | 5:36df561f3ac1 | 575 | case 1: |
wiesdat | 5:36df561f3ac1 | 576 | cout<<"fase2"<<endl; |
wiesdat | 4:c22f3095b130 | 577 | armstand=armposition(y1,y2); |
wiesdat | 6:b69b9597d4fc | 578 | gotopos(armstand); |
wiesdat | 3:611fd72c9d46 | 579 | cout<<"armstand "<<armstand<<endl; |
wiesdat | 5:36df561f3ac1 | 580 | |
wiesdat | 5:36df561f3ac1 | 581 | //armtopos(armstand); |
wiesdat | 5:36df561f3ac1 | 582 | //cout<<"badjedont: "<<badjedone<<endl; |
wiesdat | 5:36df561f3ac1 | 583 | break; |
wiesdat | 5:36df561f3ac1 | 584 | |
wiesdat | 5:36df561f3ac1 | 585 | case 2: |
wiesdat | 9:80693874f9ce | 586 | cout<<"sla"<<endl; |
wiesdat | 9:80693874f9ce | 587 | sla(armstand); |
wiesdat | 9:80693874f9ce | 588 | resetarm(); |
wiesdat | 5:36df561f3ac1 | 589 | badjedone=0; |
wiesdat | 5:36df561f3ac1 | 590 | break; |
wiesdat | 5:36df561f3ac1 | 591 | default: |
wiesdat | 5:36df561f3ac1 | 592 | break; |
wiesdat | 0:25a2e7ea29f3 | 593 | } |
wiesdat | 5:36df561f3ac1 | 594 | |
wiesdat | 0:25a2e7ea29f3 | 595 | } |
wiesdat | 0:25a2e7ea29f3 | 596 | } |
wiesdat | 5:36df561f3ac1 | 597 | |
wiesdat | 5:36df561f3ac1 | 598 | } |
wiesdat | 0:25a2e7ea29f3 | 599 | |
wiesdat | 5:36df561f3ac1 | 600 |