Ljubivoj Cvitas
/
SunflowerMach1
Ovo je kopija vertije od Milana
Fork of SunflowerMach1 by
Diff: MotorDrivers/Motor.cpp
- Revision:
- 4:03b68322905f
- Parent:
- 3:bebfc64cefe4
- Child:
- 6:902bec57d9ae
diff -r bebfc64cefe4 -r 03b68322905f MotorDrivers/Motor.cpp --- a/MotorDrivers/Motor.cpp Sat Nov 09 13:44:18 2013 +0000 +++ b/MotorDrivers/Motor.cpp Sat Nov 09 18:35:13 2013 +0000 @@ -8,51 +8,22 @@ positiveOut = 0; negativeOut = 0; - - _isMoving = false; -} - -void Motor::movePositive() { - - direction = 1; - move(); -} - -void Motor::moveNegative() { - - direction = -1; - move(); } -void Motor::move() { - - positiveOut = 0; - negativeOut = 0; - - switch(direction) { - case 0: - return; - case 1: - positiveOut = 1; - break; - case -1: - negativeOut = 1; - break; - } +void Motor::start() { for (float i = 1; i > 0; i -= motorPwmChangeSpeed) { pwmOut = i; wait(motorPwmWaitTime); } pwmOut = 0; - _isMoving = true; - -// wait_ms(motorDriveTime); -// stop(); } void Motor::stop() { + if(direction == 0) + return; + for (float i = 0; i < 1; i += motorPwmChangeSpeed) { pwmOut = i; wait(motorPwmWaitTime); @@ -62,10 +33,35 @@ positiveOut = 0; negativeOut = 0; direction = 0; - _isMoving = false; +} + +void Motor::movePositive() { + + if(direction == 1) + return; + + if(direction == -1) + stop(); + + positiveOut = 1; + direction = 1; + start(); +} + +void Motor::moveNegative() { + + if(direction == -1) + return; + + if(direction == 1) + stop(); + + negativeOut = 1; + direction = -1; + start(); } bool Motor::isMoving() { - return _isMoving; + return direction == 0; }