Dominik Święch
/
Kola_Servo
main + engine
Fork of Komunikacja_read_write by
Diff: Engine.cpp
- Revision:
- 0:2294f5ee0610
diff -r 000000000000 -r 2294f5ee0610 Engine.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Engine.cpp Wed Jun 01 10:47:53 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