FRC_equipe1 / Mbed 2 deprecated FRC_2019

Dependencies:   mbed

Committer:
Wael_H
Date:
Thu Jun 06 12:28:19 2019 +0000
Revision:
24:314b1f6607c5
Parent:
23:bb1535360a98
Child:
25:033263cf832c
arret d'urgence avec les deux CNY

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Wael_H 2:8971078b1ccf 1 #include "mbed.h"
Wael_H 5:34048faec367 2 #include "CAN_asser.h"
Wael_H 10:efa507ba2b35 3 #include "Robot.h"
Wael_H 10:efa507ba2b35 4
Wael_H 24:314b1f6607c5 5 void automate_testDeplacement(Robot&);
Wael_H 24:314b1f6607c5 6 bool automate_arretUrgence(Robot&);
Wael_H 8:94ecfe411d02 7
Wael_H 2:8971078b1ccf 8 int main(void)
Wael_H 2:8971078b1ccf 9 {
Wael_H 10:efa507ba2b35 10 Robot robot;
Wael_H 24:314b1f6607c5 11
Wael_H 24:314b1f6607c5 12 robot.setSpeed(80,400);
theolp 17:aae5361ddddf 13
Wael_H 24:314b1f6607c5 14 Timer timer_dbug;
Wael_H 24:314b1f6607c5 15 timer_dbug.start();
theolp 20:a1b5d032b422 16
Wael_H 15:3d4543a6c100 17 while(1)
theolp 17:aae5361ddddf 18 {
Wael_H 24:314b1f6607c5 19 automate_testDeplacement(robot);
theolp 17:aae5361ddddf 20
Wael_H 24:314b1f6607c5 21 if(timer_dbug.read() > 0.5f)
Wael_H 24:314b1f6607c5 22 {
Wael_H 24:314b1f6607c5 23 timer_dbug.stop();
Wael_H 24:314b1f6607c5 24 timer_dbug.reset();
Wael_H 24:314b1f6607c5 25 timer_dbug.start();
Wael_H 24:314b1f6607c5 26 }
theolp 17:aae5361ddddf 27 }
Wael_H 15:3d4543a6c100 28 }
Wael_H 15:3d4543a6c100 29
Wael_H 24:314b1f6607c5 30 void automate_testDeplacement(Robot& robot)
Wael_H 24:314b1f6607c5 31 {
Wael_H 24:314b1f6607c5 32 typedef enum{ AVANCE, ARRET_URGENCE } type_etat;
Wael_H 24:314b1f6607c5 33 static type_etat etat = AVANCE;
Wael_H 23:bb1535360a98 34
Wael_H 7:753e901d441b 35
Wael_H 7:753e901d441b 36 switch(etat)
Wael_H 9:2113adf37c66 37 {
Wael_H 24:314b1f6607c5 38 case AVANCE:
Wael_H 24:314b1f6607c5 39 robot.avance(2500);
Wael_H 24:314b1f6607c5 40 if( automate_arretUrgence(robot) )
Wael_H 24:314b1f6607c5 41 etat = ARRET_URGENCE;
Wael_H 13:9c62e263f245 42 break;
Wael_H 13:9c62e263f245 43
Wael_H 24:314b1f6607c5 44 case ARRET_URGENCE:
Wael_H 24:314b1f6607c5 45 robot.stop();
Wael_H 13:9c62e263f245 46 break;
Wael_H 13:9c62e263f245 47 }
Wael_H 13:9c62e263f245 48 }
Wael_H 23:bb1535360a98 49
Wael_H 24:314b1f6607c5 50 bool automate_arretUrgence(Robot& robot)
Wael_H 24:314b1f6607c5 51 {
Wael_H 24:314b1f6607c5 52 typedef enum{RAS, PERCEPTION, ARRET_URGENCE, ATTENTE_REPLACEMENT} type_etat;
Wael_H 24:314b1f6607c5 53 static type_etat etat = RAS;
Wael_H 24:314b1f6607c5 54
Wael_H 24:314b1f6607c5 55 // Timer pour la durée sur la ligne blanche
Wael_H 24:314b1f6607c5 56 static Timer timerCNY;
Wael_H 24:314b1f6607c5 57
Wael_H 24:314b1f6607c5 58 switch(etat)
Wael_H 23:bb1535360a98 59 {
Wael_H 24:314b1f6607c5 60 case RAS :
Wael_H 24:314b1f6607c5 61 if(robot.surBlanc(Robot::CNY_GAUCHE) && robot.surBlanc(Robot::CNY_DROIT)){
Wael_H 24:314b1f6607c5 62 etat = PERCEPTION;
Wael_H 24:314b1f6607c5 63 timerCNY.start();
Wael_H 24:314b1f6607c5 64 }
Wael_H 23:bb1535360a98 65 break;
Wael_H 23:bb1535360a98 66
Wael_H 24:314b1f6607c5 67 case PERCEPTION :
Wael_H 24:314b1f6607c5 68 if(robot.surBlanc(Robot::CNY_GAUCHE) && robot.surBlanc(Robot::CNY_DROIT) && timerCNY.read() >= 0.15f )
Wael_H 24:314b1f6607c5 69 etat = ARRET_URGENCE;
Wael_H 24:314b1f6607c5 70 else if( timerCNY.read() >= 0.15f ){
Wael_H 24:314b1f6607c5 71 etat = RAS;
Wael_H 24:314b1f6607c5 72 timerCNY.stop();
Wael_H 24:314b1f6607c5 73 timerCNY.reset();
Wael_H 24:314b1f6607c5 74 }
Wael_H 23:bb1535360a98 75 break;
Wael_H 23:bb1535360a98 76
Wael_H 24:314b1f6607c5 77 case ARRET_URGENCE :
Wael_H 24:314b1f6607c5 78 timerCNY.stop();
Wael_H 24:314b1f6607c5 79 timerCNY.reset();
Wael_H 24:314b1f6607c5 80
Wael_H 24:314b1f6607c5 81 etat = ATTENTE_REPLACEMENT;
Wael_H 23:bb1535360a98 82
Wael_H 24:314b1f6607c5 83 return true;
Wael_H 24:314b1f6607c5 84
Wael_H 24:314b1f6607c5 85 case ATTENTE_REPLACEMENT :
Wael_H 24:314b1f6607c5 86 if(!robot.surBlanc(Robot::CNY_GAUCHE) && !robot.surBlanc(Robot::CNY_DROIT))
Wael_H 24:314b1f6607c5 87 etat = RAS;
Wael_H 23:bb1535360a98 88 break;
Wael_H 23:bb1535360a98 89 }
Wael_H 24:314b1f6607c5 90
Wael_H 24:314b1f6607c5 91 return false;
Wael_H 23:bb1535360a98 92 }
Wael_H 24:314b1f6607c5 93