Test moteur

Dependencies:   Encoder_Nucleo_16_bits PwmIn mbed

Fork of TestBoardv2_boussole_pixi by ilan Sandoz

Files at this revision

API Documentation at this revision

Comitter:
Dvlader
Date:
Sat Jun 10 05:09:17 2017 +0000
Parent:
9:53dd6df76cf8
Commit message:
A tester !!!; Si ?a fonctionne, ajoutez En = 1 ? la fonction motor_command

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 53dd6df76cf8 -r a98764d33fd5 main.cpp
--- a/main.cpp	Fri Jun 09 16:53:32 2017 +0000
+++ b/main.cpp	Sat Jun 10 05:09:17 2017 +0000
@@ -2,9 +2,9 @@
 #include "PwmIn.h"
 #include "Nucleo_Encoder_16_bits.h"
 
-#define Rotation 1, 100, -1, 100
-#define Vitesse1 1, 50, 1, 50
-#define Vitesse2 1, 100, 1, 100
+#define Avance_rapide 100, 100
+//#define Vitesse1 1, 50, 1, 50
+//#define Vitesse2 1, 100, 1, 100
 
 PwmOut      Pwm_MG  (PB_10);
 PwmOut      Pwm_MD  (PB_3);
@@ -12,23 +12,43 @@
 DigitalOut  SensG   (PC_8);
 DigitalOut  SensD   (PC_6);
 
-void moteur_command(double sensD, double pwmD, double sensG, double pwmG);
+void motor_command(int mg_command, int md_command, float* mg_pwm, float* md_pwm, int* mg_sens, int* md_sens);
+
+//Instructions
+
+//mg_command et md_command compris entre -100 et 100
+//void moteur_command(double sensD, double pwmD, double sensG, double pwmG);
 
 void main (void)
 {
-    moteur_command(Rotation);
-    wait_ms(500);
-    moteur_command(Vitesse1);
-    wait_ms(500);
-    moteur_command(Vitesse2);
-    wait_ms(500);
-    }
+    //Variables
+    En = 1;
+    float md_pwm = 0;
+    float mg_pwm = 0;
+    int md_sens = 1;
+    int mg_sens = 1;
+    
+    while(1)
+    {
+        //Appel fonction
+
+        motor_command(Avance_rapide, &mg_pwm, &md_pwm, &mg_sens, &md_sens);
+        }
+}
 
-void moteur_command(double sensD, double pwmD, double sensG, double pwmG)
-{
-    En = 1;
-    SensD = sensD;
-    Pwm_MD = pwmD;
-    SensG = sensG;
-    Pwm_MG = pwmG;
+void motor_command(int mg_command, int md_command, float* mg_pwm, float* md_pwm, int* mg_sens, int* md_sens) {
+    if(mg_command >= 0) {
+        *mg_sens = 0;
+        *mg_pwm = ((mg_command%101)/100);
+    } else {
+        *mg_sens = 1;
+        *mg_pwm = ((-mg_command%101)/100);
+    }
+    if(md_command >= 0) {
+        *mg_sens = 0;
+        *md_pwm = ((md_command%101)/100);
+    } else {
+        *md_sens = 1;
+        *md_pwm = ((-md_command%101)/100);
+    }
 }
\ No newline at end of file