Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: BLE_WALLBOT_BLE net_trap_noBLE MoveTest Avoid ... more
Revision 2:ad4e7374e5c1, committed 2014-06-29
- Comitter:
- jksoft
- Date:
- Sun Jun 29 06:47:01 2014 +0000
- Parent:
- 0:810f315ba3dc
- Child:
- 3:34ddc9038d9d
- Commit message:
- First edition.
Changed in this revision
| TB6612.cpp | Show annotated file Show diff for this revision Revisions of this file |
| TB6612.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/TB6612.cpp Tue Oct 23 15:24:30 2012 +0000
+++ b/TB6612.cpp Sun Jun 29 06:47:01 2014 +0000
@@ -1,9 +1,26 @@
-/**
- * Motor Driver TB6612 Control Library
+/* wallbot mini Library
+ *
+ * wallbotmini.cpp
+ *
+ * Copyright (c) 2010-2013 jksoft
*
- * -- TB6612 is a device of the TOSHIBA.
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
*
- * Copyright (C) 2012 Junichi Katsu (JKSOFT)
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
*/
@@ -18,18 +35,12 @@
_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;
+float TB6612::speed(float speed) {
if( speed > 0.0 )
{
@@ -48,24 +59,5 @@
_fwd = 1;
_rev = 1;
}
-}
-
-
-// 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)
-{
- speed(sspeed);
- timer_flag = true;
- timer.attach(this,&TB6612::timeout,time);
-}
-
-
-void TB6612::timeout()
-{
- timer_flag = false;
- speed(bspeed);
-}
-
+ return speed==0 ? 0 : speed > 0 ? 1 : -1;
+}
\ No newline at end of file
--- a/TB6612.h Tue Oct 23 15:24:30 2012 +0000
+++ b/TB6612.h Sun Jun 29 06:47:01 2014 +0000
@@ -1,9 +1,26 @@
-/**
- * Motor Driver TB6612 Control Library
+/* mbed TB6612FNG Library
+ *
+ * TB6612.h
+ *
+ * Copyright (c) 2010-2013 jksoft
*
- * -- TB6612 is a device of the rohm.
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
*
- * Copyright (C) 2012 Junichi Katsu (JKSOFT)
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
*/
#ifndef MBED_TB6612_H
@@ -11,11 +28,51 @@
#include "mbed.h"
+/** TB6612FNG Library
+ *
+ * Example:
+ * @code
+ * // Drive the Motor
+
+#include "mbed.h"
+#include "TB6612.h"
+
+TB6612 motor(p21,p5,p6); // PWMA,AIN1,AIN2
+
+int main() {
+
+ motor = 0.0; // Motor stopped.
+
+ while(1)
+ {
+ motor = 0.5; // Motor forward.
+ wait(2.0);
+ motor = -0.5; // Motor reversal.
+ wait(2.0);
+ }
+ }
+
+ * @endcode
+ */
+
class TB6612 {
+ // Public functions
public:
+ /** Create a TB6612 connected to the specified pins.
+ * @param pwm A PwmOut pin, driving the H-bridge enable line to control the speed.
+ * @param fwd A DigitalOut, set high when the motor should go forward.
+ * @param rev A DigitalOut, set high when the motor should go backwards.
+ */
TB6612(PinName pwm, PinName fwd, PinName rev);
- void speed(float speed);
- void move(float speed , float time);
+ /** Directly control the speed and direction of the motor
+ *
+ * @param speed A normalised number -1.0 - 1.0 represents the full range.
+ * @return return the stopped state or direction of rotation.
+ */
+ float speed(float speed);
+ /** A operator shorthand for speed()
+ *
+ */
void operator= ( float value )
{
speed(value);
@@ -25,11 +82,6 @@
PwmOut _pwm;
DigitalOut _fwd;
DigitalOut _rev;
- Timeout timer;
- float bspeed;
- bool timer_flag;
- void timeout();
-
};
#endif