TB6612FNG用のモータコントロールライブラリ
Dependents: TB6612FNG_test line_trace_sample line_trace_sample_saitou line_trace_sample_tamada ... more
Diff: TB6612.cpp
- Revision:
- 1:051a7ecff13e
- Parent:
- 0:810f315ba3dc
--- a/TB6612.cpp Tue Oct 23 15:24:30 2012 +0000 +++ b/TB6612.cpp Mon Nov 12 16:39:11 2012 +0000 @@ -17,29 +17,22 @@ _rev = 0; _pwm = 0.0; _pwm.period(0.001); - - bspeed = 0.0; - timer_flag = false; } // Speed Control // arg -// float speed -1.0 - 0.0 - 1.0 -void TB6612::speed(float speed) { - - if( timer_flag == true ) return; - - bspeed = speed; - - if( speed > 0.0 ) +// int speed -100 -- 0 -- 100 +void TB6612::speed(int speed) { + + if( speed > 0 ) { - _pwm = speed; + _pwm = ((float)speed) / 100.0; _fwd = 1; _rev = 0; } - else if( speed < 0.0 ) + else if( speed < 0 ) { - _pwm = -speed; + _pwm = -((float)speed) / 100.0; _fwd = 0; _rev = 1; } @@ -53,19 +46,10 @@ // Speed Control with time-out // arg -// float sspeed:-1.0 - 0.0 - 1.0 -// float time :0.0- -void TB6612::move(float sspeed , float time) +// int speed -100 -- 0 -- 100 +// int time 0 +void TB6612::move(int sspeed , int time) { speed(sspeed); - timer_flag = true; - timer.attach(this,&TB6612::timeout,time); + wait_ms(time); } - - -void TB6612::timeout() -{ - timer_flag = false; - speed(bspeed); -} -