It is a library for controlling Wallbot mini

Dependents:   wallbotmini_test

Committer:
jksoft
Date:
Sat Nov 02 01:04:00 2013 +0000
Revision:
0:a11da93ea3f6
Rev1

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jksoft 0:a11da93ea3f6 1 /**
jksoft 0:a11da93ea3f6 2 * Motor Driver TB6612 Control Library
jksoft 0:a11da93ea3f6 3 *
jksoft 0:a11da93ea3f6 4 * -- TB6612 is a device of the TOSHIBA.
jksoft 0:a11da93ea3f6 5 *
jksoft 0:a11da93ea3f6 6 * Copyright (C) 2012 Junichi Katsu (JKSOFT)
jksoft 0:a11da93ea3f6 7 */
jksoft 0:a11da93ea3f6 8
jksoft 0:a11da93ea3f6 9
jksoft 0:a11da93ea3f6 10 #include "TB6612.h"
jksoft 0:a11da93ea3f6 11
jksoft 0:a11da93ea3f6 12 // TB6612 Class Constructor
jksoft 0:a11da93ea3f6 13 TB6612::TB6612(PinName pwm, PinName fwd, PinName rev):
jksoft 0:a11da93ea3f6 14 _pwm(pwm), _fwd(fwd), _rev(rev) {
jksoft 0:a11da93ea3f6 15
jksoft 0:a11da93ea3f6 16 _fwd = 0;
jksoft 0:a11da93ea3f6 17 _rev = 0;
jksoft 0:a11da93ea3f6 18 _pwm = 0.0;
jksoft 0:a11da93ea3f6 19 _pwm.period(0.001);
jksoft 0:a11da93ea3f6 20
jksoft 0:a11da93ea3f6 21 bspeed = 0.0;
jksoft 0:a11da93ea3f6 22 timer_flag = false;
jksoft 0:a11da93ea3f6 23 }
jksoft 0:a11da93ea3f6 24
jksoft 0:a11da93ea3f6 25 // Speed Control
jksoft 0:a11da93ea3f6 26 // arg
jksoft 0:a11da93ea3f6 27 // float speed -1.0 - 0.0 - 1.0
jksoft 0:a11da93ea3f6 28 void TB6612::speed(float speed) {
jksoft 0:a11da93ea3f6 29
jksoft 0:a11da93ea3f6 30 if( timer_flag == true ) return;
jksoft 0:a11da93ea3f6 31
jksoft 0:a11da93ea3f6 32 bspeed = speed;
jksoft 0:a11da93ea3f6 33
jksoft 0:a11da93ea3f6 34 if( speed > 0.0 )
jksoft 0:a11da93ea3f6 35 {
jksoft 0:a11da93ea3f6 36 _pwm = speed;
jksoft 0:a11da93ea3f6 37 _fwd = 1;
jksoft 0:a11da93ea3f6 38 _rev = 0;
jksoft 0:a11da93ea3f6 39 }
jksoft 0:a11da93ea3f6 40 else if( speed < 0.0 )
jksoft 0:a11da93ea3f6 41 {
jksoft 0:a11da93ea3f6 42 _pwm = -speed;
jksoft 0:a11da93ea3f6 43 _fwd = 0;
jksoft 0:a11da93ea3f6 44 _rev = 1;
jksoft 0:a11da93ea3f6 45 }
jksoft 0:a11da93ea3f6 46 else
jksoft 0:a11da93ea3f6 47 {
jksoft 0:a11da93ea3f6 48 _fwd = 1;
jksoft 0:a11da93ea3f6 49 _rev = 1;
jksoft 0:a11da93ea3f6 50 }
jksoft 0:a11da93ea3f6 51 }
jksoft 0:a11da93ea3f6 52
jksoft 0:a11da93ea3f6 53
jksoft 0:a11da93ea3f6 54 // Speed Control with time-out
jksoft 0:a11da93ea3f6 55 // arg
jksoft 0:a11da93ea3f6 56 // float sspeed:-1.0 - 0.0 - 1.0
jksoft 0:a11da93ea3f6 57 // float time :0.0-
jksoft 0:a11da93ea3f6 58 void TB6612::move(float sspeed , float time)
jksoft 0:a11da93ea3f6 59 {
jksoft 0:a11da93ea3f6 60 speed(sspeed);
jksoft 0:a11da93ea3f6 61 timer_flag = true;
jksoft 0:a11da93ea3f6 62 timer.attach(this,&TB6612::timeout,time);
jksoft 0:a11da93ea3f6 63 }
jksoft 0:a11da93ea3f6 64
jksoft 0:a11da93ea3f6 65
jksoft 0:a11da93ea3f6 66 void TB6612::timeout()
jksoft 0:a11da93ea3f6 67 {
jksoft 0:a11da93ea3f6 68 timer_flag = false;
jksoft 0:a11da93ea3f6 69 speed(bspeed);
jksoft 0:a11da93ea3f6 70 }
jksoft 0:a11da93ea3f6 71