Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
Diff: main.cpp
- Revision:
- 34:cea05fa02f37
- Parent:
- 33:c70ded6dd380
- Child:
- 35:6c6321b97ae6
diff -r c70ded6dd380 -r cea05fa02f37 main.cpp
--- a/main.cpp Fri Jun 07 11:42:29 2019 +0000
+++ b/main.cpp Fri Jun 07 14:20:02 2019 +0000
@@ -22,62 +22,52 @@
Robot robot;
while(1)
- {
- automate_run(robot);
- // Trois balles en début de partie à l'aveugle
-
- /*if( !automate_aveugle(robot, ejecte) );
- else if(automate_fin_de_partie(robot))
- {
- robot.stopRouleau();
- break;
- }
-
- automate_ejecte(robot, ejecte);*/
-
- // Gestion du lancer de balle
- /*automate_testABalle(robot, ejecte);
- automate_ejecte(robot, ejecte);
-
- // Recherche de balles
- automate_testLasers(robot);
- if(!robot.aBalle())
- automate_deplacement(robot);
-
- // Gestion de la vitesse en fonction de l'état actuel
- automate_vitesse(robot);*/
- }
+ automate_run(robot);
}
void automate_run(Robot& robot)
{
bool ejecte = false;
- typedef enum{ATTENTE,RUN} type_etat;
+ typedef enum{ATTENTE, RUN_AVEUGLE, RECHERCHE_BALLES, FIN_PARTIE} type_etat;
static type_etat etat = ATTENTE;
static Timer T_partie;
+ if(T_partie.read() > 80.0f)
+ etat = FIN_PARTIE;
+
switch(etat)
{
case ATTENTE:
if(!Robot::Jack)
{
T_partie.start();
- etat = RUN;
+ etat = RUN_AVEUGLE;
}
break;
- case RUN:
- if(T_partie.read() < 30.0f)
- {
- /*while( !*/automate_aveugle(robot, ejecte)/* )*/;
- automate_ejecte(robot, ejecte);
- }
- else
- {
- T_partie.stop();
- robot.stopRouleau();
- automate_fin_de_partie(robot);
- }
+
+ case RUN_AVEUGLE:
+ automate_aveugle(robot, ejecte);
+ automate_ejecte(robot, ejecte);
break;
+
+ case RECHERCHE_BALLES:
+ // Gestion du lancer de balle
+ automate_testABalle(robot, ejecte);
+ automate_ejecte(robot, ejecte);
+
+ // Recherche de balles
+ automate_testLasers(robot);
+ if(!robot.aBalle())
+ automate_deplacement(robot);
+
+ // Gestion de la vitesse en fonction de l'état actuel
+ automate_vitesse(robot);
+ break;
+
+ case FIN_PARTIE:
+ T_partie.stop();
+ robot.stopRouleau();
+ break;
}
}
@@ -115,94 +105,44 @@
return false;
}
-/*bool automate_arretUrgence(Robot& robot)
-{
- typedef enum{RAS, PERCEPTION, ARRET_URGENCE, ATTENTE_REPLACEMENT} type_etat;
- static type_etat etat = RAS;
-
- // Timer pour la durée sur la ligne blanche
- static Timer timerCNY;
-
- switch(etat)
- {
- case RAS :
- if( robot.surBlanc( Robot::CNY_GAUCHE ) && robot.surBlanc( Robot::CNY_DROIT )){
- etat = PERCEPTION;
- timerCNY.start();
- }
- break;
-
- case PERCEPTION :
- if( robot.surBlanc( Robot::CNY_GAUCHE ) && robot.surBlanc( Robot::CNY_DROIT ) && timerCNY.read() >= 0.15f )
- etat = ARRET_URGENCE;
- else if( timerCNY.read() >= 0.15f ){
- etat = RAS;
- timerCNY.stop();
- timerCNY.reset();
- }
- break;
-
- case ARRET_URGENCE :
- timerCNY.stop();
- timerCNY.reset();
-
- etat = ATTENTE_REPLACEMENT;
-
- return true;
-
- case ATTENTE_REPLACEMENT :
- if( !robot.surBlanc( Robot:: CNY_GAUCHE ) && !robot.surBlanc( Robot::CNY_DROIT ))
- etat = RAS;
- break;
- }
-
- return false;
-}*/
-
bool automate_aveugle(Robot& robot, bool& ejecte)
{
- typedef enum{STRAIGHT1, PREMIER_TOURNE_D, TOURNE_D, STRAIGHT2, TOURNE_G} type_etat;
+ typedef enum{STRAIGHT1, TOURNE_G, STRAIGHT2, STRAIGHT3, FIN_AVEUGLE} type_etat;
static type_etat etat = STRAIGHT1;
- static Timer T_ejecte;
- static int cptBalles = 0;
-
- if(cptBalles == 2)
- return true;
-
switch(etat)
{
case STRAIGHT1:
if(robot.avance(1850 - DIST_CENTRE))
- {
- ejecte = true;
- etat = PREMIER_TOURNE_D;
- }
- break;
-
- case PREMIER_TOURNE_D:
- if(robot.tourne(ANGLE_DROIT))
- etat = STRAIGHT2;
- break;
-
- case TOURNE_D:
- if(robot.tourne(ANGLE_DROIT))
- etat = STRAIGHT2;
- break;
-
- case STRAIGHT2:
- if(robot.avance(1500))
etat = TOURNE_G;
break;
case TOURNE_G:
- if(robot.tourne(-ANGLE_DROIT))
+ if( robot.tourne(-100) )
+ {
+ ejecte = true;
+ etat = STRAIGHT2;
+ }
+ break;
+
+ case STRAIGHT2:
+ if( robot.GoToXYT(2000, 1850, 180) )
{
ejecte = true;
- cptBalles++;
- etat = TOURNE_D;
+ etat = STRAIGHT3;
}
break;
+
+ case STRAIGHT3:
+ if( robot.GoToXYT(3500, 1850, 50) )
+ {
+ ejecte = true;
+ etat = FIN_AVEUGLE;
+ }
+ break;
+
+ case FIN_AVEUGLE:
+ return true;
}
return false;
@@ -317,6 +257,7 @@
case CORRECT_DROITE:
robot.tourne(450);
+ break;
case GO_STRAIGHT:
robot.avance();