Library that controls BD6211F of rohm.

Dependents:   WallBot_Simple WallbotTypeN

Files at this revision

API Documentation at this revision

Comitter:
jksoft
Date:
Wed Apr 27 02:51:14 2011 +0000
Commit message:

Changed in this revision

BD6211F.cpp Show annotated file Show diff for this revision Revisions of this file
BD6211F.h Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r e27bf165308f BD6211F.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/BD6211F.cpp	Wed Apr 27 02:51:14 2011 +0000
@@ -0,0 +1,68 @@
+/**
+ * Motor Driver BD6211F Control Library
+ *
+ * -- BD6211F is a device of the rohm. 
+ *
+ * Copyright (C) 2011 Junichi Katsu (JKSOFT) 
+ */
+
+
+#include "BD6211F.h"
+
+// BD6211F Class Constructor
+BD6211F::BD6211F(PinName fwd, PinName rev):
+        _fwd(fwd), _rev(rev) {
+
+    _fwd.period(0.00005);
+    _rev.period(0.00005);
+    _fwd = 0.0;
+    _rev = 0.0;
+    bspeed = 0.0;
+    timer_flag = false;
+}
+
+// Speed Control
+//  arg
+//   float speed�F-1.0 �` 0.0 �` 1.0
+void BD6211F::speed(float speed) {
+    
+    if( timer_flag == true )    return;
+    
+    bspeed = speed;
+    
+    if( speed > 0.0 )
+    {
+        _fwd = speed;
+        _rev = 0.0;
+    }
+    else if( speed < 0.0 )
+    {
+        _fwd = 0.0;
+        _rev = -speed;
+    }
+    else
+    {
+        _fwd = 1.0;
+        _rev = 1.0;
+    }
+}
+
+
+// Speed Control with time-out
+//  arg
+//   float sspeed:-1.0 &#65533;` 0.0 &#65533;` 1.0
+//   float time  :0.0&#65533;`
+void BD6211F::move(float sspeed , float time)
+{
+    speed(sspeed);
+    timer_flag = true;
+    timer.attach(this,&BD6211F::timeout,time);
+}
+
+
+void BD6211F::timeout()
+{
+    timer_flag = false;
+    speed(bspeed);
+}
+
diff -r 000000000000 -r e27bf165308f BD6211F.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/BD6211F.h	Wed Apr 27 02:51:14 2011 +0000
@@ -0,0 +1,34 @@
+/**
+ * Motor Driver BD6211F Control Library
+ *
+ * -- BD6211F is a device of the rohm. 
+ *
+ * Copyright (C) 2011 Junichi Katsu (JKSOFT) 
+ */
+
+#ifndef MBED_BD6211F_H
+#define MBED_BD6211F_H
+
+#include "mbed.h"
+
+class BD6211F {
+public:
+    BD6211F(PinName fwd, PinName rev);
+    void speed(float speed);
+    void move(float speed , float time);
+	void operator= ( float value )
+	{
+		speed(value);
+	}
+	
+protected:
+    PwmOut _fwd;
+    PwmOut _rev;
+    Timeout timer;
+    float    bspeed;
+    bool     timer_flag;
+    void timeout();
+
+};
+
+#endif