kazushiro tanimoto
/
sagawa_lpc1114
Sagawa Electronics,inc.
Fork of sagawa_lpc1114 by
TB6612FNG/TB6612.cpp@1:dbde3f68f80d, 2016-11-26 (annotated)
- Committer:
- zero515
- Date:
- Sat Nov 26 19:09:24 2016 +0000
- Revision:
- 1:dbde3f68f80d
- Parent:
- 0:d90f3421aaef
up
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
zero515 | 0:d90f3421aaef | 1 | #include "TB6612.h" |
zero515 | 0:d90f3421aaef | 2 | |
zero515 | 0:d90f3421aaef | 3 | // TB6612 Class Constructor |
zero515 | 0:d90f3421aaef | 4 | TB6612::TB6612(PinName pwm, PinName fwd, PinName rev): |
zero515 | 0:d90f3421aaef | 5 | _pwm(pwm), _fwd(fwd), _rev(rev) { |
zero515 | 0:d90f3421aaef | 6 | |
zero515 | 0:d90f3421aaef | 7 | _fwd = 0; |
zero515 | 0:d90f3421aaef | 8 | _rev = 0; |
zero515 | 0:d90f3421aaef | 9 | _pwm = 0.0; |
zero515 | 0:d90f3421aaef | 10 | stat = 0; |
zero515 | 0:d90f3421aaef | 11 | _pwm.period(0.001); |
zero515 | 0:d90f3421aaef | 12 | |
zero515 | 0:d90f3421aaef | 13 | } |
zero515 | 0:d90f3421aaef | 14 | |
zero515 | 0:d90f3421aaef | 15 | // Speed Control |
zero515 | 0:d90f3421aaef | 16 | // arg |
zero515 | 0:d90f3421aaef | 17 | // float speed -1.0 - 0.0 - 1.0 |
zero515 | 0:d90f3421aaef | 18 | float TB6612::speed(float speed) { |
zero515 | 0:d90f3421aaef | 19 | |
zero515 | 0:d90f3421aaef | 20 | |
zero515 | 0:d90f3421aaef | 21 | |
zero515 | 0:d90f3421aaef | 22 | if( speed > 0.0 ) |
zero515 | 0:d90f3421aaef | 23 | { |
zero515 | 0:d90f3421aaef | 24 | if( speed > 0.7) speed = 0.7; |
zero515 | 0:d90f3421aaef | 25 | _pwm = speed; |
zero515 | 0:d90f3421aaef | 26 | _fwd = 1; |
zero515 | 0:d90f3421aaef | 27 | _rev = 0; |
zero515 | 0:d90f3421aaef | 28 | stat = 1; |
zero515 | 0:d90f3421aaef | 29 | } |
zero515 | 0:d90f3421aaef | 30 | else if( speed < 0.0 ) |
zero515 | 0:d90f3421aaef | 31 | { |
zero515 | 0:d90f3421aaef | 32 | if( speed < -0.7) speed = -0.7; |
zero515 | 0:d90f3421aaef | 33 | _pwm = -speed; |
zero515 | 0:d90f3421aaef | 34 | _fwd = 0; |
zero515 | 0:d90f3421aaef | 35 | _rev = 1; |
zero515 | 0:d90f3421aaef | 36 | stat = -1; |
zero515 | 0:d90f3421aaef | 37 | } |
zero515 | 0:d90f3421aaef | 38 | else |
zero515 | 0:d90f3421aaef | 39 | { |
zero515 | 0:d90f3421aaef | 40 | _fwd = 1; |
zero515 | 0:d90f3421aaef | 41 | _rev = 1; |
zero515 | 0:d90f3421aaef | 42 | stat = 0; |
zero515 | 0:d90f3421aaef | 43 | } |
zero515 | 0:d90f3421aaef | 44 | return speed==0 ? 0 : speed > 0 ? 1 : -1; |
zero515 | 0:d90f3421aaef | 45 | } |