Motor control, feedback, PI controller, BiQuad filter
Dependencies: FastPWM HIDScope MODSERIAL biquadFilter mbed QEI
Diff: main.cpp
- Revision:
- 9:076eb8beea30
- Parent:
- 8:ceb9abb5a4a8
--- a/main.cpp Mon Oct 15 12:13:42 2018 +0000 +++ b/main.cpp Mon Oct 15 12:38:37 2018 +0000 @@ -32,18 +32,21 @@ // Returns reference velocity in rad/s. // Positive value means clockwise rotation. // 60 rpm = 60*2*pi/60 = 6.28 ~ 6.2 rad/s - const float maxVelocity=6.2; // in rad/s of course! + const double maxVelocity= 6.2; // in rad/s of course! double referenceVelocity; // in rad/s - if (button2) - { - // Clockwise rotation - referenceVelocity = potMeterIn * maxVelocity; - } - else - { - // Counterclockwise rotation + switch(motor1_direction) + { + case 0: // Clockwise rotation + referenceVelocity = -1*potMeterIn * maxVelocity; + pc.printf("Velocity is %d\r\n", referenceVelocity); + break; + case 1: // Counterclockwise rotation referenceVelocity = -1*potMeterIn * maxVelocity; - } + pc.printf("Velocity is %d\r\n", referenceVelocity); + break; + default: + pc.printf("It goes wrong, the velocity is not -1 or 1"); + } return referenceVelocity; }