Library for the CustomExplorerRobot.
Dependents: CustomExplorerRobot_test
Diff: BD6212/BD6212.cpp
- Revision:
- 0:ad4667fc5a76
diff -r 000000000000 -r ad4667fc5a76 BD6212/BD6212.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/BD6212/BD6212.cpp Sat Feb 27 09:20:21 2016 +0000 @@ -0,0 +1,36 @@ +#include "mbed.h" +#include "BD6212.h" + +BD6212::BD6212(PinName fwd, PinName rev) : _fwd(fwd), _rev(rev){ + _fwd.period_us(20); + _rev.period_us(20); + _fwd = 0.0f; + _rev = 0.0f; + + bspeed = 0.0f; +} + +void BD6212::speed(float speed){ + _fwd.period_us(20); + _rev.period_us(20); + if(speed != bspeed){ + if(speed > 0.0f){ + _fwd = speed; + _rev = 0.0f; + }else if(speed < 0.0f){ + _fwd = 0.0f; + _rev = -speed; + }else{ + _fwd = 1.0f; + _rev = 1.0f; + } + bspeed = speed; + } +} + +void BD6212::coast(void){ + _fwd.period_us(20); + _rev.period_us(20); + _fwd = 0.0f; + _rev = 0.0f; +}