Bryce Williams / LMD18200

Files at this revision

API Documentation at this revision

Comitter:
electromotivated
Date:
Fri Jan 01 20:40:15 2016 +0000
Commit message:
Upload;

Changed in this revision

LMD18200.cpp Show annotated file Show diff for this revision Revisions of this file
LMD18200.h Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r 52968fafce73 LMD18200.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LMD18200.cpp	Fri Jan 01 20:40:15 2016 +0000
@@ -0,0 +1,27 @@
+#include "LMD18200.h"
+#include <algorithm>
+
+LMD18200::LMD18200(PinName pwm, PinName dir) : speed(pwm), direction(dir){
+    speed = 0.0;
+    direction = 0;
+}
+
+void LMD18200::setSpeed(float spd){
+    spd = clip(spd, 0.0, 1.0);      // Clamp value
+    speed = spd;                    // Set PWM Speed
+}
+
+void LMD18200::setDirection(int dir){
+    direction = dir;
+}
+
+/*
+    Clips value to lower/ uppper
+    @param value    The value to clip
+    @param lower    The mininum allowable value
+    @param upper    The maximum allowable value
+    @return         The resulting clipped value
+*/
+float LMD18200::clip(float value, float lower, float upper){
+    return std::max(lower, std::min(value, upper));
+}
diff -r 000000000000 -r 52968fafce73 LMD18200.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LMD18200.h	Fri Jan 01 20:40:15 2016 +0000
@@ -0,0 +1,41 @@
+#ifndef LMD18200_H
+#define LMD18200_H
+
+#include "mbed.h"
+
+/*
+    Very simple class for the LMD18200 H-Bridge Breakout Board
+*/
+
+class LMD18200{
+    public:
+    /*
+        Constructor for LMD18200 objects
+        @param pwm  PWM Pin used to set speed
+        @param dir  Digital Pin used to set direction
+    */
+    LMD18200(PinName pwm, PinName dir);
+    
+    /*
+        Set speed of motor
+        @param spd  The speed of the motor, as a percentage, 
+                    normalized between 0 and 1
+    */
+    void setSpeed(float spd);
+    
+    /*
+        Set the direction of the motor
+        @param dir  The direction of the motor, 0 or 1: 0 = FWD, 1 = REVERSE
+                    
+    */
+    void setDirection(int dir);
+    
+    private:
+    PwmOut speed;
+    DigitalOut direction;
+    /*
+        Clamps value between lower and upper values
+    */
+    float clip(float value, float lower, float upper);
+};
+#endif
\ No newline at end of file