TB6612FNG用のモータコントロールライブラリ
Dependents: BLE_WALLBOT_BLE net_trap_noBLE MoveTest Avoid ... more
TB6612.h
00001 /* mbed TB6612FNG Library 00002 * 00003 * TB6612.h 00004 * 00005 * Copyright (c) 2010-2013 jksoft 00006 * 00007 * Permission is hereby granted, free of charge, to any person obtaining a copy 00008 * of this software and associated documentation files (the "Software"), to deal 00009 * in the Software without restriction, including without limitation the rights 00010 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 00011 * copies of the Software, and to permit persons to whom the Software is 00012 * furnished to do so, subject to the following conditions: 00013 * 00014 * The above copyright notice and this permission notice shall be included in 00015 * all copies or substantial portions of the Software. 00016 * 00017 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 00018 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00019 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 00020 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 00021 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00022 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 00023 * THE SOFTWARE. 00024 */ 00025 00026 #ifndef MBED_TB6612_H 00027 #define MBED_TB6612_H 00028 00029 #include "mbed.h" 00030 00031 /** TB6612FNG Library 00032 * 00033 * Example: 00034 * @code 00035 * // Drive the Motor 00036 00037 #include "mbed.h" 00038 #include "TB6612.h" 00039 00040 TB6612 motor(p21,p5,p6); // PWMA,AIN1,AIN2 00041 00042 int main() { 00043 00044 motor = 0.0; // Motor stopped. 00045 00046 while(1) 00047 { 00048 motor = 0.5; // Motor forward. 00049 wait(2.0); 00050 motor = -0.5; // Motor reversal. 00051 wait(2.0); 00052 } 00053 } 00054 00055 * @endcode 00056 */ 00057 00058 class TB6612 { 00059 // Public functions 00060 public: 00061 /** Create a TB6612 connected to the specified pins. 00062 * @param pwm A PwmOut pin, driving the H-bridge enable line to control the speed.(PwmOutに対応したポートを指定します。) 00063 * @param fwd A DigitalOut, set high when the motor should go forward.(DigitalOutに対応したポートを指定します。) 00064 * @param rev A DigitalOut, set high when the motor should go backwards.(DigitalOutに対応したポートを指定します。) 00065 */ 00066 TB6612(PinName pwm, PinName fwd, PinName rev); 00067 /** Directly control the speed and direction of the motor 00068 * 00069 * @param speed A normalised number -1.0 - 1.0 represents the full range. 00070 * @return return the stopped state or direction of rotation. 00071 */ 00072 float speed(float speed); 00073 /** A operator shorthand for speed() 00074 * 00075 */ 00076 void operator= ( float value ) 00077 { 00078 speed(value); 00079 } 00080 operator int() 00081 { 00082 return(stat); 00083 } 00084 00085 protected: 00086 PwmOut _pwm; 00087 DigitalOut _fwd; 00088 DigitalOut _rev; 00089 int stat; 00090 }; 00091 00092 #endif
Generated on Sun Jul 17 2022 01:36:14 by 1.7.2