Program for testing motion boards (double motor controller)

Dependencies:   mbed

Program to test motion boards (double motor controller).

The mbed board reads from a joystick and then sends the commands to the motor board (l293d), which lets the small caterpillar go ahead, go back and turn.

/media/uploads/mariob/2014-06-14_23.36.59.jpg /media/uploads/mariob/2014-06-14_23.36.46.jpg

Files at this revision

API Documentation at this revision

Comitter:
mariob
Date:
Sat Jun 14 21:56:12 2014 +0000
Commit message:
example to test motion boards

Changed in this revision

dc_motor.cpp Show annotated file Show diff for this revision Revisions of this file
dc_motor.hpp Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r 5307ae36f268 dc_motor.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/dc_motor.cpp	Sat Jun 14 21:56:12 2014 +0000
@@ -0,0 +1,14 @@
+#include "dc_motor.hpp"
+
+DC_motor::DC_motor (PinName ppwm, PinName pdir): pwm(ppwm), dir(pdir)
+{
+    pwm.period(0.001);
+    pwm = 0;
+    dir = 0;
+}
+
+void DC_motor::speed (float speed)
+{
+    dir = speed>0.0;
+    pwm = abs(speed);
+}
diff -r 000000000000 -r 5307ae36f268 dc_motor.hpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/dc_motor.hpp	Sat Jun 14 21:56:12 2014 +0000
@@ -0,0 +1,19 @@
+#ifndef DC_MOTOR
+#define DC_MOTOR
+
+#include "mbed.h"
+
+class DC_motor
+{
+    PwmOut pwm;
+    DigitalOut dir;
+
+public:
+
+    DC_motor (PinName ppwm, PinName pdir);
+
+    void speed(float speed);
+
+};
+
+#endif
diff -r 000000000000 -r 5307ae36f268 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Sat Jun 14 21:56:12 2014 +0000
@@ -0,0 +1,26 @@
+#include "mbed.h"
+#include "dc_motor.hpp"
+
+int main ()
+{
+    AnalogIn vert(p20);
+    AnalogIn horz(p19);
+    DC_motor m_sx(p21, p22);
+    DC_motor m_dx(p23, p24);
+
+    while(1) {
+        wait(0.2);
+        float v = vert.read();
+        float h = horz.read();
+        float speed_sx = (v-0.5)*2.0;
+        if (h>0.5)
+            speed_sx *= (1.0-(h-0.5)*2.0);
+        float speed_dx = (v-0.5)*2.0;
+        if (h<0.5)
+            speed_dx *= ((h+0.5)*2.0-1.0);
+        m_sx.speed(speed_sx);
+        m_dx.speed(speed_dx);
+//        printf("VERT(%f), HORZ(%f), sx(%f), dx(%f)\n\r",
+//                vert.read(), horz.read(), speed_sx, speed_dx);
+    }
+}
diff -r 000000000000 -r 5307ae36f268 mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Sat Jun 14 21:56:12 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/024bf7f99721
\ No newline at end of file