![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
main + engine
Fork of Kola_Servo by
Engine.cpp@3:0de9cb065bee, 2016-06-14 (annotated)
- Committer:
- yruiewyrui3
- Date:
- Tue Jun 14 07:39:51 2016 +0000
- Revision:
- 3:0de9cb065bee
- Parent:
- 0:2294f5ee0610
vol.2_milion
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
yruiewyrui3 | 0:2294f5ee0610 | 1 | #include "Engine.h" |
yruiewyrui3 | 0:2294f5ee0610 | 2 | |
yruiewyrui3 | 0:2294f5ee0610 | 3 | // przelicza procenty na pwn: |
yruiewyrui3 | 0:2294f5ee0610 | 4 | // - wartosc poczatkowa - 0.2377, |
yruiewyrui3 | 0:2294f5ee0610 | 5 | // - prog - 0.0077 |
yruiewyrui3 | 0:2294f5ee0610 | 6 | float Engine::getPwm(float speed){ |
yruiewyrui3 | 0:2294f5ee0610 | 7 | if (speed == 0) |
yruiewyrui3 | 0:2294f5ee0610 | 8 | return 0; |
yruiewyrui3 | 0:2294f5ee0610 | 9 | else if (speed > 0) |
yruiewyrui3 | 0:2294f5ee0610 | 10 | return 0.2377f + (fabs(speed) - 1) * 0.0077f; |
yruiewyrui3 | 0:2294f5ee0610 | 11 | else |
yruiewyrui3 | 0:2294f5ee0610 | 12 | return 0.406f + (fabs(speed) - 1) * 0.006f; |
yruiewyrui3 | 0:2294f5ee0610 | 13 | } |
yruiewyrui3 | 0:2294f5ee0610 | 14 | |
yruiewyrui3 | 0:2294f5ee0610 | 15 | void Engine::move(int speed){ |
yruiewyrui3 | 0:2294f5ee0610 | 16 | if (speed > 100) |
yruiewyrui3 | 0:2294f5ee0610 | 17 | speed =100; |
yruiewyrui3 | 0:2294f5ee0610 | 18 | else if (speed < -100) |
yruiewyrui3 | 0:2294f5ee0610 | 19 | speed = -100; |
yruiewyrui3 | 0:2294f5ee0610 | 20 | |
yruiewyrui3 | 0:2294f5ee0610 | 21 | if (speed == 0){ |
yruiewyrui3 | 0:2294f5ee0610 | 22 | //soft stop |
yruiewyrui3 | 0:2294f5ee0610 | 23 | _fwd = 0; |
yruiewyrui3 | 0:2294f5ee0610 | 24 | _rev = 0; |
yruiewyrui3 | 0:2294f5ee0610 | 25 | return; |
yruiewyrui3 | 0:2294f5ee0610 | 26 | } |
yruiewyrui3 | 0:2294f5ee0610 | 27 | |
yruiewyrui3 | 0:2294f5ee0610 | 28 | if (speed < 0){ |
yruiewyrui3 | 0:2294f5ee0610 | 29 | _fwd = 0; |
yruiewyrui3 | 0:2294f5ee0610 | 30 | _rev = 1; |
yruiewyrui3 | 0:2294f5ee0610 | 31 | } |
yruiewyrui3 | 0:2294f5ee0610 | 32 | |
yruiewyrui3 | 0:2294f5ee0610 | 33 | else{ |
yruiewyrui3 | 0:2294f5ee0610 | 34 | _fwd = 1; |
yruiewyrui3 | 0:2294f5ee0610 | 35 | _rev = 0; |
yruiewyrui3 | 0:2294f5ee0610 | 36 | } |
yruiewyrui3 | 0:2294f5ee0610 | 37 | |
yruiewyrui3 | 0:2294f5ee0610 | 38 | _pwm = getPwm(speed); |
yruiewyrui3 | 0:2294f5ee0610 | 39 | } |
yruiewyrui3 | 0:2294f5ee0610 | 40 | |
yruiewyrui3 | 0:2294f5ee0610 | 41 | //hard stop |
yruiewyrui3 | 0:2294f5ee0610 | 42 | void Engine::stop(){ |
yruiewyrui3 | 0:2294f5ee0610 | 43 | _pwm = 0; |
yruiewyrui3 | 0:2294f5ee0610 | 44 | } |