![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
.
Dependencies: HCSR04v2 Servo mbed
Fork of CZOSINHO by
Diff: Engine.cpp
- Revision:
- 0:5919ea7b3b90
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Engine.cpp Tue Jun 21 07:45:32 2016 +0000 @@ -0,0 +1,44 @@ +#include "Engine.h" + +// przelicza procenty na pwn: +// - wartosc poczatkowa - 0.2377, +// - prog - 0.0077 +float Engine::getPwm(float speed){ + if (speed == 0) + return 0; + else if (speed > 0) + return 0.2377f + (fabs(speed) - 1) * 0.0077f; + else + return 0.406f + (fabs(speed) - 1) * 0.006f; + } + +void Engine::move(int speed){ + if (speed > 100) + speed =100; + else if (speed < -100) + speed = -100; + + if (speed == 0){ + //soft stop + _fwd = 0; + _rev = 0; + return; + } + + if (speed < 0){ + _fwd = 0; + _rev = 1; + } + + else{ + _fwd = 1; + _rev = 0; + } + + _pwm = getPwm(speed); +} + +//hard stop +void Engine::stop(){ + _pwm = 0; +} \ No newline at end of file