Feedforward controller
Dependencies: MODSERIAL QEI mbed
Fork of Tut5_motor_controller by
Diff: main.cpp
- Revision:
- 3:cc3766838777
- Parent:
- 2:abd40da4a5e2
- Child:
- 4:983b50758735
--- a/main.cpp Wed Oct 04 15:02:08 2017 +0000 +++ b/main.cpp Thu Oct 05 13:10:39 2017 +0000 @@ -6,19 +6,22 @@ DigitalOut gpo(D0); -DigitalOut led(LED_BLUE); +DigitalOut ledb(LED_BLUE); +DigitalOut ledr(LED_RED); +DigitalOut ledg(LED_GREEN); DigitalOut motor1DC(D7); PwmOut motor1PWM(D6); DigitalOut motor2DC(D4); PwmOut motor2PWM(D5); -AnalogIn potMeterIn(A0); +AnalogIn potMeterIn1(A0); +AnalogIn PotMeterIn2(A1); + DigitalIn button1(D11); MODSERIAL pc(USBTX,USBRX); - +Ticker controller; -Ticker controller; float GetReferenceVelocity() { @@ -31,11 +34,15 @@ if (button1) { // Clockwise rotation - referenceVelocity = potMeterIn * maxVelocity; + referenceVelocity = potMeterIn1 * maxVelocity; + ledr = 1; + ledb = 0; } else { // Counterclockwise rotation - referenceVelocity = -1*potMeterIn * maxVelocity; + referenceVelocity = -1*potMeterIn1 * maxVelocity; + ledb = 1; + ledr = 0; } return referenceVelocity; } @@ -68,21 +75,21 @@ SetMotor1(motorValue); } + + int main() { pc.baud(115200); QEI Encoder(D12,D13,NC,32); - - //float v = GetReferenceVelocity(); - //float controlValue = FeedForwardControl(v); - //SetMotor1(controlValue); + + ledr = 1; + ledb = 1; + ledg = 1; controller.attach(&MeasureAndControl, 0.1); - + while(1) - { - - + { int counts = Encoder.getPulses(); float rV = GetReferenceVelocity(); float mV = FeedForwardControl(rV);