Gestion pont-H pour moteur CC

Revision:
0:af7b948d1f33
Child:
1:4dc14e8e5ff7
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/yMOTOR.cpp	Sat Sep 12 12:41:43 2015 +0000
@@ -0,0 +1,80 @@
+/**
+ * @file    yMOTOR.cpp
+ * @brief   Class 'yMOTOR'
+ * @version V0.1
+ * @date    12-Sept-2015
+ * @note    by Jean92 \n
+ *          Controlleur pour Pont-H (MC33886)" \n
+ *
+ */
+#include "mbed.h"
+#include "yMOTOR.h"
+
+/** Constructeur de la class yMOTOR */
+yMOTOR::yMOTOR(PinName pwm, PinName av, PinName ar):
+                _pwm(pwm), _av(av), _ar(ar) {
+     // init PWM
+    _pwm.period(yPeriod_def);
+    _pwm = 0.0;
+    
+    // moteur a l'arret
+    _ar = 0;
+    _av = 0;
+
+    // memory of speed
+    this->m_speed = 0.0;
+}
+
+/** Traiter le changement de vitesse */
+void yMOTOR::Speed(float speed) {
+    if (abs(speed) < yDB_def) {     // stop motor
+        _ar = 0;
+        _av = 0;
+        _pwm = 0.0;
+        this->m_speed = 0.0;
+    }
+    else {
+        _av = (speed > yDB_def);
+        _ar = (speed < -yDB_def);
+        _pwm = abs(speed);
+        this->m_speed = speed;
+    } 
+} 
+
+/** Changer la periode de PWM */
+void yMOTOR::Period(float seconds) {
+    _pwm.period(seconds);
+}
+
+/** Marche/Arret request */
+void yMOTOR::MarArr(int mararr) {
+    if (mararr == yMARCHE) {
+        Speed(this->m_speed);
+    }
+    else if (mararr == yARRET) {
+        _ar = 0;
+        _av = 0;
+        this->m_speed = 0.0;
+    }
+}
+
+/** Etat marche (running state) */
+bool yMOTOR::Run() {
+    return (abs(this->m_speed) > yDB_def);
+}
+
+/** Vitesse effective */
+float yMOTOR::Velocity() {
+    return this->m_speed;   
+}
+
+/** Destructeur */
+yMOTOR::~yMOTOR()
+{ // ne rien mettre ici
+}
+
+/**
+ * @note \n
+ *         That's all folks!
+ */
+ 
\ No newline at end of file