MODSERIAL PID controller edit
Dependencies: HIDScope MODSERIAL QEI biquadFilter mbed
Fork of PID_controller_Motor by
main.cpp@13:b0d3c547bf2f, 2016-10-21 (annotated)
- Committer:
- MBroek
- Date:
- Fri Oct 21 08:44:18 2016 +0000
- Revision:
- 13:b0d3c547bf2f
- Parent:
- 12:8aba69d8d0d0
- Child:
- 14:f51d51395803
Werkende initializatie, complete chaos in de main loop
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
MBroek | 0:9e053ed05c69 | 1 | |
MBroek | 0:9e053ed05c69 | 2 | |
MBroek | 0:9e053ed05c69 | 3 | // HET DEFINIEREN VAN ALLES ========================================================================================== |
MBroek | 0:9e053ed05c69 | 4 | |
MBroek | 0:9e053ed05c69 | 5 | // Includen van alle libraries --------------------------------------- |
MBroek | 0:9e053ed05c69 | 6 | #include "mbed.h" |
MBroek | 0:9e053ed05c69 | 7 | #include "MODSERIAL.h" |
MBroek | 0:9e053ed05c69 | 8 | #include "QEI.h" |
MBroek | 0:9e053ed05c69 | 9 | #include "math.h" |
MBroek | 3:581c5918b590 | 10 | #include "HIDScope.h" |
MBroek | 3:581c5918b590 | 11 | |
MBroek | 3:581c5918b590 | 12 | // Definieren van de HIDscope ---------------------------------------- |
MBroek | 7:435f984781ab | 13 | HIDScope scope(3); |
MBroek | 0:9e053ed05c69 | 14 | |
MBroek | 0:9e053ed05c69 | 15 | |
MBroek | 0:9e053ed05c69 | 16 | // Definieren van de Serial en Encoder ------------------------------- |
MBroek | 0:9e053ed05c69 | 17 | MODSERIAL pc(USBTX, USBRX); |
MBroek | 0:9e053ed05c69 | 18 | #define SERIALBAUD 115200 |
MBroek | 0:9e053ed05c69 | 19 | |
MBroek | 0:9e053ed05c69 | 20 | QEI encoder_motor1(D10,D11,NC,64); |
MBroek | 0:9e053ed05c69 | 21 | QEI encoder_motor2(D12,D13,NC,64); |
MBroek | 0:9e053ed05c69 | 22 | |
MBroek | 0:9e053ed05c69 | 23 | |
MBroek | 0:9e053ed05c69 | 24 | // Definieren van de Motorpins --------------------------------------- |
MBroek | 0:9e053ed05c69 | 25 | DigitalOut motor1_direction_pin(D7); |
MBroek | 0:9e053ed05c69 | 26 | PwmOut motor1_speed_pin(D6); |
MBroek | 0:9e053ed05c69 | 27 | |
MBroek | 0:9e053ed05c69 | 28 | DigitalOut motor2_direction_pin(D4); |
MBroek | 0:9e053ed05c69 | 29 | PwmOut motor2_speed_pin(D5); |
MBroek | 0:9e053ed05c69 | 30 | |
MBroek | 0:9e053ed05c69 | 31 | |
MBroek | 0:9e053ed05c69 | 32 | //Definieren van bord-elementen -------------------------------------- |
MBroek | 3:581c5918b590 | 33 | InterruptIn kill_switch(D8); |
MBroek | 3:581c5918b590 | 34 | InterruptIn test_button(D9); |
MBroek | 1:5b3fa8e47e8b | 35 | AnalogIn pot1(A1); // Dit is de gesimuleerde emg1 |
MBroek | 1:5b3fa8e47e8b | 36 | AnalogIn pot2(A2); // Dit is de gesimuleerde emg2 |
MBroek | 0:9e053ed05c69 | 37 | |
MBroek | 13:b0d3c547bf2f | 38 | InterruptIn start_button(SW2); |
MBroek | 13:b0d3c547bf2f | 39 | InterruptIn initializing_stopper(SW3); |
MBroek | 13:b0d3c547bf2f | 40 | |
MBroek | 13:b0d3c547bf2f | 41 | DigitalOut ledred(LED_RED, 1); |
MBroek | 13:b0d3c547bf2f | 42 | DigitalOut ledgreen(LED_GREEN, 1); |
MBroek | 13:b0d3c547bf2f | 43 | |
MBroek | 0:9e053ed05c69 | 44 | |
MBroek | 4:6524b198721f | 45 | //Definieren van de tickers ------------------------------------------ |
MBroek | 4:6524b198721f | 46 | Ticker test_ticker; |
MBroek | 4:6524b198721f | 47 | Ticker hidscope_ticker; |
MBroek | 4:6524b198721f | 48 | |
MBroek | 4:6524b198721f | 49 | |
MBroek | 0:9e053ed05c69 | 50 | |
MBroek | 0:9e053ed05c69 | 51 | // HET VASTSTELLEN VAN ALLE TE GEBRUIKEN VARIABELEN EN CONSTANTEN ====================================================== |
MBroek | 4:6524b198721f | 52 | |
MBroek | 13:b0d3c547bf2f | 53 | bool starting = false; // conditie om programma te starten |
MBroek | 13:b0d3c547bf2f | 54 | |
MBroek | 13:b0d3c547bf2f | 55 | |
MBroek | 13:b0d3c547bf2f | 56 | double error_prev_1_in = 0.0, error_int_1_in = 0.0; // De error waardes voor het initialiseren |
MBroek | 13:b0d3c547bf2f | 57 | double PID_output_1_in = 0.0; // De PID output voor het initialiseren |
MBroek | 13:b0d3c547bf2f | 58 | bool initializing = true; // conditie voor het initialiseren |
MBroek | 13:b0d3c547bf2f | 59 | |
MBroek | 13:b0d3c547bf2f | 60 | |
MBroek | 0:9e053ed05c69 | 61 | volatile bool safe = true; // Conditie voor de while-loop in main |
MBroek | 0:9e053ed05c69 | 62 | |
MBroek | 4:6524b198721f | 63 | double position_motor1; |
MBroek | 4:6524b198721f | 64 | |
MBroek | 4:6524b198721f | 65 | int counts1; // Pulses van motoren |
MBroek | 4:6524b198721f | 66 | int counts2; |
MBroek | 0:9e053ed05c69 | 67 | |
MBroek | 0:9e053ed05c69 | 68 | const double pi = 3.14159265358979323846264338327950288419716939937510; // pi |
MBroek | 4:6524b198721f | 69 | const double rad_per_count = pi/8400.0; // Aantal rad per puls uit encoder |
MBroek | 0:9e053ed05c69 | 70 | |
MBroek | 11:91613b22bc00 | 71 | const double radius_tandwiel = 1.0; |
MBroek | 9:f735baee0c2b | 72 | const double meter_per_count = rad_per_count * radius_tandwiel; // Het aantal meter dat het karretje aflegt per puls, DIT IS NOG ONBEKEND!!! |
MBroek | 1:5b3fa8e47e8b | 73 | |
MBroek | 4:6524b198721f | 74 | double error1_int = 0.00000; // Initiele error integral waardes |
MBroek | 4:6524b198721f | 75 | double error2_int = 0.00000; |
MBroek | 0:9e053ed05c69 | 76 | |
MBroek | 0:9e053ed05c69 | 77 | const double T_getpos = 0.01; // Periode van de frequentie van het aanroepen van de positiechecker (get_position) |
MBroek | 0:9e053ed05c69 | 78 | |
MBroek | 4:6524b198721f | 79 | volatile bool flag1 = false, flag2 = false; // De flags voor de functies aangeroepen door de tickers |
MBroek | 4:6524b198721f | 80 | |
MBroek | 6:e0857842e8cd | 81 | const double Kp_1 = 1.0000000; // De PID variablen voor motor 1 |
MBroek | 8:919ddba2875e | 82 | const double Kd_1 = 0.1; |
MBroek | 8:919ddba2875e | 83 | const double Ki_1 = 0.3; |
MBroek | 4:6524b198721f | 84 | |
MBroek | 9:f735baee0c2b | 85 | const double Kp_2 = 1.0000000; // De PID variablen voor motor 2 |
MBroek | 9:f735baee0c2b | 86 | const double Kd_2 = 0.1; |
MBroek | 9:f735baee0c2b | 87 | const double Ki_2 = 0.3; |
MBroek | 5:c510ab61af28 | 88 | |
MBroek | 9:f735baee0c2b | 89 | const double vrijheid_m1_rad = 0.5*pi; // Dit is de uiterste postitie vd arm in radialen |
MBroek | 9:f735baee0c2b | 90 | const double vrijheid_m2_meter = 0.25; // Dit is de helft vd arm, dit is wat het karretje heen en weer kan bewegen |
MBroek | 5:c510ab61af28 | 91 | |
MBroek | 12:8aba69d8d0d0 | 92 | const double starting_pos_m1 = 0.5*pi; // Startin posities van de motoren |
MBroek | 13:b0d3c547bf2f | 93 | const double starting_pos_m2 = 0.25; |
MBroek | 11:91613b22bc00 | 94 | |
MBroek | 13:b0d3c547bf2f | 95 | double reference_position_motor1 = 0; // Dit zijn de eerste posities waar de motoren heen willen bij de initialisatie |
MBroek | 10:755b9228cc42 | 96 | double reference_position_motor2 = 0; |
MBroek | 9:f735baee0c2b | 97 | |
MBroek | 13:b0d3c547bf2f | 98 | double PID_output_1 = 0.0; // De eerste PID_output, deze is nul anders gaan de motoren draaien |
MBroek | 13:b0d3c547bf2f | 99 | double PID_output_2 = 0.0; |
MBroek | 5:c510ab61af28 | 100 | |
MBroek | 13:b0d3c547bf2f | 101 | double error_prev_1 = 0.0; // De initiele previous error |
MBroek | 13:b0d3c547bf2f | 102 | double error_int_1 = 0.0; // De initiele intergral error |
MBroek | 10:755b9228cc42 | 103 | |
MBroek | 13:b0d3c547bf2f | 104 | double error_prev_2 = 0.0; |
MBroek | 13:b0d3c547bf2f | 105 | double error_int_2 = 0.0; |
MBroek | 5:c510ab61af28 | 106 | |
MBroek | 13:b0d3c547bf2f | 107 | bool which_motor = false; |
MBroek | 9:f735baee0c2b | 108 | |
MBroek | 0:9e053ed05c69 | 109 | |
MBroek | 0:9e053ed05c69 | 110 | |
MBroek | 0:9e053ed05c69 | 111 | |
MBroek | 0:9e053ed05c69 | 112 | |
MBroek | 0:9e053ed05c69 | 113 | // ALLE FUNCTIES BUITEN DE MAIN-LOOP ==================================================================================== |
MBroek | 0:9e053ed05c69 | 114 | |
MBroek | 13:b0d3c547bf2f | 115 | // De program starter ------------------------------------------------ |
MBroek | 13:b0d3c547bf2f | 116 | void start_program(){ |
MBroek | 13:b0d3c547bf2f | 117 | starting = true; |
MBroek | 13:b0d3c547bf2f | 118 | pc.printf("Starting\n\r"); |
MBroek | 13:b0d3c547bf2f | 119 | } |
MBroek | 13:b0d3c547bf2f | 120 | |
MBroek | 13:b0d3c547bf2f | 121 | |
MBroek | 0:9e053ed05c69 | 122 | // De emergency break ------------------------------------------------ |
MBroek | 0:9e053ed05c69 | 123 | void emergency_stop(){ |
MBroek | 0:9e053ed05c69 | 124 | safe = false; |
MBroek | 0:9e053ed05c69 | 125 | pc.printf("Emergency stop!!! Please reset your K64F board\r\n"); |
MBroek | 0:9e053ed05c69 | 126 | } |
MBroek | 0:9e053ed05c69 | 127 | |
MBroek | 1:5b3fa8e47e8b | 128 | |
MBroek | 13:b0d3c547bf2f | 129 | // De initialiseer beeindiger knop ------------------------------------------------ |
MBroek | 13:b0d3c547bf2f | 130 | void stop_initializing(){ |
MBroek | 13:b0d3c547bf2f | 131 | initializing = false; |
MBroek | 13:b0d3c547bf2f | 132 | pc.printf("Initializing ended\r\n"); |
MBroek | 13:b0d3c547bf2f | 133 | } |
MBroek | 13:b0d3c547bf2f | 134 | |
MBroek | 13:b0d3c547bf2f | 135 | |
MBroek | 9:f735baee0c2b | 136 | // Functie voor het switchen tussen de motors ------------------------------ |
MBroek | 9:f735baee0c2b | 137 | void motor_switch(){ |
MBroek | 9:f735baee0c2b | 138 | which_motor = !which_motor; // =0 activeert motor1 en =1 activeert motor2 |
MBroek | 9:f735baee0c2b | 139 | } |
MBroek | 9:f735baee0c2b | 140 | |
MBroek | 9:f735baee0c2b | 141 | |
MBroek | 1:5b3fa8e47e8b | 142 | // Functie voor het vinden van de positie van motor 1 --------------------- |
MBroek | 13:b0d3c547bf2f | 143 | double get_position_m1(const double radpercount){ //returned de positie van de motor in radialen (positie vd arm in radialen) |
MBroek | 0:9e053ed05c69 | 144 | counts1 = encoder_motor1.getPulses(); // Leest aantal pulses uit encoder af |
MBroek | 13:b0d3c547bf2f | 145 | return radpercount * counts1; // rekent positie motor1 uit en geeft deze als output vd functie |
MBroek | 1:5b3fa8e47e8b | 146 | } |
MBroek | 1:5b3fa8e47e8b | 147 | |
MBroek | 1:5b3fa8e47e8b | 148 | |
MBroek | 1:5b3fa8e47e8b | 149 | // Functie voor vinden van de positie van motor 2 ----------------------------- |
MBroek | 13:b0d3c547bf2f | 150 | double get_position_m2(const double meterpercount){ // returned de positie van het karretje in meter |
MBroek | 1:5b3fa8e47e8b | 151 | counts2 = encoder_motor2.getPulses(); // leest aantal pulses vd encoder af |
MBroek | 13:b0d3c547bf2f | 152 | return meterpercount * counts2; // rekent de positie van het karretje uit en geeft dit als output vd functie |
MBroek | 1:5b3fa8e47e8b | 153 | } |
MBroek | 1:5b3fa8e47e8b | 154 | |
MBroek | 1:5b3fa8e47e8b | 155 | |
MBroek | 5:c510ab61af28 | 156 | // Functie voor het vinden van de reference position van motor 1 -------------------- |
MBroek | 13:b0d3c547bf2f | 157 | double get_reference_position_m1(const double aantal_rad){ |
MBroek | 4:6524b198721f | 158 | double ref_pos = pot1.read() - pot2.read(); // De reference position als output (zit tussen -1 en 1, -1 is maximaal links en 1 is maximaal rechts) |
MBroek | 13:b0d3c547bf2f | 159 | return ref_pos * aantal_rad; // Aantal rad is de uiterste positie vd arm in radialen |
MBroek | 5:c510ab61af28 | 160 | } |
MBroek | 5:c510ab61af28 | 161 | |
MBroek | 5:c510ab61af28 | 162 | |
MBroek | 5:c510ab61af28 | 163 | // Functie voor het vinden van de reference position van motor 2 -------------------- |
MBroek | 13:b0d3c547bf2f | 164 | double get_reference_position_m2(const double aantal_meter){ |
MBroek | 5:c510ab61af28 | 165 | double ref_pos = pot1.read() - pot2.read(); // De reference position als output (zit tussen -1 en 1, -1 is maximaal links en 1 is maximaal rechts) |
MBroek | 13:b0d3c547bf2f | 166 | return ref_pos * aantal_meter; // Aantal meter is hoeveelheid radialen van middelpunt tot minima. |
MBroek | 1:5b3fa8e47e8b | 167 | } |
MBroek | 0:9e053ed05c69 | 168 | |
MBroek | 3:581c5918b590 | 169 | |
MBroek | 3:581c5918b590 | 170 | // HIDScope functie ---------------------------------------------------------------------- |
MBroek | 7:435f984781ab | 171 | void set_scope(double input1, double input2, double input3){ |
MBroek | 7:435f984781ab | 172 | scope.set(0, input1); |
MBroek | 7:435f984781ab | 173 | scope.set(1, input2); |
MBroek | 7:435f984781ab | 174 | scope.set(2, input3); |
MBroek | 3:581c5918b590 | 175 | scope.send(); |
MBroek | 3:581c5918b590 | 176 | } |
MBroek | 3:581c5918b590 | 177 | |
MBroek | 0:9e053ed05c69 | 178 | |
MBroek | 1:5b3fa8e47e8b | 179 | // De PID-controller voor de motors ------------------------------------------------- |
MBroek | 6:e0857842e8cd | 180 | double PID_controller(double ref_pos, double mot_pos, double &e_prev, double &e_int, const double Kp, const double Kd, const double Ki){ |
MBroek | 0:9e053ed05c69 | 181 | double error = ref_pos - mot_pos; // error uitrekenen |
MBroek | 6:e0857842e8cd | 182 | double error_dif = (error-e_prev)/T_getpos; // De error differentieren |
MBroek | 1:5b3fa8e47e8b | 183 | //error_dif = ..... // Filter biquad poep |
MBroek | 6:e0857842e8cd | 184 | e_prev = error; // Hier wordt de error opgeslagen voor de volgende keer |
MBroek | 6:e0857842e8cd | 185 | e_int = e_int + T_getpos*error; // De error integreren |
MBroek | 6:e0857842e8cd | 186 | return Kp*error + Ki*e_int + Kd*error_dif; // De uiteindelijke PID output |
MBroek | 0:9e053ed05c69 | 187 | } |
MBroek | 0:9e053ed05c69 | 188 | |
MBroek | 0:9e053ed05c69 | 189 | |
MBroek | 2:6bef5397e8a9 | 190 | // Motor 1 besturen --------------------------------------------------------------------- |
MBroek | 2:6bef5397e8a9 | 191 | void set_motor1(double motor_input){ // functie die de motor aanstuurt mt als input de PID-output |
MBroek | 2:6bef5397e8a9 | 192 | if (motor_input >= 0){ // Dit checkt welke kant de motor op moet draaien |
MBroek | 2:6bef5397e8a9 | 193 | motor1_direction_pin = 1; // Clockwise |
MBroek | 2:6bef5397e8a9 | 194 | } |
MBroek | 2:6bef5397e8a9 | 195 | else { |
MBroek | 2:6bef5397e8a9 | 196 | motor1_direction_pin = 0; // CounterClockwise |
MBroek | 2:6bef5397e8a9 | 197 | } |
MBroek | 2:6bef5397e8a9 | 198 | if (fabs(motor_input)>1){ // Dit fixed de PwmOutput op maximaal 1 |
MBroek | 2:6bef5397e8a9 | 199 | motor_input = 1; |
MBroek | 2:6bef5397e8a9 | 200 | } |
MBroek | 2:6bef5397e8a9 | 201 | motor1_speed_pin = fabs(motor_input); // Dit geeft de uiteindelijke input door aan de motor |
MBroek | 2:6bef5397e8a9 | 202 | } |
MBroek | 2:6bef5397e8a9 | 203 | |
MBroek | 2:6bef5397e8a9 | 204 | |
MBroek | 2:6bef5397e8a9 | 205 | // Motor 2 besturen --------------------------------------------------------------------- |
MBroek | 2:6bef5397e8a9 | 206 | void set_motor2(double motor_input){ // functie die de motor aanstuurt mt als input de PID-output |
MBroek | 2:6bef5397e8a9 | 207 | if (motor_input >= 0){ // Dit checkt welke kant de motor op moet draaien |
MBroek | 2:6bef5397e8a9 | 208 | motor2_direction_pin = 1; // Clockwise |
MBroek | 2:6bef5397e8a9 | 209 | } |
MBroek | 2:6bef5397e8a9 | 210 | else { |
MBroek | 2:6bef5397e8a9 | 211 | motor2_direction_pin = 0; // CounterClockwise |
MBroek | 2:6bef5397e8a9 | 212 | } |
MBroek | 2:6bef5397e8a9 | 213 | if (fabs(motor_input)>1){ // Dit fixed de PwmOutput op maximaal 1 |
MBroek | 2:6bef5397e8a9 | 214 | motor_input = 1; |
MBroek | 2:6bef5397e8a9 | 215 | } |
MBroek | 2:6bef5397e8a9 | 216 | motor2_speed_pin = fabs(motor_input); // Dit geeft de uiteindelijke input door aan de motor |
MBroek | 2:6bef5397e8a9 | 217 | } |
MBroek | 2:6bef5397e8a9 | 218 | |
MBroek | 0:9e053ed05c69 | 219 | |
MBroek | 4:6524b198721f | 220 | // De go-flag functies ----------------------------------------------------------------- |
MBroek | 4:6524b198721f | 221 | void flag1_activate(){flag1=true;} // Activeert de flag |
MBroek | 4:6524b198721f | 222 | void flag2_activate(){flag2=true;} |
MBroek | 4:6524b198721f | 223 | |
MBroek | 4:6524b198721f | 224 | |
MBroek | 0:9e053ed05c69 | 225 | |
MBroek | 0:9e053ed05c69 | 226 | // DE MAIN ================================================================================================================= |
MBroek | 0:9e053ed05c69 | 227 | int main() |
MBroek | 0:9e053ed05c69 | 228 | { |
MBroek | 0:9e053ed05c69 | 229 | pc.baud(SERIALBAUD); |
MBroek | 0:9e053ed05c69 | 230 | |
MBroek | 0:9e053ed05c69 | 231 | kill_switch.fall(&emergency_stop); // Activeert kill switch |
MBroek | 9:f735baee0c2b | 232 | test_button.fall(&motor_switch); // Switcht motoren |
MBroek | 13:b0d3c547bf2f | 233 | start_button.fall(&start_program); |
MBroek | 13:b0d3c547bf2f | 234 | initializing_stopper.fall(&stop_initializing); |
MBroek | 13:b0d3c547bf2f | 235 | |
MBroek | 0:9e053ed05c69 | 236 | |
MBroek | 4:6524b198721f | 237 | test_ticker.attach(&flag1_activate,0.1); // Activeert de go-flag van motor positie |
MBroek | 13:b0d3c547bf2f | 238 | hidscope_ticker.attach(&flag2_activate,0.01); |
MBroek | 13:b0d3c547bf2f | 239 | |
MBroek | 13:b0d3c547bf2f | 240 | while(1){ |
MBroek | 13:b0d3c547bf2f | 241 | if(starting){ // Activeert het programma |
MBroek | 13:b0d3c547bf2f | 242 | |
MBroek | 13:b0d3c547bf2f | 243 | // Initialisatie --------------------------------------- |
MBroek | 13:b0d3c547bf2f | 244 | while(initializing){ |
MBroek | 13:b0d3c547bf2f | 245 | if (flag1){ |
MBroek | 13:b0d3c547bf2f | 246 | flag1 = false; |
MBroek | 13:b0d3c547bf2f | 247 | ledred = !ledred; |
MBroek | 13:b0d3c547bf2f | 248 | PID_output_1_in = PID_controller(reference_position_motor1, get_position_m1(rad_per_count)+starting_pos_m1, error_prev_1_in, error_int_1_in, Kp_1, Kd_1, Ki_1); |
MBroek | 13:b0d3c547bf2f | 249 | set_motor1(PID_output_1_in); |
MBroek | 13:b0d3c547bf2f | 250 | } |
MBroek | 13:b0d3c547bf2f | 251 | } |
MBroek | 13:b0d3c547bf2f | 252 | |
MBroek | 13:b0d3c547bf2f | 253 | ledred.write(1); |
MBroek | 13:b0d3c547bf2f | 254 | encoder_motor1.reset(); |
MBroek | 4:6524b198721f | 255 | |
MBroek | 0:9e053ed05c69 | 256 | while(safe){ // Draait loop zolang alles veilig is. |
MBroek | 4:6524b198721f | 257 | if (flag1){ |
MBroek | 4:6524b198721f | 258 | flag1 = false; |
MBroek | 13:b0d3c547bf2f | 259 | ledgreen = !ledgreen; |
MBroek | 9:f735baee0c2b | 260 | if (!which_motor){ // als which_motor=0 gaat motor 1 lopen |
MBroek | 13:b0d3c547bf2f | 261 | PID_output_1 = PID_controller(get_reference_position_m1(vrijheid_m1_rad), get_position_m1(rad_per_count), error_prev_1, error_int_1, Kp_1, Kd_1, Ki_1); |
MBroek | 9:f735baee0c2b | 262 | set_motor1(PID_output_1); |
MBroek | 9:f735baee0c2b | 263 | } |
MBroek | 9:f735baee0c2b | 264 | else{ |
MBroek | 13:b0d3c547bf2f | 265 | PID_output_2 = PID_controller(get_reference_position_m2(vrijheid_m2_meter), get_position_m2(meter_per_count), error_prev_2, error_int_2, Kp_2, Kd_2, Ki_2); |
MBroek | 9:f735baee0c2b | 266 | set_motor2(PID_output_2); |
MBroek | 9:f735baee0c2b | 267 | } |
MBroek | 4:6524b198721f | 268 | } |
MBroek | 4:6524b198721f | 269 | if (flag2){ |
MBroek | 4:6524b198721f | 270 | flag2 = false; |
MBroek | 13:b0d3c547bf2f | 271 | set_scope(PID_output_1, get_reference_position_m1(vrijheid_m1_rad), get_position_m1(meter_per_count)); |
MBroek | 4:6524b198721f | 272 | } |
MBroek | 0:9e053ed05c69 | 273 | } |
MBroek | 0:9e053ed05c69 | 274 | |
MBroek | 0:9e053ed05c69 | 275 | motor1_speed_pin = 0; //Dit zet de motoren uit nadat de kill switch is gebruikt |
MBroek | 0:9e053ed05c69 | 276 | motor2_speed_pin = 0; |
MBroek | 0:9e053ed05c69 | 277 | } |
MBroek | 13:b0d3c547bf2f | 278 | } |
MBroek | 13:b0d3c547bf2f | 279 | } |
MBroek | 0:9e053ed05c69 | 280 | |
MBroek | 0:9e053ed05c69 | 281 | |
MBroek | 0:9e053ed05c69 | 282 | |
MBroek | 0:9e053ed05c69 | 283 | |
MBroek | 0:9e053ed05c69 | 284 | |
MBroek | 0:9e053ed05c69 | 285 | |
MBroek | 0:9e053ed05c69 | 286 | |
MBroek | 0:9e053ed05c69 | 287 | |
MBroek | 0:9e053ed05c69 | 288 | |
MBroek | 0:9e053ed05c69 | 289 | |
MBroek | 0:9e053ed05c69 | 290 | |
MBroek | 0:9e053ed05c69 | 291 | |
MBroek | 0:9e053ed05c69 | 292 | |
MBroek | 0:9e053ed05c69 | 293 | |
MBroek | 0:9e053ed05c69 | 294 | |
MBroek | 0:9e053ed05c69 | 295 | |
MBroek | 0:9e053ed05c69 | 296 | |
MBroek | 0:9e053ed05c69 | 297 | |
MBroek | 0:9e053ed05c69 | 298 | |
MBroek | 0:9e053ed05c69 | 299 | |
MBroek | 0:9e053ed05c69 | 300 | |
MBroek | 0:9e053ed05c69 | 301 | |
MBroek | 0:9e053ed05c69 | 302 | |
MBroek | 0:9e053ed05c69 | 303 | |
MBroek | 0:9e053ed05c69 | 304 | |
MBroek | 0:9e053ed05c69 | 305 | |
MBroek | 0:9e053ed05c69 | 306 | |
MBroek | 0:9e053ed05c69 | 307 | |
MBroek | 0:9e053ed05c69 | 308 | |
MBroek | 0:9e053ed05c69 | 309 | |
MBroek | 0:9e053ed05c69 | 310 | |
MBroek | 0:9e053ed05c69 | 311 | |
MBroek | 0:9e053ed05c69 | 312 | |
MBroek | 0:9e053ed05c69 | 313 | |
MBroek | 0:9e053ed05c69 | 314 | |
MBroek | 0:9e053ed05c69 | 315 | |
MBroek | 0:9e053ed05c69 | 316 | |
MBroek | 0:9e053ed05c69 | 317 | |
MBroek | 0:9e053ed05c69 | 318 | |
MBroek | 0:9e053ed05c69 | 319 | |
MBroek | 0:9e053ed05c69 | 320 | |
MBroek | 0:9e053ed05c69 | 321 | |
MBroek | 0:9e053ed05c69 | 322 | |
MBroek | 0:9e053ed05c69 | 323 | |
MBroek | 0:9e053ed05c69 | 324 | |
MBroek | 0:9e053ed05c69 | 325 | |
MBroek | 0:9e053ed05c69 | 326 | |
MBroek | 0:9e053ed05c69 | 327 | |
MBroek | 0:9e053ed05c69 | 328 | |
MBroek | 0:9e053ed05c69 | 329 | |
MBroek | 0:9e053ed05c69 | 330 | |
MBroek | 0:9e053ed05c69 | 331 | |
MBroek | 0:9e053ed05c69 | 332 | |
MBroek | 0:9e053ed05c69 | 333 |