FN

Dependencies:   mbed RF24Network RF24

Files at this revision

API Documentation at this revision

Comitter:
guillaume6544
Date:
Wed May 01 16:39:19 2019 +0000
Parent:
9:ec9bf9f7645f
Commit message:
corrige erreur courte distance

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r ec9bf9f7645f -r 09b236addeb5 main.cpp
--- a/main.cpp	Mon Apr 08 12:51:46 2019 +0000
+++ b/main.cpp	Wed May 01 16:39:19 2019 +0000
@@ -6,25 +6,45 @@
 InterruptIn button(D8);
 AnalogIn LM35(A2);
 void position_abs(double, double, double, double,double);
-
+ 
 RF24 radio(SPI_MOSI, SPI_MISO, SPI_SCK, D9, SPI_CS );
 Timer timer;
 unsigned int temps;
 int a=0;
 float temperature;
 float vitesse;
-
+ 
 const int n = 3;
 int addr[n] = {01,02,03};
-float d[n];
+double d[n];
+double dist;
 int indice=0;
-
+ 
 void pressed()
 {
     button.disable_irq();
     timer.stop();
     temps = timer.read_us();
-    d[indice-1]=(temps-370.0)*(vitesse/1000000.0);
+    dist=(temps-370.0)*(vitesse/1000000.0);  //calcule la distance (eqution de calibration du système, considére la reponse et vitesse)
+    if(dist<0.14){
+        dist=dist+0.06;
+        d[indice-1]=dist;
+    }
+    if(dist>0.14 && dist<0.26){
+        dist=dist+0.05;
+        d[indice-1]=dist;
+    }
+    if(dist>0.26 && dist<0.34){
+        dist=dist+0.04;
+        d[indice-1]=dist;
+    }
+    if(dist>0.34 && dist<0.51){
+        dist=dist+0.03;
+        d[indice-1]=dist;
+    }
+    else{
+         d[indice-1]=dist;  
+    }
     //printf("distance=%f\r\n",(temps-70.0)*(vitesse/1000000.0);
     //wait_ms(3);
     timer.reset();
@@ -60,7 +80,7 @@
 };
  
 void emmeteur(){
-
+ 
             pc.printf("Sending : %d...",indice+1);
             payload_t payload_tx;
             payload_tx.ms = t_packet.read_ms();
@@ -79,7 +99,7 @@
      
 }
  void emmeteur2(){
-
+ 
            pc.printf("Sending : 2...");
             payload_t payload_tx;
             payload_tx.ms = t_packet.read_ms();
@@ -104,7 +124,7 @@
  
     pc.printf("mBed RF24Network node: Tx\r\n");
     radio.begin();
-    network.begin(/*channel*/ 90, /*node address*/ this_node);
+    network.begin(/*channel*/ 53, /*node address*/ this_node);
     wait_ms(2000);
     t.start();
     t_packet.start();
@@ -139,12 +159,12 @@
             button.enable_irq();
             emmeteur();
             button.enable_irq();
-
+ 
             indice++;
         }
     }
 }
-
+ 
 void position_abs(double L, double l, double d1, double d2, double d3)
 {
         printf("Hellooooooo auj!! \r\n");
@@ -202,3 +222,4 @@
         double yt = (y1+y2+y3)/3;
         printf(" yt= %lf \r\n",yt);
 }
+ 
\ No newline at end of file