AresENSEA-CDF2020 / Mbed 2 deprecated AresCDFMainCode

Dependencies:   mbed DRV8825

Files at this revision

API Documentation at this revision

Comitter:
Nanaud
Date:
Tue Nov 03 16:29:13 2020 +0000
Parent:
25:869b1c1f51a7
Commit message:
UI

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
odo_asserv.cpp Show annotated file Show diff for this revision Revisions of this file
odo_asserv.h Show annotated file Show diff for this revision Revisions of this file
pins.cpp Show annotated file Show diff for this revision Revisions of this file
pins.h Show annotated file Show diff for this revision Revisions of this file
diff -r 869b1c1f51a7 -r bb2b778bd351 captUS.cpp
--- a/captUS.cpp	Thu Oct 29 07:53:25 2020 +0000
+++ b/captUS.cpp	Tue Nov 03 16:29:13 2020 +0000
@@ -2,8 +2,8 @@
 #include "pins.h"
 
 /* #define */
-#define DISTLIM 600 // Distance max de détection
-#define OFFSET 200
+#define DISTLIM 700 // Distance max de détection
+#define OFFSET 100
 #define MAXMOY 3 // Nombre de mesure pour la moyenne
 
 /* Variables globales */
@@ -13,7 +13,6 @@
 unsigned int us_high[6] = {0}; // Valeurs du timer lorsqu'il y a une interruption sur front montant
 unsigned int us_low[6] = {0}; // Valeurs du timer lorsqu'il y a une interruption sur front descendant
 unsigned int us_diff[6] = {0}; // Différence entre ces deux temps
-//bool us_verif[6] = {0}; // Permet d'enchainer dans le bon ordre : front montant puis front descendant
 bool us_verif2[2][6] = {0};
 
 unsigned int us_dist[6] = {0}; // Valeurs des distances
