TB6612FNG用のモータコントロールライブラリ
Dependents: BLE_WALLBOT_BLE net_trap_noBLE MoveTest Avoid ... more
TB6612.cpp
00001 /* wallbot mini Library 00002 * 00003 * wallbotmini.cpp 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 00027 #include "TB6612.h" 00028 00029 // TB6612 Class Constructor 00030 TB6612::TB6612(PinName pwm, PinName fwd, PinName rev): 00031 _pwm(pwm), _fwd(fwd), _rev(rev) { 00032 00033 _fwd = 0; 00034 _rev = 0; 00035 _pwm = 0.0; 00036 stat = 0; 00037 _pwm.period(0.001); 00038 00039 } 00040 00041 // Speed Control 00042 // arg 00043 // float speed -1.0 - 0.0 - 1.0 00044 float TB6612::speed(float speed) { 00045 00046 if( speed > 0.0 ) 00047 { 00048 _pwm = speed; 00049 _fwd = 1; 00050 _rev = 0; 00051 stat = 1; 00052 } 00053 else if( speed < 0.0 ) 00054 { 00055 _pwm = -speed; 00056 _fwd = 0; 00057 _rev = 1; 00058 stat = -1; 00059 } 00060 else 00061 { 00062 _fwd = 1; 00063 _rev = 1; 00064 stat = 0; 00065 } 00066 return speed==0 ? 0 : speed > 0 ? 1 : -1; 00067 }
Generated on Tue Dec 18 2018 15:13:23 by
