![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Feedforward controller
Dependencies: MODSERIAL QEI mbed
Fork of Tut5_motor_controller by
Diff: main.cpp
- Revision:
- 2:abd40da4a5e2
- Parent:
- 1:659489c32e75
- Child:
- 3:cc3766838777
--- a/main.cpp Wed Oct 04 14:15:39 2017 +0000 +++ b/main.cpp Wed Oct 04 15:02:08 2017 +0000 @@ -8,15 +8,15 @@ DigitalOut gpo(D0); DigitalOut led(LED_BLUE); DigitalOut motor1DC(D7); -DigitalOut motor1PWM(D6); +PwmOut motor1PWM(D6); DigitalOut motor2DC(D4); -DigitalOut motor2PWM(D5); +PwmOut motor2PWM(D5); AnalogIn potMeterIn(A0); DigitalIn button1(D11); MODSERIAL pc(USBTX,USBRX); -QEI Encoder(D12,D13,NC,32); // Input for the Encoder + Ticker controller; @@ -65,24 +65,31 @@ { float referenceVelocity = GetReferenceVelocity(); float motorValue = FeedForwardControl(referenceVelocity); - setMotor1(motorValue); + SetMotor1(motorValue); } int main() { pc.baud(115200); + QEI Encoder(D12,D13,NC,32); //float v = GetReferenceVelocity(); //float controlValue = FeedForwardControl(v); //SetMotor1(controlValue); - controller.attach(&MeasureAndControl,0.01); - - int counts = Encoder.getPulses(); - pc.printf("\r `control value: %f reference velocity: %f. Motor Value is: %f number of counts: %i\n",referenceVelocity ,motorValue,counts); + controller.attach(&MeasureAndControl, 0.1); while(1) - {} + { + + + int counts = Encoder.getPulses(); + float rV = GetReferenceVelocity(); + float mV = FeedForwardControl(rV); + + pc.printf("\r reference velocity: %f. Motor Value is: %f number of counts: %i\n",mV,rV,counts); + } + }