FRC_equipe1 / Mbed 2 deprecated FRC_2019

Dependencies:   mbed

Committer:
Wael_H
Date:
Thu Jun 06 14:22:58 2019 +0000
Revision:
27:e103da412e2b
Parent:
26:fa8a8fa175cb
Child:
28:82571fd665bf
je reprends ca apres l'homlogation

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 27:e103da412e2b 5 void automate_testLasers(Robot&);
Wael_H 27:e103da412e2b 6 void automate_testABalle(Robot&);
Wael_H 27:e103da412e2b 7 void automate_deplacement(Robot&);
Wael_H 27:e103da412e2b 8 void automate_vitesse(Robot&);
Wael_H 27:e103da412e2b 9
Wael_H 27:e103da412e2b 10 typedef enum{TURN_FAST, CORRECT_GAUCHE, CORRECT_DROITE, GO_STRAIGHT} type_etat_deplacement;
Wael_H 27:e103da412e2b 11 type_etat_deplacement etat_deplacement = TURN_FAST;
Wael_H 27:e103da412e2b 12
Wael_H 8:94ecfe411d02 13
Wael_H 2:8971078b1ccf 14 int main(void)
Wael_H 2:8971078b1ccf 15 {
Wael_H 10:efa507ba2b35 16 Robot robot;
theolp 17:aae5361ddddf 17
Wael_H 27:e103da412e2b 18 robot.setSpeed(80,450); // vitesse de rotation de recherche de la balle
theolp 20:a1b5d032b422 19
Wael_H 15:3d4543a6c100 20 while(1)
Wael_H 25:033263cf832c 21 if(!Robot::Jack)
theolp 17:aae5361ddddf 22 {
Wael_H 27:e103da412e2b 23 automate_testABalle(robot);
Wael_H 27:e103da412e2b 24
Wael_H 27:e103da412e2b 25 automate_testLasers(robot);
theolp 17:aae5361ddddf 26
Wael_H 27:e103da412e2b 27 if(!robot.aBalle())
Wael_H 27:e103da412e2b 28 automate_deplacement(robot);
Wael_H 27:e103da412e2b 29
Wael_H 27:e103da412e2b 30 automate_vitesse(robot);
theolp 17:aae5361ddddf 31 }
Wael_H 15:3d4543a6c100 32 }
Wael_H 15:3d4543a6c100 33
Wael_H 27:e103da412e2b 34
Wael_H 27:e103da412e2b 35 void automate_testLasers(Robot& robot)
Wael_H 27:e103da412e2b 36 {
Wael_H 27:e103da412e2b 37 static const int diffMurBalle = 20;
Wael_H 27:e103da412e2b 38 static float past_gauche, past_droit, actual_gauche, actual_droit;
Wael_H 27:e103da412e2b 39 static float distBalle;
Wael_H 27:e103da412e2b 40
Wael_H 27:e103da412e2b 41 actual_gauche = robot.getDist(Laser::Gauche);
Wael_H 27:e103da412e2b 42 actual_droit = robot.getDist(Laser::Droit);
Wael_H 27:e103da412e2b 43
Wael_H 27:e103da412e2b 44 switch(etat_deplacement)
Wael_H 27:e103da412e2b 45 {
Wael_H 27:e103da412e2b 46 case TURN_FAST:
Wael_H 27:e103da412e2b 47 if(actual_droit < past_droit - diffMurBalle)
Wael_H 27:e103da412e2b 48 {
Wael_H 27:e103da412e2b 49 distBalle = actual_droit;
Wael_H 27:e103da412e2b 50 robot.stop();
Wael_H 27:e103da412e2b 51 etat_deplacement = CORRECT_GAUCHE;
Wael_H 27:e103da412e2b 52 }
Wael_H 27:e103da412e2b 53 break;
Wael_H 27:e103da412e2b 54
Wael_H 27:e103da412e2b 55 case CORRECT_GAUCHE:
Wael_H 27:e103da412e2b 56
Wael_H 27:e103da412e2b 57 break;
Wael_H 27:e103da412e2b 58
Wael_H 27:e103da412e2b 59 case CORRECT_DROITE:
Wael_H 27:e103da412e2b 60 break;
Wael_H 27:e103da412e2b 61
Wael_H 27:e103da412e2b 62 case GO_STRAIGHT:
Wael_H 27:e103da412e2b 63 break;
Wael_H 27:e103da412e2b 64 }
Wael_H 27:e103da412e2b 65
Wael_H 27:e103da412e2b 66
Wael_H 27:e103da412e2b 67 past_gauche = actual_gauche;
Wael_H 27:e103da412e2b 68 past_droit = actual_droit;
Wael_H 27:e103da412e2b 69 }
Wael_H 27:e103da412e2b 70
Wael_H 27:e103da412e2b 71 void automate_testABalle(Robot& robot)
Wael_H 24:314b1f6607c5 72 {
Wael_H 27:e103da412e2b 73 typedef enum {ATTENTE,ABALLE} type_etat;
Wael_H 27:e103da412e2b 74 static type_etat etat = ATTENTE;
Wael_H 23:bb1535360a98 75
Wael_H 27:e103da412e2b 76 static Timer T_ejecte;
Wael_H 7:753e901d441b 77
Wael_H 7:753e901d441b 78 switch(etat)
Wael_H 9:2113adf37c66 79 {
Wael_H 27:e103da412e2b 80 case ATTENTE:
Wael_H 27:e103da412e2b 81 if(robot.aBalle())
Wael_H 27:e103da412e2b 82 {
Wael_H 27:e103da412e2b 83 robot.stop();
Wael_H 27:e103da412e2b 84 robot.exploseBallon();
Wael_H 27:e103da412e2b 85 etat = ABALLE;
Wael_H 27:e103da412e2b 86 robot.setSpeed(80,500); //vitesse de rotation vers le terrain ennemi
Wael_H 27:e103da412e2b 87 }
Wael_H 27:e103da412e2b 88 else if( T_ejecte.read() >= 1.0f )
Wael_H 27:e103da412e2b 89 {
Wael_H 27:e103da412e2b 90 robot.gobe(25);
Wael_H 27:e103da412e2b 91 T_ejecte.stop();
Wael_H 27:e103da412e2b 92 T_ejecte.reset();
Wael_H 27:e103da412e2b 93 }
Wael_H 13:9c62e263f245 94 break;
Wael_H 13:9c62e263f245 95
Wael_H 27:e103da412e2b 96 case ABALLE:
Wael_H 27:e103da412e2b 97 if(robot.tourne(1800))
Wael_H 27:e103da412e2b 98 robot.ejecte(70);
Wael_H 27:e103da412e2b 99
Wael_H 27:e103da412e2b 100 if(!robot.aBalle())
Wael_H 27:e103da412e2b 101 {
Wael_H 27:e103da412e2b 102 robot.arreteDisquette();
Wael_H 27:e103da412e2b 103 T_ejecte.start();
Wael_H 27:e103da412e2b 104 etat = ATTENTE;
Wael_H 27:e103da412e2b 105 etat_deplacement = TURN_FAST;
Wael_H 27:e103da412e2b 106 }
Wael_H 13:9c62e263f245 107 break;
Wael_H 13:9c62e263f245 108 }
Wael_H 13:9c62e263f245 109 }
Wael_H 23:bb1535360a98 110
Wael_H 27:e103da412e2b 111 void automate_deplacement(Robot& robot)
Wael_H 27:e103da412e2b 112 {
Wael_H 27:e103da412e2b 113 switch(etat_deplacement)
Wael_H 23:bb1535360a98 114 {
Wael_H 27:e103da412e2b 115 case TURN_FAST:
Wael_H 27:e103da412e2b 116 robot.tourne();
Wael_H 27:e103da412e2b 117 break;
Wael_H 27:e103da412e2b 118
Wael_H 27:e103da412e2b 119 case CORRECT_GAUCHE:
Wael_H 27:e103da412e2b 120 robot.tourne(-450);
Wael_H 23:bb1535360a98 121 break;
Wael_H 23:bb1535360a98 122
Wael_H 27:e103da412e2b 123 case CORRECT_DROITE:
Wael_H 27:e103da412e2b 124 robot.tourne(450);
Wael_H 27:e103da412e2b 125
Wael_H 27:e103da412e2b 126 case GO_STRAIGHT:
Wael_H 27:e103da412e2b 127 robot.avance();
Wael_H 27:e103da412e2b 128 break;
Wael_H 27:e103da412e2b 129 }
Wael_H 27:e103da412e2b 130 }
Wael_H 27:e103da412e2b 131
Wael_H 27:e103da412e2b 132 void automate_vitesse(Robot& robot)
Wael_H 27:e103da412e2b 133 {
Wael_H 27:e103da412e2b 134 switch(etat_deplacement)
Wael_H 27:e103da412e2b 135 {
Wael_H 27:e103da412e2b 136 case TURN_FAST:
Wael_H 27:e103da412e2b 137 robot.setSpeed(80,450);
Wael_H 23:bb1535360a98 138 break;
Wael_H 23:bb1535360a98 139
Wael_H 27:e103da412e2b 140 case CORRECT_GAUCHE:
Wael_H 27:e103da412e2b 141 robot.setSpeed(50,300);
Wael_H 27:e103da412e2b 142 break;
Wael_H 23:bb1535360a98 143
Wael_H 27:e103da412e2b 144 case CORRECT_DROITE:
Wael_H 27:e103da412e2b 145 robot.setSpeed(50,300);
Wael_H 27:e103da412e2b 146 break;
Wael_H 24:314b1f6607c5 147
Wael_H 27:e103da412e2b 148 case GO_STRAIGHT:
Wael_H 27:e103da412e2b 149 robot.setSpeed(80,400);
Wael_H 23:bb1535360a98 150 break;
Wael_H 23:bb1535360a98 151 }
Wael_H 27:e103da412e2b 152 }