control flow doet nog niks
Dependencies: Encoder HIDScope MODSERIAL mbed
Diff: main.cpp
- Revision:
- 4:072b99947fc6
- Parent:
- 3:7273bbe6aa02
- Child:
- 5:67afe491a1e3
diff -r 7273bbe6aa02 -r 072b99947fc6 main.cpp --- a/main.cpp Fri Oct 09 20:13:19 2015 +0000 +++ b/main.cpp Sat Oct 10 08:26:48 2015 +0000 @@ -37,10 +37,17 @@ AnalogIn potright(A0); // define the potmeter outputpins AnalogIn potleft(A1); -// RESETBUTTON - DigitalIn button(PTA4); // defines the button used for a encoder reset - int button_pressed = 0; +// BUTTONS + DigitalIn buttonlinks(PTA4); + DigitalIn buttonrechts(PTC6); + // init values + bool loop_start = false; + bool calib_start = false; +// LED + DigitalOut ledred(LED1); + DigitalOut ledgreen(LED2); + DigitalOut ledblue(LED3); // REFERENCE SIGNAL SETTINGS // Define signal amplification (needed with EMG, used in control loop, precise amp determination is a work in progress!!!!) ?? @@ -207,8 +214,10 @@ double output1 = PID(error1, m1_Kp, m1_Ki, m1_Kd, controlstep, m1_err_int, m1_prev_err); pc.printf("output 1 %f \n",output1); - // ws best locatie om output te blokkeren als grenzen bereikt zijn, simpel if-loopje met rad1 + // ws best locatie om output te blokkeren als grenzen bereikt zijn, simpel if-loopje met rad1?? + + // onderstaand kan vervangen worden door een functie voor beide motoren?? if(output1 > 0) { // uses the calculated output to determine the direction of the motor motor1_rich.write(0); motor1_aan.write(output1); @@ -257,25 +266,60 @@ int main() { pc.baud(115200); - // Ticker calling the primary functions. If neccessary use the ticker to change bools and execute in the main loop as shown in the sheets. - controller1.attach(&motor1_activate, controlstep); - // controller2.attach(&motor2_activate, controlstep); Disabled while debugging PID-controller + controller1.attach(&motor1_activate, controlstep); // call a go-flag + // controller2.attach(&motor2_activate, controlstep); Disabled while debugging PID-controller ?? while(true) { - if(motor1_go) + // button functions + if(buttonlinks.read() == 0) { - motor1_go = false; - motor1_control(); + loop_start = !loop_start; // reverse the boolean loop_start value + wait(buttonlinks.read() == 1); + wait(0.3); // check if it causes instability!! ?? } - if(motor2_go) + + if(buttonrechts.read() == 0) + { + calib_start = !calib_start; // reverse the boolean calib_start value + wait(buttonrechts.read() == 1); + wait(0.3); // check if it causes instability!! ?? + } + + // Main Control stuff and options + if(loop_start == true && calib_start == false) // check if start button = true then start the main control loops { - motor2_go = false; - motor2_control(); + ledred.write(1); + ledgreen.write(1); + ledblue.write(0); + + if(motor1_go) + { + motor1_go = false; + motor1_control(); + } + if(motor2_go) + { + motor2_go = false; + motor2_control(); + } } - if(button.read() == button_pressed) // reset the encoder to reference position + if(loop_start == false && calib_start == true) // start calibration procedures + { + ledred.write(1); + ledgreen.write(0); + ledblue.write(1); + } + if(loop_start == true && calib_start == true) // check if both buttons are enabled and stop everything { - motor1_enc.setPosition(reference1); - motor2_enc.setPosition(reference2); + ledred.write(0); + ledgreen.write(1); + ledblue.write(1); + } + else + { + ledred.write(1); + ledgreen.write(1); + ledblue.write(1); } } } \ No newline at end of file