@@ -178,12 +177,6 @@
 
 void captUS_convToDist()
 {
-    /**************************************
-     * Nous convertisons grâce au valeur  *
-     * qui sont retournées par echoRiseX  *
-     * et echoFallx                       *
-     **************************************/
-
     for(int i = 0; i<6; i++) {
         if(us_verif2[0][i] == true && us_verif2[1][i] == true)
             us_dist[i] = (int) (((us_low[i] - us_high[i])*340)/1000); //conversion en distance(mm)
diff -r 869b1c1f51a7 -r bb2b778bd351 captUS.h
--- a/captUS.h	Thu Oct 29 07:53:25 2020 +0000
+++ b/captUS.h	Tue Nov 03 16:29:13 2020 +0000
@@ -1,8 +1,5 @@
 // Nom du fichier : captUS.h
 
-//#ifndef CAPTUS_H
-//#define CAPTUS_H
-//#include "mbed.h"
 #include "math.h"
 
 #define LONGUEUR_TAB 2000
@@ -11,8 +8,6 @@
 #define THETA 60
 
 // extern
-//extern double us_out[6];
-
 extern unsigned int us_high[6];
 extern unsigned int us_low[6];
 extern unsigned int us_diff[6];
@@ -27,7 +22,7 @@
 
 // Prototypes
 void captUS_trig();
-//void captUS_init();
+void captUS_convToDist(void);
 
 void echoRise1();
 void echoFall1();
@@ -42,27 +37,3 @@
 void echoRise6();
 void echoFall6();
 
-/**********************************
- * Création d'une fonction qui    *
- * convertis le temps en distance *
- **********************************/
-void captUS_convToDist(void);
- 
- 
-/********************************************
- * 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
\ No newline at end of file
diff -r 869b1c1f51a7 -r bb2b778bd351 main.cpp
--- a/main.cpp	Thu Oct 29 07:53:25 2020 +0000
+++ b/main.cpp	Tue Nov 03 16:29:13 2020 +0000
@@ -11,6 +11,7 @@
 Ticker TickerGlobal; // Comptage du temps écoulé
 int cptGlobal = 0;
 bool match = 0; // Match == 1 => Le match est en cours
+//bool toggledSwitch = 0;
 
 
 /* Prototypes */
@@ -71,27 +72,54 @@
     /* Autres */
     //btnBlue.rise(&boutonBleu);
 
+    if (SwitchStrategie == 1) {
+        stratX_select = objX_bleu;
+        x = x_init_bleu;
+        y = y_init;
+        O = O_init_bleu;
+        Led = 1;
+    } else {
+        stratX_select = objX_jaune;
+        x = x_init_jaune;
+        y = y_init;
+        O = O_init_jaune;
+        Led = 0;
+    }
+
     /* Boucle infinie */
     while(1) {
         if (Tirette == 1 && match == 0) { // Stand-by
             // Le match n'a pas encore commencé
-            // La LED est allumée
             // Le compteur du match reste à 0
-            Led = 1;
+            //Led = 1;
             match = 0;
             cptGlobal=0;
+
+            if (SwitchStrategie == 1) {
+                stratX_select = objX_bleu;
+                x = x_init_bleu;
+                y = y_init;
+                O = O_init_bleu;
+                Led = 1;
+            } else {
+                stratX_select = objX_jaune;
+                x = x_init_jaune;
+                y = y_init;
+                O = O_init_jaune;
+                Led = 0;
+            }
         }
 
         else if (Tirette == 0 && match == 0) { // Début du match
             // Le match débute
             // La LED s'éteind
-            Led = 0;
+            //Led = 0;
             match = 1;
             cptGlobal = 0;
-            
+
             indiceStrategie = 1;
             action = objEtape[indiceStrategie];
-            xC = objX[indiceStrategie];
+            xC = stratX_select[indiceStrategie];
             yC = objY[indiceStrategie];
         }
 
diff -r 869b1c1f51a7 -r bb2b778bd351 odo_asserv.cpp
--- a/odo_asserv.cpp	Thu Oct 29 07:53:25 2020 +0000
+++ b/odo_asserv.cpp	Tue Nov 03 16:29:13 2020 +0000
@@ -2,36 +2,30 @@
 #include "pins.h"
 
 /* #define & constantes */
-#define VMAXROT 0.040 // 0.020
-#define VMAXLIN 0.100 // 0.060
-
-/* Choix côté */
+#define VMAXROT 0.050 // 0.020
+#define VMAXLIN 0.110 // 0.060
 
-// Côté bleu
-#define X_INIT 110
-#define Y_INIT 1070
-#define O_INIT 0
-
-
-/*
-// Côté jaune
-#define X_INIT 2890
-#define Y_INIT 1070
-#define O_INIT 3.1414
-*/
-
+/* Pointeurs */
+//double *strategie_X_bleu = NULL;
+//double *strategie_X_jaune = NULL;
+double *stratX_select = NULL;
+const double x_init_bleu = 113;
+const double x_init_jaune = 2887;
+const double y_init = 1071;
+const double O_init_bleu = 0;
+const double O_init_jaune = 3.1414; 
 
 #define entraxe 253 // (Valeur théorique = 255)
 const double coeffG = 0.16008537; // mm/tic
 const double coeffD = 0.16059957; // mm/tic
 /* COEFF ROTATION */
-const double coeffPro = 0.040; // 0.020
-const double coeffDer = 0.030; // 0.010
+const double coeffPro = 0.050; // 0.020
+const double coeffDer = 0.040; // 0.010
 /* COEFF LIGNE DROITE */
-const double coeffProDist = 0.003; // 0.0008
+const double coeffProDist = 0.002; // 0.0008
 const double coeffDerDist = 0.003; // 0.0008
 
-#define ACC_ROT 0.002
+#define ACC_ROT 0.003
 #define ACC_LIN 0.002
 
 /* Stratégie */
@@ -43,27 +37,50 @@
 double objY[NbObj] = {0,1070,1650,1300};
 int objRecule[NbObj]= {0,0,0,0};*/
 
+// Côté bleu
+/*
+#define X_INIT 110
+#define Y_INIT 1070
+#define O_INIT 0
+*/
 
- // Stratégie Lucas Blue
+/*
+// Côté jaune
+#define X_INIT 2890
+#define Y_INIT 1070
+#define O_INIT 3.1414
+*/
+
+/* // Stratégie Lucas Blue
 int objEtape[NbObj] = {0,1,1,1,1,1,1,1,1,1};
 double objX[NbObj] = {110,200,660,627,450,235,698,300,300,230};
 double objY[NbObj] = {1070,1070,1200,743,920,1124,672,460,1100,750};
 int objRecule[NbObj]= {0,0,0,0,0,0,1,0,0,1}; 
+*/
 
-/*// Stratégie Lucas Yellow
+/* // Stratégie Lucas Yellow
 int objEtape[NbObj] = {0,1,1,1,1,1,1,1,1,1};
 double objX[NbObj] = {2890,2800,2340,2373,2550,2765,2302,2700,2700,2800};
 double objY[NbObj] = {1070,1070,1200,743,920,1124,672,460,1100,750};
 int objRecule[NbObj]= {0,0,0,0,0,0,1,0,0,1};
 */
 
+// Stratégie Pharoah
+
+int objEtape[NbObj] = {0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1};
+double objX_bleu[NbObj] = {110,253,793,671,529,134,598,868,868,474,353,262,262,262,950,250,350};
+double objX_jaune[NbObj] = {2887,2747,2207,2329,2471,2866,2402,2132,2132,2526,2647,2738,2738,2738,2050,2750,2650};
+double objY[NbObj] = {1070,1070,1347,1490,1490,1490,1490,1226,589,589,738,817,1411,1290,920,920,920};
+int objRecule[NbObj]= {0,0,0,0,0,0,1,0,0,0,0,0,0,1,0,0,1};
+
+
 /* Variable globale */
 Ticker Ticker_asserv; // Ticker pour l'asservissement en position
 
 int action = 0; // Actions possibles : Rotation & Avancer/Reculer
 long comptG = 0, comptD = 0; // Nb de tics compté par roue
 double dDist = 0, dAngl = 0; // Distance moyenne du robot et orientation
-double x = X_INIT, y = Y_INIT, O = O_INIT;
+double x = 0, y = 0, O = 0;
 
 /* Interruptions codeurs */
 
@@ -79,9 +96,6 @@
     else comptD++;
 }
 
-
-
-
 void odo2()
 {
     dDist = (double) ((comptG * coeffG) + (comptD * coeffD)) / 2.0f;
@@ -272,7 +286,7 @@
                     action = 0;
                 } else {
                     action = objEtape[indiceStrategie];
-                    xC = objX[indiceStrategie];
+                    xC = stratX_select[indiceStrategie];
                     yC = objY[indiceStrategie];
                 }
 
diff -r 869b1c1f51a7 -r bb2b778bd351 odo_asserv.h
--- a/odo_asserv.h	Thu Oct 29 07:53:25 2020 +0000
+++ b/odo_asserv.h	Tue Nov 03 16:29:13 2020 +0000
@@ -1,16 +1,26 @@
 // Nom du fichier : odo_asserv.h
 
-#define NbObj 10
+// Stratégie Lucas : 10 points
+// Stratégie Pharoah : 31 points
+#define NbObj 17
 
 extern int indiceStrategie;
 extern int objEtape[NbObj];
-extern double objX[NbObj];
+extern double objX_bleu[NbObj];
+extern double objX_jaune[NbObj];
 extern double objY[NbObj];
 extern int objRecule[NbObj];
 
 extern bool acc;
 extern bool stt;
 
+extern double* stratX_select;
+extern const double x_init_bleu;
+extern const double x_init_jaune;
+extern const double y_init;
+extern const double O_init_bleu;
+extern const double O_init_jaune; 
+
 // extern
 // CODEURS
 extern const double coeffGLong;
diff -r 869b1c1f51a7 -r bb2b778bd351 pins.cpp
--- a/pins.cpp	Thu Oct 29 07:53:25 2020 +0000
+++ b/pins.cpp	Tue Nov 03 16:29:13 2020 +0000
@@ -4,6 +4,7 @@
 DigitalOut Led(LED1); // LED allumée pendant le stand-by
 DigitalIn Tirette(PC_8);
 InterruptIn BtnBlue(PC_13);
+DigitalIn SwitchStrategie(PC_11);
 
 /* Capteurs à ultrasons */
 DigitalOut trigger(PB_9);
diff -r 869b1c1f51a7 -r bb2b778bd351 pins.h
--- a/pins.h	Thu Oct 29 07:53:25 2020 +0000
+++ b/pins.h	Tue Nov 03 16:29:13 2020 +0000
@@ -17,6 +17,7 @@
 extern DigitalOut Led;
 extern DigitalIn Tirette;
 extern InterruptIn BtnBlue;
+extern DigitalIn SwitchStrategie;
 
 extern DigitalOut trigger;
 extern InterruptIn echo1;