Capteur_US

Dependencies:   mbed DRV8825

Files at this revision

API Documentation at this revision

Comitter:
g0dd4
Date:
Tue Oct 13 14:50:31 2020 +0000
Parent:
15:43f5bda97488
Commit message:
Conversion du temps en distance ; Detection d'un obstacle; Changement de base; Test_fonctionnelle ;

Changed in this revision

captUS.cpp Show annotated file Show diff for this revision Revisions of this file
captUS.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 43f5bda97488 -r 4c0b1647e8ae captUS.cpp
--- a/captUS.cpp	Mon Sep 28 19:17:00 2020 +0000
+++ b/captUS.cpp	Tue Oct 13 14:50:31 2020 +0000
@@ -1,16 +1,22 @@
+#include "captUS.h"
+#include "pins.h"
+#include "math.h"
 //Nom du fichier : captUS.cpp
-#include "pins.h"
 
 // Variables globales & timers
 float us_out[6];
+float* distance;
 Timer tps;
 Ticker ticker_US;
 
+
 void captUS_init(){
+    ::distance = new float(6); //équivalent au malloc()
     tps.reset();
     tps.start();
 }
 
+
 void captUS_trig(){
     tps.reset();
     trigger=1;
@@ -39,22 +45,56 @@
 
 float* convertToDistance(){
     /**************************************
-     *création d'un tableau où l'ensemble *
-     *des distance serons stockées        *
-     **************************************/
-    float distance[6];
-    
-    /**************************************
      * Nous convertisons grâce au valeur  *
      * qui sont retournées par echoRiseX  *
      * et echoFallx                       *
      **************************************/
-    for(char i = 0; i<6;i++)
-        distance[i] = 10*(us_out[i].read_us()-correction)/58.0 ;
+    
+    for(char i = 0; i<6;i++){
+        ::distance[i] = (us_out[i]*340)/1000;//conversion en distance(mm)
+    }
+    
+    /****************************************
+     * nous retournons l'adresse du tableau *
+     ****************************************/
+    return ::distance;
+}
+
+bool obstacleSpoted(float dist,double x_robot,double y_robot ,double phi, char I_theta){
+    /**************************
+     * convertion de ° en rad *
+     **************************/
+    double phiG = ((phi+(I_theta*THETA))*_PI_)/180;
+
+    /***********************************
+     * convertion de la norme grâce à  *
+     * la norme et à l'angle           *
+     ***********************************/
+    double x_dect = dist * cos(phiG) + x_robot;
+    double y_dect = dist * sin(phiG) + y_robot;
+    
     
-    /*************************************
-     * Nous retournons le tableau qui    *
-     * contiens l'ensemble des distances *
-     *************************************/ 
-    return distance;    
+    changementBase(&x_dect,&y_dect);
+    /*********************************************
+     * vérification de la position de l'obstacle *
+     *********************************************/
+    if(x_dect > LARGEUR_TAB || x_dect < 0||y_dect >LONGUEUR_TAB||y_dect < 0){
+        return false;
+    }
+    else{
+        return true;
+    }
+
 }
+
+void changementBase(double* x_detect, double* y_detect){
+    /*****************************
+     * l'origine de notres table *
+     * se situe au coins         *
+     * supérieur                 * 
+     *****************************/
+    *y_detect+=505;
+    *x_detect+=5;
+}
+
+
diff -r 43f5bda97488 -r 4c0b1647e8ae captUS.h
--- a/captUS.h	Mon Sep 28 19:17:00 2020 +0000
+++ b/captUS.h	Tue Oct 13 14:50:31 2020 +0000
@@ -1,4 +1,13 @@
+#ifndef CAPTUS_H
+#define CAPTUS_H
+#include "mbed.h"
+#include "math.h"
+
 // Nom du fichier : captUS.h
+#define LONGUEUR_TAB 2000
+#define LARGEUR_TAB 3000
+#define _PI_ 3.14159265359
+#define THETA 60
 
 // extern
 extern float us_out[6];
@@ -26,4 +35,23 @@
  * Création d'une fonction qui    *
  * convertis le temps en distance *
  **********************************/
-float* convertToDistance();
\ No newline at end of file
+float* convertToDistance();
+
+
+/********************************************
+ * nous permet de placer l'origine au coins *
+ * de la table                              *
+ ********************************************/
+void changementBase(double* x_detect, double* y_detect);
+
+/*******************************************
+ * nous permet de détecter un obstacle     *
+ *                                         *
+ * false : personne | true : quelquechoses *
+ *******************************************/
+bool obstacleSpoted(float dist,double x_robot,double y_robot ,double phi, char I_theta);
+
+
+
+
+#endif // CAPTUS_H
diff -r 43f5bda97488 -r 4c0b1647e8ae main.cpp
--- a/main.cpp	Mon Sep 28 19:17:00 2020 +0000
+++ b/main.cpp	Tue Oct 13 14:50:31 2020 +0000
@@ -22,6 +22,7 @@
 
     // debug
     pc.attach(&serialIT); // Interruption liaison série
+    
     bt.attach(&bluetoothIT); // Interruption  bluetooth
     pc.baud(9600);
     pc.format(8,SerialBase::None,1);
@@ -57,8 +58,32 @@
     cddA.rise(&cddaRise);
     cdgA.mode(PullUp);
     cddA.mode(PullUp);
-
+    
+    
+    float* dist; // adresse du tableau distance
     while(1) {
-        
+    
     }
 }
+/*
+   while(1) {
+        captUS_trig();   
+        dist = convertToDistance();
+        for(char i = 0; i < 6 ; i++)
+            printf("%d : %f\n\r",i,dist[i]);
+        
+        printf("\n\r");
+        printf("\n\r");
+        printf("\n\r");
+        
+        
+        
+        for(char i = 0; i < 6 ; i++)
+            printf("%d : %d\n\r",i,obstacleSpoted(dist[i],1500,0 ,0,i));
+        
+        
+        
+        wait(1);
+    }
+
+*/
\ No newline at end of file