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:
- 23:917179f72762
- Parent:
- 22:2e473e9798c0
- Child:
- 24:672abc3f02b7
--- a/main.cpp Fri Oct 06 10:43:24 2017 +0000 +++ b/main.cpp Fri Oct 06 12:03:26 2017 +0000 @@ -43,7 +43,7 @@ // MOTOR CONTROL PART bool m1_direction = false; -int posRevRange = 5; // describes the ends of the position range in complete motor output shaft revolutions in both directions +int posRevRange = 2; // describes the ends of the position range in complete motor output shaft revolutions in both directions const float maxAngle = 2*3.14*posRevRange; // max angle in radians const float Ts = 0.1; @@ -73,7 +73,7 @@ pc.printf("%0.2f revolutions \r\n", motor1Position); posError = getReferencePosition() - motor1Position; - integralError = integralError + Ts*totalError; + integralError = integralError + Ts*posError; totalError = posError + integralError; pc.printf("Error is %0.2f \r \n", totalError); } @@ -81,7 +81,7 @@ // motorController sets a motorValue based on the position error. Sign indicates direction and magnitude indicates speed. Right now this is a simple feedforward float motorController(float posError, float integralError){ float k_p = 5*pot2.read(); // use potmeter 2 to adjust k_p within range 0 to 1 - float k_i = 0.0000000001; + float k_i = 0.001; // How do I pick a reasonable value for k_i? double motorValue = (posError*k_p)/maxAngle + 0.35 + k_i*integralError; // motorValue is the normalized voltage applied to motor magnitude pin between -1 and 1 added 0.35 as motorvalue of 0.35 does nothing return motorValue; }