Prog Thib Ju

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
MaxLaMenace
Date:
Mon Apr 15 11:44:17 2019 +0000
Parent:
0:5535594ef331
Commit message:
R;

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Thu Apr 11 12:05:57 2019 +0000
+++ b/main.cpp	Mon Apr 15 11:44:17 2019 +0000
@@ -1,46 +1,75 @@
 #include "mbed.h"
  
-
+// Definition des variables : moteur
 PwmOut moteur1(D10); 
 PwmOut moteur2(D9);
 DigitalOut Trig(D12);
 InterruptIn reception(D8);
 
-DigitalOut myled(LED1);
+Serial pc(USBTX, USBRX);
 
-DigitalOut LED(LED1);
-Serial pc(USBTX, USBRX);
-Timer t;
+Timer t2;
 double  distance ;
 double rc;
 
+// Definition des variables : codeur
+InterruptIn ComptIncr(PA_8);
+
+Timer t1;
+
+float tps1;
+float tps2;
+float k;
+int a;
+float b;
+
+// Definition des fonctions : moteur
+
 void front_montant()
 {
-    t.start();
+    t2.start();
 }
 
 void front_descendant()
 {
-    t.stop();
-    double distance = 330*t.read()/2*1.06;
-   // pc.printf("Distance = %f \r\n",330*t.read()/2*1.06);
+    t2.stop();
+    double distance = 330*t2.read()/2*1.06;
     pc.printf("Distance = %lf \r\n", distance);
-    t.reset();
-    myled =1;
+    t2.reset();
     if (distance<=0.10){ rc = 0;}
     if (distance<=0.20 && distance>0.10){ rc = 0.5;}
     if (distance >=0.20) { rc = 1; }
-    //if (distance<=0.40 && distance>0.20){ rc = 0.6;}
-    //if (distance<=0.50 && distance>0.40){ rc = 0.8;}
-    //pc.printf("rapport cyclique = \r \n"); 
-    //pc.scanf("%lf" ,&rc);
-    pc.printf("Nouvelle valeur du rapport cyclique = %lf \r \n", rc);
     moteur2.write(rc);
+    
+    pc.printf("RC = %lf \r\n", rc);
 } 
 
+// Definition des fonctions : codeur
+
+void vitesse();
+
+void vitesse(){
+    if (a == 0){
+        tps1 = t1.read();
+        k = 0;
+        }    
+        a++;
+    if (a == 81) {
+        tps2 = t1.read();
+        k = tps2 - tps1;
+      // printf("Intervalle de temps =%f\n",k);
+        a = 0;
+        //printf("Vitesse = %f tours/s\n", 10/t.read());
+    }  
+}    
+
+// Debut du main
 int main() 
 {
-    t.reset();
+    
+    
+    // Initialisation Moteur
+    t2.reset();
     reception.rise(&front_montant);
     reception.fall(&front_descendant);
     moteur1.period_ms(10);
@@ -49,19 +78,29 @@
     moteur2.write(0);
     pc.baud(9600);
     
+    // Initialisation Codeur
+    a = 0;
+    k = 0;
+    b = 0;
+    t1.start();
+
+    ComptIncr.rise(&vitesse);
+    
+    // Debut du while
     while(1)
     {
+        // Partie moteur
         Trig = 1;
         wait(0.001);
         Trig =0 ; 
         wait(0.001);
-    /*    Trig = 0;
-        Trig = 1;    
+
     
-    //pc.printf("rapport cyclique = \r \n"); 
-    //pc.scanf("%lf" ,&rc);
-        pc.printf("Nouvelle valeur du rapport cyclique = %lf \r \n", rc);
-        moteur_cc_pwm.write(rc);
-    */    
+        // Partie codeur
+        b = t1.read();
+        //printf("Compteur = %d\n", a);
+        //printf("Temps 1 = %f\n", tps1);
+        //printf("Temps 2 = %f\n", tps2);
+        //printf("Test temps 1 = %f\n", b);
     }
 }
\ No newline at end of file