Ljubivoj Cvitas
/
SunflowerMach1a
Slow version
Fork of SunflowerMach1 by
Diff: Motor.cpp
- Revision:
- 1:2e7d4aa6e79e
- Parent:
- 0:7447b8021b33
diff -r 7447b8021b33 -r 2e7d4aa6e79e Motor.cpp --- a/Motor.cpp Fri Nov 08 19:09:47 2013 +0000 +++ b/Motor.cpp Fri Nov 08 22:33:31 2013 +0000 @@ -1,7 +1,7 @@ #include "Motor.h" -Motor::Motor(PinName positivePin, PinName negativePin): positiveOut(positivePin), negativeOut(negativePin) { - +Motor::Motor(PinName positivePin, PinName negativePin, PinName enablePin): positiveOut(positivePin), negativeOut(negativePin), enableOut(enablePin) { +enableOut.period(0.010); // set PWM period to 10 ms } void Motor::movePositive() { @@ -10,12 +10,22 @@ move(); } +void Motor::moveNegativeSlow() { + + direction = -1; + moveslow(); +} +void Motor::movePositiveSlow() { + + direction = 1; + moveslow(); +} + void Motor::moveNegative() { direction = -1; move(); } - void Motor::move() { positiveOut = 0; @@ -34,10 +44,45 @@ wait_ms(motorDriveTime); } +void Motor::moveslow() { + positiveOut = 0; + negativeOut = 0; + + switch(direction) { + case 0: + return; + case 1: + positiveOut = 1; + break; + case -1: + negativeOut = 1; + break; + } + for (int i=0; i<1; i=i+0.1) { // slow running start 0.5 s + enableOut= i; + wait(0.05); + } + wait_ms(motorDriveTime); +} +void Motor::initpwm() { + + enableOut.period(0.010); // set PWM period to 10 ms + enableOut = 0.5; // set initial duty cycle to 50% +} void Motor::stop() { positiveOut = 0; negativeOut = 0; direction = 0; } +void Motor::stopslow() { + + for (int i=1; i>0; i=i-0.1) { + enableOut= i; + wait(0.05); + } + positiveOut = 0; + negativeOut = 0; + direction = 0; +}