Control up to two motors using filtered EMG signals and a PID controller
Dependencies: FastPWM HIDScope MODSERIAL QEI Matrix biquadFilter controller errorFetch mbed motorConfig refGen MatrixMath inverseKinematics
Fork of Minor_test_serial by
Diff: main.cpp
- Revision:
- 20:4ce3fb543a45
- Parent:
- 19:f08b5cd2b7ce
- Child:
- 21:d266d1e503ce
diff -r f08b5cd2b7ce -r 4ce3fb543a45 main.cpp --- a/main.cpp Fri Oct 06 05:29:52 2017 +0000 +++ b/main.cpp Fri Oct 06 07:23:26 2017 +0000 @@ -36,15 +36,17 @@ // MOTOR CONTROL PART +bool m1_direction = false; + // Function getReferenceVelocity returns reference r between -8.4 and 8.4 rad/s float getReferenceVelocity(){ const float maxVelocity = 8.4; // max velocity in rad/s double r; - if(motor1_direction = false){ + if(m1_direction == false){ // Clockwise rotation yields positive reference r = maxVelocity*pot.read(); } - if(motor1_direction = true){ + if(m1_direction == true){ // Counterclockwise rotation yields negative reference r = -1*maxVelocity*pot.read(); } @@ -103,7 +105,7 @@ void M1switchDirection(){ - motor1_direction = !motor1_direction; + m1_direction = !m1_direction; } // readEncoder reads counts and revs and logs results to serial window @@ -118,7 +120,7 @@ int main() { pc.printf("Main function"); - motor1_direction = false; // False = clockwise rotation + motor1_direction = 0; // False = clockwise rotation motor1_pwm.period(pwmPeriod);//T=1/f sw2.fall(&killSwitch); sw3.fall(&turnMotorsOn);