Drive Motor Group B4-B5

Fork of ArduMotoShield by Didier Donsez

Files at this revision

API Documentation at this revision

Comitter:
donsez
Date:
Sat Nov 08 15:44:22 2014 +0000
Child:
1:1c712818d82a
Commit message:
Create simple library and program for the SparkFun Ardumoto Shield https://www.sparkfun.com/products/9815;

Changed in this revision

ArduMotoShield.cpp Show annotated file Show diff for this revision Revisions of this file
ArduMotoShield.h Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ArduMotoShield.cpp	Sat Nov 08 15:44:22 2014 +0000
@@ -0,0 +1,110 @@
+/* 
+Simple library for the SparkFun Ardumoto Shield https://www.sparkfun.com/products/9815
+with the ST Nucleo F401RE
+ 
+The SparkFun Ardumoto shield can control two DC motors (up to 2 amps per motor). It is based on the L298 H-bridge. 
+
+Developped by : Didier Donsez & Jérome Maisonnasse
+ 
+ License: CC-SA 3.0, feel free to use this code however you'd like.
+ Please improve upon it! Let me know how you've made it better.
+ 
+ This is really simple example code to get you some basic functionality with the Ardumoto Shield.
+ 
+ */
+
+#include "ArduMotoShield.h"
+#include "mbed.h"
+
+// depend of the Vin and the max voltage of the motors
+float MAXPWM = 0.5f;
+                
+#define LOW 0
+#define HIGH 1
+
+DigitalOut inApin(D12, LOW); //direction control for motor outputs 1 and 2 is on digital pin 12
+DigitalOut inBpin(D13, LOW); //direction control for motor outputs 3 and 4 is on digital pin 13
+PwmOut pwmApin(D3); //PWM control for motor outputs 1 and 2 is on digital pin 3
+PwmOut pwmBpin(D11); //PWM control for motor outputs 3 and 4 is on digital pin 11
+
+bool isSetup=false;
+
+void ArduMotoShield::setVoltages(float vin, float vmaxmotor)
+{  
+
+    if(vin<vmaxmotor)
+        MAXPWM=1.0f;
+    else
+        MAXPWM=vmaxmotor/vin;
+}
+
+
+void ArduMotoShield::setup()
+{  
+    pwmApin.period_ms(10);
+    pwmApin.pulsewidth_ms(1);
+    pwmApin.write(0.0f);
+
+    pwmBpin.period_ms(10);
+    pwmBpin.pulsewidth_ms(1);  
+    pwmBpin.write(0.0f);
+    
+    isSetup=true;        
+}
+
+// Basic ArduMotoShield operations
+
+void ArduMotoShield::forward() //full speed forward
+{ 
+        if(!isSetup) setup();
+
+        inApin.write(LOW);
+        inBpin.write(LOW);
+        pwmApin.write(MAXPWM);
+        pwmBpin.write(MAXPWM);
+        printf("Forward\n");
+}
+
+void ArduMotoShield::backward() //full speed backward
+{
+        if(!isSetup) setup();
+
+        inApin.write(HIGH);
+        inBpin.write(HIGH);
+        pwmApin.write(MAXPWM);
+        pwmBpin.write(MAXPWM);
+        printf("Backward\n");
+}
+
+void ArduMotoShield::stop()
+{
+        if(!isSetup) setup();
+
+        inApin.write(LOW);
+        inBpin.write(LOW);
+        pwmApin.write(0.0f);
+        pwmBpin.write(0.0f);
+        printf("Stop\n");
+}
+
+void ArduMotoShield::right()
+{
+        if(!isSetup) setup();
+
+        inApin.write(HIGH);
+        inBpin.write(LOW);
+        pwmApin.write(MAXPWM);
+        pwmBpin.write(MAXPWM);
+        printf("Right\n");
+}
+
+void ArduMotoShield::left()
+{
+        if(!isSetup) setup();
+
+        inApin.write(LOW);
+        inBpin.write(HIGH);
+        pwmApin.write(MAXPWM);
+        pwmBpin.write(MAXPWM);
+        printf("Left\n");
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ArduMotoShield.h	Sat Nov 08 15:44:22 2014 +0000
@@ -0,0 +1,35 @@
+/* 
+ Simple library for the SparkFun Ardumoto Shield https://www.sparkfun.com/products/9815
+ with the ST Nucleo F401RE
+ 
+The SparkFun Ardumoto shield can control two DC motors (up to 2 amps per motor). It is based on the L298 H-bridge. 
+
+Developped by : Didier Donsez & Jérome Maisonnasse
+ 
+ License: CC-SA 3.0, feel free to use this code however you'd like.
+ Please improve upon it! Let me know how you've made it better.
+ 
+ This is really simple example code to get you some basic functionality with the Ardumoto Shield.
+ 
+ */
+
+
+#ifndef MBED_ARDUMOTOSHIELD_H
+#define MBED_ARDUMOTOSHIELD_H
+
+#include "mbed.h"
+
+class ArduMotoShield {
+public:
+    static void setVoltages(float vin, float vmaxmotor);
+
+    static void stop();
+    static void forward();
+    static void backward();
+    static void left();
+    static void right();
+private:
+    static void setup();
+};
+
+#endif