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@28:82571fd665bf, 2019-06-06 (annotated)
- Committer:
- Wael_H
- Date:
- Thu Jun 06 16:01:05 2019 +0000
- Revision:
- 28:82571fd665bf
- Parent:
- 27:e103da412e2b
- Child:
- 29:6bce50d6530c
- Child:
- 30:ee3e274e4b55
Je continue vraiment ca apres les homologations
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 | 28:82571fd665bf | 5 | bool automate_aveugle(Robot&); |
Wael_H | 27:e103da412e2b | 6 | void automate_testLasers(Robot&); |
Wael_H | 27:e103da412e2b | 7 | void automate_testABalle(Robot&); |
Wael_H | 27:e103da412e2b | 8 | void automate_deplacement(Robot&); |
Wael_H | 27:e103da412e2b | 9 | void automate_vitesse(Robot&); |
Wael_H | 27:e103da412e2b | 10 | |
Wael_H | 27:e103da412e2b | 11 | typedef enum{TURN_FAST, CORRECT_GAUCHE, CORRECT_DROITE, GO_STRAIGHT} type_etat_deplacement; |
Wael_H | 27:e103da412e2b | 12 | type_etat_deplacement etat_deplacement = TURN_FAST; |
Wael_H | 27:e103da412e2b | 13 | |
Wael_H | 8:94ecfe411d02 | 14 | |
Wael_H | 2:8971078b1ccf | 15 | int main(void) |
Wael_H | 2:8971078b1ccf | 16 | { |
Wael_H | 10:efa507ba2b35 | 17 | Robot robot; |
theolp | 17:aae5361ddddf | 18 | |
Wael_H | 27:e103da412e2b | 19 | robot.setSpeed(80,450); // vitesse de rotation de recherche de la balle |
theolp | 20:a1b5d032b422 | 20 | |
Wael_H | 15:3d4543a6c100 | 21 | while(1) |
Wael_H | 25:033263cf832c | 22 | if(!Robot::Jack) |
theolp | 17:aae5361ddddf | 23 | { |
Wael_H | 28:82571fd665bf | 24 | while(!automate_aveugle(robot)); |
Wael_H | 28:82571fd665bf | 25 | |
Wael_H | 27:e103da412e2b | 26 | automate_testABalle(robot); |
Wael_H | 27:e103da412e2b | 27 | |
Wael_H | 27:e103da412e2b | 28 | automate_testLasers(robot); |
theolp | 17:aae5361ddddf | 29 | |
Wael_H | 27:e103da412e2b | 30 | if(!robot.aBalle()) |
Wael_H | 27:e103da412e2b | 31 | automate_deplacement(robot); |
Wael_H | 27:e103da412e2b | 32 | |
Wael_H | 27:e103da412e2b | 33 | automate_vitesse(robot); |
theolp | 17:aae5361ddddf | 34 | } |
Wael_H | 15:3d4543a6c100 | 35 | } |
Wael_H | 15:3d4543a6c100 | 36 | |
Wael_H | 28:82571fd665bf | 37 | bool automate_aveugle(Robot& robot) |
Wael_H | 28:82571fd665bf | 38 | { |
Wael_H | 28:82571fd665bf | 39 | typedef enum{STRAIGHT1, TOURNE_D, STRAIGHT2, TOURNE_G} type_etat; |
Wael_H | 28:82571fd665bf | 40 | static type_etat etat = STRAIGHT1; |
Wael_H | 28:82571fd665bf | 41 | |
Wael_H | 28:82571fd665bf | 42 | static Timer T_ejecte; |
Wael_H | 28:82571fd665bf | 43 | |
Wael_H | 28:82571fd665bf | 44 | switch(etat) |
Wael_H | 28:82571fd665bf | 45 | { |
Wael_H | 28:82571fd665bf | 46 | case STRAIGHT1: |
Wael_H | 28:82571fd665bf | 47 | robot.avance(); |
Wael_H | 28:82571fd665bf | 48 | if(robot.aBalle()) |
Wael_H | 28:82571fd665bf | 49 | { |
Wael_H | 28:82571fd665bf | 50 | robot.stop(); |
Wael_H | 28:82571fd665bf | 51 | robot.ejecte(); |
Wael_H | 28:82571fd665bf | 52 | etat = TOURNE_D; |
Wael_H | 28:82571fd665bf | 53 | } |
Wael_H | 28:82571fd665bf | 54 | else if( T_ejecte.read() >= 1.0f ) |
Wael_H | 28:82571fd665bf | 55 | { |
Wael_H | 28:82571fd665bf | 56 | robot.gobe(); |
Wael_H | 28:82571fd665bf | 57 | T_ejecte.stop(); |
Wael_H | 28:82571fd665bf | 58 | T_ejecte.reset(); |
Wael_H | 28:82571fd665bf | 59 | } |
Wael_H | 28:82571fd665bf | 60 | break; |
Wael_H | 28:82571fd665bf | 61 | |
Wael_H | 28:82571fd665bf | 62 | case TOURNE_D: |
Wael_H | 28:82571fd665bf | 63 | if( T_ejecte.read() >= 1.0f ) |
Wael_H | 28:82571fd665bf | 64 | { |
Wael_H | 28:82571fd665bf | 65 | robot.gobe(); |
Wael_H | 28:82571fd665bf | 66 | T_ejecte.stop(); |
Wael_H | 28:82571fd665bf | 67 | T_ejecte.reset(); |
Wael_H | 28:82571fd665bf | 68 | } |
Wael_H | 28:82571fd665bf | 69 | |
Wael_H | 28:82571fd665bf | 70 | if(robot.tourne(900)) |
Wael_H | 28:82571fd665bf | 71 | etat = STRAIGHT2; |
Wael_H | 28:82571fd665bf | 72 | break; |
Wael_H | 28:82571fd665bf | 73 | |
Wael_H | 28:82571fd665bf | 74 | case STRAIGHT2: |
Wael_H | 28:82571fd665bf | 75 | robot.avance(); |
Wael_H | 28:82571fd665bf | 76 | if(robot.aBalle()) |
Wael_H | 28:82571fd665bf | 77 | { |
Wael_H | 28:82571fd665bf | 78 | robot.stop(); |
Wael_H | 28:82571fd665bf | 79 | etat = TOURNE_G; |
Wael_H | 28:82571fd665bf | 80 | } |
Wael_H | 28:82571fd665bf | 81 | break; |
Wael_H | 28:82571fd665bf | 82 | |
Wael_H | 28:82571fd665bf | 83 | case TOURNE_G: |
Wael_H | 28:82571fd665bf | 84 | if(robot.tourne(-900)) |
Wael_H | 28:82571fd665bf | 85 | robot.ejecte(); |
Wael_H | 28:82571fd665bf | 86 | |
Wael_H | 28:82571fd665bf | 87 | if(!robot.aBalle()) |
Wael_H | 28:82571fd665bf | 88 | { |
Wael_H | 28:82571fd665bf | 89 | T_ejecte.start(); |
Wael_H | 28:82571fd665bf | 90 | etat = TOURNE_D; |
Wael_H | 28:82571fd665bf | 91 | } |
Wael_H | 28:82571fd665bf | 92 | break; |
Wael_H | 28:82571fd665bf | 93 | } |
Wael_H | 28:82571fd665bf | 94 | |
Wael_H | 28:82571fd665bf | 95 | return false; |
Wael_H | 28:82571fd665bf | 96 | } |
Wael_H | 28:82571fd665bf | 97 | |
Wael_H | 27:e103da412e2b | 98 | |
Wael_H | 27:e103da412e2b | 99 | void automate_testLasers(Robot& robot) |
Wael_H | 27:e103da412e2b | 100 | { |
Wael_H | 27:e103da412e2b | 101 | static const int diffMurBalle = 20; |
Wael_H | 27:e103da412e2b | 102 | static float past_gauche, past_droit, actual_gauche, actual_droit; |
Wael_H | 27:e103da412e2b | 103 | static float distBalle; |
Wael_H | 27:e103da412e2b | 104 | |
Wael_H | 27:e103da412e2b | 105 | actual_gauche = robot.getDist(Laser::Gauche); |
Wael_H | 27:e103da412e2b | 106 | actual_droit = robot.getDist(Laser::Droit); |
Wael_H | 27:e103da412e2b | 107 | |
Wael_H | 27:e103da412e2b | 108 | switch(etat_deplacement) |
Wael_H | 27:e103da412e2b | 109 | { |
Wael_H | 27:e103da412e2b | 110 | case TURN_FAST: |
Wael_H | 27:e103da412e2b | 111 | if(actual_droit < past_droit - diffMurBalle) |
Wael_H | 27:e103da412e2b | 112 | { |
Wael_H | 27:e103da412e2b | 113 | distBalle = actual_droit; |
Wael_H | 27:e103da412e2b | 114 | robot.stop(); |
Wael_H | 27:e103da412e2b | 115 | etat_deplacement = CORRECT_GAUCHE; |
Wael_H | 27:e103da412e2b | 116 | } |
Wael_H | 27:e103da412e2b | 117 | break; |
Wael_H | 27:e103da412e2b | 118 | |
Wael_H | 27:e103da412e2b | 119 | case CORRECT_GAUCHE: |
Wael_H | 27:e103da412e2b | 120 | |
Wael_H | 27:e103da412e2b | 121 | break; |
Wael_H | 27:e103da412e2b | 122 | |
Wael_H | 27:e103da412e2b | 123 | case CORRECT_DROITE: |
Wael_H | 27:e103da412e2b | 124 | break; |
Wael_H | 27:e103da412e2b | 125 | |
Wael_H | 27:e103da412e2b | 126 | case GO_STRAIGHT: |
Wael_H | 27:e103da412e2b | 127 | break; |
Wael_H | 27:e103da412e2b | 128 | } |
Wael_H | 27:e103da412e2b | 129 | |
Wael_H | 27:e103da412e2b | 130 | |
Wael_H | 27:e103da412e2b | 131 | past_gauche = actual_gauche; |
Wael_H | 27:e103da412e2b | 132 | past_droit = actual_droit; |
Wael_H | 27:e103da412e2b | 133 | } |
Wael_H | 27:e103da412e2b | 134 | |
Wael_H | 27:e103da412e2b | 135 | void automate_testABalle(Robot& robot) |
Wael_H | 24:314b1f6607c5 | 136 | { |
Wael_H | 27:e103da412e2b | 137 | typedef enum {ATTENTE,ABALLE} type_etat; |
Wael_H | 27:e103da412e2b | 138 | static type_etat etat = ATTENTE; |
Wael_H | 23:bb1535360a98 | 139 | |
Wael_H | 27:e103da412e2b | 140 | static Timer T_ejecte; |
Wael_H | 7:753e901d441b | 141 | |
Wael_H | 7:753e901d441b | 142 | switch(etat) |
Wael_H | 9:2113adf37c66 | 143 | { |
Wael_H | 27:e103da412e2b | 144 | case ATTENTE: |
Wael_H | 27:e103da412e2b | 145 | if(robot.aBalle()) |
Wael_H | 27:e103da412e2b | 146 | { |
Wael_H | 27:e103da412e2b | 147 | robot.stop(); |
Wael_H | 27:e103da412e2b | 148 | etat = ABALLE; |
Wael_H | 27:e103da412e2b | 149 | robot.setSpeed(80,500); //vitesse de rotation vers le terrain ennemi |
Wael_H | 27:e103da412e2b | 150 | } |
Wael_H | 27:e103da412e2b | 151 | else if( T_ejecte.read() >= 1.0f ) |
Wael_H | 27:e103da412e2b | 152 | { |
Wael_H | 28:82571fd665bf | 153 | robot.gobe(); |
Wael_H | 27:e103da412e2b | 154 | T_ejecte.stop(); |
Wael_H | 27:e103da412e2b | 155 | T_ejecte.reset(); |
Wael_H | 27:e103da412e2b | 156 | } |
Wael_H | 13:9c62e263f245 | 157 | break; |
Wael_H | 13:9c62e263f245 | 158 | |
Wael_H | 27:e103da412e2b | 159 | case ABALLE: |
Wael_H | 27:e103da412e2b | 160 | if(robot.tourne(1800)) |
Wael_H | 28:82571fd665bf | 161 | robot.ejecte(); |
Wael_H | 27:e103da412e2b | 162 | |
Wael_H | 27:e103da412e2b | 163 | if(!robot.aBalle()) |
Wael_H | 27:e103da412e2b | 164 | { |
Wael_H | 27:e103da412e2b | 165 | T_ejecte.start(); |
Wael_H | 27:e103da412e2b | 166 | etat = ATTENTE; |
Wael_H | 27:e103da412e2b | 167 | etat_deplacement = TURN_FAST; |
Wael_H | 27:e103da412e2b | 168 | } |
Wael_H | 13:9c62e263f245 | 169 | break; |
Wael_H | 13:9c62e263f245 | 170 | } |
Wael_H | 13:9c62e263f245 | 171 | } |
Wael_H | 23:bb1535360a98 | 172 | |
Wael_H | 27:e103da412e2b | 173 | void automate_deplacement(Robot& robot) |
Wael_H | 27:e103da412e2b | 174 | { |
Wael_H | 27:e103da412e2b | 175 | switch(etat_deplacement) |
Wael_H | 23:bb1535360a98 | 176 | { |
Wael_H | 27:e103da412e2b | 177 | case TURN_FAST: |
Wael_H | 27:e103da412e2b | 178 | robot.tourne(); |
Wael_H | 27:e103da412e2b | 179 | break; |
Wael_H | 27:e103da412e2b | 180 | |
Wael_H | 27:e103da412e2b | 181 | case CORRECT_GAUCHE: |
Wael_H | 27:e103da412e2b | 182 | robot.tourne(-450); |
Wael_H | 23:bb1535360a98 | 183 | break; |
Wael_H | 23:bb1535360a98 | 184 | |
Wael_H | 27:e103da412e2b | 185 | case CORRECT_DROITE: |
Wael_H | 27:e103da412e2b | 186 | robot.tourne(450); |
Wael_H | 27:e103da412e2b | 187 | |
Wael_H | 27:e103da412e2b | 188 | case GO_STRAIGHT: |
Wael_H | 27:e103da412e2b | 189 | robot.avance(); |
Wael_H | 27:e103da412e2b | 190 | break; |
Wael_H | 27:e103da412e2b | 191 | } |
Wael_H | 27:e103da412e2b | 192 | } |
Wael_H | 27:e103da412e2b | 193 | |
Wael_H | 27:e103da412e2b | 194 | void automate_vitesse(Robot& robot) |
Wael_H | 27:e103da412e2b | 195 | { |
Wael_H | 27:e103da412e2b | 196 | switch(etat_deplacement) |
Wael_H | 27:e103da412e2b | 197 | { |
Wael_H | 27:e103da412e2b | 198 | case TURN_FAST: |
Wael_H | 27:e103da412e2b | 199 | robot.setSpeed(80,450); |
Wael_H | 23:bb1535360a98 | 200 | break; |
Wael_H | 23:bb1535360a98 | 201 | |
Wael_H | 27:e103da412e2b | 202 | case CORRECT_GAUCHE: |
Wael_H | 27:e103da412e2b | 203 | robot.setSpeed(50,300); |
Wael_H | 27:e103da412e2b | 204 | break; |
Wael_H | 23:bb1535360a98 | 205 | |
Wael_H | 27:e103da412e2b | 206 | case CORRECT_DROITE: |
Wael_H | 27:e103da412e2b | 207 | robot.setSpeed(50,300); |
Wael_H | 27:e103da412e2b | 208 | break; |
Wael_H | 24:314b1f6607c5 | 209 | |
Wael_H | 27:e103da412e2b | 210 | case GO_STRAIGHT: |
Wael_H | 27:e103da412e2b | 211 | robot.setSpeed(80,400); |
Wael_H | 23:bb1535360a98 | 212 | break; |
Wael_H | 23:bb1535360a98 | 213 | } |
Wael_H | 27:e103da412e2b | 214 | } |