2014-10-15 Arm 1 naar thuispositie. Eerste poging, fout in keep_in_range

Dependencies:   Encoder MODSERIAL TextLCD mbed mbed-dsp

Committer:
JKleinRot
Date:
Mon Nov 03 11:13:33 2014 +0000
Revision:
25:71e52c56be13
Parent:
24:a1fdc830f96c
Child:
26:438a498e5526
2014-11-03 State BBBB werkt, gaat netjes terug, ook verandert voor de andere cases

Who changed what in which revision?

UserRevisionLine numberNew contents of line
JKleinRot 0:859c89785d3f 1 #include "mbed.h" //Mbed bibliotheek inladen, standaard functies
JKleinRot 0:859c89785d3f 2 #include "MODSERIAL.h" //MODSERIAL bibliotheek inladen, communicatie met PC
JKleinRot 0:859c89785d3f 3 #include "encoder.h" //Encoder bibliotheek inladen, communicatie met encoder
JKleinRot 0:859c89785d3f 4 #include "TextLCD.h" //LCD scherm bibliotheek inladen, communicatie met LCD scherm
JKleinRot 15:3ebd0e666a9c 5 #include "arm_math.h" //Filter bibliotheek inladen, makkelijk de filters maken, minder grote lappen tekst
JKleinRot 0:859c89785d3f 6
JKleinRot 0:859c89785d3f 7 //Constanten definiëren en waarde geven
JKleinRot 11:e9b906b5f572 8 #define SAMPLETIME_REGELAAR 0.005 //Sampletijd ticker regelaar motor
JKleinRot 25:71e52c56be13 9 #define SAMPLETIME_EMG 0.005 //Sampletijd ticker EMG meten
JKleinRot 20:1cb0cf0d49ac 10 #define KP_arm1 0.02 //Factor proprotionele regelaar arm 1
JKleinRot 25:71e52c56be13 11 #define KI_arm1 0 //Factor integraal regelaar arm 1
JKleinRot 25:71e52c56be13 12 #define KD_arm1 0 //Factor afgeleide regelaar arm 1
JKleinRot 23:5267c928ae2b 13 #define KP_arm2 0.01 //Factor proprotionele regelaar arm 2
JKleinRot 21:f4e9f6c28de1 14 #define KI_arm2 0 //Factor integraal regelaar arm 2
JKleinRot 21:f4e9f6c28de1 15 #define KD_arm2 0 //Factor afgeleide regelaar arm 2
JKleinRot 0:859c89785d3f 16
JKleinRot 16:c34c5d9dfe1a 17 //Filtercoëfficiënten per filter, allemaal 2e orde filters, zo cascade van hogere orde mogelijk
JKleinRot 16:c34c5d9dfe1a 18 //High Pass filter
JKleinRot 15:3ebd0e666a9c 19 #define A1 1
JKleinRot 18:d3a7f8b4cb22 20 #define A2 -1.561018075800718
JKleinRot 18:d3a7f8b4cb22 21 #define A3 0.641351538057563
JKleinRot 18:d3a7f8b4cb22 22 #define B1 0.800592403464570
JKleinRot 18:d3a7f8b4cb22 23 #define B2 -1.601184806929141
JKleinRot 18:d3a7f8b4cb22 24 #define B3 0.800592403464570
JKleinRot 13:54ee98850a15 25
JKleinRot 16:c34c5d9dfe1a 26 //Notch filter
JKleinRot 13:54ee98850a15 27 #define C1 1
JKleinRot 18:d3a7f8b4cb22 28 #define C2 -1.18733334554802E-16
JKleinRot 18:d3a7f8b4cb22 29 #define C3 0.939062505817492
JKleinRot 18:d3a7f8b4cb22 30 #define D1 0.969531252908746
JKleinRot 18:d3a7f8b4cb22 31 #define D2 -1.18733334554802E-16
JKleinRot 18:d3a7f8b4cb22 32 #define D3 0.969531252908746
JKleinRot 13:54ee98850a15 33
JKleinRot 16:c34c5d9dfe1a 34 //Low pass filter
JKleinRot 13:54ee98850a15 35 #define E1 1
JKleinRot 18:d3a7f8b4cb22 36 #define E2 -1.77863177782459
JKleinRot 18:d3a7f8b4cb22 37 #define E3 0.800802646665708
JKleinRot 18:d3a7f8b4cb22 38 #define F1 0.00554271721028068
JKleinRot 18:d3a7f8b4cb22 39 #define F2 0.0110854344205614
JKleinRot 18:d3a7f8b4cb22 40 #define F3 0.00554271721028068
JKleinRot 18:d3a7f8b4cb22 41
JKleinRot 15:3ebd0e666a9c 42
JKleinRot 0:859c89785d3f 43 //Pinverdeling en naamgeving variabelen
JKleinRot 17:c694a0e63a89 44 TextLCD lcd(PTD1, PTA12, PTB2, PTB3, PTC2, PTD3, TextLCD::LCD16x2); //LCD scherm
JKleinRot 16:c34c5d9dfe1a 45 MODSERIAL pc(USBTX, USBRX); //PC
JKleinRot 0:859c89785d3f 46
JKleinRot 16:c34c5d9dfe1a 47 PwmOut pwm_motor_arm1(PTA5); //PWM naar motor arm 1
JKleinRot 16:c34c5d9dfe1a 48 DigitalOut dir_motor_arm1(PTA4); //Richting van motor arm 1
JKleinRot 23:5267c928ae2b 49 Encoder puls_motor_arm1(PTD2, PTD0); //Encoder pulsen tellen van motor arm 1, (geel, wit)
JKleinRot 16:c34c5d9dfe1a 50 PwmOut pwm_motor_arm2(PTC8); //PWM naar motor arm 2
JKleinRot 16:c34c5d9dfe1a 51 DigitalOut dir_motor_arm2(PTC9); //Ricting van motor arm 2
JKleinRot 16:c34c5d9dfe1a 52 Encoder puls_motor_arm2(PTD5, PTA13); //Encoder pulsen tellen van motor arm 2, (geel, wit)
JKleinRot 16:c34c5d9dfe1a 53 AnalogIn EMG_bi(PTB1); //Uitlezen EMG signaal biceps
JKleinRot 17:c694a0e63a89 54 AnalogIn EMG_tri(PTB0); //Uitlezen EMG signaal triceps
JKleinRot 16:c34c5d9dfe1a 55 //Blauw op 3,3 V en groen op GND, voeding beide encoders
JKleinRot 1:e5e1eb9d0025 56
JKleinRot 25:71e52c56be13 57 Ticker ticker_regelaar; //Ticker voor flag veranderen referentie
JKleinRot 25:71e52c56be13 58 Ticker ticker_EMG; //Ticker voor flag EMG meten
JKleinRot 25:71e52c56be13 59 Ticker ticker_motor_arm1_pid; //Ticker voor PID regelaar motor arm 1
JKleinRot 25:71e52c56be13 60 Ticker ticker_motor_arm2_pid; //Ticker voor PID regelaar motor arm 2
JKleinRot 25:71e52c56be13 61
JKleinRot 16:c34c5d9dfe1a 62 Timer biceps_kalibratie; //Timer voor kalibratiemeting EMG biceps
JKleinRot 16:c34c5d9dfe1a 63 Timer triceps_kalibratie; //Timer voor kalibratiemeting EMG triceps
JKleinRot 25:71e52c56be13 64 Timer EMG; //Timer voor aantal seconden EMG meten
JKleinRot 1:e5e1eb9d0025 65
JKleinRot 9:454e7da8ab65 66 //States definiëren
JKleinRot 25:71e52c56be13 67 enum pipostate {RUST, KALIBRATIE_ARM1, KALIBRATIE_ARM2, EMG_KALIBRATIE_BICEPS, EMG_KALIBRATIE_TRICEPS, START, B, T, BB, BT, TB, TT, BBB, BBT, BTB, BTT, TBB, TBT, TTB, TTT, BBBB, BBBT, BBTB, BBTT, BTBB, BTBT, BTTB, BTTT, TBBB, TBBT, TBTB, TBTT, TTBB, TTBT, TTTB, TTTT, WACHT, THUISPOSITIE_MIDDEN, THUISPOSITIE_RECHTS}; //Alle states benoemen, ieder krijgt een getal beginnend met 0
JKleinRot 9:454e7da8ab65 68 uint8_t state = RUST; //State is rust aan het begin
JKleinRot 9:454e7da8ab65 69
JKleinRot 6:3b6fad529520 70 //Gedefinieerde datatypen en naamgeving en beginwaarden
JKleinRot 11:e9b906b5f572 71 float pwm_to_motor_arm1; //PWM output naar motor arm 1
JKleinRot 11:e9b906b5f572 72 float pwm_to_motor_arm2; //PWM output naar motor arm 2
JKleinRot 13:54ee98850a15 73 float error_arm1_kalibratie; //Error in pulsen arm 1
JKleinRot 13:54ee98850a15 74 float vorige_error_arm1 = 0; //Derivative actie van regelaar arm 1
JKleinRot 13:54ee98850a15 75 float integraal_arm1 = 0; //Integraal actie van regelaar arm 1
JKleinRot 13:54ee98850a15 76 float afgeleide_arm1; //Afgeleide actie van regelaar arm 1
JKleinRot 13:54ee98850a15 77 float error_arm2_kalibratie; //Error in pulsen arm 2
JKleinRot 13:54ee98850a15 78 float vorige_error_arm2 = 0; //Derivative actie van regelaar arm 2
JKleinRot 13:54ee98850a15 79 float integraal_arm2 = 0; //Integraal actie van regelaar arm 2
JKleinRot 13:54ee98850a15 80 float afgeleide_arm2; //Afgeleide actie van regelaar arm 2
JKleinRot 13:54ee98850a15 81 float xb; //Gemeten EMG waarde biceps
JKleinRot 16:c34c5d9dfe1a 82 float xt; //Gemeten EMG waarde triceps
JKleinRot 19:38c9d177b6ee 83 float referentie_arm1 = 0;
JKleinRot 19:38c9d177b6ee 84 float referentie_arm2 = 0;
JKleinRot 23:5267c928ae2b 85 float t = 0;
JKleinRot 23:5267c928ae2b 86
JKleinRot 25:71e52c56be13 87 //Gedefinieerde filters met constanten en gefilterde waarden
JKleinRot 16:c34c5d9dfe1a 88 arm_biquad_casd_df1_inst_f32 highpass_biceps; //Highpass_biceps IIR filter in direct form 1
JKleinRot 17:c694a0e63a89 89 float highpass_biceps_const[] = {B1, B2, B3, -A2, -A3, B1, B2, B3, -A2, -A3}; //Filtercoëfficiënten van het filter
JKleinRot 17:c694a0e63a89 90 float highpass_biceps_states[8]; //Aantal states van het filter, het aantal y(n-x) en x(n-x)
JKleinRot 13:54ee98850a15 91
JKleinRot 16:c34c5d9dfe1a 92 arm_biquad_casd_df1_inst_f32 notch_biceps; //Notch_biceps IIR filter in direct form 1
JKleinRot 17:c694a0e63a89 93 float notch_biceps_const[] = {D1, D2, D3, -C2, -C3, D1, D2, D3, -C2, -C3}; //Filtercoëfficiënten van het filter
JKleinRot 17:c694a0e63a89 94 float notch_biceps_states[8]; //Aantal states van het filter
JKleinRot 15:3ebd0e666a9c 95
JKleinRot 16:c34c5d9dfe1a 96 arm_biquad_casd_df1_inst_f32 lowpass_biceps; //Lowpass_biceps IIR filter in direct form 1
JKleinRot 17:c694a0e63a89 97 float lowpass_biceps_const[] = {F1, F2, F3, -E2, -E3, F1, F2, F3, -E2, -E3}; //Filtercoëfficiënten van het filter
JKleinRot 17:c694a0e63a89 98 float lowpass_biceps_states[8]; //Aantal states van het filter
JKleinRot 15:3ebd0e666a9c 99
JKleinRot 16:c34c5d9dfe1a 100 float xbf; //Gefilterde EMG waarde biceps
JKleinRot 16:c34c5d9dfe1a 101 float xbfmax = 0; //Maximale gefilterde EMG waarde biceps
JKleinRot 13:54ee98850a15 102
JKleinRot 16:c34c5d9dfe1a 103 arm_biquad_casd_df1_inst_f32 highpass_triceps; //Highpass_triceps IIR filter in direct form 1, waarde wordt opgeslagen in een float
JKleinRot 17:c694a0e63a89 104 float highpass_triceps_const[] = {B1, B2, B3, -A2, -A3, B1, B2, B3, -A2, -A3}; //Filtercoëfficiënten van het filter
JKleinRot 17:c694a0e63a89 105 float highpass_triceps_states[8]; //Aantal states van het filter
JKleinRot 13:54ee98850a15 106
JKleinRot 16:c34c5d9dfe1a 107 arm_biquad_casd_df1_inst_f32 notch_triceps; //Notch_triceps IIR filter in direct form 1, waarde wordt opgeslagen in een float
JKleinRot 17:c694a0e63a89 108 float notch_triceps_const[] = {D1, D2, D3, -C2, -C3, D1, D2, D3, -C2, -C3}; //Filtercoëfficiënten van het filter
JKleinRot 17:c694a0e63a89 109 float notch_triceps_states[8]; //Aantal states van het filter
JKleinRot 13:54ee98850a15 110
JKleinRot 16:c34c5d9dfe1a 111 arm_biquad_casd_df1_inst_f32 lowpass_triceps; //Lowpass_biceps IIR filter in direct form 1, waarde wordt opgeslagen in een float
JKleinRot 17:c694a0e63a89 112 float lowpass_triceps_const[] = {F1, F2, F3, -E2, -E3, F1, F2, F3, -E2, -E3}; //Filtercoëfficiënten van het filter
JKleinRot 17:c694a0e63a89 113 float lowpass_triceps_states[8]; //Aantal states van het filter
JKleinRot 13:54ee98850a15 114
JKleinRot 16:c34c5d9dfe1a 115 float xtf; //Gefilterde EMG waarde triceps
JKleinRot 16:c34c5d9dfe1a 116 float xtfmax = 0; //Maximale gefilterde EMG waarde triceps
JKleinRot 15:3ebd0e666a9c 117
JKleinRot 16:c34c5d9dfe1a 118 float xbt; //Thresholdwaarde EMG biceps
JKleinRot 16:c34c5d9dfe1a 119 float xtt; //Thresholdwaarde EMG triceps
JKleinRot 7:dd3cba61b34b 120
JKleinRot 6:3b6fad529520 121 volatile bool regelaar_ticker_flag; //Definiëren flag als bool die verandert kan worden in programma
JKleinRot 10:52b22bff409a 122 void setregelaar_ticker_flag() //Setregelaar_ticker_flag zet de regelaar_ticker_flag op true
JKleinRot 10:52b22bff409a 123 {
JKleinRot 10:52b22bff409a 124 regelaar_ticker_flag = true;
JKleinRot 1:e5e1eb9d0025 125 }
JKleinRot 1:e5e1eb9d0025 126
JKleinRot 6:3b6fad529520 127 volatile bool regelaar_EMG_flag; //Definiëren flag als bool die verandert kan worden in programma
JKleinRot 10:52b22bff409a 128 void setregelaar_EMG_flag() //Setregelaar_EMG_flag zet de regelaar_EMG_flag op true
JKleinRot 10:52b22bff409a 129 {
JKleinRot 10:52b22bff409a 130 regelaar_EMG_flag = true;
JKleinRot 4:69540b9c0646 131 }
JKleinRot 4:69540b9c0646 132
JKleinRot 10:52b22bff409a 133 void keep_in_range(float * in, float min, float max) //Zorgt ervoor dat een getal niet buiten een bepaald minimum en maximum komt
JKleinRot 10:52b22bff409a 134 {
JKleinRot 19:38c9d177b6ee 135 if (*in < min) { //Als de waarde kleiner is als het minimum wordt de waarde het minimum
JKleinRot 2:0cb899f2800a 136 *in = min;
JKleinRot 2:0cb899f2800a 137 }
JKleinRot 19:38c9d177b6ee 138 if (*in > max) { //Als de waarde groter is dan het maximum is de waarde het maximum
JKleinRot 2:0cb899f2800a 139 *in = max;
JKleinRot 19:38c9d177b6ee 140 } else { //In alle andere gevallen is de waarde de waarde zelf
JKleinRot 2:0cb899f2800a 141 *in = *in;
JKleinRot 2:0cb899f2800a 142 }
JKleinRot 2:0cb899f2800a 143 }
JKleinRot 1:e5e1eb9d0025 144
JKleinRot 25:71e52c56be13 145 void motor_arm1_pid() //PID regelaar van motor arm 1
JKleinRot 10:52b22bff409a 146 {
JKleinRot 19:38c9d177b6ee 147 error_arm1_kalibratie = (referentie_arm1 - puls_motor_arm1.getPosition()); //PWM naar motor is het verschil tussen het voorgestelde aantal pulsen en de huidige positie maal een factor
JKleinRot 20:1cb0cf0d49ac 148 integraal_arm1 = integraal_arm1 + error_arm1_kalibratie*SAMPLETIME_REGELAAR; //Integraal deel van regelaar
JKleinRot 20:1cb0cf0d49ac 149 afgeleide_arm1 = (error_arm1_kalibratie - vorige_error_arm1)/SAMPLETIME_REGELAAR; //Afgeleide deel van regelaar
JKleinRot 20:1cb0cf0d49ac 150 pwm_to_motor_arm1 = error_arm1_kalibratie*KP_arm1 + integraal_arm1*KI_arm1 + afgeleide_arm1*KD_arm1;//Output naar motor na PID regelaar
JKleinRot 25:71e52c56be13 151 vorige_error_arm1 = error_arm1_kalibratie; //Vorige error is de volgende keer de huidige error van deze keer
JKleinRot 25:71e52c56be13 152 keep_in_range(&pwm_to_motor_arm1, -1, 1); //Stelt 1 en -1 in als de maximale en minimale waarde die de pwm mag hebben
JKleinRot 19:38c9d177b6ee 153
JKleinRot 21:f4e9f6c28de1 154 if (pwm_to_motor_arm1 > 0) { //Als PWM is positief, dan richting 1
JKleinRot 23:5267c928ae2b 155 dir_motor_arm1.write(0);
JKleinRot 21:f4e9f6c28de1 156 } else { //Anders richting nul
JKleinRot 23:5267c928ae2b 157 dir_motor_arm1.write(1);
JKleinRot 7:dd3cba61b34b 158 }
JKleinRot 18:d3a7f8b4cb22 159
JKleinRot 11:e9b906b5f572 160 pwm_motor_arm1.write(fabs(pwm_to_motor_arm1)); //Output PWM naar motor is de absolute waarde van de berekende PWM
JKleinRot 20:1cb0cf0d49ac 161 }
JKleinRot 10:52b22bff409a 162
JKleinRot 25:71e52c56be13 163 void motor_arm2_pid() //PID regelaar van motor arm 2
JKleinRot 20:1cb0cf0d49ac 164 {
JKleinRot 20:1cb0cf0d49ac 165 error_arm2_kalibratie = (referentie_arm2 - puls_motor_arm2.getPosition()); //PWM naar motor is het verschil tussen het voorgestelde aantal pulsen en de huidige positie maal een factor
JKleinRot 20:1cb0cf0d49ac 166 integraal_arm2 = integraal_arm2 + error_arm2_kalibratie*SAMPLETIME_REGELAAR; //Integraal deel van regelaar
JKleinRot 20:1cb0cf0d49ac 167 afgeleide_arm2 = (error_arm2_kalibratie - vorige_error_arm2)/SAMPLETIME_REGELAAR; //Afgeleide deel van regelaar
JKleinRot 20:1cb0cf0d49ac 168 pwm_to_motor_arm2 = error_arm2_kalibratie*KP_arm2 + integraal_arm2*KI_arm2 + afgeleide_arm2*KD_arm2;//Output naar motor na PID regelaar
JKleinRot 25:71e52c56be13 169 vorige_error_arm2 = error_arm2_kalibratie; //Vorige error is de volgende keer de huidige error van deze keer
JKleinRot 25:71e52c56be13 170 keep_in_range(&pwm_to_motor_arm2, -1, 1); //Stelt 1 en -1 in als de maximale en minimale waarde die de pwm mag hebben
JKleinRot 19:38c9d177b6ee 171
JKleinRot 20:1cb0cf0d49ac 172 if (pwm_to_motor_arm2 > 0) { //Als PWM is positief, dan richting 1
JKleinRot 20:1cb0cf0d49ac 173 dir_motor_arm2.write(1);
JKleinRot 20:1cb0cf0d49ac 174 } else { //Anders richting nul
JKleinRot 20:1cb0cf0d49ac 175 dir_motor_arm2.write(0);
JKleinRot 20:1cb0cf0d49ac 176 }
JKleinRot 20:1cb0cf0d49ac 177 pwm_motor_arm2.write(fabs(pwm_to_motor_arm2)); //Output PWM naar motor is de absolute waarde van de berekende PWM
JKleinRot 10:52b22bff409a 178 }
JKleinRot 7:dd3cba61b34b 179
JKleinRot 16:c34c5d9dfe1a 180 void filter_biceps() //Filtert het EMG signaal van de biceps
JKleinRot 13:54ee98850a15 181 {
JKleinRot 16:c34c5d9dfe1a 182 arm_biquad_cascade_df1_f32(&highpass_biceps, &xb, &xbf, 1); //Highpass filter voor het EMG signaal van de biceps, filtert de xb en schrijft het over in de xbf, 1 EMG waarde filteren per keer
JKleinRot 19:38c9d177b6ee 183
JKleinRot 16:c34c5d9dfe1a 184 arm_biquad_cascade_df1_f32(&notch_biceps, &xbf, &xbf, 1); //Notch filter voor het EMG signaal van de biceps, filtert de xbf uit de highpass en schrijft het opnieuw in de xbf, 1 EMG waarde filteren per keer
JKleinRot 16:c34c5d9dfe1a 185
JKleinRot 16:c34c5d9dfe1a 186 xbf = fabs(xbf); //Rectifier, schrijft de absolute waarde van de xbf uit de notch opnieuw in de xbf, fabs omdat het een float is
JKleinRot 15:3ebd0e666a9c 187
JKleinRot 16:c34c5d9dfe1a 188 arm_biquad_cascade_df1_f32(&lowpass_biceps, &xbf, &xbf, 1); //Lowpass filter voor het EMG signaal van de biceps, filtert de xbf uit de rectifier en schrijft het opnieuw in de xbf, 1 EMG waarde filteren per keer
JKleinRot 19:38c9d177b6ee 189
JKleinRot 16:c34c5d9dfe1a 190 pc.printf("xbf is %f\n\r", xbf); //De gefilterde EMG waarde van de biceps naar pc sturen
JKleinRot 16:c34c5d9dfe1a 191 }
JKleinRot 15:3ebd0e666a9c 192
JKleinRot 16:c34c5d9dfe1a 193 void filter_triceps() //Filtert het EMG signaal van de triceps
JKleinRot 16:c34c5d9dfe1a 194 {
JKleinRot 16:c34c5d9dfe1a 195 arm_biquad_cascade_df1_f32(&highpass_triceps, &xt, &xtf, 1); //Highpass filter voor het EMG signaal van de triceps, filtert de xt en schrijft het over in de xtf, 1 EMG waarde filteren per keer
JKleinRot 16:c34c5d9dfe1a 196
JKleinRot 16:c34c5d9dfe1a 197 arm_biquad_cascade_df1_f32(&notch_triceps, &xtf, &xtf, 1); //Notch filter voor het EMG signaal van de triceps, filtert de xtf uit de highpass en schrijft het opnieuw in de xtf, 1 EMG waarde filteren per keer
JKleinRot 15:3ebd0e666a9c 198
JKleinRot 16:c34c5d9dfe1a 199 xtf = fabs(xtf); //Rectifier, schrijft de absolute waarde van de xtf uit de notch opnieuw in de xtf, fabs omdat het een float is
JKleinRot 16:c34c5d9dfe1a 200
JKleinRot 16:c34c5d9dfe1a 201 arm_biquad_cascade_df1_f32(&lowpass_triceps, &xtf, &xtf, 1); //Lowpass filter voor het EMG signaal van de triceps, filtert de xtf uit de rectifier en schrijft het opnieuw in de xtf, 1 EMG waarde filteren per keer
JKleinRot 16:c34c5d9dfe1a 202
JKleinRot 16:c34c5d9dfe1a 203 pc.printf("xtf is %f\n\r", xtf); //De gefilterde EMG waarde van de triceps naar pc sturen
JKleinRot 15:3ebd0e666a9c 204
JKleinRot 13:54ee98850a15 205 }
JKleinRot 13:54ee98850a15 206
JKleinRot 25:71e52c56be13 207 void EMG_meten() //Meet de EMG van de biceps en de triceps
JKleinRot 22:838a17065bc7 208 {
JKleinRot 22:838a17065bc7 209 xb = EMG_bi.read(); //EMG signaal biceps uitlezen
JKleinRot 22:838a17065bc7 210 filter_biceps(); //EMG signaal biceps filteren
JKleinRot 22:838a17065bc7 211 xt = EMG_tri.read(); //EMG signaal triceps uitlezen
JKleinRot 22:838a17065bc7 212 filter_triceps(); //EMG signaal triceps filteren
JKleinRot 22:838a17065bc7 213 }
JKleinRot 22:838a17065bc7 214
JKleinRot 22:838a17065bc7 215
JKleinRot 16:c34c5d9dfe1a 216 int main() //Main script
JKleinRot 15:3ebd0e666a9c 217 {
JKleinRot 25:71e52c56be13 218 ticker_motor_arm1_pid.attach(motor_arm1_pid,SAMPLETIME_REGELAAR); //Iedere SAMPLETIME_REGELAAR wordt door de PID regelaar bekeken of er een andere referentie is en stuurt indien nodig een pwm naar de motor
JKleinRot 25:71e52c56be13 219 ticker_motor_arm2_pid.attach(motor_arm2_pid,SAMPLETIME_REGELAAR); //Iederen SAMPLETIME_REGELAAR wordt door de PID regelaar bekeken of er een andere referentie is en stuurt indien nodig een pwm naar de motor
JKleinRot 21:f4e9f6c28de1 220
JKleinRot 19:38c9d177b6ee 221 while(1) { //Oneindige while loop, anders wordt er na het uitvoeren van de eerste case niets meer gedaan
JKleinRot 10:52b22bff409a 222 pc.baud(38400); //PC baud rate is 38400 bits/seconde
JKleinRot 10:52b22bff409a 223
JKleinRot 19:38c9d177b6ee 224 switch(state) { //Switch benoemen, zorgt ervoor dat in de goede volgorde de dingen worden doorlopen, aan einde een case wordt de state de naam van de nieuwe case
JKleinRot 10:52b22bff409a 225
JKleinRot 19:38c9d177b6ee 226 case RUST: { //Aanzetten
JKleinRot 19:38c9d177b6ee 227 pc.printf("RUST\n\r"); //Begin RUST naar pc sturen
JKleinRot 16:c34c5d9dfe1a 228 lcd.locate(0,0); //Zet de tekst op de eerste regel
JKleinRot 16:c34c5d9dfe1a 229 lcd.printf(" BMT K9 GR. 4 "); //Tekst op LCD scherm
JKleinRot 16:c34c5d9dfe1a 230 lcd.locate(0,1); //Zet de tekst op de tweede regel
JKleinRot 16:c34c5d9dfe1a 231 lcd.printf("HOI! IK BEN PIPO"); //Tekst op LCD scherm
JKleinRot 16:c34c5d9dfe1a 232 wait(2); //Twee seconden wachten
JKleinRot 16:c34c5d9dfe1a 233 lcd.cls(); //Maak LCD scherm leeg
JKleinRot 14:e1816efa712d 234 pc.printf("RUST afgerond\n\r"); //Tekst voor controle Aanzetten
JKleinRot 25:71e52c56be13 235 state = KALIBRATIE_ARM1; //Door naar de volgende state
JKleinRot 16:c34c5d9dfe1a 236 break; //Stopt acties in deze case
JKleinRot 10:52b22bff409a 237 }
JKleinRot 10:52b22bff409a 238
JKleinRot 19:38c9d177b6ee 239 case KALIBRATIE_ARM1: { //Arm 1 naar thuispositie
JKleinRot 16:c34c5d9dfe1a 240 pc.printf("KALIBRATIE_ARM1\n\r"); //Begin KALIBRATIE_ARM1 naar pc sturen
JKleinRot 16:c34c5d9dfe1a 241 wait(1); //Een seconde wachten
JKleinRot 15:3ebd0e666a9c 242
JKleinRot 10:52b22bff409a 243 ticker_regelaar.attach(setregelaar_ticker_flag,SAMPLETIME_REGELAAR); //Ticker iedere zoveel seconde de flag op laten steken
JKleinRot 10:52b22bff409a 244
JKleinRot 19:38c9d177b6ee 245 while(state == KALIBRATIE_ARM1) {
JKleinRot 16:c34c5d9dfe1a 246 while(regelaar_ticker_flag != true); //Als geen flag opgestoken, dan niks doen, wel flag, dan uit de while loop en door naar volgende regel
JKleinRot 10:52b22bff409a 247 regelaar_ticker_flag = false; //Flag weer naar beneden, zodat deze straks weer omhoog kan
JKleinRot 10:52b22bff409a 248
JKleinRot 25:71e52c56be13 249 referentie_arm1 = referentie_arm1 + 180.0/200.0; //Referentie loopt in één seconde op tot het gewenste aantal pulsen
JKleinRot 21:f4e9f6c28de1 250
JKleinRot 25:71e52c56be13 251 pc.printf("pulsmotorgetposition1 %d ", puls_motor_arm1.getPosition()); //Huidig aantal getelde pulsen van de encoder naar pc sturen
JKleinRot 25:71e52c56be13 252 pc.printf("pwmmotor1 %f ", pwm_to_motor_arm1); //Huidige PWM waarde naar motor naar pc sturen
JKleinRot 25:71e52c56be13 253 pc.printf("referentie1 %f\n\r", referentie_arm1); //Huidige referentie naar pc sturen
JKleinRot 25:71e52c56be13 254
JKleinRot 25:71e52c56be13 255 if (puls_motor_arm1.getPosition() >= 180) { //Als het gewenste aantal pulsen behaald is
JKleinRot 25:71e52c56be13 256 referentie_arm1 = 180; //Blijft de referentie op dat aantal pulsen staan
JKleinRot 25:71e52c56be13 257 state = KALIBRATIE_ARM2; //Door naar de volgende state
JKleinRot 20:1cb0cf0d49ac 258 }
JKleinRot 10:52b22bff409a 259 }
JKleinRot 10:52b22bff409a 260 wait(1); //Een seconde wachten
JKleinRot 11:e9b906b5f572 261 break; //Stopt acties in deze case
JKleinRot 10:52b22bff409a 262 }
JKleinRot 10:52b22bff409a 263
JKleinRot 19:38c9d177b6ee 264 case KALIBRATIE_ARM2: { //Arm 2 naar thuispositie
JKleinRot 19:38c9d177b6ee 265 pc.printf("KALIBRATIE_ARM2\n\r"); //Begin KALIBRATIE_ARM2 naar pc sturen
JKleinRot 16:c34c5d9dfe1a 266 wait(1); //Een seconde wachten
JKleinRot 10:52b22bff409a 267
JKleinRot 10:52b22bff409a 268 //ticker_regelaar.attach(setregelaar_ticker_flag,SAMPLETIME_REGELAAR); //Ticker iedere zoveel seconde de flag op laten steken
JKleinRot 10:52b22bff409a 269
JKleinRot 19:38c9d177b6ee 270 while(state == KALIBRATIE_ARM2) {
JKleinRot 16:c34c5d9dfe1a 271 while(regelaar_ticker_flag != true); //Als geen flag opgestoken, dan niks doen, wel flag, dan uit de while loop en door naar volgende regel
JKleinRot 10:52b22bff409a 272 regelaar_ticker_flag = false; //Flag weer naar beneden, zodat deze straks weer omhoog kan
JKleinRot 10:52b22bff409a 273
JKleinRot 25:71e52c56be13 274 referentie_arm2 = referentie_arm2 + 123.0/200.0; //Referentie loopt in één seconde op tot het gewenste aantal pulsen
JKleinRot 21:f4e9f6c28de1 275
JKleinRot 25:71e52c56be13 276 pc.printf("pulsmotorgetposition2 %d ", puls_motor_arm2.getPosition()); //Huidig aantal getelde pulsen van de encoder naar pc sturen
JKleinRot 25:71e52c56be13 277 pc.printf("pwmmotor2 %f ", pwm_to_motor_arm2); //Huidige PWM waarde naar motor naar pc sturen
JKleinRot 25:71e52c56be13 278 pc.printf("referentie2 %f\n\r", referentie_arm2); //Huidige referentie naar pc sturen
JKleinRot 25:71e52c56be13 279
JKleinRot 25:71e52c56be13 280 if(puls_motor_arm2.getPosition() >= 123) { //Als het gewenste aantal pulsen behaald is
JKleinRot 25:71e52c56be13 281 referentie_arm2 = 123; //Blijft de referentie op dat aantal pulsen staan
JKleinRot 25:71e52c56be13 282 state = EMG_KALIBRATIE_BICEPS; //Door naar de volgende state
JKleinRot 20:1cb0cf0d49ac 283 }
JKleinRot 10:52b22bff409a 284 }
JKleinRot 11:e9b906b5f572 285 wait(1); //Een seconde wachten
JKleinRot 16:c34c5d9dfe1a 286 break; //Stopt acties in deze case
JKleinRot 10:52b22bff409a 287 }
JKleinRot 15:3ebd0e666a9c 288
JKleinRot 19:38c9d177b6ee 289 case EMG_KALIBRATIE_BICEPS: { //Kalibratie biceps voor bepalen threshold
JKleinRot 16:c34c5d9dfe1a 290 pc.printf("EMG__KALIBRATIE_BICEPS\n\r"); //Begin EMG_KALIBRATIE_BICEPS naar pc sturen
JKleinRot 19:38c9d177b6ee 291
JKleinRot 16:c34c5d9dfe1a 292 lcd.locate(0,0); //Zet tekst op eerste regel
JKleinRot 16:c34c5d9dfe1a 293 lcd.printf(" SPAN IN 5 SEC. "); //Tekst op LCD scherm
JKleinRot 16:c34c5d9dfe1a 294 lcd.locate(0,1); //Zet tekst op tweede regel
JKleinRot 16:c34c5d9dfe1a 295 lcd.printf(" 2 X BICEPS AAN "); //Tekst op LCD scherm
JKleinRot 25:71e52c56be13 296 wait(1); //Een seconden wachten
JKleinRot 25:71e52c56be13 297 lcd.cls(); //LCD scherm leegmaken
JKleinRot 15:3ebd0e666a9c 298
JKleinRot 17:c694a0e63a89 299 arm_biquad_cascade_df1_init_f32(&highpass_biceps, 2, highpass_biceps_const, highpass_biceps_states); //Highpassfilter biceps met bijbehorende filtercoëfficiënten en states definiëren, cascade van 2 tweede orde filters
JKleinRot 17:c694a0e63a89 300 arm_biquad_cascade_df1_init_f32(&notch_biceps, 2, notch_biceps_const, notch_biceps_states); //Notchfilter biceps met bijbehorende filtercoëfficiënten en states definiëren
JKleinRot 17:c694a0e63a89 301 arm_biquad_cascade_df1_init_f32(&lowpass_biceps, 2, lowpass_biceps_const, lowpass_biceps_states); //Lowpassfilter biceps met bijbehorende filtercoëfficiënten en states definiëren, cascade van 2 tweede orde filters
JKleinRot 15:3ebd0e666a9c 302
JKleinRot 16:c34c5d9dfe1a 303 ticker_EMG.attach(setregelaar_EMG_flag,SAMPLETIME_EMG); //Ticker iedere zoveel seconde de flag op laten steken
JKleinRot 16:c34c5d9dfe1a 304 biceps_kalibratie.start(); //Timer aanzetten die de tijd meet vanaf dit punt
JKleinRot 15:3ebd0e666a9c 305
JKleinRot 19:38c9d177b6ee 306 while(biceps_kalibratie.read() <= 5) { //Zolang de timer nog geen 5 seconden heeft gemeten
JKleinRot 19:38c9d177b6ee 307
JKleinRot 15:3ebd0e666a9c 308 while(regelaar_EMG_flag != true) ; //Als geen flag opgestoken, dan niks doen, wel flag, dan uit de while loop en door naar volgende regel
JKleinRot 15:3ebd0e666a9c 309 regelaar_EMG_flag = false; //Flag weer naar beneden, zodat deze straks weer omhoog kan
JKleinRot 15:3ebd0e666a9c 310
JKleinRot 15:3ebd0e666a9c 311 xb = EMG_bi.read(); //EMG meten van biceps
JKleinRot 15:3ebd0e666a9c 312
JKleinRot 17:c694a0e63a89 313 filter_biceps(); //Voer acties uit om EMG signaal van de biceps te filteren
JKleinRot 15:3ebd0e666a9c 314
JKleinRot 19:38c9d177b6ee 315 if(int(biceps_kalibratie.read()) == 0) { //Wanneer de timer nog geen een seconde heeft gemeten
JKleinRot 17:c694a0e63a89 316 lcd.locate(0,0); //Zet de tekst op de eerste regel
JKleinRot 17:c694a0e63a89 317 lcd.printf(" 5 "); //Tekst op LCD scherm
JKleinRot 17:c694a0e63a89 318 pc.printf("4"); //Controle naar pc sturen
JKleinRot 17:c694a0e63a89 319 }
JKleinRot 19:38c9d177b6ee 320 if(int(biceps_kalibratie.read()) == 1) { //Wanneer de timer nog geen twee seconden heeft gemeten
JKleinRot 17:c694a0e63a89 321 lcd.locate(0,0); //Zet de tekst op de eerste regel
JKleinRot 17:c694a0e63a89 322 lcd.printf(" 4 "); //Tekst op LCD scherm
JKleinRot 17:c694a0e63a89 323 pc.printf("3"); //Controle naar pc sturen
JKleinRot 14:e1816efa712d 324 }
JKleinRot 19:38c9d177b6ee 325 if(int(biceps_kalibratie.read()) == 2) { //Wanneer de timer nog geen drie seconden heeft gemeten
JKleinRot 17:c694a0e63a89 326 lcd.locate(0,0); //Zet de tekst op de eerste regel
JKleinRot 17:c694a0e63a89 327 lcd.printf(" 3 "); //Tekst op LCD scherm
JKleinRot 17:c694a0e63a89 328 pc.printf("2"); //Controle naar pc sturen
JKleinRot 14:e1816efa712d 329 }
JKleinRot 19:38c9d177b6ee 330 if(int(biceps_kalibratie.read()) == 3) { //Wanneer de timer nog geen vier seconden heeft gemeten
JKleinRot 17:c694a0e63a89 331 lcd.locate(0,0); //Zet de tekst op de eerste regel
JKleinRot 17:c694a0e63a89 332 lcd.printf(" 2 "); //Tekst op LCD scherm
JKleinRot 17:c694a0e63a89 333 pc.printf("1"); //Controle naar pc sturen
JKleinRot 14:e1816efa712d 334 }
JKleinRot 19:38c9d177b6ee 335 if(int(biceps_kalibratie.read()) == 4) { //Wanneer de timer nog geen vijf seconden heeft gemeten
JKleinRot 17:c694a0e63a89 336 lcd.locate(0,0); //Zet de tekst op de eerste regel
JKleinRot 17:c694a0e63a89 337 lcd.printf(" 1 "); //Tekst op LCD scherm
JKleinRot 17:c694a0e63a89 338 pc.printf("1"); //Controle naar pc sturen
JKleinRot 15:3ebd0e666a9c 339 }
JKleinRot 15:3ebd0e666a9c 340
JKleinRot 21:f4e9f6c28de1 341 if(xbf >= xbfmax) { //Als de gefilterde EMG waarde groter is dan xbfmax
JKleinRot 21:f4e9f6c28de1 342 xbfmax = xbf; //Dan wordt deze gefilterde EMG waarde de nieuwe xbfmax
JKleinRot 21:f4e9f6c28de1 343 }
JKleinRot 15:3ebd0e666a9c 344 }
JKleinRot 19:38c9d177b6ee 345
JKleinRot 25:71e52c56be13 346 xbt = xbfmax * 0.90; //De threshold voor de biceps wordt 80% van de xfbmax na de 5 seconden meten
JKleinRot 25:71e52c56be13 347 pc.printf("maximale biceps %f", xbfmax); //Maximale gefilterde EMG waarde naar pc sturen
JKleinRot 17:c694a0e63a89 348 pc.printf("threshold is %f\n\r", xbt); //Thresholdwaarde naar pc sturen
JKleinRot 17:c694a0e63a89 349 state = EMG_KALIBRATIE_TRICEPS; //Gaat door naar kalibratie van de EMG van de triceps
JKleinRot 17:c694a0e63a89 350 break; //Stopt alle acties in deze case
JKleinRot 15:3ebd0e666a9c 351 }
JKleinRot 15:3ebd0e666a9c 352
JKleinRot 25:71e52c56be13 353 case EMG_KALIBRATIE_TRICEPS: { //Kalibratie triceps voor bepalen threshold
JKleinRot 17:c694a0e63a89 354 pc.printf("EMG__KALIBRATIE_TRICEPS\n\r"); //Begin EMG_KALIBRATIE_TRICEPS naar pc sturen
JKleinRot 15:3ebd0e666a9c 355
JKleinRot 17:c694a0e63a89 356 lcd.locate(0,0); //Zet de tekst op de eerste regel
JKleinRot 17:c694a0e63a89 357 lcd.printf(" SPAN IN 5 SEC. "); //Tekst op LCD scherm
JKleinRot 17:c694a0e63a89 358 lcd.locate(0,1); //Zet tekst op eerste regel
JKleinRot 17:c694a0e63a89 359 lcd.printf(" 2 X TRICEPS AAN"); //Tekst op LCD scherm
JKleinRot 25:71e52c56be13 360 wait(1); //Een seconde wachten
JKleinRot 25:71e52c56be13 361 lcd.cls(); //LCD scherm leegmaken
JKleinRot 15:3ebd0e666a9c 362
JKleinRot 19:38c9d177b6ee 363 arm_biquad_cascade_df1_init_f32(&highpass_triceps, 2, highpass_triceps_const, highpass_triceps_states); //Highpassfilter triceps met bijbehorende filtercoëfficiënten en states definiëren, cascade van 2 tweede orde filters
JKleinRot 17:c694a0e63a89 364 arm_biquad_cascade_df1_init_f32(&notch_triceps, 2, notch_triceps_const, notch_triceps_states); //Notchfilter triceps met bijbehorende filtercoëfficiënten en states definiëren
JKleinRot 17:c694a0e63a89 365 arm_biquad_cascade_df1_init_f32(&lowpass_triceps, 2, lowpass_triceps_const, lowpass_triceps_states); //Lowpassfilter triceps met bijbehorende filtercoëfficiënten en states definiëren, cascade van 2 tweede orde filters
JKleinRot 15:3ebd0e666a9c 366
JKleinRot 17:c694a0e63a89 367 triceps_kalibratie.start(); //Timer aanzetten die de tijd meet vanaf dit punt
JKleinRot 15:3ebd0e666a9c 368
JKleinRot 19:38c9d177b6ee 369 while(triceps_kalibratie.read() <= 5) { //Zolang de timer nog geen 5 seconden heeft gemeten
JKleinRot 15:3ebd0e666a9c 370 while(regelaar_EMG_flag != true) ; //Als geen flag opgestoken, dan niks doen, wel flag, dan uit de while loop en door naar volgende regel
JKleinRot 15:3ebd0e666a9c 371 regelaar_EMG_flag = false; //Flag weer naar beneden, zodat deze straks weer omhoog kan
JKleinRot 15:3ebd0e666a9c 372
JKleinRot 17:c694a0e63a89 373 xt = EMG_tri.read(); //EMG meten van ticeps
JKleinRot 15:3ebd0e666a9c 374
JKleinRot 17:c694a0e63a89 375 filter_triceps(); //Voer acties uit om EMG signaal van de triceps te meten
JKleinRot 15:3ebd0e666a9c 376
JKleinRot 19:38c9d177b6ee 377 if(int(triceps_kalibratie.read()) == 0) { //Wanneer de timer nog geen twee seconden heeft gemeten
JKleinRot 17:c694a0e63a89 378 lcd.locate(0,0); //Zet de tekst op de eerste regel
JKleinRot 17:c694a0e63a89 379 lcd.printf(" 5 "); //Tekst op LCD scherm
JKleinRot 17:c694a0e63a89 380 pc.printf("4"); //Controle naar pc sturen
JKleinRot 17:c694a0e63a89 381 }
JKleinRot 19:38c9d177b6ee 382 if(int(triceps_kalibratie.read()) == 1) { //Wanneer de timer nog geen twee seconden heeft gemeten
JKleinRot 17:c694a0e63a89 383 lcd.locate(0,0); //Zet de tekst op de eerste regel
JKleinRot 17:c694a0e63a89 384 lcd.printf(" 4 "); //Tekst op LCD scherm
JKleinRot 17:c694a0e63a89 385 pc.printf("3"); //Controle naar pc sturen
JKleinRot 15:3ebd0e666a9c 386 }
JKleinRot 19:38c9d177b6ee 387 if(int(triceps_kalibratie.read()) == 2) { //Wanneer de timer nog geen drie seconden heeft gemeten
JKleinRot 17:c694a0e63a89 388 lcd.locate(0,0); //Zet de tekst op de eerste regel
JKleinRot 17:c694a0e63a89 389 lcd.printf(" 3 "); //Tekst op LCD scherm
JKleinRot 17:c694a0e63a89 390 pc.printf("2"); //Controle naar pc sturen
JKleinRot 15:3ebd0e666a9c 391 }
JKleinRot 19:38c9d177b6ee 392 if(int(triceps_kalibratie.read()) == 3) { //Wanneer de timer nog geen vier seconden heeft gemeten
JKleinRot 17:c694a0e63a89 393 lcd.locate(0,0); //Zet de tekst op de eerste regel
JKleinRot 17:c694a0e63a89 394 lcd.printf(" 2 "); //Tekst op LCD scherm
JKleinRot 17:c694a0e63a89 395 pc.printf("1"); //Controle naar pc sturen
JKleinRot 15:3ebd0e666a9c 396 }
JKleinRot 19:38c9d177b6ee 397 if(int(triceps_kalibratie.read()) == 4) { //Wanneer de timer nog geen vijf seconden heeft gemeten
JKleinRot 17:c694a0e63a89 398 lcd.locate(0,0); //Zet de tekst op de eerste regel
JKleinRot 17:c694a0e63a89 399 lcd.printf(" 1 "); //Tekst op LCD scherm
JKleinRot 17:c694a0e63a89 400 pc.printf("1"); //Controle naar pc sturen
JKleinRot 14:e1816efa712d 401 }
JKleinRot 15:3ebd0e666a9c 402
JKleinRot 21:f4e9f6c28de1 403
JKleinRot 21:f4e9f6c28de1 404 if(xtf >= xtfmax) { //Als de gefilterde EMG waarde groter is dan xtfmax
JKleinRot 21:f4e9f6c28de1 405 xtfmax = xtf; //Dan wordt deze gefilterde EMG waarde de nieuwe xtfmax
JKleinRot 21:f4e9f6c28de1 406 }
JKleinRot 10:52b22bff409a 407 }
JKleinRot 19:38c9d177b6ee 408
JKleinRot 21:f4e9f6c28de1 409 xtt = xtfmax * 0.90; //Thresholdwaarde is 80% van de xtfmax na 5 seconden meten
JKleinRot 25:71e52c56be13 410 pc.printf("maximale triceps %f", xtfmax); //Maximale gefilterde EMG waarde naar pc sturen
JKleinRot 17:c694a0e63a89 411 pc.printf("threshold is %f\n\r", xtt); //Thresholdwaarde naar pc sturen
JKleinRot 17:c694a0e63a89 412 state = START; //Gaat door naar het slaan, kalibratie nu afgerond
JKleinRot 17:c694a0e63a89 413 break; //Stopt alle acties in deze case
JKleinRot 10:52b22bff409a 414 }
JKleinRot 15:3ebd0e666a9c 415
JKleinRot 25:71e52c56be13 416 case START: { //Eerste keuze maken voor doel
JKleinRot 17:c694a0e63a89 417 lcd.locate(0,0); //Zet tekst op eerste regel
JKleinRot 17:c694a0e63a89 418 lcd.printf(" START "); //Tekst op LCD scherm
JKleinRot 19:38c9d177b6ee 419
JKleinRot 17:c694a0e63a89 420 pc.printf("START\n\r"); //Controle naar pc sturen
JKleinRot 19:38c9d177b6ee 421
JKleinRot 19:38c9d177b6ee 422 while(state == START) {
JKleinRot 17:c694a0e63a89 423 while(regelaar_EMG_flag != true); //Als geen flag opgestoken, dan niks doen, wel flag, dan uit de while loop en door naar volgende regel
JKleinRot 17:c694a0e63a89 424 regelaar_EMG_flag = false; //Flag weer naar beneden, zodat deze straks weer omhoog kan
JKleinRot 15:3ebd0e666a9c 425
JKleinRot 17:c694a0e63a89 426 xb = EMG_bi.read(); //EMG signaal biceps uitlezen
JKleinRot 17:c694a0e63a89 427 filter_biceps(); //EMG signaal biceps filteren
JKleinRot 17:c694a0e63a89 428 xt = EMG_tri.read(); //EMG signaal triceps uitlezen
JKleinRot 17:c694a0e63a89 429 filter_triceps(); //EMG signaal triceps filteren
JKleinRot 15:3ebd0e666a9c 430
JKleinRot 25:71e52c56be13 431 if(xbf >= xbt) { //Als de gefilterde EMG van de biceps groter is dan de ingestelde threshold
JKleinRot 17:c694a0e63a89 432 state = B; //Ga door naar state B
JKleinRot 15:3ebd0e666a9c 433 }
JKleinRot 25:71e52c56be13 434 if(xtf >= xtt) { //Als de gefilterde EMG van de triceps groter is dan de ingestelde threshold
JKleinRot 17:c694a0e63a89 435 state = T; //Ga door naar state T
JKleinRot 15:3ebd0e666a9c 436 }
JKleinRot 15:3ebd0e666a9c 437 }
JKleinRot 17:c694a0e63a89 438 break; //Stopt met de acties in deze case
JKleinRot 16:c34c5d9dfe1a 439 }
JKleinRot 19:38c9d177b6ee 440
JKleinRot 25:71e52c56be13 441 case B: { //Tweede keuze maken voor doel
JKleinRot 17:c694a0e63a89 442 lcd.locate(0,0); //Zet tekst op eerste regel
JKleinRot 19:38c9d177b6ee 443 lcd.printf(" B "); //Tekst op LCD scherm
JKleinRot 17:c694a0e63a89 444 pc.printf("B\n\r"); //Controle naar pc sturen
JKleinRot 23:5267c928ae2b 445
JKleinRot 25:71e52c56be13 446 EMG.start(); //Timer aanzetten voor EMG meten
JKleinRot 23:5267c928ae2b 447
JKleinRot 25:71e52c56be13 448 while(EMG.read() <= 2) { //Timer nog geen drie seconden gemeten
JKleinRot 22:838a17065bc7 449 while(regelaar_EMG_flag != true); //Als geen flag opgestoken, dan niks doen, wel flag, dan uit de while loop en door naar volgende regel
JKleinRot 22:838a17065bc7 450 regelaar_EMG_flag = false; //Flag weer naar beneden, zodat deze straks weer omhoog kan
JKleinRot 23:5267c928ae2b 451
JKleinRot 25:71e52c56be13 452 EMG_meten(); //EMG meten van biceps en triceps
JKleinRot 22:838a17065bc7 453 }
JKleinRot 23:5267c928ae2b 454
JKleinRot 19:38c9d177b6ee 455 while(state == B) {
JKleinRot 19:38c9d177b6ee 456 while(regelaar_EMG_flag != true); //Als geen flag opgestoken, dan niks doen, wel flag, dan uit de while loop en door naar volgende regel
JKleinRot 19:38c9d177b6ee 457 regelaar_EMG_flag = false; //Flag weer naar beneden, zodat deze straks weer omhoog kan
JKleinRot 23:5267c928ae2b 458
JKleinRot 25:71e52c56be13 459 EMG_meten(); //EMG meten van biceps en triceps
JKleinRot 23:5267c928ae2b 460
JKleinRot 25:71e52c56be13 461 if(xbf >= xbt) { //Als de gefilterde EMG van de biceps groter is dan de ingestelde threshold
JKleinRot 19:38c9d177b6ee 462 state = BB; //Ga door naar state BB
JKleinRot 19:38c9d177b6ee 463 }
JKleinRot 21:f4e9f6c28de1 464 if(xtf>= xtt) { //Als de gefilterde EMG van de triceps groter is dan de ingestelde threshold
JKleinRot 19:38c9d177b6ee 465 state = BT; //Ga door naar state BT
JKleinRot 19:38c9d177b6ee 466 }
JKleinRot 19:38c9d177b6ee 467 }
JKleinRot 19:38c9d177b6ee 468 break; //Stop met alle acties in deze case
JKleinRot 19:38c9d177b6ee 469 }
JKleinRot 19:38c9d177b6ee 470
JKleinRot 25:71e52c56be13 471 case T: { //Tweede keuze maken voor doel
JKleinRot 19:38c9d177b6ee 472 lcd.locate(0,0); //Zet tekst op eerste regel
JKleinRot 19:38c9d177b6ee 473 lcd.printf(" T "); //Tekst op LCD scherm
JKleinRot 19:38c9d177b6ee 474 pc.printf("T\n\r"); //Controle naar pc sturen
JKleinRot 23:5267c928ae2b 475
JKleinRot 25:71e52c56be13 476 EMG.start(); //Timer aanzetten voor EMG meten
JKleinRot 23:5267c928ae2b 477
JKleinRot 25:71e52c56be13 478 while(EMG.read() <= 2) { //Timer nog geen drie seconden gemeten
JKleinRot 22:838a17065bc7 479 while(regelaar_EMG_flag != true); //Als geen flag opgestoken, dan niks doen, wel flag, dan uit de while loop en door naar volgende regel
JKleinRot 22:838a17065bc7 480 regelaar_EMG_flag = false; //Flag weer naar beneden, zodat deze straks weer omhoog kan
JKleinRot 23:5267c928ae2b 481
JKleinRot 25:71e52c56be13 482 EMG_meten(); //EMG meten van biceps en triceps
JKleinRot 22:838a17065bc7 483 }
JKleinRot 19:38c9d177b6ee 484
JKleinRot 19:38c9d177b6ee 485 while(state == T) {
JKleinRot 17:c694a0e63a89 486 while(regelaar_EMG_flag != true); //Als geen flag opgestoken, dan niks doen, wel flag, dan uit de while loop en door naar volgende regel
JKleinRot 17:c694a0e63a89 487 regelaar_EMG_flag = false; //Flag weer naar beneden, zodat deze straks weer omhoog kan
JKleinRot 15:3ebd0e666a9c 488
JKleinRot 25:71e52c56be13 489 EMG_meten(); //EMG meten van biceps en triceps
JKleinRot 16:c34c5d9dfe1a 490
JKleinRot 25:71e52c56be13 491 if(xbf >= xbt) { //Als de gefilterde EMG van de biceps groter is dan de ingestelde threshold
JKleinRot 19:38c9d177b6ee 492 state = TB; //Ga door naar state TB
JKleinRot 16:c34c5d9dfe1a 493 }
JKleinRot 25:71e52c56be13 494 if(xtf >= xtt) { //Als de gefilterde EMG van de triceps groter is dan de ingestelde threshold
JKleinRot 19:38c9d177b6ee 495 state = TT; //Ga door naar state TT
JKleinRot 16:c34c5d9dfe1a 496 }
JKleinRot 16:c34c5d9dfe1a 497 }
JKleinRot 17:c694a0e63a89 498 break; //Stop met alle acties in deze case
JKleinRot 16:c34c5d9dfe1a 499 }
JKleinRot 16:c34c5d9dfe1a 500
JKleinRot 25:71e52c56be13 501 case BB: { //Derde keuze maken voor doel
JKleinRot 17:c694a0e63a89 502 lcd.locate(0,0); //Zet tekst op eerste regel
JKleinRot 19:38c9d177b6ee 503 lcd.printf(" BB "); //Tekst op LCD scherm
JKleinRot 19:38c9d177b6ee 504 pc.printf("BB\n\r"); //Controle naar pc sturen
JKleinRot 23:5267c928ae2b 505
JKleinRot 25:71e52c56be13 506 EMG.reset(); //Timer resetten
JKleinRot 25:71e52c56be13 507 EMG.start(); //Timer aanzetten voor EMG meten
JKleinRot 23:5267c928ae2b 508
JKleinRot 25:71e52c56be13 509 while(EMG.read() <= 2) { //Timer nog geen drie seconden gemeten
JKleinRot 22:838a17065bc7 510 while(regelaar_EMG_flag != true); //Als geen flag opgestoken, dan niks doen, wel flag, dan uit de while loop en door naar volgende regel
JKleinRot 22:838a17065bc7 511 regelaar_EMG_flag = false; //Flag weer naar beneden, zodat deze straks weer omhoog kan
JKleinRot 23:5267c928ae2b 512
JKleinRot 25:71e52c56be13 513 EMG_meten(); //EMG meten van biceps en triceps
JKleinRot 22:838a17065bc7 514 }
JKleinRot 16:c34c5d9dfe1a 515
JKleinRot 19:38c9d177b6ee 516 while(state == BB) {
JKleinRot 17:c694a0e63a89 517 while(regelaar_EMG_flag != true); //Als geen flag opgestoken, dan niks doen, wel flag, dan uit de while loop en door naar volgende regel
JKleinRot 17:c694a0e63a89 518 regelaar_EMG_flag = false; //Flag weer naar beneden, zodat deze straks weer omhoog kan
JKleinRot 16:c34c5d9dfe1a 519
JKleinRot 25:71e52c56be13 520 EMG_meten(); //EMG meten van biceps en triceps
JKleinRot 16:c34c5d9dfe1a 521
JKleinRot 25:71e52c56be13 522 if(xbf >= xbt) { //Als de gefilterde EMG van de biceps groter is dan de ingestelde threshold
JKleinRot 19:38c9d177b6ee 523 state = BBB; //Ga door naar state BBB
JKleinRot 16:c34c5d9dfe1a 524 }
JKleinRot 25:71e52c56be13 525 if(xtf >= xtt) { //Als de gefilterde EMG van de triceps groter is dan de ingestelde threshold
JKleinRot 19:38c9d177b6ee 526 state = BBT; //Ga door naar state BBT
JKleinRot 16:c34c5d9dfe1a 527 }
JKleinRot 16:c34c5d9dfe1a 528 }
JKleinRot 17:c694a0e63a89 529 break; //Stop met alle acties in deze case
JKleinRot 16:c34c5d9dfe1a 530 }
JKleinRot 19:38c9d177b6ee 531
JKleinRot 25:71e52c56be13 532 case BT: { //Derde keuze maken voor doel
JKleinRot 17:c694a0e63a89 533 lcd.locate(0,0); //Zet tekst op eerste regel
JKleinRot 19:38c9d177b6ee 534 lcd.printf(" BT "); //Tekst op LCD scherm
JKleinRot 19:38c9d177b6ee 535 pc.printf("BT\n\r"); //Controle naar pc sturen
JKleinRot 23:5267c928ae2b 536
JKleinRot 25:71e52c56be13 537 EMG.reset(); //Timer resetten
JKleinRot 25:71e52c56be13 538 EMG.start(); //Timer aanzetten voor EMG meten
JKleinRot 23:5267c928ae2b 539
JKleinRot 25:71e52c56be13 540 while(EMG.read() <= 2) { //Timer nog geen drie seconden gemeten
JKleinRot 22:838a17065bc7 541 while(regelaar_EMG_flag != true); //Als geen flag opgestoken, dan niks doen, wel flag, dan uit de while loop en door naar volgende regel
JKleinRot 22:838a17065bc7 542 regelaar_EMG_flag = false; //Flag weer naar beneden, zodat deze straks weer omhoog kan
JKleinRot 23:5267c928ae2b 543
JKleinRot 25:71e52c56be13 544 EMG_meten(); //EMG meten van biceps en triceps
JKleinRot 22:838a17065bc7 545 }
JKleinRot 15:3ebd0e666a9c 546
JKleinRot 19:38c9d177b6ee 547 while(state == BT) {
JKleinRot 17:c694a0e63a89 548 while(regelaar_EMG_flag != true); //Als geen flag opgestoken, dan niks doen, wel flag, dan uit de while loop en door naar volgende regel
JKleinRot 17:c694a0e63a89 549 regelaar_EMG_flag = false; //Flag weer naar beneden, zodat deze straks weer omhoog kan
JKleinRot 15:3ebd0e666a9c 550
JKleinRot 22:838a17065bc7 551 EMG_meten();
JKleinRot 17:c694a0e63a89 552
JKleinRot 25:71e52c56be13 553 if(xbf >= xbt) { //Als de gefilterde EMG van de biceps groter is dan de ingestelde threshold
JKleinRot 19:38c9d177b6ee 554 state = BTB; //Ga door naar state BTB
JKleinRot 17:c694a0e63a89 555 }
JKleinRot 25:71e52c56be13 556 if(xtf >= xtt) { //Als de gefilterde EMG van de triceps groter is dan de ingestelde threshold
JKleinRot 19:38c9d177b6ee 557 state = BTT; //Ga door naar state BTT
JKleinRot 17:c694a0e63a89 558 }
JKleinRot 17:c694a0e63a89 559 }
JKleinRot 19:38c9d177b6ee 560 break; //Stop met alle acties in deze case
JKleinRot 17:c694a0e63a89 561 }
JKleinRot 19:38c9d177b6ee 562
JKleinRot 25:71e52c56be13 563 case TB: { //Derde keuze maken voor doel
JKleinRot 17:c694a0e63a89 564 lcd.locate(0,0); //Zet tekst op eerste regel
JKleinRot 19:38c9d177b6ee 565 lcd.printf(" TB "); //Tekst op LCD scherm
JKleinRot 19:38c9d177b6ee 566 pc.printf("TB\n\r"); //Controle naar pc sturen
JKleinRot 23:5267c928ae2b 567
JKleinRot 25:71e52c56be13 568 EMG.reset(); //Timer resetten
JKleinRot 25:71e52c56be13 569 EMG.start(); //Timer aanzetten voor EMG meten
JKleinRot 23:5267c928ae2b 570
JKleinRot 25:71e52c56be13 571 while(EMG.read() <= 2) { //Timer nog geen drie seconden gemeten
JKleinRot 22:838a17065bc7 572 while(regelaar_EMG_flag != true); //Als geen flag opgestoken, dan niks doen, wel flag, dan uit de while loop en door naar volgende regel
JKleinRot 22:838a17065bc7 573 regelaar_EMG_flag = false; //Flag weer naar beneden, zodat deze straks weer omhoog kan
JKleinRot 23:5267c928ae2b 574
JKleinRot 25:71e52c56be13 575 EMG_meten(); //EMG meten van biceps en triceps
JKleinRot 22:838a17065bc7 576 }
JKleinRot 17:c694a0e63a89 577
JKleinRot 19:38c9d177b6ee 578 while(state == TB) {
JKleinRot 17:c694a0e63a89 579 while(regelaar_EMG_flag != true); //Als geen flag opgestoken, dan niks doen, wel flag, dan uit de while loop en door naar volgende regel
JKleinRot 17:c694a0e63a89 580 regelaar_EMG_flag = false; //Flag weer naar beneden, zodat deze straks weer omhoog kan
JKleinRot 17:c694a0e63a89 581
JKleinRot 25:71e52c56be13 582 EMG_meten(); //EMG meten van biceps en triceps
JKleinRot 17:c694a0e63a89 583
JKleinRot 25:71e52c56be13 584 if(xbf >= xbt) { //Als de gefilterde EMG van de biceps groter is dan de ingestelde threshold
JKleinRot 19:38c9d177b6ee 585 state = TBB; //Ga door naar state TBB
JKleinRot 17:c694a0e63a89 586 }
JKleinRot 25:71e52c56be13 587 if(xtf >= xtt) { //Als de gefilterde EMG van de triceps groter is dan de ingestelde threshold
JKleinRot 19:38c9d177b6ee 588 state = TBT; //Ga door naar state TBT
JKleinRot 17:c694a0e63a89 589 }
JKleinRot 17:c694a0e63a89 590 }
JKleinRot 19:38c9d177b6ee 591 break; //Stop met alle acties in deze case
JKleinRot 19:38c9d177b6ee 592 }
JKleinRot 17:c694a0e63a89 593
JKleinRot 25:71e52c56be13 594 case TT: { //Derde keuze maken voor doel
JKleinRot 17:c694a0e63a89 595 lcd.locate(0,0); //Zet tekst op eerste regel
JKleinRot 19:38c9d177b6ee 596 lcd.printf(" TT "); //Tekst op LCD scherm
JKleinRot 19:38c9d177b6ee 597 pc.printf("TT\n\r"); //Controle naar pc sturen
JKleinRot 23:5267c928ae2b 598
JKleinRot 25:71e52c56be13 599 EMG.reset(); //Timer resetten
JKleinRot 25:71e52c56be13 600 EMG.start(); //Timer aanzetten voor EMG meten
JKleinRot 23:5267c928ae2b 601
JKleinRot 25:71e52c56be13 602 while(EMG.read() <= 2) { //Timer nog geen drie seconden gemeten
JKleinRot 22:838a17065bc7 603 while(regelaar_EMG_flag != true); //Als geen flag opgestoken, dan niks doen, wel flag, dan uit de while loop en door naar volgende regel
JKleinRot 22:838a17065bc7 604 regelaar_EMG_flag = false; //Flag weer naar beneden, zodat deze straks weer omhoog kan
JKleinRot 23:5267c928ae2b 605
JKleinRot 25:71e52c56be13 606 EMG_meten(); //EMG meten van biceps en triceps
JKleinRot 22:838a17065bc7 607 }
JKleinRot 17:c694a0e63a89 608
JKleinRot 19:38c9d177b6ee 609 while(state == TT) {
JKleinRot 17:c694a0e63a89 610 while(regelaar_EMG_flag != true); //Als geen flag opgestoken, dan niks doen, wel flag, dan uit de while loop en door naar volgende regel
JKleinRot 17:c694a0e63a89 611 regelaar_EMG_flag = false; //Flag weer naar beneden, zodat deze straks weer omhoog kan
JKleinRot 17:c694a0e63a89 612
JKleinRot 25:71e52c56be13 613 EMG_meten(); //EMG meten van biceps en triceps
JKleinRot 17:c694a0e63a89 614
JKleinRot 25:71e52c56be13 615 if(xbf >= xbt) { //Als de gefilterde EMG van de biceps groter is dan de ingestelde threshold
JKleinRot 19:38c9d177b6ee 616 state = TTB; //Ga door naar state TTB
JKleinRot 17:c694a0e63a89 617 }
JKleinRot 25:71e52c56be13 618 if(xtf >= xtt) { //Als de gefilterde EMG van de triceps groter is dan de ingestelde threshold
JKleinRot 19:38c9d177b6ee 619 state = TTT; //Ga door naar state TTT
JKleinRot 17:c694a0e63a89 620 }
JKleinRot 17:c694a0e63a89 621 }
JKleinRot 19:38c9d177b6ee 622 break; //Stop met alle acties in deze case
JKleinRot 17:c694a0e63a89 623 }
JKleinRot 19:38c9d177b6ee 624
JKleinRot 25:71e52c56be13 625 case BBB: { //Vierde keuze maken voor doel
JKleinRot 17:c694a0e63a89 626 lcd.locate(0,0); //Zet tekst op eerste regel
JKleinRot 19:38c9d177b6ee 627 lcd.printf(" BBB "); //Tekst op LCD scherm
JKleinRot 19:38c9d177b6ee 628 pc.printf("BBB\n\r"); //Controle naar pc sturen
JKleinRot 23:5267c928ae2b 629
JKleinRot 25:71e52c56be13 630 EMG.reset(); //Timer resetten
JKleinRot 25:71e52c56be13 631 EMG.start(); //Timer aanzetten voor EMG meten
JKleinRot 23:5267c928ae2b 632
JKleinRot 25:71e52c56be13 633 while(EMG.read() <= 2) { //Timer nog geen drie seconden gemeten
JKleinRot 22:838a17065bc7 634 while(regelaar_EMG_flag != true); //Als geen flag opgestoken, dan niks doen, wel flag, dan uit de while loop en door naar volgende regel
JKleinRot 22:838a17065bc7 635 regelaar_EMG_flag = false; //Flag weer naar beneden, zodat deze straks weer omhoog kan
JKleinRot 23:5267c928ae2b 636
JKleinRot 25:71e52c56be13 637 EMG_meten(); //EMG meten van biceps en triceps
JKleinRot 22:838a17065bc7 638 }
JKleinRot 17:c694a0e63a89 639
JKleinRot 19:38c9d177b6ee 640 while(state == BBB) {
JKleinRot 17:c694a0e63a89 641 while(regelaar_EMG_flag != true); //Als geen flag opgestoken, dan niks doen, wel flag, dan uit de while loop en door naar volgende regel
JKleinRot 17:c694a0e63a89 642 regelaar_EMG_flag = false; //Flag weer naar beneden, zodat deze straks weer omhoog kan
JKleinRot 17:c694a0e63a89 643
JKleinRot 25:71e52c56be13 644 EMG_meten(); //EMG meten van biceps en triceps
JKleinRot 17:c694a0e63a89 645
JKleinRot 25:71e52c56be13 646 if(xbf >= xbt) { //Als de gefilterde EMG van de biceps groter is dan de ingestelde threshold
JKleinRot 19:38c9d177b6ee 647 state = BBBB; //Ga door naar state BBBB
JKleinRot 17:c694a0e63a89 648 }
JKleinRot 25:71e52c56be13 649 if(xtf >= xtt) { //Als de gefilterde EMG van de triceps groter is dan de ingestelde threshold
JKleinRot 19:38c9d177b6ee 650 state = BBBT; //Ga door naar state BBBT
JKleinRot 17:c694a0e63a89 651 }
JKleinRot 17:c694a0e63a89 652 }
JKleinRot 19:38c9d177b6ee 653 break; //Stop met alle acties in deze case
JKleinRot 17:c694a0e63a89 654 }
JKleinRot 17:c694a0e63a89 655
JKleinRot 19:38c9d177b6ee 656
JKleinRot 25:71e52c56be13 657 case BBT: { //Vierde keuze maken in doel
JKleinRot 17:c694a0e63a89 658 lcd.locate(0,0); //Zet tekst op eerste regel
JKleinRot 19:38c9d177b6ee 659 lcd.printf(" BBT "); //Tekst op LCD scherm
JKleinRot 19:38c9d177b6ee 660 pc.printf("BBT\n\r"); //Controle naar pc sturen
JKleinRot 23:5267c928ae2b 661
JKleinRot 25:71e52c56be13 662 EMG.reset(); //Timer resetten
JKleinRot 25:71e52c56be13 663 EMG.start(); //Timer aanzetten voor EMG meten
JKleinRot 23:5267c928ae2b 664
JKleinRot 25:71e52c56be13 665 while(EMG.read() <= 2) { //Timer nog geen drie seconden gemeten
JKleinRot 22:838a17065bc7 666 while(regelaar_EMG_flag != true); //Als geen flag opgestoken, dan niks doen, wel flag, dan uit de while loop en door naar volgende regel
JKleinRot 22:838a17065bc7 667 regelaar_EMG_flag = false; //Flag weer naar beneden, zodat deze straks weer omhoog kan
JKleinRot 23:5267c928ae2b 668
JKleinRot 25:71e52c56be13 669 EMG_meten(); //EMG meten van biceps en triceps
JKleinRot 22:838a17065bc7 670 }
JKleinRot 17:c694a0e63a89 671
JKleinRot 19:38c9d177b6ee 672 while(state == BBT) {
JKleinRot 17:c694a0e63a89 673 while(regelaar_EMG_flag != true); //Als geen flag opgestoken, dan niks doen, wel flag, dan uit de while loop en door naar volgende regel
JKleinRot 17:c694a0e63a89 674 regelaar_EMG_flag = false; //Flag weer naar beneden, zodat deze straks weer omhoog kan
JKleinRot 17:c694a0e63a89 675
JKleinRot 25:71e52c56be13 676 EMG_meten(); //EMG meten van biceps en triceps
JKleinRot 17:c694a0e63a89 677
JKleinRot 25:71e52c56be13 678 if(xbf >= xbt) { //Als de gefilterde EMG van de biceps groter is dan de ingestelde threshold
JKleinRot 19:38c9d177b6ee 679 state = BBTB; //Ga door naar state BBTB
JKleinRot 17:c694a0e63a89 680 }
JKleinRot 25:71e52c56be13 681 if(xtf >= xtt) { //Als de gefilterde EMG van de triceps groter is dan de ingestelde threshold
JKleinRot 19:38c9d177b6ee 682 state = BBTT; //Ga door naar state BBTT
JKleinRot 17:c694a0e63a89 683 }
JKleinRot 17:c694a0e63a89 684 }
JKleinRot 19:38c9d177b6ee 685 break; //Stop met alle acties in deze case
JKleinRot 17:c694a0e63a89 686 }
JKleinRot 19:38c9d177b6ee 687
JKleinRot 25:71e52c56be13 688 case BTB: { //Vierde keuze maken voor doel
JKleinRot 17:c694a0e63a89 689 lcd.locate(0,0); //Zet tekst op eerste regel
JKleinRot 19:38c9d177b6ee 690 lcd.printf(" BTB "); //Tekst op LCD scherm
JKleinRot 19:38c9d177b6ee 691 pc.printf("BTB\n\r"); //Controle naar pc sturen
JKleinRot 23:5267c928ae2b 692
JKleinRot 25:71e52c56be13 693 EMG.reset(); //Timer resetten
JKleinRot 25:71e52c56be13 694 EMG.start(); //Timer aanzetten voor EMG meten
JKleinRot 23:5267c928ae2b 695
JKleinRot 25:71e52c56be13 696 while(EMG.read() <= 2) { //Timer nog geen drie seconden gemeten
JKleinRot 22:838a17065bc7 697 while(regelaar_EMG_flag != true); //Als geen flag opgestoken, dan niks doen, wel flag, dan uit de while loop en door naar volgende regel
JKleinRot 22:838a17065bc7 698 regelaar_EMG_flag = false; //Flag weer naar beneden, zodat deze straks weer omhoog kan
JKleinRot 23:5267c928ae2b 699
JKleinRot 25:71e52c56be13 700 EMG_meten(); //EMG meten van biceps en triceps
JKleinRot 22:838a17065bc7 701 }
JKleinRot 17:c694a0e63a89 702
JKleinRot 19:38c9d177b6ee 703 while(state == BTB) {
JKleinRot 17:c694a0e63a89 704 while(regelaar_EMG_flag != true); //Als geen flag opgestoken, dan niks doen, wel flag, dan uit de while loop en door naar volgende regel
JKleinRot 17:c694a0e63a89 705 regelaar_EMG_flag = false; //Flag weer naar beneden, zodat deze straks weer omhoog kan
JKleinRot 17:c694a0e63a89 706
JKleinRot 25:71e52c56be13 707 EMG_meten(); //EMG meten van biceps en triceps
JKleinRot 17:c694a0e63a89 708
JKleinRot 25:71e52c56be13 709 if(xbf >= xbt) { //Als de gefilterde EMG van de biceps groter is dan de ingestelde threshold
JKleinRot 19:38c9d177b6ee 710 state = BTBB; //Ga door naar state BTBB
JKleinRot 17:c694a0e63a89 711 }
JKleinRot 25:71e52c56be13 712 if(xtf >= xtt) { //Als de gefilterde EMG van de triceps groter is dan de ingestelde threshold
JKleinRot 19:38c9d177b6ee 713 state = BTBT; //Ga door naar state BTBT
JKleinRot 17:c694a0e63a89 714 }
JKleinRot 17:c694a0e63a89 715 }
JKleinRot 19:38c9d177b6ee 716 break; //Stop met alle acties in deze case
JKleinRot 17:c694a0e63a89 717 }
JKleinRot 19:38c9d177b6ee 718
JKleinRot 25:71e52c56be13 719 case BTT: { //Vierde keuze maken voor doel
JKleinRot 17:c694a0e63a89 720 lcd.locate(0,0); //Zet tekst op eerste regel
JKleinRot 19:38c9d177b6ee 721 lcd.printf(" BTT "); //Tekst op LCD scherm
JKleinRot 19:38c9d177b6ee 722 pc.printf("BTT\n\r"); //Controle naar pc sturen
JKleinRot 23:5267c928ae2b 723
JKleinRot 25:71e52c56be13 724 EMG.reset(); //Timer resetten
JKleinRot 25:71e52c56be13 725 EMG.start(); //Timer aanzetten voor EMG meten
JKleinRot 23:5267c928ae2b 726
JKleinRot 25:71e52c56be13 727 while(EMG.read() <= 2) { //Timer nog geen drie seconden gemeten
JKleinRot 22:838a17065bc7 728 while(regelaar_EMG_flag != true); //Als geen flag opgestoken, dan niks doen, wel flag, dan uit de while loop en door naar volgende regel
JKleinRot 22:838a17065bc7 729 regelaar_EMG_flag = false; //Flag weer naar beneden, zodat deze straks weer omhoog kan
JKleinRot 23:5267c928ae2b 730
JKleinRot 25:71e52c56be13 731 EMG_meten(); //EMG meten van biceps en triceps
JKleinRot 22:838a17065bc7 732 }
JKleinRot 17:c694a0e63a89 733
JKleinRot 19:38c9d177b6ee 734 while(state == BTT) {
JKleinRot 17:c694a0e63a89 735 while(regelaar_EMG_flag != true); //Als geen flag opgestoken, dan niks doen, wel flag, dan uit de while loop en door naar volgende regel
JKleinRot 17:c694a0e63a89 736 regelaar_EMG_flag = false; //Flag weer naar beneden, zodat deze straks weer omhoog kan
JKleinRot 17:c694a0e63a89 737
JKleinRot 25:71e52c56be13 738 EMG_meten(); //EMG meten van biceps en triceps
JKleinRot 17:c694a0e63a89 739
JKleinRot 25:71e52c56be13 740 if(xbf >= xbt) { //Als de gefilterde EMG van de biceps groter is dan de ingestelde threshold
JKleinRot 19:38c9d177b6ee 741 state = BTTB; //Ga door naar state BTTB
JKleinRot 17:c694a0e63a89 742 }
JKleinRot 25:71e52c56be13 743 if(xtf >= xtt) { //Als de gefilterde EMG van de triceps groter is dan de ingestelde threshold
JKleinRot 19:38c9d177b6ee 744 state = BTTT; //Ga door naar state BTTT
JKleinRot 17:c694a0e63a89 745 }
JKleinRot 17:c694a0e63a89 746 }
JKleinRot 19:38c9d177b6ee 747 break; //Stop met alle acties in deze case
JKleinRot 19:38c9d177b6ee 748 }
JKleinRot 19:38c9d177b6ee 749
JKleinRot 25:71e52c56be13 750 case TBB: { //Vierde keuze maken voor doel
JKleinRot 17:c694a0e63a89 751 lcd.locate(0,0); //Zet tekst op eerste regel
JKleinRot 19:38c9d177b6ee 752 lcd.printf(" TBB "); //Tekst op LCD scherm
JKleinRot 19:38c9d177b6ee 753 pc.printf("TBB\n\r"); //Controle naar pc sturen
JKleinRot 23:5267c928ae2b 754
JKleinRot 25:71e52c56be13 755 EMG.reset(); //Timer resetten
JKleinRot 25:71e52c56be13 756 EMG.start(); //Timer aanzetten voor EMG meten
JKleinRot 23:5267c928ae2b 757
JKleinRot 25:71e52c56be13 758 while(EMG.read() <= 2) { //Timer nog geen drie seconden gemeten
JKleinRot 22:838a17065bc7 759 while(regelaar_EMG_flag != true); //Als geen flag opgestoken, dan niks doen, wel flag, dan uit de while loop en door naar volgende regel
JKleinRot 22:838a17065bc7 760 regelaar_EMG_flag = false; //Flag weer naar beneden, zodat deze straks weer omhoog kan
JKleinRot 23:5267c928ae2b 761
JKleinRot 25:71e52c56be13 762 EMG_meten(); //EMG meten van biceps en triceps
JKleinRot 22:838a17065bc7 763 }
JKleinRot 17:c694a0e63a89 764
JKleinRot 19:38c9d177b6ee 765 while(state == TBB) {
JKleinRot 17:c694a0e63a89 766 while(regelaar_EMG_flag != true); //Als geen flag opgestoken, dan niks doen, wel flag, dan uit de while loop en door naar volgende regel
JKleinRot 17:c694a0e63a89 767 regelaar_EMG_flag = false; //Flag weer naar beneden, zodat deze straks weer omhoog kan
JKleinRot 17:c694a0e63a89 768
JKleinRot 25:71e52c56be13 769 EMG_meten(); //EMG meten van biceps en triceps
JKleinRot 17:c694a0e63a89 770
JKleinRot 25:71e52c56be13 771 if(xbf >= xbt) { //Als de gefilterde EMG van de biceps groter is dan de ingestelde threshold
JKleinRot 19:38c9d177b6ee 772 state = TBBB; //Ga door naar state TBBB
JKleinRot 17:c694a0e63a89 773 }
JKleinRot 25:71e52c56be13 774 if(xtf >= xtt) { //Als de gefilterde EMG van de triceps groter is dan de ingestelde threshold
JKleinRot 19:38c9d177b6ee 775 state = TBBT; //Ga door naar state TBBT
JKleinRot 17:c694a0e63a89 776 }
JKleinRot 17:c694a0e63a89 777 }
JKleinRot 19:38c9d177b6ee 778 break; //Stop met alle acties in deze case
JKleinRot 17:c694a0e63a89 779 }
JKleinRot 19:38c9d177b6ee 780
JKleinRot 25:71e52c56be13 781 case TBT: { //Vierde keuze maken voor doel
JKleinRot 17:c694a0e63a89 782 lcd.locate(0,0); //Zet tekst op eerste regel
JKleinRot 19:38c9d177b6ee 783 lcd.printf(" TBT "); //Tekst op LCD scherm
JKleinRot 19:38c9d177b6ee 784 pc.printf("TBT\n\r"); //Controle naar pc sturen
JKleinRot 23:5267c928ae2b 785
JKleinRot 25:71e52c56be13 786 EMG.reset(); //Timer resetten
JKleinRot 25:71e52c56be13 787 EMG.start(); //Timer aanzetten voor EMG meten
JKleinRot 23:5267c928ae2b 788
JKleinRot 25:71e52c56be13 789 while(EMG.read() <= 2) { //Timer nog geen drie seconden gemeten
JKleinRot 22:838a17065bc7 790 while(regelaar_EMG_flag != true); //Als geen flag opgestoken, dan niks doen, wel flag, dan uit de while loop en door naar volgende regel
JKleinRot 22:838a17065bc7 791 regelaar_EMG_flag = false; //Flag weer naar beneden, zodat deze straks weer omhoog kan
JKleinRot 23:5267c928ae2b 792
JKleinRot 25:71e52c56be13 793 EMG_meten(); //EMG meten van biceps en triceps
JKleinRot 22:838a17065bc7 794 }
JKleinRot 17:c694a0e63a89 795
JKleinRot 19:38c9d177b6ee 796 while(state == TBT) {
JKleinRot 17:c694a0e63a89 797 while(regelaar_EMG_flag != true); //Als geen flag opgestoken, dan niks doen, wel flag, dan uit de while loop en door naar volgende regel
JKleinRot 17:c694a0e63a89 798 regelaar_EMG_flag = false; //Flag weer naar beneden, zodat deze straks weer omhoog kan
JKleinRot 17:c694a0e63a89 799
JKleinRot 25:71e52c56be13 800 EMG_meten(); //EMG meten van biceps en triceps
JKleinRot 17:c694a0e63a89 801
JKleinRot 21:f4e9f6c28de1 802 if(xbf >= xbt) { //Als de gefilterde EMG van de biceps groter is dan de ingestelde threshold
JKleinRot 19:38c9d177b6ee 803 state = TBTB; //Ga door naar state TBTB
JKleinRot 17:c694a0e63a89 804 }
JKleinRot 21:f4e9f6c28de1 805 if(xtf >= xtt) { //Als de gefilterde EMG van de triceps groter is dan de ingestelde threshold
JKleinRot 19:38c9d177b6ee 806 state = TBTT; //Ga door naar state TBTT
JKleinRot 17:c694a0e63a89 807 }
JKleinRot 17:c694a0e63a89 808 }
JKleinRot 19:38c9d177b6ee 809 break; //Stop met alle acties in deze case
JKleinRot 17:c694a0e63a89 810 }
JKleinRot 19:38c9d177b6ee 811
JKleinRot 25:71e52c56be13 812 case TTB: { //Vierde keuze maken voor doel
JKleinRot 17:c694a0e63a89 813 lcd.locate(0,0); //Zet tekst op eerste regel
JKleinRot 22:838a17065bc7 814 lcd.printf(" TTB "); //Tekst op LCD scherm
JKleinRot 22:838a17065bc7 815 pc.printf("TTB\n\r"); //Controle naar pc sturen
JKleinRot 23:5267c928ae2b 816
JKleinRot 25:71e52c56be13 817 EMG.reset(); //Timer resetten
JKleinRot 25:71e52c56be13 818 EMG.start(); //Timer aanzetten voor EMG meten
JKleinRot 23:5267c928ae2b 819
JKleinRot 25:71e52c56be13 820 while(EMG.read() <= 2) { //Timer nog geen drie seconden gemeten
JKleinRot 22:838a17065bc7 821 while(regelaar_EMG_flag != true); //Als geen flag opgestoken, dan niks doen, wel flag, dan uit de while loop en door naar volgende regel
JKleinRot 22:838a17065bc7 822 regelaar_EMG_flag = false; //Flag weer naar beneden, zodat deze straks weer omhoog kan
JKleinRot 23:5267c928ae2b 823
JKleinRot 25:71e52c56be13 824 EMG_meten(); //EMG meten van biceps en triceps
JKleinRot 22:838a17065bc7 825 }
JKleinRot 17:c694a0e63a89 826
JKleinRot 22:838a17065bc7 827 while(state == TTB) {
JKleinRot 17:c694a0e63a89 828 while(regelaar_EMG_flag != true); //Als geen flag opgestoken, dan niks doen, wel flag, dan uit de while loop en door naar volgende regel
JKleinRot 17:c694a0e63a89 829 regelaar_EMG_flag = false; //Flag weer naar beneden, zodat deze straks weer omhoog kan
JKleinRot 17:c694a0e63a89 830
JKleinRot 25:71e52c56be13 831 EMG_meten(); //EMG meten van biceps en triceps
JKleinRot 17:c694a0e63a89 832
JKleinRot 21:f4e9f6c28de1 833 if(xbf >= xbt) { //Als de gefilterde EMG van de biceps groter is dan de ingestelde threshold
JKleinRot 17:c694a0e63a89 834 state = TTBB; //Ga door naar state TTBB
JKleinRot 17:c694a0e63a89 835 }
JKleinRot 21:f4e9f6c28de1 836 if(xtf >= xtt) { //Als de gefilterde EMG van de triceps groter is dan de ingestelde threshold
JKleinRot 17:c694a0e63a89 837 state = TTBT; //Ga door naar state TTBT
JKleinRot 17:c694a0e63a89 838 }
JKleinRot 17:c694a0e63a89 839 }
JKleinRot 19:38c9d177b6ee 840 break; //Stop met alle acties in deze case
JKleinRot 19:38c9d177b6ee 841 }
JKleinRot 19:38c9d177b6ee 842
JKleinRot 25:71e52c56be13 843 case TTT: { //Vierde keuze maken voor doel
JKleinRot 17:c694a0e63a89 844 lcd.locate(0,0); //Zet tekst op eerste regel
JKleinRot 17:c694a0e63a89 845 lcd.printf(" TTT "); //Tekst op LCD scherm
JKleinRot 17:c694a0e63a89 846 pc.printf("TTT\n\r"); //Controle naar pc sturen
JKleinRot 23:5267c928ae2b 847
JKleinRot 25:71e52c56be13 848 EMG.reset(); //Timer resetten
JKleinRot 25:71e52c56be13 849 EMG.start(); //Timer aanzetten voor EMG meten
JKleinRot 23:5267c928ae2b 850
JKleinRot 25:71e52c56be13 851 while(EMG.read() <= 2) { //Timer nog geen drie seconden gemeten
JKleinRot 22:838a17065bc7 852 while(regelaar_EMG_flag != true); //Als geen flag opgestoken, dan niks doen, wel flag, dan uit de while loop en door naar volgende regel
JKleinRot 22:838a17065bc7 853 regelaar_EMG_flag = false; //Flag weer naar beneden, zodat deze straks weer omhoog kan
JKleinRot 23:5267c928ae2b 854
JKleinRot 25:71e52c56be13 855 EMG_meten(); //EMG meten van biceps en triceps
JKleinRot 22:838a17065bc7 856 }
JKleinRot 17:c694a0e63a89 857
JKleinRot 19:38c9d177b6ee 858 while(state == TTT) {
JKleinRot 17:c694a0e63a89 859 while(regelaar_EMG_flag != true); //Als geen flag opgestoken, dan niks doen, wel flag, dan uit de while loop en door naar volgende regel
JKleinRot 17:c694a0e63a89 860 regelaar_EMG_flag = false; //Flag weer naar beneden, zodat deze straks weer omhoog kan
JKleinRot 17:c694a0e63a89 861
JKleinRot 25:71e52c56be13 862 EMG_meten(); //EMG meten van biceps en triceps
JKleinRot 17:c694a0e63a89 863
JKleinRot 21:f4e9f6c28de1 864 if(xbf >= xbt) { //Als de gefilterde EMG van de biceps groter is dan de ingestelde threshold
JKleinRot 17:c694a0e63a89 865 state = TTTB; //Ga door naar state TTTB
JKleinRot 17:c694a0e63a89 866 }
JKleinRot 21:f4e9f6c28de1 867 if(xtf >= xtt) { //Als de gefilterde EMG van de triceps groter is dan de ingestelde threshold
JKleinRot 17:c694a0e63a89 868 state = TTTT; //Ga door naar state TTTT
JKleinRot 17:c694a0e63a89 869 }
JKleinRot 17:c694a0e63a89 870 }
JKleinRot 19:38c9d177b6ee 871 break; //Stop met alle acties in deze case
JKleinRot 17:c694a0e63a89 872 }
JKleinRot 19:38c9d177b6ee 873
JKleinRot 25:71e52c56be13 874 case BBBB: { //Motoraansturing voor doel rechtsonder
JKleinRot 17:c694a0e63a89 875 lcd.locate(0,0); //Zet tekst op eerste regel
JKleinRot 17:c694a0e63a89 876 lcd.printf(" BBBB "); //Tekst op LCD scherm
JKleinRot 17:c694a0e63a89 877 pc.printf("BBBB\n\r"); //Controle naar pc sturen
JKleinRot 17:c694a0e63a89 878
JKleinRot 19:38c9d177b6ee 879 while(state == BBBB) {
JKleinRot 25:71e52c56be13 880 while(regelaar_ticker_flag != true); //Als geen flag opgestoken, dan niks doen, wel flag, dan uit de while loop en door naar volgende regel
JKleinRot 25:71e52c56be13 881 regelaar_ticker_flag = false; //Flag weer naar beneden, zodat deze straks weer omhoog kan
JKleinRot 25:71e52c56be13 882
JKleinRot 25:71e52c56be13 883 while(puls_motor_arm1.getPosition() > -84) {
JKleinRot 25:71e52c56be13 884 referentie_arm1 = referentie_arm1 - 264.0/200.0;
JKleinRot 25:71e52c56be13 885 pc.printf("referentie arm 1 %f ", referentie_arm1);
JKleinRot 25:71e52c56be13 886 pc.printf("get position 1 %d ", puls_motor_arm1.getPosition());
JKleinRot 25:71e52c56be13 887 pc.printf("pwm motor 1 %f\n\r", pwm_to_motor_arm1);
JKleinRot 25:71e52c56be13 888 }
JKleinRot 25:71e52c56be13 889 pc.printf("arm 1 op positie");
JKleinRot 25:71e52c56be13 890
JKleinRot 25:71e52c56be13 891 while(puls_motor_arm2.getPosition() < 211) {
JKleinRot 25:71e52c56be13 892 referentie_arm2 = referentie_arm2 + 88.0/200.0;
JKleinRot 25:71e52c56be13 893 pc.printf("referentie arm 2 %f ", referentie_arm2);
JKleinRot 25:71e52c56be13 894 pc.printf("get position 2 %d ", puls_motor_arm2.getPosition());
JKleinRot 25:71e52c56be13 895 pc.printf("pwm motor 2 %f\n\r", pwm_to_motor_arm2);
JKleinRot 25:71e52c56be13 896 }
JKleinRot 25:71e52c56be13 897 pc.printf("arm2 op positie");
JKleinRot 25:71e52c56be13 898
JKleinRot 25:71e52c56be13 899 while(puls_motor_arm2.getPosition() > 36) {
JKleinRot 25:71e52c56be13 900
JKleinRot 25:71e52c56be13 901 referentie_arm2 = -0.5 * 100000 * t * t;
JKleinRot 25:71e52c56be13 902 t = t + 0.005;
JKleinRot 25:71e52c56be13 903
JKleinRot 25:71e52c56be13 904 pc.printf("referentie arm 2 %f ", referentie_arm2);
JKleinRot 25:71e52c56be13 905 pc.printf("get position %d ", puls_motor_arm2.getPosition());
JKleinRot 25:71e52c56be13 906 pc.printf("pwm motor 2 %f", pwm_to_motor_arm2);
JKleinRot 25:71e52c56be13 907 pc.printf("t is %f\n\r", t);
JKleinRot 25:71e52c56be13 908 }
JKleinRot 25:71e52c56be13 909
JKleinRot 25:71e52c56be13 910 if(puls_motor_arm2.getPosition() <= 36) {
JKleinRot 25:71e52c56be13 911 wait(1);
JKleinRot 25:71e52c56be13 912 while(puls_motor_arm2.getPosition() < 211) {
JKleinRot 25:71e52c56be13 913 referentie_arm2 = referentie_arm2 + 175.0/200.0;
JKleinRot 25:71e52c56be13 914
JKleinRot 25:71e52c56be13 915 pc.printf("referentie arm 2 %f ", referentie_arm2);
JKleinRot 25:71e52c56be13 916 pc.printf("get position %d ", puls_motor_arm2.getPosition());
JKleinRot 25:71e52c56be13 917 pc.printf("pwm motor 2 %f\n\r ", pwm_to_motor_arm2);
JKleinRot 25:71e52c56be13 918 }
JKleinRot 25:71e52c56be13 919
JKleinRot 25:71e52c56be13 920 if(puls_motor_arm2.getPosition() >= 211) {
JKleinRot 25:71e52c56be13 921 pc.printf("staat stil\n\r");
JKleinRot 25:71e52c56be13 922 state = THUISPOSITIE_RECHTS;
JKleinRot 25:71e52c56be13 923 }
JKleinRot 25:71e52c56be13 924 }
JKleinRot 19:38c9d177b6ee 925 }
JKleinRot 19:38c9d177b6ee 926 break; //Stop met alle acties in deze case
JKleinRot 19:38c9d177b6ee 927 }
JKleinRot 19:38c9d177b6ee 928
JKleinRot 25:71e52c56be13 929 case BBBT: { //Geen motoraansturing
JKleinRot 17:c694a0e63a89 930 lcd.locate(0,0); //Zet tekst op eerste regel
JKleinRot 17:c694a0e63a89 931 lcd.printf(" BBBT "); //Tekst op LCD scherm
JKleinRot 17:c694a0e63a89 932 pc.printf("BBBT\n\r"); //Controle naar pc sturen
JKleinRot 17:c694a0e63a89 933
JKleinRot 19:38c9d177b6ee 934 while(state == BBBT) {
JKleinRot 25:71e52c56be13 935 lcd.printf(" GEEN DOEL ");
JKleinRot 25:71e52c56be13 936 wait(1);
JKleinRot 25:71e52c56be13 937 state = WACHT;
JKleinRot 19:38c9d177b6ee 938 }
JKleinRot 19:38c9d177b6ee 939 break; //Stop met alle acties in deze case
JKleinRot 17:c694a0e63a89 940 }
JKleinRot 19:38c9d177b6ee 941
JKleinRot 25:71e52c56be13 942 case BBTB: { //Motoraansturing voor doel rechtsmidden
JKleinRot 17:c694a0e63a89 943 lcd.locate(0,0); //Zet tekst op eerste regel
JKleinRot 17:c694a0e63a89 944 lcd.printf(" BBTB "); //Tekst op LCD scherm
JKleinRot 17:c694a0e63a89 945 pc.printf("BBTB\n\r"); //Controle naar pc sturen
JKleinRot 17:c694a0e63a89 946
JKleinRot 19:38c9d177b6ee 947 while(state == BBTB) {
JKleinRot 25:71e52c56be13 948 while(regelaar_ticker_flag != true); //Als geen flag opgestoken, dan niks doen, wel flag, dan uit de while loop en door naar volgende regel
JKleinRot 25:71e52c56be13 949 regelaar_ticker_flag = false; //Flag weer naar beneden, zodat deze straks weer omhoog kan
JKleinRot 25:71e52c56be13 950
JKleinRot 25:71e52c56be13 951 while(puls_motor_arm1.getPosition() > -84) {
JKleinRot 25:71e52c56be13 952 referentie_arm1 = referentie_arm1 - 264.0/200.0;
JKleinRot 25:71e52c56be13 953 pc.printf("referentie arm 1 %f ", referentie_arm1);
JKleinRot 25:71e52c56be13 954 pc.printf("get position 1 %d ", puls_motor_arm1.getPosition());
JKleinRot 25:71e52c56be13 955 pc.printf("pwm motor 1 %f\n\r", pwm_to_motor_arm1);
JKleinRot 25:71e52c56be13 956 }
JKleinRot 25:71e52c56be13 957 pc.printf("arm 1 op positie");
JKleinRot 25:71e52c56be13 958
JKleinRot 25:71e52c56be13 959 while(puls_motor_arm2.getPosition() < 211) {
JKleinRot 25:71e52c56be13 960 referentie_arm2 = referentie_arm2 + 88.0/200.0;
JKleinRot 25:71e52c56be13 961 pc.printf("referentie arm 2 %f ", referentie_arm2);
JKleinRot 25:71e52c56be13 962 pc.printf("get position 2 %d ", puls_motor_arm2.getPosition());
JKleinRot 25:71e52c56be13 963 pc.printf("pwm motor 2 %f\n\r", pwm_to_motor_arm2);
JKleinRot 25:71e52c56be13 964 }
JKleinRot 25:71e52c56be13 965 pc.printf("arm2 op positie");
JKleinRot 25:71e52c56be13 966
JKleinRot 25:71e52c56be13 967
JKleinRot 25:71e52c56be13 968
JKleinRot 25:71e52c56be13 969 while(puls_motor_arm2.getPosition() > 36) {
JKleinRot 25:71e52c56be13 970
JKleinRot 25:71e52c56be13 971 referentie_arm2 = -0.5 * 150000 * t * t;
JKleinRot 25:71e52c56be13 972 t = t + 0.005;
JKleinRot 25:71e52c56be13 973
JKleinRot 25:71e52c56be13 974 pc.printf("referentie arm 2 %f ", referentie_arm2);
JKleinRot 25:71e52c56be13 975 pc.printf("get position %d ", puls_motor_arm2.getPosition());
JKleinRot 25:71e52c56be13 976 pc.printf("pwm motor 2 %f", pwm_to_motor_arm2);
JKleinRot 25:71e52c56be13 977 pc.printf("t is %f\n\r", t);
JKleinRot 25:71e52c56be13 978 }
JKleinRot 25:71e52c56be13 979
JKleinRot 25:71e52c56be13 980 if(puls_motor_arm2.getPosition() <= 36) {
JKleinRot 25:71e52c56be13 981 wait(1);
JKleinRot 25:71e52c56be13 982 while(puls_motor_arm2.getPosition() < 211) {
JKleinRot 25:71e52c56be13 983 referentie_arm2 = referentie_arm2 + 175.0/200.0;
JKleinRot 25:71e52c56be13 984
JKleinRot 25:71e52c56be13 985 pc.printf("referentie arm 2 %f ", referentie_arm2);
JKleinRot 25:71e52c56be13 986 pc.printf("get position %d ", puls_motor_arm2.getPosition());
JKleinRot 25:71e52c56be13 987 pc.printf("pwm motor 2 %f\n\r ", pwm_to_motor_arm2);
JKleinRot 25:71e52c56be13 988 }
JKleinRot 25:71e52c56be13 989
JKleinRot 25:71e52c56be13 990 if(puls_motor_arm2.getPosition() >= 211) {
JKleinRot 25:71e52c56be13 991 pc.printf("staat stil\n\r");
JKleinRot 25:71e52c56be13 992 state = THUISPOSITIE_RECHTS;
JKleinRot 25:71e52c56be13 993 }
JKleinRot 25:71e52c56be13 994 }
JKleinRot 19:38c9d177b6ee 995 }
JKleinRot 19:38c9d177b6ee 996 break; //Stop met alle acties in deze case
JKleinRot 17:c694a0e63a89 997 }
JKleinRot 19:38c9d177b6ee 998
JKleinRot 25:71e52c56be13 999 case BBTT: { //Motoraansturing voor doel rechtsboven
JKleinRot 17:c694a0e63a89 1000 lcd.locate(0,0); //Zet tekst op eerste regel
JKleinRot 17:c694a0e63a89 1001 lcd.printf(" BBTT "); //Tekst op LCD scherm
JKleinRot 17:c694a0e63a89 1002 pc.printf("BBTT\n\r"); //Controle naar pc sturen
JKleinRot 17:c694a0e63a89 1003
JKleinRot 19:38c9d177b6ee 1004 while(state == BBTT) {
JKleinRot 25:71e52c56be13 1005 while(regelaar_ticker_flag != true); //Als geen flag opgestoken, dan niks doen, wel flag, dan uit de while loop en door naar volgende regel
JKleinRot 25:71e52c56be13 1006 regelaar_ticker_flag = false; //Flag weer naar beneden, zodat deze straks weer omhoog kan
JKleinRot 25:71e52c56be13 1007
JKleinRot 25:71e52c56be13 1008 while(puls_motor_arm1.getPosition() > -84) {
JKleinRot 25:71e52c56be13 1009 referentie_arm1 = referentie_arm1 - 264.0/200.0;
JKleinRot 25:71e52c56be13 1010 pc.printf("referentie arm 1 %f ", referentie_arm1);
JKleinRot 25:71e52c56be13 1011 pc.printf("get position 1 %d ", puls_motor_arm1.getPosition());
JKleinRot 25:71e52c56be13 1012 pc.printf("pwm motor 1 %f\n\r", pwm_to_motor_arm1);
JKleinRot 25:71e52c56be13 1013 }
JKleinRot 25:71e52c56be13 1014 pc.printf("arm 1 op positie");
JKleinRot 25:71e52c56be13 1015
JKleinRot 25:71e52c56be13 1016 while(puls_motor_arm2.getPosition() < 211) {
JKleinRot 25:71e52c56be13 1017 referentie_arm2 = referentie_arm2 + 88.0/200.0;
JKleinRot 25:71e52c56be13 1018 pc.printf("referentie arm 2 %f ", referentie_arm2);
JKleinRot 25:71e52c56be13 1019 pc.printf("get position 2 %d ", puls_motor_arm2.getPosition());
JKleinRot 25:71e52c56be13 1020 pc.printf("pwm motor 2 %f\n\r", pwm_to_motor_arm2);
JKleinRot 25:71e52c56be13 1021 }
JKleinRot 25:71e52c56be13 1022 pc.printf("arm2 op positie");
JKleinRot 25:71e52c56be13 1023
JKleinRot 25:71e52c56be13 1024 while(puls_motor_arm2.getPosition() > 36) {
JKleinRot 25:71e52c56be13 1025
JKleinRot 25:71e52c56be13 1026 referentie_arm2 = -0.5 * 200000 * t * t;
JKleinRot 25:71e52c56be13 1027 t = t + 0.005;
JKleinRot 25:71e52c56be13 1028
JKleinRot 25:71e52c56be13 1029 pc.printf("referentie arm 2 %f ", referentie_arm2);
JKleinRot 25:71e52c56be13 1030 pc.printf("get position %d ", puls_motor_arm2.getPosition());
JKleinRot 25:71e52c56be13 1031 pc.printf("pwm motor 2 %f", pwm_to_motor_arm2);
JKleinRot 25:71e52c56be13 1032 pc.printf("t is %f\n\r", t);
JKleinRot 25:71e52c56be13 1033 }
JKleinRot 25:71e52c56be13 1034
JKleinRot 25:71e52c56be13 1035 if(puls_motor_arm2.getPosition() <= 36) {
JKleinRot 25:71e52c56be13 1036 wait(1);
JKleinRot 25:71e52c56be13 1037 while(puls_motor_arm2.getPosition() < 211) {
JKleinRot 25:71e52c56be13 1038 referentie_arm2 = referentie_arm2 + 175.0/200.0;
JKleinRot 25:71e52c56be13 1039
JKleinRot 25:71e52c56be13 1040 pc.printf("referentie arm 2 %f ", referentie_arm2);
JKleinRot 25:71e52c56be13 1041 pc.printf("get position %d ", puls_motor_arm2.getPosition());
JKleinRot 25:71e52c56be13 1042 pc.printf("pwm motor 2 %f\n\r ", pwm_to_motor_arm2);
JKleinRot 25:71e52c56be13 1043 }
JKleinRot 25:71e52c56be13 1044
JKleinRot 25:71e52c56be13 1045 if(puls_motor_arm2.getPosition() >= 211) {
JKleinRot 25:71e52c56be13 1046 pc.printf("staat stil\n\r");
JKleinRot 25:71e52c56be13 1047 state = THUISPOSITIE_RECHTS;
JKleinRot 25:71e52c56be13 1048 }
JKleinRot 25:71e52c56be13 1049 }
JKleinRot 19:38c9d177b6ee 1050 }
JKleinRot 19:38c9d177b6ee 1051 break; //Stop met alle acties in deze case
JKleinRot 17:c694a0e63a89 1052 }
JKleinRot 19:38c9d177b6ee 1053
JKleinRot 25:71e52c56be13 1054 case BTBB: { //Geen motoraansturing
JKleinRot 17:c694a0e63a89 1055 lcd.locate(0,0); //Zet tekst op eerste regel
JKleinRot 17:c694a0e63a89 1056 lcd.printf(" BTBB "); //Tekst op LCD scherm
JKleinRot 17:c694a0e63a89 1057 pc.printf("BTBB\n\r"); //Controle naar pc sturen
JKleinRot 17:c694a0e63a89 1058
JKleinRot 19:38c9d177b6ee 1059 while(state == BTBB) {
JKleinRot 25:71e52c56be13 1060 lcd.printf(" GEEN DOEL ");
JKleinRot 25:71e52c56be13 1061 wait(1);
JKleinRot 25:71e52c56be13 1062 state = WACHT;
JKleinRot 19:38c9d177b6ee 1063 }
JKleinRot 19:38c9d177b6ee 1064 break; //Stop met alle acties in deze case
JKleinRot 17:c694a0e63a89 1065 }
JKleinRot 19:38c9d177b6ee 1066
JKleinRot 25:71e52c56be13 1067 case BTBT: { //Geen motoraansturing
JKleinRot 17:c694a0e63a89 1068 lcd.locate(0,0); //Zet tekst op eerste regel
JKleinRot 17:c694a0e63a89 1069 lcd.printf(" BTBT "); //Tekst op LCD scherm
JKleinRot 17:c694a0e63a89 1070 pc.printf("BTBT\n\r"); //Controle naar pc sturen
JKleinRot 17:c694a0e63a89 1071
JKleinRot 19:38c9d177b6ee 1072 while(state == BTBT) {
JKleinRot 25:71e52c56be13 1073 lcd.printf(" GEEN DOEL ");
JKleinRot 25:71e52c56be13 1074 wait(1);
JKleinRot 25:71e52c56be13 1075 state = WACHT;
JKleinRot 19:38c9d177b6ee 1076 }
JKleinRot 19:38c9d177b6ee 1077 break; //Stop met alle acties in deze case
JKleinRot 17:c694a0e63a89 1078 }
JKleinRot 19:38c9d177b6ee 1079
JKleinRot 25:71e52c56be13 1080 case BTTB: { //Geen motoraansturing
JKleinRot 17:c694a0e63a89 1081 lcd.locate(0,0); //Zet tekst op eerste regel
JKleinRot 17:c694a0e63a89 1082 lcd.printf(" BTTB "); //Tekst op LCD scherm
JKleinRot 17:c694a0e63a89 1083 pc.printf("BTTB\n\r"); //Controle naar pc sturen
JKleinRot 17:c694a0e63a89 1084
JKleinRot 19:38c9d177b6ee 1085 while(state == BTTB) {
JKleinRot 25:71e52c56be13 1086 lcd.printf(" GEEN DOEL ");
JKleinRot 25:71e52c56be13 1087 wait(1);
JKleinRot 25:71e52c56be13 1088 state = WACHT;
JKleinRot 19:38c9d177b6ee 1089 }
JKleinRot 19:38c9d177b6ee 1090 break; //Stop met alle acties in deze case
JKleinRot 17:c694a0e63a89 1091 }
JKleinRot 19:38c9d177b6ee 1092
JKleinRot 25:71e52c56be13 1093 case BTTT: { //Geen motoraansturing
JKleinRot 17:c694a0e63a89 1094 lcd.locate(0,0); //Zet tekst op eerste regel
JKleinRot 17:c694a0e63a89 1095 lcd.printf(" BTTT "); //Tekst op LCD scherm
JKleinRot 17:c694a0e63a89 1096 pc.printf("BTTT\n\r"); //Controle naar pc sturen
JKleinRot 17:c694a0e63a89 1097
JKleinRot 19:38c9d177b6ee 1098 while(state == BTTT) {
JKleinRot 25:71e52c56be13 1099 lcd.printf(" GEEN DOEL ");
JKleinRot 25:71e52c56be13 1100 wait(1);
JKleinRot 25:71e52c56be13 1101 state = WACHT;
JKleinRot 19:38c9d177b6ee 1102 }
JKleinRot 19:38c9d177b6ee 1103 break; //Stop met alle acties in deze case
JKleinRot 17:c694a0e63a89 1104 }
JKleinRot 19:38c9d177b6ee 1105
JKleinRot 25:71e52c56be13 1106 case TBBB: { //Motoraansturing voor doel middenonder
JKleinRot 17:c694a0e63a89 1107 lcd.locate(0,0); //Zet tekst op eerste regel
JKleinRot 17:c694a0e63a89 1108 lcd.printf(" TBBB "); //Tekst op LCD scherm
JKleinRot 17:c694a0e63a89 1109 pc.printf("TBBB\n\r"); //Controle naar pc sturen
JKleinRot 17:c694a0e63a89 1110
JKleinRot 19:38c9d177b6ee 1111 while(state == TBBB) {
JKleinRot 19:38c9d177b6ee 1112 while(regelaar_ticker_flag != true); //Als geen flag opgestoken, dan niks doen, wel flag, dan uit de while loop en door naar volgende regel
JKleinRot 19:38c9d177b6ee 1113 regelaar_ticker_flag = false; //Flag weer naar beneden, zodat deze straks weer omhoog kan
JKleinRot 19:38c9d177b6ee 1114
JKleinRot 23:5267c928ae2b 1115 while(puls_motor_arm1.getPosition() > 48) {
JKleinRot 23:5267c928ae2b 1116 referentie_arm1 = referentie_arm1 - 132.0/200.0;
JKleinRot 23:5267c928ae2b 1117 pc.printf("referentie arm 1 %f ", referentie_arm1);
JKleinRot 23:5267c928ae2b 1118 pc.printf("get position 1 %d ", puls_motor_arm1.getPosition());
JKleinRot 23:5267c928ae2b 1119 pc.printf("pwm motor 1 %f\n\r", pwm_to_motor_arm1);
JKleinRot 23:5267c928ae2b 1120 }
JKleinRot 23:5267c928ae2b 1121 pc.printf("arm 1 op positie");
JKleinRot 19:38c9d177b6ee 1122
JKleinRot 23:5267c928ae2b 1123 while(puls_motor_arm2.getPosition() < 167) {
JKleinRot 23:5267c928ae2b 1124 referentie_arm2 = referentie_arm2 + 44.0/200.0;
JKleinRot 23:5267c928ae2b 1125 pc.printf("referentie arm 2 %f ", referentie_arm2);
JKleinRot 23:5267c928ae2b 1126 pc.printf("get position 2 %d ", puls_motor_arm2.getPosition());
JKleinRot 23:5267c928ae2b 1127 pc.printf("pwm motor 2 %f\n\r", pwm_to_motor_arm2);
JKleinRot 23:5267c928ae2b 1128 }
JKleinRot 23:5267c928ae2b 1129 pc.printf("arm2 op positie");
JKleinRot 23:5267c928ae2b 1130
JKleinRot 25:71e52c56be13 1131 while(puls_motor_arm2.getPosition() > -8) {
JKleinRot 23:5267c928ae2b 1132
JKleinRot 25:71e52c56be13 1133 referentie_arm2 = -0.5 * 100000 * t * t;
JKleinRot 25:71e52c56be13 1134 t = t + 0.005;
JKleinRot 23:5267c928ae2b 1135
JKleinRot 25:71e52c56be13 1136 pc.printf("referentie arm 2 %f ", referentie_arm2);
JKleinRot 25:71e52c56be13 1137 pc.printf("get position %d ", puls_motor_arm2.getPosition());
JKleinRot 25:71e52c56be13 1138 pc.printf("pwm motor 2 %f", pwm_to_motor_arm2);
JKleinRot 25:71e52c56be13 1139 pc.printf("t is %f\n\r", t);
JKleinRot 25:71e52c56be13 1140 }
JKleinRot 23:5267c928ae2b 1141
JKleinRot 25:71e52c56be13 1142 if(puls_motor_arm2.getPosition() <= -8) {
JKleinRot 25:71e52c56be13 1143 wait(1);
JKleinRot 25:71e52c56be13 1144 while(puls_motor_arm2.getPosition() < 167) {
JKleinRot 25:71e52c56be13 1145 referentie_arm2 = referentie_arm2 + 175.0/200.0;
JKleinRot 23:5267c928ae2b 1146
JKleinRot 23:5267c928ae2b 1147 pc.printf("referentie arm 2 %f ", referentie_arm2);
JKleinRot 23:5267c928ae2b 1148 pc.printf("get position %d ", puls_motor_arm2.getPosition());
JKleinRot 25:71e52c56be13 1149 pc.printf("pwm motor 2 %f\n\r ", pwm_to_motor_arm2);
JKleinRot 23:5267c928ae2b 1150 }
JKleinRot 23:5267c928ae2b 1151
JKleinRot 25:71e52c56be13 1152 if(puls_motor_arm2.getPosition() >= 167) {
JKleinRot 25:71e52c56be13 1153 pc.printf("staat stil\n\r");
JKleinRot 25:71e52c56be13 1154 state = THUISPOSITIE_MIDDEN;
JKleinRot 21:f4e9f6c28de1 1155 }
JKleinRot 19:38c9d177b6ee 1156 }
JKleinRot 19:38c9d177b6ee 1157 }
JKleinRot 24:a1fdc830f96c 1158 break; //Stop met alle acties in deze case
JKleinRot 24:a1fdc830f96c 1159 }
JKleinRot 23:5267c928ae2b 1160
JKleinRot 25:71e52c56be13 1161 case TBBT: { //Geen motoraansturing
JKleinRot 25:71e52c56be13 1162 lcd.locate(0,0); //Zet tekst op eerste regel
JKleinRot 25:71e52c56be13 1163 lcd.printf(" TBBT "); //Tekst op LCD scherm
JKleinRot 25:71e52c56be13 1164 pc.printf("TBBT\n\r"); //Controle naar pc sturen
JKleinRot 25:71e52c56be13 1165
JKleinRot 25:71e52c56be13 1166 while(state == TBBT) {
JKleinRot 25:71e52c56be13 1167 lcd.printf(" GEEN DOEL ");
JKleinRot 25:71e52c56be13 1168 wait(1);
JKleinRot 25:71e52c56be13 1169 state = WACHT;
JKleinRot 25:71e52c56be13 1170 }
JKleinRot 25:71e52c56be13 1171 break; //Stop met alle acties in deze case
JKleinRot 25:71e52c56be13 1172 }
JKleinRot 25:71e52c56be13 1173
JKleinRot 25:71e52c56be13 1174 case TBTB: { //Motoraansturing voor doel midden
JKleinRot 25:71e52c56be13 1175 lcd.locate(0,0); //Zet tekst op eerste regel
JKleinRot 25:71e52c56be13 1176 lcd.printf(" TBTB "); //Tekst op LCD scherm
JKleinRot 25:71e52c56be13 1177 pc.printf("TBTB\n\r"); //Controle naar pc sturen
JKleinRot 25:71e52c56be13 1178
JKleinRot 25:71e52c56be13 1179 while(state == TBTB) {
JKleinRot 25:71e52c56be13 1180 while(regelaar_ticker_flag != true); //Als geen flag opgestoken, dan niks doen, wel flag, dan uit de while loop en door naar volgende regel
JKleinRot 25:71e52c56be13 1181 regelaar_ticker_flag = false; //Flag weer naar beneden, zodat deze straks weer omhoog kan
JKleinRot 25:71e52c56be13 1182
JKleinRot 25:71e52c56be13 1183 while(puls_motor_arm1.getPosition() > 48) {
JKleinRot 25:71e52c56be13 1184 referentie_arm1 = referentie_arm1 - 132.0/200.0;
JKleinRot 25:71e52c56be13 1185 pc.printf("referentie arm 1 %f ", referentie_arm1);
JKleinRot 25:71e52c56be13 1186 pc.printf("get position 1 %d ", puls_motor_arm1.getPosition());
JKleinRot 25:71e52c56be13 1187 pc.printf("pwm motor 1 %f\n\r", pwm_to_motor_arm1);
JKleinRot 25:71e52c56be13 1188 }
JKleinRot 25:71e52c56be13 1189 pc.printf("arm 1 op positie");
JKleinRot 25:71e52c56be13 1190
JKleinRot 25:71e52c56be13 1191 while(puls_motor_arm2.getPosition() < 167) {
JKleinRot 25:71e52c56be13 1192 referentie_arm2 = referentie_arm2 + 44.0/200.0;
JKleinRot 25:71e52c56be13 1193 pc.printf("referentie arm 2 %f ", referentie_arm2);
JKleinRot 25:71e52c56be13 1194 pc.printf("get position 2 %d ", puls_motor_arm2.getPosition());
JKleinRot 25:71e52c56be13 1195 pc.printf("pwm motor 2 %f\n\r", pwm_to_motor_arm2);
JKleinRot 25:71e52c56be13 1196 }
JKleinRot 25:71e52c56be13 1197 pc.printf("arm2 op positie");
JKleinRot 25:71e52c56be13 1198
JKleinRot 25:71e52c56be13 1199 while(puls_motor_arm2.getPosition() > -8) {
JKleinRot 25:71e52c56be13 1200
JKleinRot 25:71e52c56be13 1201 referentie_arm2 = -0.5 * 150000 * t * t;
JKleinRot 25:71e52c56be13 1202 t = t + 0.005;
JKleinRot 25:71e52c56be13 1203
JKleinRot 25:71e52c56be13 1204 pc.printf("referentie arm 2 %f ", referentie_arm2);
JKleinRot 25:71e52c56be13 1205 pc.printf("get position %d ", puls_motor_arm2.getPosition());
JKleinRot 25:71e52c56be13 1206 pc.printf("pwm motor 2 %f", pwm_to_motor_arm2);
JKleinRot 25:71e52c56be13 1207 pc.printf("t is %f\n\r", t);
JKleinRot 25:71e52c56be13 1208 }
JKleinRot 25:71e52c56be13 1209
JKleinRot 25:71e52c56be13 1210 if(puls_motor_arm2.getPosition() <= -8) {
JKleinRot 25:71e52c56be13 1211 wait(1);
JKleinRot 25:71e52c56be13 1212 while(puls_motor_arm2.getPosition() < 167) {
JKleinRot 25:71e52c56be13 1213 referentie_arm2 = referentie_arm2 + 175.0/200.0;
JKleinRot 25:71e52c56be13 1214
JKleinRot 25:71e52c56be13 1215 pc.printf("referentie arm 2 %f ", referentie_arm2);
JKleinRot 25:71e52c56be13 1216 pc.printf("get position %d ", puls_motor_arm2.getPosition());
JKleinRot 25:71e52c56be13 1217 pc.printf("pwm motor 2 %f\n\r ", pwm_to_motor_arm2);
JKleinRot 25:71e52c56be13 1218 }
JKleinRot 25:71e52c56be13 1219
JKleinRot 25:71e52c56be13 1220 if(puls_motor_arm2.getPosition() >= 167) {
JKleinRot 25:71e52c56be13 1221 pc.printf("staat stil\n\r");
JKleinRot 25:71e52c56be13 1222 state = THUISPOSITIE_MIDDEN;
JKleinRot 25:71e52c56be13 1223 }
JKleinRot 25:71e52c56be13 1224 }
JKleinRot 25:71e52c56be13 1225 }
JKleinRot 25:71e52c56be13 1226 break; //Stop met alle acties in deze case
JKleinRot 25:71e52c56be13 1227 }
JKleinRot 25:71e52c56be13 1228
JKleinRot 25:71e52c56be13 1229 case TBTT: { //Motoraansturing voor doel middenboven
JKleinRot 25:71e52c56be13 1230 lcd.locate(0,0); //Zet tekst op eerste regel
JKleinRot 25:71e52c56be13 1231 lcd.printf(" TBTT "); //Tekst op LCD scherm
JKleinRot 25:71e52c56be13 1232 pc.printf("TBTT\n\r"); //Controle naar pc sturen
JKleinRot 25:71e52c56be13 1233
JKleinRot 25:71e52c56be13 1234 while(state == TBTT) {
JKleinRot 25:71e52c56be13 1235 while(regelaar_ticker_flag != true); //Als geen flag opgestoken, dan niks doen, wel flag, dan uit de while loop en door naar volgende regel
JKleinRot 25:71e52c56be13 1236 regelaar_ticker_flag = false; //Flag weer naar beneden, zodat deze straks weer omhoog kan
JKleinRot 25:71e52c56be13 1237
JKleinRot 25:71e52c56be13 1238 while(puls_motor_arm1.getPosition() > 48) {
JKleinRot 25:71e52c56be13 1239 referentie_arm1 = referentie_arm1 - 132.0/200.0;
JKleinRot 25:71e52c56be13 1240 pc.printf("referentie arm 1 %f ", referentie_arm1);
JKleinRot 25:71e52c56be13 1241 pc.printf("get position 1 %d ", puls_motor_arm1.getPosition());
JKleinRot 25:71e52c56be13 1242 pc.printf("pwm motor 1 %f\n\r", pwm_to_motor_arm1);
JKleinRot 25:71e52c56be13 1243 }
JKleinRot 25:71e52c56be13 1244 pc.printf("arm 1 op positie");
JKleinRot 25:71e52c56be13 1245
JKleinRot 25:71e52c56be13 1246 while(puls_motor_arm2.getPosition() < 167) {
JKleinRot 25:71e52c56be13 1247 referentie_arm2 = referentie_arm2 + 44.0/200.0;
JKleinRot 25:71e52c56be13 1248 pc.printf("referentie arm 2 %f ", referentie_arm2);
JKleinRot 25:71e52c56be13 1249 pc.printf("get position 2 %d ", puls_motor_arm2.getPosition());
JKleinRot 25:71e52c56be13 1250 pc.printf("pwm motor 2 %f\n\r", pwm_to_motor_arm2);
JKleinRot 25:71e52c56be13 1251 }
JKleinRot 25:71e52c56be13 1252 pc.printf("arm2 op positie");
JKleinRot 25:71e52c56be13 1253
JKleinRot 25:71e52c56be13 1254 while(puls_motor_arm2.getPosition() > -8) {
JKleinRot 25:71e52c56be13 1255
JKleinRot 25:71e52c56be13 1256 referentie_arm2 = -0.5 * 200000 * t * t;
JKleinRot 25:71e52c56be13 1257 t = t + 0.005;
JKleinRot 25:71e52c56be13 1258
JKleinRot 25:71e52c56be13 1259 pc.printf("referentie arm 2 %f ", referentie_arm2);
JKleinRot 25:71e52c56be13 1260 pc.printf("get position %d ", puls_motor_arm2.getPosition());
JKleinRot 25:71e52c56be13 1261 pc.printf("pwm motor 2 %f", pwm_to_motor_arm2);
JKleinRot 25:71e52c56be13 1262 pc.printf("t is %f\n\r", t);
JKleinRot 25:71e52c56be13 1263 }
JKleinRot 25:71e52c56be13 1264
JKleinRot 25:71e52c56be13 1265 if(puls_motor_arm2.getPosition() <= -8) {
JKleinRot 25:71e52c56be13 1266 wait(1);
JKleinRot 25:71e52c56be13 1267 while(puls_motor_arm2.getPosition() < 167) {
JKleinRot 25:71e52c56be13 1268 referentie_arm2 = referentie_arm2 + 175.0/200.0;
JKleinRot 25:71e52c56be13 1269
JKleinRot 25:71e52c56be13 1270 pc.printf("referentie arm 2 %f ", referentie_arm2);
JKleinRot 25:71e52c56be13 1271 pc.printf("get position %d ", puls_motor_arm2.getPosition());
JKleinRot 25:71e52c56be13 1272 pc.printf("pwm motor 2 %f\n\r ", pwm_to_motor_arm2);
JKleinRot 25:71e52c56be13 1273 }
JKleinRot 25:71e52c56be13 1274
JKleinRot 25:71e52c56be13 1275 if(puls_motor_arm2.getPosition() >= 167) {
JKleinRot 25:71e52c56be13 1276 pc.printf("staat stil\n\r");
JKleinRot 25:71e52c56be13 1277 state = THUISPOSITIE_MIDDEN;
JKleinRot 25:71e52c56be13 1278 }
JKleinRot 25:71e52c56be13 1279 }
JKleinRot 25:71e52c56be13 1280 }
JKleinRot 25:71e52c56be13 1281 break; //Stop met alle acties in deze case
JKleinRot 25:71e52c56be13 1282 }
JKleinRot 25:71e52c56be13 1283
JKleinRot 25:71e52c56be13 1284 case TTBB: { //Motoraansturing voor doel linksonder
JKleinRot 24:a1fdc830f96c 1285 lcd.locate(0,0); //Zet tekst op eerste regel
JKleinRot 24:a1fdc830f96c 1286 lcd.printf(" TTBB "); //Tekst op LCD scherm
JKleinRot 24:a1fdc830f96c 1287 pc.printf("TTBB\n\r"); //Controle naar pc sturen
JKleinRot 24:a1fdc830f96c 1288
JKleinRot 24:a1fdc830f96c 1289 while(state == TTBB) {
JKleinRot 24:a1fdc830f96c 1290 while(regelaar_ticker_flag != true); //Als geen flag opgestoken, dan niks doen, wel flag, dan uit de while loop en door naar volgende regel
JKleinRot 24:a1fdc830f96c 1291 regelaar_ticker_flag = false; //Flag weer naar beneden, zodat deze straks weer omhoog kan
JKleinRot 24:a1fdc830f96c 1292
JKleinRot 25:71e52c56be13 1293 referentie_arm2 = -0.5 * 100000 * t * t;
JKleinRot 24:a1fdc830f96c 1294 t = t + 0.005;
JKleinRot 24:a1fdc830f96c 1295
JKleinRot 24:a1fdc830f96c 1296 pc.printf("referentie arm 2 %f ", referentie_arm2);
JKleinRot 24:a1fdc830f96c 1297 pc.printf("get position %d ", puls_motor_arm2.getPosition());
JKleinRot 24:a1fdc830f96c 1298 pc.printf("pwm motor 2 %f", pwm_to_motor_arm2);
JKleinRot 24:a1fdc830f96c 1299 pc.printf("t is %f\n\r", t);
JKleinRot 24:a1fdc830f96c 1300
JKleinRot 25:71e52c56be13 1301 if(puls_motor_arm2.getPosition() <= -175) {
JKleinRot 24:a1fdc830f96c 1302 wait(1);
JKleinRot 25:71e52c56be13 1303 while(puls_motor_arm2.getPosition() < 0) {
JKleinRot 25:71e52c56be13 1304 referentie_arm2 = referentie_arm2 + 175.0/200.0;
JKleinRot 24:a1fdc830f96c 1305
JKleinRot 24:a1fdc830f96c 1306 pc.printf("referentie arm 2 %f ", referentie_arm2);
JKleinRot 24:a1fdc830f96c 1307 pc.printf("get position %d ", puls_motor_arm2.getPosition());
JKleinRot 24:a1fdc830f96c 1308 pc.printf("pwm motor 2 %f\n\r ", pwm_to_motor_arm2);
JKleinRot 24:a1fdc830f96c 1309 }
JKleinRot 24:a1fdc830f96c 1310
JKleinRot 25:71e52c56be13 1311 if(puls_motor_arm2.getPosition() >= 0) {
JKleinRot 24:a1fdc830f96c 1312 pc.printf("staat stil\n\r");
JKleinRot 24:a1fdc830f96c 1313 state = WACHT;
JKleinRot 24:a1fdc830f96c 1314 }
JKleinRot 23:5267c928ae2b 1315 }
JKleinRot 24:a1fdc830f96c 1316 }
JKleinRot 24:a1fdc830f96c 1317 break; //Stop met alle acties in deze case
JKleinRot 24:a1fdc830f96c 1318 }
JKleinRot 23:5267c928ae2b 1319
JKleinRot 25:71e52c56be13 1320 case TTBT: { //Geen motoraansturing
JKleinRot 24:a1fdc830f96c 1321 lcd.locate(0,0); //Zet tekst op eerste regel
JKleinRot 24:a1fdc830f96c 1322 lcd.printf(" TTBT "); //Tekst op LCD scherm
JKleinRot 24:a1fdc830f96c 1323 pc.printf("TTBT\n\r"); //Controle naar pc sturen
JKleinRot 24:a1fdc830f96c 1324
JKleinRot 24:a1fdc830f96c 1325 while(state == TTBT) {
JKleinRot 24:a1fdc830f96c 1326 lcd.printf(" GEEN DOEL ");
JKleinRot 24:a1fdc830f96c 1327 wait(1);
JKleinRot 24:a1fdc830f96c 1328 state = WACHT;
JKleinRot 24:a1fdc830f96c 1329 }
JKleinRot 24:a1fdc830f96c 1330 break; //Stop met alle acties in deze case
JKleinRot 24:a1fdc830f96c 1331 }
JKleinRot 24:a1fdc830f96c 1332
JKleinRot 25:71e52c56be13 1333 case TTTB: { //Motoraansturing voor doel linksmidden
JKleinRot 24:a1fdc830f96c 1334 lcd.locate(0,0); //Zet tekst op eerste regel
JKleinRot 24:a1fdc830f96c 1335 lcd.printf(" TTTB "); //Tekst op LCD scherm
JKleinRot 24:a1fdc830f96c 1336 pc.printf("TTTB\n\r"); //Controle naar pc sturen
JKleinRot 24:a1fdc830f96c 1337
JKleinRot 24:a1fdc830f96c 1338 while(state == TTTB) {
JKleinRot 24:a1fdc830f96c 1339
JKleinRot 24:a1fdc830f96c 1340 while(regelaar_ticker_flag != true); //Als geen flag opgestoken, dan niks doen, wel flag, dan uit de while loop en door naar volgende regel
JKleinRot 24:a1fdc830f96c 1341 regelaar_ticker_flag = false; //Flag weer naar beneden, zodat deze straks weer omhoog kan
JKleinRot 24:a1fdc830f96c 1342
JKleinRot 25:71e52c56be13 1343 referentie_arm2 = -0.5 * 150000 * t * t;
JKleinRot 24:a1fdc830f96c 1344 t = t + 0.005;
JKleinRot 24:a1fdc830f96c 1345
JKleinRot 24:a1fdc830f96c 1346 pc.printf("referentie arm 2 %f ", referentie_arm2);
JKleinRot 24:a1fdc830f96c 1347 pc.printf("get position %d ", puls_motor_arm2.getPosition());
JKleinRot 24:a1fdc830f96c 1348 pc.printf("pwm motor 2 %f", pwm_to_motor_arm2);
JKleinRot 24:a1fdc830f96c 1349 pc.printf("t is %f\n\r", t);
JKleinRot 24:a1fdc830f96c 1350
JKleinRot 25:71e52c56be13 1351 if(puls_motor_arm2.getPosition() <= -175) {
JKleinRot 24:a1fdc830f96c 1352 wait(1);
JKleinRot 25:71e52c56be13 1353 while(puls_motor_arm2.getPosition() < 0) {
JKleinRot 25:71e52c56be13 1354 referentie_arm2 = referentie_arm2 + 175.0/200.0;
JKleinRot 24:a1fdc830f96c 1355
JKleinRot 24:a1fdc830f96c 1356 pc.printf("referentie arm 2 %f ", referentie_arm2);
JKleinRot 24:a1fdc830f96c 1357 pc.printf("get position %d ", puls_motor_arm2.getPosition());
JKleinRot 24:a1fdc830f96c 1358 pc.printf("pwm motor 2 %f\n\r ", pwm_to_motor_arm2);
JKleinRot 24:a1fdc830f96c 1359 }
JKleinRot 24:a1fdc830f96c 1360
JKleinRot 25:71e52c56be13 1361 if(puls_motor_arm2.getPosition() >= 0) {
JKleinRot 24:a1fdc830f96c 1362 pc.printf("staat stil\n\r");
JKleinRot 24:a1fdc830f96c 1363 state = WACHT;
JKleinRot 24:a1fdc830f96c 1364 }
JKleinRot 23:5267c928ae2b 1365 }
JKleinRot 23:5267c928ae2b 1366 }
JKleinRot 19:38c9d177b6ee 1367
JKleinRot 24:a1fdc830f96c 1368 break; //Stop met alle acties in deze case
JKleinRot 24:a1fdc830f96c 1369 }
JKleinRot 24:a1fdc830f96c 1370
JKleinRot 25:71e52c56be13 1371 case TTTT: { //Motoraansturing voor doel linksboven
JKleinRot 24:a1fdc830f96c 1372 lcd.locate(0,0); //Zet tekst op eerste regel
JKleinRot 24:a1fdc830f96c 1373 lcd.printf(" TTTT "); //Tekst op LCD scherm
JKleinRot 24:a1fdc830f96c 1374 pc.printf("TTBB\n\r"); //Controle naar pc sturen
JKleinRot 24:a1fdc830f96c 1375
JKleinRot 24:a1fdc830f96c 1376 while(state == TTTT) {
JKleinRot 24:a1fdc830f96c 1377 while(regelaar_ticker_flag != true); //Als geen flag opgestoken, dan niks doen, wel flag, dan uit de while loop en door naar volgende regel
JKleinRot 24:a1fdc830f96c 1378 regelaar_ticker_flag = false; //Flag weer naar beneden, zodat deze straks weer omhoog kan
JKleinRot 24:a1fdc830f96c 1379
JKleinRot 25:71e52c56be13 1380 referentie_arm2 = -0.5 * 200000 * t * t;
JKleinRot 24:a1fdc830f96c 1381 t = t + 0.005;
JKleinRot 24:a1fdc830f96c 1382
JKleinRot 24:a1fdc830f96c 1383 pc.printf("referentie arm 2 %f ", referentie_arm2);
JKleinRot 24:a1fdc830f96c 1384 pc.printf("get position %d ", puls_motor_arm2.getPosition());
JKleinRot 24:a1fdc830f96c 1385 pc.printf("pwm motor 2 %f", pwm_to_motor_arm2);
JKleinRot 24:a1fdc830f96c 1386 pc.printf("t is %f\n\r", t);
JKleinRot 24:a1fdc830f96c 1387
JKleinRot 25:71e52c56be13 1388 if(puls_motor_arm2.getPosition() <= -175) {
JKleinRot 24:a1fdc830f96c 1389 wait(1);
JKleinRot 25:71e52c56be13 1390 while(puls_motor_arm2.getPosition() < 0) {
JKleinRot 25:71e52c56be13 1391 referentie_arm2 = referentie_arm2 + 175.0/200.0;
JKleinRot 24:a1fdc830f96c 1392
JKleinRot 24:a1fdc830f96c 1393
JKleinRot 24:a1fdc830f96c 1394 pc.printf("referentie arm 2 %f ", referentie_arm2);
JKleinRot 24:a1fdc830f96c 1395 pc.printf("get position %d ", puls_motor_arm2.getPosition());
JKleinRot 24:a1fdc830f96c 1396 pc.printf("pwm motor 2 %f\n\r ", pwm_to_motor_arm2);
JKleinRot 24:a1fdc830f96c 1397 }
JKleinRot 24:a1fdc830f96c 1398
JKleinRot 25:71e52c56be13 1399 if(puls_motor_arm2.getPosition() >= 0) {
JKleinRot 24:a1fdc830f96c 1400 pc.printf("staat stil\n\r");
JKleinRot 24:a1fdc830f96c 1401 state = WACHT;
JKleinRot 24:a1fdc830f96c 1402 }
JKleinRot 24:a1fdc830f96c 1403 }
JKleinRot 24:a1fdc830f96c 1404 }
JKleinRot 24:a1fdc830f96c 1405 }
JKleinRot 24:a1fdc830f96c 1406
JKleinRot 24:a1fdc830f96c 1407 case THUISPOSITIE_MIDDEN: {
JKleinRot 24:a1fdc830f96c 1408 while(puls_motor_arm2.getPosition() > 123) {
JKleinRot 25:71e52c56be13 1409 while(regelaar_ticker_flag != true); //Als geen flag opgestoken, dan niks doen, wel flag, dan uit de while loop en door naar volgende regel
JKleinRot 25:71e52c56be13 1410 regelaar_ticker_flag = false; //Flag weer naar beneden, zodat deze straks weer omhoog kan
JKleinRot 25:71e52c56be13 1411
JKleinRot 24:a1fdc830f96c 1412 referentie_arm2 = referentie_arm2 - 44.0/200.0;
JKleinRot 25:71e52c56be13 1413 pc.printf("referentie arm 2 %f ", referentie_arm2);
JKleinRot 25:71e52c56be13 1414 pc.printf("get position %d ", puls_motor_arm2.getPosition());
JKleinRot 25:71e52c56be13 1415 pc.printf("pwm motor 2 %f\n\r ", pwm_to_motor_arm2);
JKleinRot 24:a1fdc830f96c 1416 }
JKleinRot 24:a1fdc830f96c 1417
JKleinRot 24:a1fdc830f96c 1418 while(puls_motor_arm1.getPosition() < 180) {
JKleinRot 25:71e52c56be13 1419 while(regelaar_ticker_flag != true); //Als geen flag opgestoken, dan niks doen, wel flag, dan uit de while loop en door naar volgende regel
JKleinRot 25:71e52c56be13 1420 regelaar_ticker_flag = false; //Flag weer naar beneden, zodat deze straks weer omhoog kan
JKleinRot 25:71e52c56be13 1421
JKleinRot 24:a1fdc830f96c 1422 referentie_arm1 = referentie_arm1 + 132.0/200.0;
JKleinRot 25:71e52c56be13 1423 pc.printf("referentie arm 1 %f ", referentie_arm1);
JKleinRot 25:71e52c56be13 1424 pc.printf("get position 1 %d ", puls_motor_arm1.getPosition());
JKleinRot 25:71e52c56be13 1425 pc.printf("pwm motor 1 %f\n\r ", pwm_to_motor_arm1);
JKleinRot 25:71e52c56be13 1426
JKleinRot 24:a1fdc830f96c 1427 }
JKleinRot 24:a1fdc830f96c 1428
JKleinRot 24:a1fdc830f96c 1429 state = WACHT;
JKleinRot 24:a1fdc830f96c 1430 break;
JKleinRot 24:a1fdc830f96c 1431 }
JKleinRot 24:a1fdc830f96c 1432
JKleinRot 25:71e52c56be13 1433 case THUISPOSITIE_RECHTS: {
JKleinRot 25:71e52c56be13 1434 pc.printf("thuispositie rechts");
JKleinRot 25:71e52c56be13 1435 while(puls_motor_arm2.getPosition() > 123) {
JKleinRot 25:71e52c56be13 1436 while(regelaar_ticker_flag != true); //Als geen flag opgestoken, dan niks doen, wel flag, dan uit de while loop en door naar volgende regel
JKleinRot 25:71e52c56be13 1437 regelaar_ticker_flag = false; //Flag weer naar beneden, zodat deze straks weer omhoog kan
JKleinRot 25:71e52c56be13 1438
JKleinRot 25:71e52c56be13 1439 referentie_arm2 = referentie_arm2 - 88.0/200.0;
JKleinRot 25:71e52c56be13 1440 pc.printf("referentie arm 2 %f ", referentie_arm2);
JKleinRot 25:71e52c56be13 1441 pc.printf("get position %d ", puls_motor_arm2.getPosition());
JKleinRot 25:71e52c56be13 1442 pc.printf("pwm motor 2 %f\n\r ", pwm_to_motor_arm2);
JKleinRot 25:71e52c56be13 1443
JKleinRot 25:71e52c56be13 1444 }
JKleinRot 25:71e52c56be13 1445
JKleinRot 25:71e52c56be13 1446 while(puls_motor_arm1.getPosition() < 180) {
JKleinRot 25:71e52c56be13 1447 while(regelaar_ticker_flag != true); //Als geen flag opgestoken, dan niks doen, wel flag, dan uit de while loop en door naar volgende regel
JKleinRot 25:71e52c56be13 1448 regelaar_ticker_flag = false; //Flag weer naar beneden, zodat deze straks weer omhoog kan
JKleinRot 25:71e52c56be13 1449
JKleinRot 25:71e52c56be13 1450 referentie_arm1 = referentie_arm1 + 264.0/200.0;
JKleinRot 25:71e52c56be13 1451 pc.printf("referentie arm 1 %f ", referentie_arm1);
JKleinRot 25:71e52c56be13 1452 pc.printf("get position 1 %d ", puls_motor_arm1.getPosition());
JKleinRot 25:71e52c56be13 1453 pc.printf("pwm motor 1 %f\n\r ", pwm_to_motor_arm1);
JKleinRot 25:71e52c56be13 1454 }
JKleinRot 25:71e52c56be13 1455 }
JKleinRot 25:71e52c56be13 1456
JKleinRot 24:a1fdc830f96c 1457 case WACHT: {
JKleinRot 24:a1fdc830f96c 1458 lcd.printf(" WACHT ");
JKleinRot 24:a1fdc830f96c 1459 wait(5);
JKleinRot 24:a1fdc830f96c 1460 state = START;
JKleinRot 23:5267c928ae2b 1461
JKleinRot 24:a1fdc830f96c 1462 default: {
JKleinRot 24:a1fdc830f96c 1463 //Default state, mocht er iets misgaan en het programma kan niet naar een volgende case
JKleinRot 24:a1fdc830f96c 1464 state = RUST; //Als dat gebeurt wordt de state rust en begint hij weer vooraan
JKleinRot 24:a1fdc830f96c 1465 }
JKleinRot 23:5267c928ae2b 1466
JKleinRot 24:a1fdc830f96c 1467 pc.printf("state: %u\n\r",state);
JKleinRot 23:5267c928ae2b 1468 }
JKleinRot 24:a1fdc830f96c 1469 //PWM moet tussen 1 en -1 blijven (niet meer dan 100% dutycycle)
JKleinRot 9:454e7da8ab65 1470 }
JKleinRot 20:1cb0cf0d49ac 1471 }
JKleinRot 24:a1fdc830f96c 1472 }