FRC_equipe1 / Mbed 2 deprecated FRC_2019

Dependencies:   mbed

Committer:
Wael_H
Date:
Tue May 28 06:48:54 2019 +0000
Revision:
13:9c62e263f245
Parent:
10:efa507ba2b35
Child:
14:1be2f691cbb4
Robot cherche, attrape et lance une balle normalement

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 13:9c62e263f245 5 void automate_testLasers(Robot&);
Wael_H 13:9c62e263f245 6 void automate_testABalle(Robot&);
Wael_H 13:9c62e263f245 7 void automate_deplacement(Robot&);
Wael_H 10:efa507ba2b35 8
Wael_H 10:efa507ba2b35 9
Wael_H 13:9c62e263f245 10 typedef enum{CHERCHE_BALLE,BALLE_GAUCHE,BALLE_DROITE,BALLE_STRAIGHT} type_etat_balle;
Wael_H 13:9c62e263f245 11 type_etat_balle etat_balle = CHERCHE_BALLE;
Wael_H 10:efa507ba2b35 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;
Wael_H 7:753e901d441b 17
Wael_H 9:2113adf37c66 18 while(1)
Wael_H 13:9c62e263f245 19 {
Wael_H 13:9c62e263f245 20 automate_testLasers(robot);
Wael_H 13:9c62e263f245 21 automate_testABalle(robot);
Wael_H 13:9c62e263f245 22 if(!robot.aBalle())
Wael_H 13:9c62e263f245 23 automate_deplacement(robot);
Wael_H 13:9c62e263f245 24 }
Wael_H 7:753e901d441b 25 }
Wael_H 7:753e901d441b 26
Wael_H 10:efa507ba2b35 27
Wael_H 13:9c62e263f245 28 void automate_testLasers(Robot& robot)
Wael_H 7:753e901d441b 29 {
Wael_H 13:9c62e263f245 30 typedef enum {ATTENTE, TURN_RIGHT, TURN_LEFT, VOIT_BALLE} type_etat;
Wael_H 13:9c62e263f245 31 static type_etat etat = ATTENTE;
Wael_H 13:9c62e263f245 32
Wael_H 13:9c62e263f245 33 static float past_gauche, past_droit, actual_gauche, actual_droit;
Wael_H 13:9c62e263f245 34
Wael_H 13:9c62e263f245 35 actual_gauche = robot.getDist(Laser::Gauche);
Wael_H 13:9c62e263f245 36 actual_droit = robot.getDist(Laser::Droit);
Wael_H 7:753e901d441b 37
Wael_H 7:753e901d441b 38 switch(etat)
Wael_H 9:2113adf37c66 39 {
Wael_H 13:9c62e263f245 40 case ATTENTE:
Wael_H 13:9c62e263f245 41 if(actual_gauche < past_gauche-10)
Wael_H 13:9c62e263f245 42 {
Wael_H 13:9c62e263f245 43 etat = TURN_LEFT;
Wael_H 13:9c62e263f245 44 robot.stop();
Wael_H 13:9c62e263f245 45 }
Wael_H 13:9c62e263f245 46
Wael_H 13:9c62e263f245 47 if(actual_droit < past_droit-10)
Wael_H 13:9c62e263f245 48 {
Wael_H 13:9c62e263f245 49 etat = TURN_RIGHT;
Wael_H 13:9c62e263f245 50 robot.stop();
Wael_H 13:9c62e263f245 51 }
Wael_H 13:9c62e263f245 52 break;
Wael_H 13:9c62e263f245 53
Wael_H 13:9c62e263f245 54
Wael_H 13:9c62e263f245 55 case TURN_LEFT:
Wael_H 13:9c62e263f245 56 etat_balle = BALLE_GAUCHE;
Wael_H 13:9c62e263f245 57
Wael_H 13:9c62e263f245 58 if(actual_droit < past_droit-10)
Wael_H 13:9c62e263f245 59 {
Wael_H 13:9c62e263f245 60 etat = VOIT_BALLE;
Wael_H 13:9c62e263f245 61 robot.stop();
Wael_H 13:9c62e263f245 62 }
Wael_H 13:9c62e263f245 63
Wael_H 13:9c62e263f245 64 if(actual_gauche > past_gauche+10)
Wael_H 13:9c62e263f245 65 {
Wael_H 13:9c62e263f245 66 etat = TURN_RIGHT;
Wael_H 13:9c62e263f245 67 robot.stop();
Wael_H 13:9c62e263f245 68 }
Wael_H 13:9c62e263f245 69 break;
Wael_H 13:9c62e263f245 70
Wael_H 13:9c62e263f245 71
Wael_H 13:9c62e263f245 72 case TURN_RIGHT:
Wael_H 13:9c62e263f245 73 etat_balle = BALLE_DROITE;
Wael_H 13:9c62e263f245 74
Wael_H 13:9c62e263f245 75 if(actual_gauche < past_gauche-10)
Wael_H 13:9c62e263f245 76 {
Wael_H 13:9c62e263f245 77 etat = VOIT_BALLE;
Wael_H 13:9c62e263f245 78 robot.stop();
Wael_H 13:9c62e263f245 79 }
Wael_H 13:9c62e263f245 80
Wael_H 13:9c62e263f245 81 if(actual_droit > past_droit+10)
Wael_H 13:9c62e263f245 82 {
Wael_H 13:9c62e263f245 83 etat = TURN_LEFT;
Wael_H 13:9c62e263f245 84 robot.stop();
Wael_H 13:9c62e263f245 85 }
Wael_H 8:94ecfe411d02 86 break;
Wael_H 8:94ecfe411d02 87
Wael_H 13:9c62e263f245 88
Wael_H 13:9c62e263f245 89 case VOIT_BALLE:
Wael_H 13:9c62e263f245 90 etat_balle = BALLE_STRAIGHT;
Wael_H 13:9c62e263f245 91
Wael_H 13:9c62e263f245 92 if(actual_gauche > past_gauche+10)
Wael_H 13:9c62e263f245 93 {
Wael_H 13:9c62e263f245 94 etat = TURN_RIGHT;
Wael_H 13:9c62e263f245 95 robot.stop();
Wael_H 13:9c62e263f245 96 }
Wael_H 13:9c62e263f245 97
Wael_H 13:9c62e263f245 98 if(actual_droit > past_droit+10)
Wael_H 13:9c62e263f245 99 {
Wael_H 13:9c62e263f245 100 etat = TURN_LEFT;
Wael_H 13:9c62e263f245 101 robot.stop();
Wael_H 13:9c62e263f245 102 }
Wael_H 13:9c62e263f245 103 break;
Wael_H 13:9c62e263f245 104 }
Wael_H 13:9c62e263f245 105
Wael_H 13:9c62e263f245 106 past_gauche = actual_gauche;
Wael_H 13:9c62e263f245 107 past_droit = actual_droit;
Wael_H 13:9c62e263f245 108 }
Wael_H 13:9c62e263f245 109
Wael_H 13:9c62e263f245 110 void automate_testABalle(Robot& robot)
Wael_H 13:9c62e263f245 111 {
Wael_H 13:9c62e263f245 112 typedef enum {ATTENTE,ABALLE} type_etat;
Wael_H 13:9c62e263f245 113 static type_etat etat = ATTENTE;
Wael_H 13:9c62e263f245 114
Wael_H 13:9c62e263f245 115 switch(etat)
Wael_H 13:9c62e263f245 116 {
Wael_H 13:9c62e263f245 117 case ATTENTE:
Wael_H 13:9c62e263f245 118 robot.gobe(40);
Wael_H 13:9c62e263f245 119 if(robot.aBalle())
Wael_H 13:9c62e263f245 120 {
Wael_H 13:9c62e263f245 121 robot.stop();
Wael_H 13:9c62e263f245 122 etat = ABALLE;
Wael_H 13:9c62e263f245 123 etat_balle = CHERCHE_BALLE;
Wael_H 13:9c62e263f245 124 }
Wael_H 13:9c62e263f245 125 break;
Wael_H 13:9c62e263f245 126
Wael_H 13:9c62e263f245 127 case ABALLE:
Wael_H 13:9c62e263f245 128 if(robot.tourne(1800))
Wael_H 13:9c62e263f245 129 {
Wael_H 13:9c62e263f245 130 robot.ejecte(60);
Wael_H 13:9c62e263f245 131 etat = ATTENTE;
Wael_H 13:9c62e263f245 132 }
Wael_H 13:9c62e263f245 133 break;
Wael_H 13:9c62e263f245 134 }
Wael_H 13:9c62e263f245 135 }
Wael_H 13:9c62e263f245 136
Wael_H 13:9c62e263f245 137 void automate_deplacement(Robot& robot)
Wael_H 13:9c62e263f245 138 {
Wael_H 13:9c62e263f245 139 switch(etat_balle)
Wael_H 13:9c62e263f245 140 {
Wael_H 13:9c62e263f245 141 case CHERCHE_BALLE:
Wael_H 13:9c62e263f245 142 robot.tourne(3600);
Wael_H 13:9c62e263f245 143 break;
Wael_H 13:9c62e263f245 144
Wael_H 13:9c62e263f245 145 case BALLE_GAUCHE:
Wael_H 13:9c62e263f245 146 robot.tourne(-50);
Wael_H 13:9c62e263f245 147 break;
Wael_H 13:9c62e263f245 148
Wael_H 13:9c62e263f245 149 case BALLE_DROITE:
Wael_H 13:9c62e263f245 150 robot.tourne(50);
Wael_H 13:9c62e263f245 151 break;
Wael_H 13:9c62e263f245 152
Wael_H 13:9c62e263f245 153 case BALLE_STRAIGHT:
Wael_H 13:9c62e263f245 154 robot.avance(100);
Wael_H 8:94ecfe411d02 155 break;
Wael_H 7:753e901d441b 156 }
Wael_H 2:8971078b1ccf 157 }