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
main.cpp@18:a7dc3a63d7eb, 2019-06-05 (annotated)
- Committer:
- Wael_H
- Date:
- Wed Jun 05 12:32:47 2019 +0000
- Revision:
- 18:a7dc3a63d7eb
- Parent:
- 15:3d4543a6c100
cherche_balle_v2
Who changed what in which revision?
User | Revision | Line number | New 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 | 18:a7dc3a63d7eb | 5 | void testLasers(Robot&, bool&); |
Wael_H | 13:9c62e263f245 | 6 | void automate_testABalle(Robot&); |
Wael_H | 18:a7dc3a63d7eb | 7 | void automate_deplacement(Robot&, bool&); |
Wael_H | 10:efa507ba2b35 | 8 | |
Wael_H | 10:efa507ba2b35 | 9 | |
Wael_H | 18:a7dc3a63d7eb | 10 | typedef enum{TURN_FAST,RETROUVE,GO_STRAIGHT,CORRECT_GAUCHE,CORRECT_DROITE} type_etat_deplacement; |
Wael_H | 15:3d4543a6c100 | 11 | type_etat_deplacement etat_deplacement = TURN_FAST; |
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 | 18:a7dc3a63d7eb | 17 | bool autorCorrect = false; |
Wael_H | 18:a7dc3a63d7eb | 18 | DigitalIn Jack(PA_15); |
Wael_H | 7:753e901d441b | 19 | |
Wael_H | 18:a7dc3a63d7eb | 20 | robot.setSpeed(100,600); |
Wael_H | 18:a7dc3a63d7eb | 21 | robot.gobe(25); |
Wael_H | 15:3d4543a6c100 | 22 | |
Wael_H | 15:3d4543a6c100 | 23 | while(1) |
Wael_H | 18:a7dc3a63d7eb | 24 | if(!Jack) |
Wael_H | 15:3d4543a6c100 | 25 | { |
Wael_H | 15:3d4543a6c100 | 26 | automate_testABalle(robot); |
Wael_H | 15:3d4543a6c100 | 27 | |
Wael_H | 18:a7dc3a63d7eb | 28 | testLasers(robot, autorCorrect); |
Wael_H | 15:3d4543a6c100 | 29 | |
Wael_H | 15:3d4543a6c100 | 30 | if(!robot.aBalle()) |
Wael_H | 18:a7dc3a63d7eb | 31 | automate_deplacement(robot, autorCorrect); |
Wael_H | 15:3d4543a6c100 | 32 | } |
Wael_H | 15:3d4543a6c100 | 33 | } |
Wael_H | 15:3d4543a6c100 | 34 | |
Wael_H | 18:a7dc3a63d7eb | 35 | void testLasers(Robot& robot, bool& autorCorrect) |
Wael_H | 18:a7dc3a63d7eb | 36 | { |
Wael_H | 18:a7dc3a63d7eb | 37 | const int diffMurBalle = 20; |
Wael_H | 15:3d4543a6c100 | 38 | static float past_gauche, past_droit, actual_gauche, actual_droit; |
Wael_H | 15:3d4543a6c100 | 39 | |
Wael_H | 15:3d4543a6c100 | 40 | actual_gauche = robot.getDist(Laser::Gauche); |
Wael_H | 15:3d4543a6c100 | 41 | actual_droit = robot.getDist(Laser::Droit); |
Wael_H | 15:3d4543a6c100 | 42 | |
Wael_H | 18:a7dc3a63d7eb | 43 | switch(etat_deplacement) |
Wael_H | 15:3d4543a6c100 | 44 | { |
Wael_H | 18:a7dc3a63d7eb | 45 | case TURN_FAST: |
Wael_H | 18:a7dc3a63d7eb | 46 | if(actual_droit < past_droit - diffMurBalle) |
Wael_H | 18:a7dc3a63d7eb | 47 | { |
Wael_H | 18:a7dc3a63d7eb | 48 | robot.stop(); |
Wael_H | 18:a7dc3a63d7eb | 49 | etat_deplacement = RETROUVE; |
Wael_H | 18:a7dc3a63d7eb | 50 | robot.setSpeed(50,300); |
Wael_H | 18:a7dc3a63d7eb | 51 | } |
Wael_H | 18:a7dc3a63d7eb | 52 | break; |
Wael_H | 18:a7dc3a63d7eb | 53 | |
Wael_H | 18:a7dc3a63d7eb | 54 | case RETROUVE: |
Wael_H | 18:a7dc3a63d7eb | 55 | if(actual_droit < past_droit - diffMurBalle) |
Wael_H | 18:a7dc3a63d7eb | 56 | { |
Wael_H | 18:a7dc3a63d7eb | 57 | robot.stop(); |
Wael_H | 18:a7dc3a63d7eb | 58 | etat_deplacement = GO_STRAIGHT; |
Wael_H | 18:a7dc3a63d7eb | 59 | robot.setSpeed(100,500); |
Wael_H | 18:a7dc3a63d7eb | 60 | } |
Wael_H | 18:a7dc3a63d7eb | 61 | break; |
Wael_H | 18:a7dc3a63d7eb | 62 | |
Wael_H | 18:a7dc3a63d7eb | 63 | /*case GO_STRAIGHT: |
Wael_H | 18:a7dc3a63d7eb | 64 | if(actual_droit > past_droit + diffMurBalle) |
Wael_H | 18:a7dc3a63d7eb | 65 | { |
Wael_H | 18:a7dc3a63d7eb | 66 | etat_deplacement = CORRECT_GAUCHE; |
Wael_H | 18:a7dc3a63d7eb | 67 | robot.setSpeed(50,300); |
Wael_H | 18:a7dc3a63d7eb | 68 | } |
Wael_H | 18:a7dc3a63d7eb | 69 | else if(actual_gauche > past_gauche + diffMurBalle) |
Wael_H | 18:a7dc3a63d7eb | 70 | { |
Wael_H | 18:a7dc3a63d7eb | 71 | etat_deplacement = CORRECT_DROITE; |
Wael_H | 18:a7dc3a63d7eb | 72 | robot.setSpeed(50,300); |
Wael_H | 18:a7dc3a63d7eb | 73 | } |
Wael_H | 18:a7dc3a63d7eb | 74 | break;*/ |
Wael_H | 18:a7dc3a63d7eb | 75 | |
Wael_H | 18:a7dc3a63d7eb | 76 | /*case CORRECT_GAUCHE: |
Wael_H | 18:a7dc3a63d7eb | 77 | if(autorCorrect) //s'il a fini d'avancer |
Wael_H | 18:a7dc3a63d7eb | 78 | if(actual_droit < past_droit - diffMurBalle) |
Wael_H | 18:a7dc3a63d7eb | 79 | { |
Wael_H | 18:a7dc3a63d7eb | 80 | robot.stop(); |
Wael_H | 18:a7dc3a63d7eb | 81 | autorCorrect = false; |
Wael_H | 18:a7dc3a63d7eb | 82 | etat_deplacement = GO_STRAIGHT; |
Wael_H | 18:a7dc3a63d7eb | 83 | robot.setSpeed(80,300); |
Wael_H | 18:a7dc3a63d7eb | 84 | } |
Wael_H | 18:a7dc3a63d7eb | 85 | break; |
Wael_H | 18:a7dc3a63d7eb | 86 | |
Wael_H | 18:a7dc3a63d7eb | 87 | case CORRECT_DROITE: |
Wael_H | 18:a7dc3a63d7eb | 88 | if(autorCorrect) //s'il a fini d'avancer |
Wael_H | 18:a7dc3a63d7eb | 89 | if(actual_gauche < past_gauche - diffMurBalle) |
Wael_H | 18:a7dc3a63d7eb | 90 | { |
Wael_H | 18:a7dc3a63d7eb | 91 | robot.stop(); |
Wael_H | 18:a7dc3a63d7eb | 92 | autorCorrect = false; |
Wael_H | 18:a7dc3a63d7eb | 93 | etat_deplacement = GO_STRAIGHT; |
Wael_H | 18:a7dc3a63d7eb | 94 | robot.setSpeed(80,300); |
Wael_H | 18:a7dc3a63d7eb | 95 | } |
Wael_H | 18:a7dc3a63d7eb | 96 | break;*/ |
Wael_H | 15:3d4543a6c100 | 97 | } |
Wael_H | 15:3d4543a6c100 | 98 | |
Wael_H | 15:3d4543a6c100 | 99 | |
Wael_H | 15:3d4543a6c100 | 100 | past_gauche = actual_gauche; |
Wael_H | 15:3d4543a6c100 | 101 | past_droit = actual_droit; |
Wael_H | 15:3d4543a6c100 | 102 | } |
Wael_H | 15:3d4543a6c100 | 103 | |
Wael_H | 15:3d4543a6c100 | 104 | void automate_testABalle(Robot& robot) |
Wael_H | 15:3d4543a6c100 | 105 | { |
Wael_H | 15:3d4543a6c100 | 106 | typedef enum {ATTENTE,ABALLE} type_etat; |
Wael_H | 15:3d4543a6c100 | 107 | static type_etat etat = ATTENTE; |
Wael_H | 15:3d4543a6c100 | 108 | |
Wael_H | 18:a7dc3a63d7eb | 109 | PwmOut Servo_Ballon(PA_10); |
Wael_H | 18:a7dc3a63d7eb | 110 | PwmOut Mot_Ballon(PB_6); |
Wael_H | 18:a7dc3a63d7eb | 111 | |
Wael_H | 18:a7dc3a63d7eb | 112 | Servo_Ballon.period_ms(20); |
Wael_H | 18:a7dc3a63d7eb | 113 | Mot_Ballon.period_ms(20); |
Wael_H | 18:a7dc3a63d7eb | 114 | |
Wael_H | 18:a7dc3a63d7eb | 115 | static Timer T_ejecte; |
Wael_H | 18:a7dc3a63d7eb | 116 | |
Wael_H | 15:3d4543a6c100 | 117 | switch(etat) |
Wael_H | 15:3d4543a6c100 | 118 | { |
Wael_H | 15:3d4543a6c100 | 119 | case ATTENTE: |
Wael_H | 15:3d4543a6c100 | 120 | if(robot.aBalle()) |
Wael_H | 15:3d4543a6c100 | 121 | { |
Wael_H | 15:3d4543a6c100 | 122 | dbug.printf("A balle\n\r"); |
Wael_H | 15:3d4543a6c100 | 123 | robot.stop(); |
Wael_H | 18:a7dc3a63d7eb | 124 | //Servo_Ballon.write(1); |
Wael_H | 18:a7dc3a63d7eb | 125 | robot.setSpeed(80,500); |
Wael_H | 15:3d4543a6c100 | 126 | etat = ABALLE; |
Wael_H | 15:3d4543a6c100 | 127 | } |
Wael_H | 18:a7dc3a63d7eb | 128 | else if( T_ejecte.read() >= 1.0f ) |
Wael_H | 18:a7dc3a63d7eb | 129 | { |
Wael_H | 18:a7dc3a63d7eb | 130 | robot.gobe(25); |
Wael_H | 18:a7dc3a63d7eb | 131 | //Reset du timer pour la prochaine balle |
Wael_H | 18:a7dc3a63d7eb | 132 | T_ejecte.stop(); |
Wael_H | 18:a7dc3a63d7eb | 133 | T_ejecte.reset(); |
Wael_H | 18:a7dc3a63d7eb | 134 | } |
Wael_H | 15:3d4543a6c100 | 135 | break; |
Wael_H | 15:3d4543a6c100 | 136 | |
Wael_H | 15:3d4543a6c100 | 137 | case ABALLE: |
Wael_H | 18:a7dc3a63d7eb | 138 | /*if(robot.tourne(1800)) |
Wael_H | 15:3d4543a6c100 | 139 | { |
Wael_H | 18:a7dc3a63d7eb | 140 | dbug.printf("Tourne\n\r");*/ |
Wael_H | 18:a7dc3a63d7eb | 141 | robot.ejecte(70); |
Wael_H | 18:a7dc3a63d7eb | 142 | //} |
Wael_H | 18:a7dc3a63d7eb | 143 | if(!robot.aBalle()) |
Wael_H | 18:a7dc3a63d7eb | 144 | { |
Wael_H | 18:a7dc3a63d7eb | 145 | //Timer qui permet à la balle d'avoir le temps de quitter le reservoir |
Wael_H | 18:a7dc3a63d7eb | 146 | T_ejecte.start(); |
Wael_H | 18:a7dc3a63d7eb | 147 | // |
Wael_H | 18:a7dc3a63d7eb | 148 | Servo_Ballon.write(0); |
Wael_H | 15:3d4543a6c100 | 149 | etat = ATTENTE; |
Wael_H | 15:3d4543a6c100 | 150 | etat_deplacement = TURN_FAST; |
Wael_H | 18:a7dc3a63d7eb | 151 | robot.setSpeed(100,600); |
Wael_H | 18:a7dc3a63d7eb | 152 | } |
Wael_H | 15:3d4543a6c100 | 153 | break; |
Wael_H | 15:3d4543a6c100 | 154 | } |
Wael_H | 15:3d4543a6c100 | 155 | } |
Wael_H | 15:3d4543a6c100 | 156 | |
Wael_H | 18:a7dc3a63d7eb | 157 | void automate_deplacement(Robot& robot, bool& autorCorrect) |
Wael_H | 15:3d4543a6c100 | 158 | { |
Wael_H | 15:3d4543a6c100 | 159 | switch(etat_deplacement) |
Wael_H | 15:3d4543a6c100 | 160 | { |
Wael_H | 15:3d4543a6c100 | 161 | case TURN_FAST: |
Wael_H | 15:3d4543a6c100 | 162 | robot.tourne(); |
Wael_H | 15:3d4543a6c100 | 163 | break; |
Wael_H | 15:3d4543a6c100 | 164 | |
Wael_H | 15:3d4543a6c100 | 165 | case RETROUVE: |
Wael_H | 15:3d4543a6c100 | 166 | robot.tourne(-450); |
Wael_H | 15:3d4543a6c100 | 167 | break; |
Wael_H | 15:3d4543a6c100 | 168 | |
Wael_H | 15:3d4543a6c100 | 169 | case GO_STRAIGHT: |
Wael_H | 15:3d4543a6c100 | 170 | robot.avance(); |
Wael_H | 18:a7dc3a63d7eb | 171 | //autorCorrect = true; |
Wael_H | 15:3d4543a6c100 | 172 | break; |
Wael_H | 18:a7dc3a63d7eb | 173 | |
Wael_H | 18:a7dc3a63d7eb | 174 | /*case CORRECT_GAUCHE: |
Wael_H | 18:a7dc3a63d7eb | 175 | robot.tourne(-30); |
Wael_H | 18:a7dc3a63d7eb | 176 | break; |
Wael_H | 18:a7dc3a63d7eb | 177 | |
Wael_H | 18:a7dc3a63d7eb | 178 | case CORRECT_DROITE: |
Wael_H | 18:a7dc3a63d7eb | 179 | robot.tourne(30); |
Wael_H | 18:a7dc3a63d7eb | 180 | break;*/ |
Wael_H | 15:3d4543a6c100 | 181 | } |
Wael_H | 15:3d4543a6c100 | 182 | } |
Wael_H | 15:3d4543a6c100 | 183 | |
Wael_H | 15:3d4543a6c100 | 184 | |
Wael_H | 15:3d4543a6c100 | 185 | |
Wael_H | 15:3d4543a6c100 | 186 | /*int main(void) |
Wael_H | 15:3d4543a6c100 | 187 | { |
Wael_H | 15:3d4543a6c100 | 188 | Robot robot; |
Wael_H | 15:3d4543a6c100 | 189 | |
Wael_H | 9:2113adf37c66 | 190 | while(1) |
Wael_H | 13:9c62e263f245 | 191 | { |
Wael_H | 15:3d4543a6c100 | 192 | if(etat_deplacement != BALLE_STRAIGHT) |
Wael_H | 15:3d4543a6c100 | 193 | automate_testLasers(robot); |
Wael_H | 15:3d4543a6c100 | 194 | |
Wael_H | 13:9c62e263f245 | 195 | automate_testABalle(robot); |
Wael_H | 15:3d4543a6c100 | 196 | |
Wael_H | 13:9c62e263f245 | 197 | if(!robot.aBalle()) |
Wael_H | 13:9c62e263f245 | 198 | automate_deplacement(robot); |
Wael_H | 13:9c62e263f245 | 199 | } |
Wael_H | 7:753e901d441b | 200 | } |
Wael_H | 7:753e901d441b | 201 | |
Wael_H | 10:efa507ba2b35 | 202 | |
Wael_H | 13:9c62e263f245 | 203 | void automate_testLasers(Robot& robot) |
Wael_H | 7:753e901d441b | 204 | { |
Wael_H | 13:9c62e263f245 | 205 | typedef enum {ATTENTE, TURN_RIGHT, TURN_LEFT, VOIT_BALLE} type_etat; |
Wael_H | 13:9c62e263f245 | 206 | static type_etat etat = ATTENTE; |
Wael_H | 13:9c62e263f245 | 207 | |
Wael_H | 13:9c62e263f245 | 208 | static float past_gauche, past_droit, actual_gauche, actual_droit; |
Wael_H | 13:9c62e263f245 | 209 | |
Wael_H | 13:9c62e263f245 | 210 | actual_gauche = robot.getDist(Laser::Gauche); |
Wael_H | 13:9c62e263f245 | 211 | actual_droit = robot.getDist(Laser::Droit); |
Wael_H | 7:753e901d441b | 212 | |
Wael_H | 7:753e901d441b | 213 | switch(etat) |
Wael_H | 9:2113adf37c66 | 214 | { |
Wael_H | 13:9c62e263f245 | 215 | case ATTENTE: |
Wael_H | 14:1be2f691cbb4 | 216 | if(actual_gauche < past_gauche-30) |
Wael_H | 13:9c62e263f245 | 217 | { |
Wael_H | 15:3d4543a6c100 | 218 | dbug.printf("TURN_LEFT\n\r"); |
Wael_H | 13:9c62e263f245 | 219 | etat = TURN_LEFT; |
Wael_H | 13:9c62e263f245 | 220 | robot.stop(); |
Wael_H | 13:9c62e263f245 | 221 | } |
Wael_H | 13:9c62e263f245 | 222 | |
Wael_H | 14:1be2f691cbb4 | 223 | if(actual_droit < past_droit-30) |
Wael_H | 13:9c62e263f245 | 224 | { |
Wael_H | 15:3d4543a6c100 | 225 | dbug.printf("TURN_RIGHT\n\r"); |
Wael_H | 13:9c62e263f245 | 226 | etat = TURN_RIGHT; |
Wael_H | 13:9c62e263f245 | 227 | robot.stop(); |
Wael_H | 13:9c62e263f245 | 228 | } |
Wael_H | 13:9c62e263f245 | 229 | break; |
Wael_H | 13:9c62e263f245 | 230 | |
Wael_H | 13:9c62e263f245 | 231 | |
Wael_H | 13:9c62e263f245 | 232 | case TURN_LEFT: |
Wael_H | 15:3d4543a6c100 | 233 | etat_deplacement = BALLE_GAUCHE; |
Wael_H | 13:9c62e263f245 | 234 | |
Wael_H | 14:1be2f691cbb4 | 235 | if(actual_droit < past_droit-30) |
Wael_H | 13:9c62e263f245 | 236 | { |
Wael_H | 15:3d4543a6c100 | 237 | dbug.printf("VOIT_BALLE\n\r"); |
Wael_H | 13:9c62e263f245 | 238 | etat = VOIT_BALLE; |
Wael_H | 13:9c62e263f245 | 239 | robot.stop(); |
Wael_H | 13:9c62e263f245 | 240 | } |
Wael_H | 13:9c62e263f245 | 241 | |
Wael_H | 14:1be2f691cbb4 | 242 | if(actual_gauche > past_gauche+30) |
Wael_H | 13:9c62e263f245 | 243 | { |
Wael_H | 15:3d4543a6c100 | 244 | dbug.printf("TURN_RIGHT\n\r"); |
Wael_H | 13:9c62e263f245 | 245 | etat = TURN_RIGHT; |
Wael_H | 13:9c62e263f245 | 246 | robot.stop(); |
Wael_H | 13:9c62e263f245 | 247 | } |
Wael_H | 13:9c62e263f245 | 248 | break; |
Wael_H | 13:9c62e263f245 | 249 | |
Wael_H | 13:9c62e263f245 | 250 | |
Wael_H | 13:9c62e263f245 | 251 | case TURN_RIGHT: |
Wael_H | 15:3d4543a6c100 | 252 | etat_deplacement = BALLE_DROITE; |
Wael_H | 13:9c62e263f245 | 253 | |
Wael_H | 14:1be2f691cbb4 | 254 | if(actual_gauche < past_gauche-30) |
Wael_H | 13:9c62e263f245 | 255 | { |
Wael_H | 15:3d4543a6c100 | 256 | dbug.printf("VOIT_BALLE\n\r"); |
Wael_H | 13:9c62e263f245 | 257 | etat = VOIT_BALLE; |
Wael_H | 13:9c62e263f245 | 258 | robot.stop(); |
Wael_H | 13:9c62e263f245 | 259 | } |
Wael_H | 13:9c62e263f245 | 260 | |
Wael_H | 14:1be2f691cbb4 | 261 | if(actual_droit > past_droit+30) |
Wael_H | 13:9c62e263f245 | 262 | { |
Wael_H | 15:3d4543a6c100 | 263 | dbug.printf("TURN_LEFT\n\r"); |
Wael_H | 13:9c62e263f245 | 264 | etat = TURN_LEFT; |
Wael_H | 13:9c62e263f245 | 265 | robot.stop(); |
Wael_H | 13:9c62e263f245 | 266 | } |
Wael_H | 8:94ecfe411d02 | 267 | break; |
Wael_H | 8:94ecfe411d02 | 268 | |
Wael_H | 13:9c62e263f245 | 269 | |
Wael_H | 13:9c62e263f245 | 270 | case VOIT_BALLE: |
Wael_H | 15:3d4543a6c100 | 271 | etat_deplacement = BALLE_STRAIGHT; |
Wael_H | 13:9c62e263f245 | 272 | |
Wael_H | 14:1be2f691cbb4 | 273 | if(actual_gauche > past_gauche+30) |
Wael_H | 13:9c62e263f245 | 274 | { |
Wael_H | 15:3d4543a6c100 | 275 | dbug.printf("TURN_RIGHT\n\r"); |
Wael_H | 13:9c62e263f245 | 276 | etat = TURN_RIGHT; |
Wael_H | 13:9c62e263f245 | 277 | robot.stop(); |
Wael_H | 13:9c62e263f245 | 278 | } |
Wael_H | 13:9c62e263f245 | 279 | |
Wael_H | 14:1be2f691cbb4 | 280 | if(actual_droit > past_droit+30) |
Wael_H | 13:9c62e263f245 | 281 | { |
Wael_H | 15:3d4543a6c100 | 282 | dbug.printf("TURN_LEFT\n\r"); |
Wael_H | 13:9c62e263f245 | 283 | etat = TURN_LEFT; |
Wael_H | 13:9c62e263f245 | 284 | robot.stop(); |
Wael_H | 13:9c62e263f245 | 285 | } |
Wael_H | 13:9c62e263f245 | 286 | break; |
Wael_H | 13:9c62e263f245 | 287 | } |
Wael_H | 13:9c62e263f245 | 288 | |
Wael_H | 13:9c62e263f245 | 289 | past_gauche = actual_gauche; |
Wael_H | 13:9c62e263f245 | 290 | past_droit = actual_droit; |
Wael_H | 13:9c62e263f245 | 291 | } |
Wael_H | 13:9c62e263f245 | 292 | |
Wael_H | 13:9c62e263f245 | 293 | void automate_testABalle(Robot& robot) |
Wael_H | 13:9c62e263f245 | 294 | { |
Wael_H | 13:9c62e263f245 | 295 | typedef enum {ATTENTE,ABALLE} type_etat; |
Wael_H | 13:9c62e263f245 | 296 | static type_etat etat = ATTENTE; |
Wael_H | 13:9c62e263f245 | 297 | |
Wael_H | 13:9c62e263f245 | 298 | switch(etat) |
Wael_H | 13:9c62e263f245 | 299 | { |
Wael_H | 13:9c62e263f245 | 300 | case ATTENTE: |
Wael_H | 15:3d4543a6c100 | 301 | robot.gobe(25); |
Wael_H | 13:9c62e263f245 | 302 | if(robot.aBalle()) |
Wael_H | 13:9c62e263f245 | 303 | { |
Wael_H | 15:3d4543a6c100 | 304 | dbug.printf("A balle\n\r"); |
Wael_H | 15:3d4543a6c100 | 305 | robot.stop(); |
Wael_H | 13:9c62e263f245 | 306 | etat = ABALLE; |
Wael_H | 15:3d4543a6c100 | 307 | etat_deplacement = CHERCHE_BALLE; |
Wael_H | 13:9c62e263f245 | 308 | } |
Wael_H | 13:9c62e263f245 | 309 | break; |
Wael_H | 13:9c62e263f245 | 310 | |
Wael_H | 13:9c62e263f245 | 311 | case ABALLE: |
Wael_H | 13:9c62e263f245 | 312 | if(robot.tourne(1800)) |
Wael_H | 13:9c62e263f245 | 313 | { |
Wael_H | 15:3d4543a6c100 | 314 | dbug.printf("Tourne\n\r"); |
Wael_H | 13:9c62e263f245 | 315 | robot.ejecte(60); |
Wael_H | 15:3d4543a6c100 | 316 | } |
Wael_H | 15:3d4543a6c100 | 317 | if(!robot.aBalle()) |
Wael_H | 13:9c62e263f245 | 318 | etat = ATTENTE; |
Wael_H | 13:9c62e263f245 | 319 | break; |
Wael_H | 13:9c62e263f245 | 320 | } |
Wael_H | 13:9c62e263f245 | 321 | } |
Wael_H | 13:9c62e263f245 | 322 | |
Wael_H | 13:9c62e263f245 | 323 | void automate_deplacement(Robot& robot) |
Wael_H | 13:9c62e263f245 | 324 | { |
Wael_H | 15:3d4543a6c100 | 325 | switch(etat_deplacement) |
Wael_H | 13:9c62e263f245 | 326 | { |
Wael_H | 13:9c62e263f245 | 327 | case CHERCHE_BALLE: |
Wael_H | 15:3d4543a6c100 | 328 | robot.tourne(); |
Wael_H | 13:9c62e263f245 | 329 | break; |
Wael_H | 13:9c62e263f245 | 330 | |
Wael_H | 13:9c62e263f245 | 331 | case BALLE_GAUCHE: |
Wael_H | 15:3d4543a6c100 | 332 | robot.tourne(-30); |
Wael_H | 13:9c62e263f245 | 333 | break; |
Wael_H | 13:9c62e263f245 | 334 | |
Wael_H | 13:9c62e263f245 | 335 | case BALLE_DROITE: |
Wael_H | 15:3d4543a6c100 | 336 | robot.tourne(30); |
Wael_H | 13:9c62e263f245 | 337 | break; |
Wael_H | 13:9c62e263f245 | 338 | |
Wael_H | 13:9c62e263f245 | 339 | case BALLE_STRAIGHT: |
Wael_H | 15:3d4543a6c100 | 340 | robot.avance(); |
Wael_H | 18:a7dc3a63d7eb | 341 | static float allerJusqua; |
Wael_H | 15:3d4543a6c100 | 342 | |
Wael_H | 15:3d4543a6c100 | 343 | if(robot.getDist(Laser::Gauche,"mm") < robot.getDist(Laser::Droit,"mm")) |
Wael_H | 15:3d4543a6c100 | 344 | allerJusqua = 0.95*robot.getDist(Laser::Gauche,"mm"); |
Wael_H | 15:3d4543a6c100 | 345 | else |
Wael_H | 15:3d4543a6c100 | 346 | allerJusqua = 0.95*robot.getDist(Laser::Droit,"mm"); |
Wael_H | 15:3d4543a6c100 | 347 | |
Wael_H | 15:3d4543a6c100 | 348 | if(allerJusqua > 2500) |
Wael_H | 15:3d4543a6c100 | 349 | allerJusqua = 2500; |
Wael_H | 15:3d4543a6c100 | 350 | |
Wael_H | 15:3d4543a6c100 | 351 | while(!robot.avance((int)allerJusqua)) |
Wael_H | 15:3d4543a6c100 | 352 | { |
Wael_H | 15:3d4543a6c100 | 353 | dbug.printf("%f\n\r", robot.getDist(Laser::Gauche,"mm")); |
Wael_H | 18:a7dc3a63d7eb | 354 | } |
Wael_H | 18:a7dc3a63d7eb | 355 | break; |
Wael_H | 7:753e901d441b | 356 | } |
Wael_H | 15:3d4543a6c100 | 357 | }*/ |