asservissement robot 2, C++, doc fournie

Dependencies:   mbed QEI L298 Asservissement

Revision:
1:11cbd2bf65d7
diff -r a6cbfa280472 -r 11cbd2bf65d7 Moteur.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Moteur.cpp	Tue Mar 19 19:24:04 2019 +0000
@@ -0,0 +1,51 @@
+#include "Moteur.h"
+
+
+#define PERIODE_PWM_MOTEUR 0.001
+
+PwmOut mypwm_a(D6);
+PwmOut mypwm_b(D11);
+
+DigitalOut in1(D7);
+DigitalOut in2(D8);
+DigitalOut in3(D9);
+DigitalOut in4(D10);
+
+
+
+void moteur_init()
+{
+    mypwm_a.period(PERIODE_PWM_MOTEUR);
+    mypwm_b.period(PERIODE_PWM_MOTEUR);
+    mypwm_a.pulsewidth(0);
+    mypwm_b.pulsewidth(0);
+}
+
+void moteur_a(float percent)
+{
+
+    if (percent>=0) {
+        in1 = 1;
+        in2 = 0;
+    } else {
+        in1 = 0;
+        in2 = 1;
+        percent = -1 * percent;
+    }
+    mypwm_a.pulsewidth((float)percent*(float)PERIODE_PWM_MOTEUR);
+}
+
+void moteur_b(float percent)
+{
+
+    if (percent>=0) {
+        in4 = 1;
+        in3 = 0;
+    } else {
+        in4 = 0;
+        in3 = 1;
+        percent = -1 * percent;
+    }
+
+    mypwm_b.pulsewidth((float)percent*(float)PERIODE_PWM_MOTEUR);
+}