
motor aansturing moet lineair zijn is het niet
Dependencies: MODSERIAL Encoder mbed HIDScope
Diff: main.cpp
- Revision:
- 19:da210f89db18
- Parent:
- 18:e3b41351ee71
--- a/main.cpp Wed Oct 07 13:25:49 2015 +0000 +++ b/main.cpp Wed Oct 07 18:27:03 2015 +0000 @@ -4,7 +4,7 @@ #include "HIDScope.h" Serial pc(USBTX,USBRX); -HIDScope scope(1); // definieerd het aantal kanalen van de scope +HIDScope scope(2); // definieerd het aantal kanalen van de scope Ticker controller1, controller2; // definieer de ticker die controler1 doet @@ -27,6 +27,7 @@ //POTMETERS AnalogIn potright(A0); AnalogIn potleft(A1); +AnalogIn gainpot(A5); // RESETBUTTON DigitalIn button(PTA4); @@ -104,6 +105,16 @@ // // // // // // EINDE FILTERZOOI +double EMG_gain () +{ + double frac = gainpot.read(); + double EMG_Gain = frac*30; + return EMG_Gain; + scope.set(1,EMG_Gain); + scope.send(); +} + +// // // // // // EXtra funties // counts 2 radians // this function takes the counts from the encoder and converts it to // the amount of radians from the zero position. @@ -159,7 +170,7 @@ // // // // // // // // // // void motor1_control() { - double input = (EMG_Filter())*15 ; + double input = EMG_Filter()*EMG_gain() ; if(input > 1 ) { input = 1; @@ -168,6 +179,7 @@ { input = 0; } + double setpoint1 = setpoint_f(input, c_setpoint1); // determine the setpoint that has been set by the inputsignal double rads1 = get_radians(motor1_enc.getPosition()); // determine the position of the motor double error1 = (setpoint1 - rads1); // determine the error (reference - position) @@ -195,7 +207,7 @@ // scope.set(4,rads2); // scope.send(); double output2 = K_control(error2, K2); // bereken de controller output voor motor 1(zie hierboven) - if(output2 > 0) { // + if(output2 > 0) { // determine the direction motor2_rich.write(0); motor2_aan.write(output2); } else if(output2 < 0) { @@ -211,7 +223,7 @@ controller2.attach(&motor2_control, controlstep); while(true) { - if(button.read() == button_pressed) + if(button.read() == button_pressed) // reset the counts { motor1_enc.setPosition(0); motor2_enc.setPosition(0);