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