V1

Dependents:   VITI_motor_angle_1 VITI_motor_angle_2 VITI_motor_angle_3

Files at this revision

API Documentation at this revision

Comitter:
gr66
Date:
Thu May 21 17:42:47 2020 +0000
Commit message:
V1

Changed in this revision

TB6549.cpp Show annotated file Show diff for this revision Revisions of this file
TB6549.h Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TB6549.cpp	Thu May 21 17:42:47 2020 +0000
@@ -0,0 +1,37 @@
+/* mbed simple H-bridge motor controller
+ * Copyright (c) 2007-2010,
+ *
+
+ */
+
+#include "TB6549.h"
+
+#include "mbed.h"
+
+Motor::Motor(PinName pwm, PinName in1, PinName in2,PinName sb):
+    _pwm(pwm), _in1(in1), _in2(in2), _sb(sb)
+{
+
+    // Set initial condition of PWM
+    _pwm.period(0.001);
+    _pwm = 0;
+
+    // Initial condition stand by
+    _in1 = 0;
+    _in2 = 0;
+    _sb = 0;
+}
+
+void Motor::speed(float speed)
+{
+    if(speed > 0) {
+        _in1=0;
+        _in2=1;
+        _sb=1;
+    } else {
+        _in1=1;
+        _in2=0;
+        _sb=1;
+    }
+    _pwm = abs(speed);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TB6549.h	Thu May 21 17:42:47 2020 +0000
@@ -0,0 +1,43 @@
+/* mbed simple H-bridge motor controller
+ * Copyright (c) 
+ 
+ */
+ 
+#ifndef MBED_MOTOR_H
+#define MBED_MOTOR_H
+ 
+#include "mbed.h"
+ 
+/** Interface to control a standard DC motor 
+ *
+ * with an H-bridge using a PwmOut and 3 DigitalOuts
+ */
+class Motor {
+public:
+ 
+    /** Create a motor control interface    
+     *
+     * @param pwm A PwmOut pin, driving the H-bridge enable line to control the speed
+     * @param in1 A DigitalOut, 
+     * @param in2 A DigitalOut, 
+     * @param sb  
+     A DigitalOut, 
+     */
+    Motor(PinName pwm, PinName in1, PinName in2, PinName sb);
+    
+    /** Set the speed of the motor
+     * 
+     * @param speed The speed of the motor as a normalised value between -1.0 and 1.0
+     */
+    void speed(float speed);
+ 
+protected:
+    PwmOut _pwm;
+    DigitalOut _in1;
+    DigitalOut _in2;
+    DigitalOut _sb;
+ 
+};
+ 
+#endif
+ 
\ No newline at end of file