wallbot control Library
Embed:
(wiki syntax)
Show/hide line numbers
TB6612.cpp
00001 /** 00002 * Motor Driver TB6612 Control Library 00003 * 00004 * -- TB6612 is a device of the TOSHIBA. 00005 * 00006 * Copyright (C) 2012 Junichi Katsu (JKSOFT) 00007 */ 00008 00009 00010 #include "TB6612.h" 00011 00012 // TB6612 Class Constructor 00013 TB6612::TB6612(PinName pwm, PinName fwd, PinName rev): 00014 _pwm(pwm), _fwd(fwd), _rev(rev) { 00015 00016 _fwd = 0; 00017 _rev = 0; 00018 _pwm = 0.0; 00019 _pwm.period(0.001); 00020 00021 bspeed = 0.0; 00022 timer_flag = false; 00023 } 00024 00025 // Speed Control 00026 // arg 00027 // float speed -1.0 - 0.0 - 1.0 00028 void TB6612::speed(float speed) { 00029 nowspeed = speed; 00030 00031 if( timer_flag == true ) return; 00032 00033 bspeed = speed; 00034 00035 if( speed > 0.0 ) 00036 { 00037 _pwm = speed; 00038 _fwd = 1; 00039 _rev = 0; 00040 } 00041 else if( speed < 0.0 ) 00042 { 00043 _pwm = -speed; 00044 _fwd = 0; 00045 _rev = 1; 00046 } 00047 else 00048 { 00049 _fwd = 1; 00050 _rev = 1; 00051 } 00052 } 00053 00054 00055 // Speed Control with time-out 00056 // arg 00057 // float sspeed:-1.0 - 0.0 - 1.0 00058 // float time :0.0- 00059 void TB6612::move(float sspeed , float time) 00060 { 00061 speed(sspeed); 00062 timer_flag = true; 00063 timer.attach(this,&TB6612::timeout,time); 00064 } 00065 00066 00067 void TB6612::timeout() 00068 { 00069 timer_flag = false; 00070 speed(bspeed); 00071 } 00072
Generated on Mon Aug 22 2022 09:01:58 by 1.7.2