This library is an attempt to encapsulate the Pololu motor board.
Revision 1:69e4a93b718d, committed 2013-02-11
- Comitter:
- buckeyes1997
- Date:
- Mon Feb 11 20:53:20 2013 +0000
- Parent:
- 0:b7c4b6de973e
- Commit message:
- added more checks on speed
Changed in this revision
Motor.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r b7c4b6de973e -r 69e4a93b718d Motor.cpp --- a/Motor.cpp Mon Feb 11 19:49:50 2013 +0000 +++ b/Motor.cpp Mon Feb 11 20:53:20 2013 +0000 @@ -4,9 +4,9 @@ Motor::Motor(PinName pwm, PinName dir1, PinName dir2): _pwm(pwm), _dir1(dir1), _dir2(dir2) { - _direction=1; - _pwm.period(0.00005); - _pwm = 0; + _direction=1; //default fwd + _pwm.period(0.00005); //20Khz + _pwm = 0; //default pwm off _dir1 = 0; _dir2 = 0; @@ -21,17 +21,51 @@ _dir1=0; _dir2=1; } + if(speed > 1) { + speed = 1; + } + if(speed < -1) { + speed = -1; + } + _pwm = abs(speed); return speed; } float Motor::speed(float speed) { + if(speed > 1) { + speed = 1; + } + if(speed < -1) { + speed = -1; + } + if(speed < 0) { + _dir1=1; + _dir2=0; + } else { + _dir1=0; + _dir2=1; + } _pwm = abs(speed); return speed; } -Motor& Motor::operator= (float speed) { +Motor& Motor::operator= (float speed) +{ + if(speed > 1) { + speed = 1; + } + if(speed < -1) { + speed = -1; + } + if(speed < 0) { + _dir1=1; + _dir2=0; + } else { + _dir1=0; + _dir2=1; + } _pwm = abs(speed); - return *this; + return *this; }