![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
group 2
Revision 0:331597250051, committed 2017-10-03
- Comitter:
- RoyvZ
- Date:
- Tue Oct 03 15:30:08 2017 +0000
- Commit message:
- kijk naar v_ref waarom hij uit en aan gaat ipv harder en zachter
Changed in this revision
diff -r 000000000000 -r 331597250051 MODSERIAL.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MODSERIAL.lib Tue Oct 03 15:30:08 2017 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/Sissors/code/MODSERIAL/#a3b2bc878529
diff -r 000000000000 -r 331597250051 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Tue Oct 03 15:30:08 2017 +0000 @@ -0,0 +1,89 @@ +#include "mbed.h" +#include "MODSERIAL.h" +#include "math.h" + +DigitalOut gpo(D0); +DigitalOut motorDirection(D4); +DigitalOut motorSpeed(D5); +AnalogIn potMeterIn(A1); +InterruptIn button1(D3); +Ticker ticker; + +MODSERIAL pc(USBTX, USBRX); + + +float GetReferenceVelocity() +{ + // Returns reference velocity in rad/s. + // Positive value means clockwise rotation. + const float maxVelocity=8.4; // in rad/s of course! + float referenceVelocity; // in rad/s + if (button1) { + // Clockwise rotation + referenceVelocity = potMeterIn * maxVelocity; + } + else { + // Counterclockwise rotation + referenceVelocity = -1*potMeterIn * maxVelocity; + } + return referenceVelocity; +} + +void setMotor(float motorValue) { + if (motorValue >= 0) + { + //float motor1DirectionPin1 = 1; + motorDirection=1; + } + else + { + //float motor1DirectionPin1 = 0; + motorDirection=0; + } + + if (fabs(motorValue)>1) + { + //float motor1MagnitudePin1 = 1; + motorSpeed = 1; + } + else + { + //float motor1MagnitudePin1 = fabs(motorValue); + motorSpeed = fabs(motorValue); + } +} + +float FeedForwardControl(float referenceVelocity) +{ + // very simple linear feed-forward control + const float MotorGain=8.4; // unit: (rad/s) / PWM + float motorValue = referenceVelocity / MotorGain; + return motorValue; +} + + +void MeasureAndControl(void) +{ + // This function measures the potmeter position, extracts a + // reference velocity from it, and controls the motor with + // a simple FeedForward controller. Call this from a Ticker. + float referenceVelocity = GetReferenceVelocity(); + float motorValue = FeedForwardControl(referenceVelocity); + setMotor(motorValue); +} + +int main() { + pc.baud(115200); + //ticker.attach(MeasureAndControl, 0.01); + while(true){ + wait(0.1); + + //pc.printf("%f\r\n",GetReferenceVelocity()); + float v_ref = GetReferenceVelocity(); + setMotor(v_ref); + pc.printf("%f \r\n", FeedForwardControl(v_ref)); + motorDirection.write(motorDirection); + motorSpeed.write(motorSpeed); //PWM Speed Control + } +} + \ No newline at end of file
diff -r 000000000000 -r 331597250051 mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Tue Oct 03 15:30:08 2017 +0000 @@ -0,0 +1,1 @@ +https://mbed.org/users/mbed_official/code/mbed/builds/235179ab3f27 \ No newline at end of file