kazushiro tanimoto
/
sagawa_lpc1114
Sagawa Electronics,inc.
Fork of sagawa_lpc1114 by
TB6612FNG/TB6612.cpp@0:d90f3421aaef, 2016-11-26 (annotated)
- Committer:
- zero515
- Date:
- Sat Nov 26 18:33:38 2016 +0000
- Revision:
- 0:d90f3421aaef
- Child:
- 1:dbde3f68f80d
sagawa mbed4adrobo sample program
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
zero515 | 0:d90f3421aaef | 1 | /* wallbot mini Library |
zero515 | 0:d90f3421aaef | 2 | * |
zero515 | 0:d90f3421aaef | 3 | * wallbotmini.cpp |
zero515 | 0:d90f3421aaef | 4 | * |
zero515 | 0:d90f3421aaef | 5 | * Copyright (c) 2010-2013 jksoft |
zero515 | 0:d90f3421aaef | 6 | * |
zero515 | 0:d90f3421aaef | 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
zero515 | 0:d90f3421aaef | 8 | * of this software and associated documentation files (the "Software"), to deal |
zero515 | 0:d90f3421aaef | 9 | * in the Software without restriction, including without limitation the rights |
zero515 | 0:d90f3421aaef | 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
zero515 | 0:d90f3421aaef | 11 | * copies of the Software, and to permit persons to whom the Software is |
zero515 | 0:d90f3421aaef | 12 | * furnished to do so, subject to the following conditions: |
zero515 | 0:d90f3421aaef | 13 | * |
zero515 | 0:d90f3421aaef | 14 | * The above copyright notice and this permission notice shall be included in |
zero515 | 0:d90f3421aaef | 15 | * all copies or substantial portions of the Software. |
zero515 | 0:d90f3421aaef | 16 | * |
zero515 | 0:d90f3421aaef | 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
zero515 | 0:d90f3421aaef | 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
zero515 | 0:d90f3421aaef | 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
zero515 | 0:d90f3421aaef | 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
zero515 | 0:d90f3421aaef | 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
zero515 | 0:d90f3421aaef | 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
zero515 | 0:d90f3421aaef | 23 | * THE SOFTWARE. |
zero515 | 0:d90f3421aaef | 24 | */ |
zero515 | 0:d90f3421aaef | 25 | |
zero515 | 0:d90f3421aaef | 26 | |
zero515 | 0:d90f3421aaef | 27 | #include "TB6612.h" |
zero515 | 0:d90f3421aaef | 28 | |
zero515 | 0:d90f3421aaef | 29 | // TB6612 Class Constructor |
zero515 | 0:d90f3421aaef | 30 | TB6612::TB6612(PinName pwm, PinName fwd, PinName rev): |
zero515 | 0:d90f3421aaef | 31 | _pwm(pwm), _fwd(fwd), _rev(rev) { |
zero515 | 0:d90f3421aaef | 32 | |
zero515 | 0:d90f3421aaef | 33 | _fwd = 0; |
zero515 | 0:d90f3421aaef | 34 | _rev = 0; |
zero515 | 0:d90f3421aaef | 35 | _pwm = 0.0; |
zero515 | 0:d90f3421aaef | 36 | stat = 0; |
zero515 | 0:d90f3421aaef | 37 | _pwm.period(0.001); |
zero515 | 0:d90f3421aaef | 38 | |
zero515 | 0:d90f3421aaef | 39 | } |
zero515 | 0:d90f3421aaef | 40 | |
zero515 | 0:d90f3421aaef | 41 | // Speed Control |
zero515 | 0:d90f3421aaef | 42 | // arg |
zero515 | 0:d90f3421aaef | 43 | // float speed -1.0 - 0.0 - 1.0 |
zero515 | 0:d90f3421aaef | 44 | float TB6612::speed(float speed) { |
zero515 | 0:d90f3421aaef | 45 | |
zero515 | 0:d90f3421aaef | 46 | |
zero515 | 0:d90f3421aaef | 47 | |
zero515 | 0:d90f3421aaef | 48 | if( speed > 0.0 ) |
zero515 | 0:d90f3421aaef | 49 | { |
zero515 | 0:d90f3421aaef | 50 | if( speed > 0.7) speed = 0.7; |
zero515 | 0:d90f3421aaef | 51 | _pwm = speed; |
zero515 | 0:d90f3421aaef | 52 | _fwd = 1; |
zero515 | 0:d90f3421aaef | 53 | _rev = 0; |
zero515 | 0:d90f3421aaef | 54 | stat = 1; |
zero515 | 0:d90f3421aaef | 55 | } |
zero515 | 0:d90f3421aaef | 56 | else if( speed < 0.0 ) |
zero515 | 0:d90f3421aaef | 57 | { |
zero515 | 0:d90f3421aaef | 58 | if( speed < -0.7) speed = -0.7; |
zero515 | 0:d90f3421aaef | 59 | _pwm = -speed; |
zero515 | 0:d90f3421aaef | 60 | _fwd = 0; |
zero515 | 0:d90f3421aaef | 61 | _rev = 1; |
zero515 | 0:d90f3421aaef | 62 | stat = -1; |
zero515 | 0:d90f3421aaef | 63 | } |
zero515 | 0:d90f3421aaef | 64 | else |
zero515 | 0:d90f3421aaef | 65 | { |
zero515 | 0:d90f3421aaef | 66 | _fwd = 1; |
zero515 | 0:d90f3421aaef | 67 | _rev = 1; |
zero515 | 0:d90f3421aaef | 68 | stat = 0; |
zero515 | 0:d90f3421aaef | 69 | } |
zero515 | 0:d90f3421aaef | 70 | return speed==0 ? 0 : speed > 0 ? 1 : -1; |
zero515 | 0:d90f3421aaef | 71 | } |