First import from throwbot
Fork of TB6612FNG2 by
TB6612.cpp@0:810f315ba3dc, 2012-10-23 (annotated)
- Committer:
- jksoft
- Date:
- Tue Oct 23 15:24:30 2012 +0000
- Revision:
- 0:810f315ba3dc
- Child:
- 1:051a7ecff13e
TB6612FNG???????????????????
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jksoft | 0:810f315ba3dc | 1 | /** |
jksoft | 0:810f315ba3dc | 2 | * Motor Driver TB6612 Control Library |
jksoft | 0:810f315ba3dc | 3 | * |
jksoft | 0:810f315ba3dc | 4 | * -- TB6612 is a device of the TOSHIBA. |
jksoft | 0:810f315ba3dc | 5 | * |
jksoft | 0:810f315ba3dc | 6 | * Copyright (C) 2012 Junichi Katsu (JKSOFT) |
jksoft | 0:810f315ba3dc | 7 | */ |
jksoft | 0:810f315ba3dc | 8 | |
jksoft | 0:810f315ba3dc | 9 | |
jksoft | 0:810f315ba3dc | 10 | #include "TB6612.h" |
jksoft | 0:810f315ba3dc | 11 | |
jksoft | 0:810f315ba3dc | 12 | // TB6612 Class Constructor |
jksoft | 0:810f315ba3dc | 13 | TB6612::TB6612(PinName pwm, PinName fwd, PinName rev): |
jksoft | 0:810f315ba3dc | 14 | _pwm(pwm), _fwd(fwd), _rev(rev) { |
jksoft | 0:810f315ba3dc | 15 | |
jksoft | 0:810f315ba3dc | 16 | _fwd = 0; |
jksoft | 0:810f315ba3dc | 17 | _rev = 0; |
jksoft | 0:810f315ba3dc | 18 | _pwm = 0.0; |
jksoft | 0:810f315ba3dc | 19 | _pwm.period(0.001); |
jksoft | 0:810f315ba3dc | 20 | |
jksoft | 0:810f315ba3dc | 21 | bspeed = 0.0; |
jksoft | 0:810f315ba3dc | 22 | timer_flag = false; |
jksoft | 0:810f315ba3dc | 23 | } |
jksoft | 0:810f315ba3dc | 24 | |
jksoft | 0:810f315ba3dc | 25 | // Speed Control |
jksoft | 0:810f315ba3dc | 26 | // arg |
jksoft | 0:810f315ba3dc | 27 | // float speed -1.0 - 0.0 - 1.0 |
jksoft | 0:810f315ba3dc | 28 | void TB6612::speed(float speed) { |
jksoft | 0:810f315ba3dc | 29 | |
jksoft | 0:810f315ba3dc | 30 | if( timer_flag == true ) return; |
jksoft | 0:810f315ba3dc | 31 | |
jksoft | 0:810f315ba3dc | 32 | bspeed = speed; |
jksoft | 0:810f315ba3dc | 33 | |
jksoft | 0:810f315ba3dc | 34 | if( speed > 0.0 ) |
jksoft | 0:810f315ba3dc | 35 | { |
jksoft | 0:810f315ba3dc | 36 | _pwm = speed; |
jksoft | 0:810f315ba3dc | 37 | _fwd = 1; |
jksoft | 0:810f315ba3dc | 38 | _rev = 0; |
jksoft | 0:810f315ba3dc | 39 | } |
jksoft | 0:810f315ba3dc | 40 | else if( speed < 0.0 ) |
jksoft | 0:810f315ba3dc | 41 | { |
jksoft | 0:810f315ba3dc | 42 | _pwm = -speed; |
jksoft | 0:810f315ba3dc | 43 | _fwd = 0; |
jksoft | 0:810f315ba3dc | 44 | _rev = 1; |
jksoft | 0:810f315ba3dc | 45 | } |
jksoft | 0:810f315ba3dc | 46 | else |
jksoft | 0:810f315ba3dc | 47 | { |
jksoft | 0:810f315ba3dc | 48 | _fwd = 1; |
jksoft | 0:810f315ba3dc | 49 | _rev = 1; |
jksoft | 0:810f315ba3dc | 50 | } |
jksoft | 0:810f315ba3dc | 51 | } |
jksoft | 0:810f315ba3dc | 52 | |
jksoft | 0:810f315ba3dc | 53 | |
jksoft | 0:810f315ba3dc | 54 | // Speed Control with time-out |
jksoft | 0:810f315ba3dc | 55 | // arg |
jksoft | 0:810f315ba3dc | 56 | // float sspeed:-1.0 - 0.0 - 1.0 |
jksoft | 0:810f315ba3dc | 57 | // float time :0.0- |
jksoft | 0:810f315ba3dc | 58 | void TB6612::move(float sspeed , float time) |
jksoft | 0:810f315ba3dc | 59 | { |
jksoft | 0:810f315ba3dc | 60 | speed(sspeed); |
jksoft | 0:810f315ba3dc | 61 | timer_flag = true; |
jksoft | 0:810f315ba3dc | 62 | timer.attach(this,&TB6612::timeout,time); |
jksoft | 0:810f315ba3dc | 63 | } |
jksoft | 0:810f315ba3dc | 64 | |
jksoft | 0:810f315ba3dc | 65 | |
jksoft | 0:810f315ba3dc | 66 | void TB6612::timeout() |
jksoft | 0:810f315ba3dc | 67 | { |
jksoft | 0:810f315ba3dc | 68 | timer_flag = false; |
jksoft | 0:810f315ba3dc | 69 | speed(bspeed); |
jksoft | 0:810f315ba3dc | 70 | } |
jksoft | 0:810f315ba3dc | 71 |