TB6612FNG用のモータコントロールライブラリ

Dependents:   BLE_WALLBOT_BLE net_trap_noBLE MoveTest Avoid ... more

Committer:
jksoft
Date:
Mon Jul 07 14:44:34 2014 +0000
Revision:
3:34ddc9038d9d
Parent:
2:ad4e7374e5c1
Child:
4:95d5e9ee8c15
???????

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jksoft 2:ad4e7374e5c1 1 /* mbed TB6612FNG Library
jksoft 2:ad4e7374e5c1 2 *
jksoft 2:ad4e7374e5c1 3 * TB6612.h
jksoft 2:ad4e7374e5c1 4 *
jksoft 2:ad4e7374e5c1 5 * Copyright (c) 2010-2013 jksoft
jksoft 0:810f315ba3dc 6 *
jksoft 2:ad4e7374e5c1 7 * Permission is hereby granted, free of charge, to any person obtaining a copy
jksoft 2:ad4e7374e5c1 8 * of this software and associated documentation files (the "Software"), to deal
jksoft 2:ad4e7374e5c1 9 * in the Software without restriction, including without limitation the rights
jksoft 2:ad4e7374e5c1 10 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
jksoft 2:ad4e7374e5c1 11 * copies of the Software, and to permit persons to whom the Software is
jksoft 2:ad4e7374e5c1 12 * furnished to do so, subject to the following conditions:
jksoft 0:810f315ba3dc 13 *
jksoft 2:ad4e7374e5c1 14 * The above copyright notice and this permission notice shall be included in
jksoft 2:ad4e7374e5c1 15 * all copies or substantial portions of the Software.
jksoft 2:ad4e7374e5c1 16 *
jksoft 2:ad4e7374e5c1 17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
jksoft 2:ad4e7374e5c1 18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
jksoft 2:ad4e7374e5c1 19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
jksoft 2:ad4e7374e5c1 20 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
jksoft 2:ad4e7374e5c1 21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
jksoft 2:ad4e7374e5c1 22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
jksoft 2:ad4e7374e5c1 23 * THE SOFTWARE.
jksoft 0:810f315ba3dc 24 */
jksoft 0:810f315ba3dc 25
jksoft 0:810f315ba3dc 26 #ifndef MBED_TB6612_H
jksoft 0:810f315ba3dc 27 #define MBED_TB6612_H
jksoft 0:810f315ba3dc 28
jksoft 0:810f315ba3dc 29 #include "mbed.h"
jksoft 0:810f315ba3dc 30
jksoft 2:ad4e7374e5c1 31 /** TB6612FNG Library
jksoft 2:ad4e7374e5c1 32 *
jksoft 2:ad4e7374e5c1 33 * Example:
jksoft 2:ad4e7374e5c1 34 * @code
jksoft 2:ad4e7374e5c1 35 * // Drive the Motor
jksoft 2:ad4e7374e5c1 36
jksoft 2:ad4e7374e5c1 37 #include "mbed.h"
jksoft 2:ad4e7374e5c1 38 #include "TB6612.h"
jksoft 2:ad4e7374e5c1 39
jksoft 2:ad4e7374e5c1 40 TB6612 motor(p21,p5,p6); // PWMA,AIN1,AIN2
jksoft 2:ad4e7374e5c1 41
jksoft 2:ad4e7374e5c1 42 int main() {
jksoft 2:ad4e7374e5c1 43
jksoft 2:ad4e7374e5c1 44 motor = 0.0; // Motor stopped.
jksoft 2:ad4e7374e5c1 45
jksoft 2:ad4e7374e5c1 46 while(1)
jksoft 2:ad4e7374e5c1 47 {
jksoft 2:ad4e7374e5c1 48 motor = 0.5; // Motor forward.
jksoft 2:ad4e7374e5c1 49 wait(2.0);
jksoft 2:ad4e7374e5c1 50 motor = -0.5; // Motor reversal.
jksoft 2:ad4e7374e5c1 51 wait(2.0);
jksoft 2:ad4e7374e5c1 52 }
jksoft 2:ad4e7374e5c1 53 }
jksoft 2:ad4e7374e5c1 54
jksoft 2:ad4e7374e5c1 55 * @endcode
jksoft 2:ad4e7374e5c1 56 */
jksoft 2:ad4e7374e5c1 57
jksoft 0:810f315ba3dc 58 class TB6612 {
jksoft 2:ad4e7374e5c1 59 // Public functions
jksoft 0:810f315ba3dc 60 public:
jksoft 2:ad4e7374e5c1 61 /** Create a TB6612 connected to the specified pins.
jksoft 3:34ddc9038d9d 62 * @param pwm A PwmOut pin, driving the H-bridge enable line to control the speed.(PwmOutに対応したポートを指定します。)
jksoft 3:34ddc9038d9d 63 * @param fwd A DigitalOut, set high when the motor should go forward.(DigitalOutに対応したポートを指定します。)
jksoft 3:34ddc9038d9d 64 * @param rev A DigitalOut, set high when the motor should go backwards.(DigitalOutに対応したポートを指定します。)
jksoft 2:ad4e7374e5c1 65 */
jksoft 0:810f315ba3dc 66 TB6612(PinName pwm, PinName fwd, PinName rev);
jksoft 2:ad4e7374e5c1 67 /** Directly control the speed and direction of the motor
jksoft 2:ad4e7374e5c1 68 *
jksoft 2:ad4e7374e5c1 69 * @param speed A normalised number -1.0 - 1.0 represents the full range.
jksoft 2:ad4e7374e5c1 70 * @return return the stopped state or direction of rotation.
jksoft 2:ad4e7374e5c1 71 */
jksoft 2:ad4e7374e5c1 72 float speed(float speed);
jksoft 2:ad4e7374e5c1 73 /** A operator shorthand for speed()
jksoft 2:ad4e7374e5c1 74 *
jksoft 2:ad4e7374e5c1 75 */
jksoft 0:810f315ba3dc 76 void operator= ( float value )
jksoft 0:810f315ba3dc 77 {
jksoft 0:810f315ba3dc 78 speed(value);
jksoft 0:810f315ba3dc 79 }
jksoft 0:810f315ba3dc 80
jksoft 0:810f315ba3dc 81 protected:
jksoft 0:810f315ba3dc 82 PwmOut _pwm;
jksoft 0:810f315ba3dc 83 DigitalOut _fwd;
jksoft 0:810f315ba3dc 84 DigitalOut _rev;
jksoft 0:810f315ba3dc 85 };
jksoft 0:810f315ba3dc 86
jksoft 0:810f315ba3dc 87 #endif