carte_strategie_2019
Dependencies: mbed SerialHalfDuplex SDFileSystem DISCO-F469NI_portrait liaison_Bluetooth ident_crac
Robots/Strategie_big.cpp@72:5b1b3e151e59, 2019-05-26 (annotated)
- Committer:
- Villanut
- Date:
- Sun May 26 23:15:47 2019 +0000
- Revision:
- 72:5b1b3e151e59
- Parent:
- 71:67cce4efd33d
- Child:
- 73:bf4d6d9db13b
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Sitkah | 29:41e02746041d | 1 | #include "global.h" |
Sitkah | 29:41e02746041d | 2 | #ifdef ROBOT_BIG |
ClementBreteau | 15:c2fc239e85df | 3 | |
Sitkah | 29:41e02746041d | 4 | |
antbig | 12:14729d584500 | 5 | unsigned char isStopEnable = 1;//Permet de savoir si il faut autoriser le stop via les balises |
antbig | 12:14729d584500 | 6 | |
antbig | 0:ad97421fb1fb | 7 | /****************************************************************************************/ |
antbig | 0:ad97421fb1fb | 8 | /* FUNCTION NAME: doFunnyAction */ |
antbig | 0:ad97421fb1fb | 9 | /* DESCRIPTION : Permet de faire la funny action en fin de partie */ |
antbig | 0:ad97421fb1fb | 10 | /****************************************************************************************/ |
antbig | 0:ad97421fb1fb | 11 | void doFunnyAction(void) { |
ClementBreteau | 18:cc5fec34ed9c | 12 | //envoie de la funny action |
ClementBreteau | 18:cc5fec34ed9c | 13 | // 0x007, 01, 01 |
ClementBreteau | 18:cc5fec34ed9c | 14 | CANMessage msgTx=CANMessage(); |
ClementBreteau | 18:cc5fec34ed9c | 15 | msgTx.id=GLOBAL_FUNNY_ACTION; |
ClementBreteau | 18:cc5fec34ed9c | 16 | msgTx.format=CANStandard; |
ClementBreteau | 18:cc5fec34ed9c | 17 | msgTx.type=CANData; |
ClementBreteau | 18:cc5fec34ed9c | 18 | msgTx.len=2; |
ClementBreteau | 18:cc5fec34ed9c | 19 | msgTx.data[0]=0x01; |
ClementBreteau | 18:cc5fec34ed9c | 20 | msgTx.data[1]=0x01; |
ClementBreteau | 18:cc5fec34ed9c | 21 | can1.write(msgTx); |
antbig | 0:ad97421fb1fb | 22 | } |
antbig | 0:ad97421fb1fb | 23 | |
antbig | 0:ad97421fb1fb | 24 | /****************************************************************************************/ |
antbig | 0:ad97421fb1fb | 25 | /* FUNCTION NAME: doAction */ |
antbig | 0:ad97421fb1fb | 26 | /* DESCRIPTION : Effectuer une action specifique */ |
antbig | 0:ad97421fb1fb | 27 | /****************************************************************************************/ |
Sitkah | 30:a1e37af4bbde | 28 | unsigned char doAction(unsigned char id, unsigned short var1, short var2) { |
antbig | 12:14729d584500 | 29 | CANMessage msgTx=CANMessage(); |
Sitkah | 30:a1e37af4bbde | 30 | msgTx.format=CANStandard; |
Sitkah | 30:a1e37af4bbde | 31 | msgTx.type=CANData; |
Sitkah | 30:a1e37af4bbde | 32 | //affichage_debug(id); |
Sitkah | 30:a1e37af4bbde | 33 | |
antbig | 0:ad97421fb1fb | 34 | switch(id) { |
Sitkah | 30:a1e37af4bbde | 35 | /////////////////////////////////////////////////////////100 à 108 : ACTIONS HERKULEX///////////////////////////////////////////// |
Villanut | 71:67cce4efd33d | 36 | case 201: |
Villanut | 71:67cce4efd33d | 37 | CANMessage msgTx=CANMessage(); |
Villanut | 71:67cce4efd33d | 38 | msgTx.id=ASCENSEUR; |
Villanut | 71:67cce4efd33d | 39 | msgTx.format=CANStandard; |
Villanut | 71:67cce4efd33d | 40 | msgTx.type=CANData; |
Villanut | 72:5b1b3e151e59 | 41 | msgTx.len=1; |
Villanut | 72:5b1b3e151e59 | 42 | msgTx.data[0]=(unsigned char)var1; |
Villanut | 71:67cce4efd33d | 43 | |
Villanut | 71:67cce4efd33d | 44 | can2.write(msgTx); |
Sitkah | 38:76f886a1c8e6 | 45 | break; |
ClementBreteau | 15:c2fc239e85df | 46 | |
Villanut | 72:5b1b3e151e59 | 47 | case 202: |
Villanut | 72:5b1b3e151e59 | 48 | msgTx.id=VIDER_CONVOYEUR; |
Artiom | 67:96f914f92d2d | 49 | |
Villanut | 72:5b1b3e151e59 | 50 | msgTx.len=1; |
Villanut | 72:5b1b3e151e59 | 51 | msgTx.data[0]=(unsigned char)var1; |
Villanut | 72:5b1b3e151e59 | 52 | |
Villanut | 72:5b1b3e151e59 | 53 | can2.write(msgTx); |
Sitkah | 30:a1e37af4bbde | 54 | break; |
Artiom | 67:96f914f92d2d | 55 | |
Villanut | 72:5b1b3e151e59 | 56 | case 203: |
Villanut | 72:5b1b3e151e59 | 57 | SendRawId(GOLDENIUM_AVANT); |
Sitkah | 30:a1e37af4bbde | 58 | break; |
Artiom | 67:96f914f92d2d | 59 | |
Villanut | 72:5b1b3e151e59 | 60 | case 204: |
Villanut | 72:5b1b3e151e59 | 61 | unsigned char arg_tempo; |
Villanut | 72:5b1b3e151e59 | 62 | if(InversStrat == 1) |
Villanut | 72:5b1b3e151e59 | 63 | { |
Villanut | 72:5b1b3e151e59 | 64 | switch(var1){ |
Villanut | 72:5b1b3e151e59 | 65 | case AV_DROIT: |
Villanut | 72:5b1b3e151e59 | 66 | arg_tempo = AV_GAUCHE; |
Villanut | 72:5b1b3e151e59 | 67 | break; |
Villanut | 72:5b1b3e151e59 | 68 | case AV_GAUCHE: |
Villanut | 72:5b1b3e151e59 | 69 | arg_tempo = AV_DROIT; |
Villanut | 72:5b1b3e151e59 | 70 | break; |
Villanut | 72:5b1b3e151e59 | 71 | default : |
Villanut | 72:5b1b3e151e59 | 72 | arg_tempo =(unsigned char)var1; |
Villanut | 72:5b1b3e151e59 | 73 | break; |
Villanut | 72:5b1b3e151e59 | 74 | } |
Villanut | 72:5b1b3e151e59 | 75 | |
Villanut | 72:5b1b3e151e59 | 76 | } |
Villanut | 72:5b1b3e151e59 | 77 | else arg_tempo =(unsigned char)var1; |
Villanut | 72:5b1b3e151e59 | 78 | SendMsgCan(HACHEUR_RELEASE_ATOM, &arg_tempo,1); |
Villanut | 72:5b1b3e151e59 | 79 | waitingAckFrom = 0; |
Villanut | 72:5b1b3e151e59 | 80 | waitingAckID =0; |
Sitkah | 38:76f886a1c8e6 | 81 | break; |
Villanut | 72:5b1b3e151e59 | 82 | |
Villanut | 72:5b1b3e151e59 | 83 | case 205: |
Villanut | 72:5b1b3e151e59 | 84 | SendRawId(PRESENTOIR_AVANT); |
Sitkah | 41:b029ddc4d60e | 85 | break; |
Sitkah | 38:76f886a1c8e6 | 86 | |
Sitkah | 38:76f886a1c8e6 | 87 | case 150: |
Sitkah | 38:76f886a1c8e6 | 88 | SCORE_GR+=var1; |
Sitkah | 38:76f886a1c8e6 | 89 | SCORE_GLOBAL=SCORE_GR+SCORE_PR; |
Sitkah | 40:21bb685b553b | 90 | //liaison_Tx.envoyer_short(0x30,SCORE_GLOBAL); |
Sitkah | 38:76f886a1c8e6 | 91 | waitingAckFrom = 0; |
Sitkah | 38:76f886a1c8e6 | 92 | waitingAckID = 0; |
Sitkah | 38:76f886a1c8e6 | 93 | break; |
Sitkah | 38:76f886a1c8e6 | 94 | |
ClementBreteau | 18:cc5fec34ed9c | 95 | |
Artiom | 67:96f914f92d2d | 96 | case 11://0 Désactiver le stop,1 Activer le stop saut de strat,2 Activer le stop avec evitement |
Villanut | 71:67cce4efd33d | 97 | isStopEnable =(unsigned char) var1; |
Artiom | 67:96f914f92d2d | 98 | SendMsgCan(0x5BC, &isStopEnable,1); |
Artiom | 67:96f914f92d2d | 99 | waitingAckFrom = 0; |
Artiom | 67:96f914f92d2d | 100 | waitingAckID =0; |
Artiom | 67:96f914f92d2d | 101 | break; |
antbig | 12:14729d584500 | 102 | case 20://Désactiver l'asservissement |
antbig | 12:14729d584500 | 103 | setAsservissementEtat(0); |
antbig | 12:14729d584500 | 104 | break; |
Artiom | 67:96f914f92d2d | 105 | |
antbig | 12:14729d584500 | 106 | case 21://Activer l'asservissement |
antbig | 12:14729d584500 | 107 | setAsservissementEtat(1); |
antbig | 12:14729d584500 | 108 | break; |
antbig | 12:14729d584500 | 109 | |
antbig | 12:14729d584500 | 110 | case 22://Changer la vitesse du robot |
Villanut | 71:67cce4efd33d | 111 | SendSpeed(var1,(unsigned short)var2, (unsigned short)var2); |
ClementBreteau | 26:2f4fcc2354f3 | 112 | waitingAckFrom = 0; |
ClementBreteau | 26:2f4fcc2354f3 | 113 | waitingAckID = 0; |
ClementBreteau | 26:2f4fcc2354f3 | 114 | wait(0.2); |
antbig | 12:14729d584500 | 115 | break; |
antbig | 12:14729d584500 | 116 | |
antbig | 12:14729d584500 | 117 | case 30://Action tempo |
Sitkah | 30:a1e37af4bbde | 118 | wait_ms(var1); |
Sitkah | 40:21bb685b553b | 119 | waitingAckFrom = 0; |
Sitkah | 40:21bb685b553b | 120 | waitingAckID = 0; |
antbig | 12:14729d584500 | 121 | break; |
antbig | 12:14729d584500 | 122 | |
Artiom | 67:96f914f92d2d | 123 | |
antbig | 12:14729d584500 | 124 | |
antbig | 0:ad97421fb1fb | 125 | default: |
antbig | 0:ad97421fb1fb | 126 | return 0;//L'action n'existe pas, il faut utiliser le CAN |
antbig | 0:ad97421fb1fb | 127 | |
antbig | 0:ad97421fb1fb | 128 | } |
antbig | 0:ad97421fb1fb | 129 | return 1;//L'action est spécifique. |
antbig | 0:ad97421fb1fb | 130 | |
antbig | 0:ad97421fb1fb | 131 | } |
antbig | 0:ad97421fb1fb | 132 | |
antbig | 0:ad97421fb1fb | 133 | /****************************************************************************************/ |
antbig | 0:ad97421fb1fb | 134 | /* FUNCTION NAME: initRobot */ |
antbig | 0:ad97421fb1fb | 135 | /* DESCRIPTION : initialiser le robot */ |
antbig | 0:ad97421fb1fb | 136 | /****************************************************************************************/ |
antbig | 9:d0042422d95a | 137 | void initRobot(void) |
antbig | 9:d0042422d95a | 138 | { |
antbig | 9:d0042422d95a | 139 | //Enregistrement de tous les AX12 présent sur la carte |
ClementBreteau | 15:c2fc239e85df | 140 | /*AX12_register(5, AX12_SERIAL2); |
antbig | 8:0edc7dfb7f7e | 141 | AX12_register(18, AX12_SERIAL2); |
antbig | 8:0edc7dfb7f7e | 142 | AX12_register(13, AX12_SERIAL2); |
antbig | 12:14729d584500 | 143 | AX12_register(1, AX12_SERIAL1); |
antbig | 12:14729d584500 | 144 | AX12_register(11, AX12_SERIAL1); |
antbig | 12:14729d584500 | 145 | AX12_register(8, AX12_SERIAL1); |
ClementBreteau | 15:c2fc239e85df | 146 | AX12_register(7, AX12_SERIAL2);*/ |
antbig | 9:d0042422d95a | 147 | |
antbig | 12:14729d584500 | 148 | //AX12_setGoal(AX12_ID_FUNNY_ACTION, AX12_ANGLE_FUNNY_ACTION_CLOSE,AX12_SPEED_FUNNY_ACTION); |
antbig | 12:14729d584500 | 149 | //AX12_processChange(); |
antbig | 11:ed13a480ddca | 150 | //runRobotTest(); |
ClementBreteau | 16:7321fb3bb396 | 151 | |
antbig | 9:d0042422d95a | 152 | } |
antbig | 9:d0042422d95a | 153 | |
antbig | 9:d0042422d95a | 154 | /****************************************************************************************/ |
antbig | 12:14729d584500 | 155 | /* FUNCTION NAME: initRobotActionneur */ |
antbig | 12:14729d584500 | 156 | /* DESCRIPTION : Initialiser la position des actionneurs du robot */ |
antbig | 12:14729d584500 | 157 | /****************************************************************************************/ |
antbig | 12:14729d584500 | 158 | void initRobotActionneur(void) |
antbig | 12:14729d584500 | 159 | { |
ClementBreteau | 23:ab87d308eaf9 | 160 | /*doAction(100,1,0); |
ClementBreteau | 23:ab87d308eaf9 | 161 | doAction(100,2,0); |
ClementBreteau | 23:ab87d308eaf9 | 162 | doAction(110,0,0); |
ClementBreteau | 23:ab87d308eaf9 | 163 | doAction(120,0,0); |
ClementBreteau | 23:ab87d308eaf9 | 164 | doAction(131,0,0);*/ |
ClementBreteau | 23:ab87d308eaf9 | 165 | |
antbig | 12:14729d584500 | 166 | } |
antbig | 12:14729d584500 | 167 | |
antbig | 12:14729d584500 | 168 | /****************************************************************************************/ |
antbig | 9:d0042422d95a | 169 | /* FUNCTION NAME: runTest */ |
antbig | 9:d0042422d95a | 170 | /* DESCRIPTION : tester l'ensemble des actionneurs du robot */ |
antbig | 9:d0042422d95a | 171 | /****************************************************************************************/ |
antbig | 9:d0042422d95a | 172 | void runRobotTest(void) |
antbig | 9:d0042422d95a | 173 | { |
ClementBreteau | 18:cc5fec34ed9c | 174 | /* |
antbig | 12:14729d584500 | 175 | int waitTime = 500; |
antbig | 12:14729d584500 | 176 | |
antbig | 9:d0042422d95a | 177 | //Test des AX12 dans l'ordre |
antbig | 9:d0042422d95a | 178 | doAction(111,0,0);//Fermeture pince arrière haute |
antbig | 12:14729d584500 | 179 | wait_ms(waitTime); |
antbig | 9:d0042422d95a | 180 | doAction(110,0,0);//Ouverture pince arrière haute |
antbig | 12:14729d584500 | 181 | wait_ms(waitTime); |
antbig | 9:d0042422d95a | 182 | doAction(113,0,0);//Fermeture pince arrière basse |
antbig | 12:14729d584500 | 183 | wait_ms(waitTime); |
antbig | 9:d0042422d95a | 184 | doAction(112,0,0);//Ouverture pince arrière basse |
antbig | 12:14729d584500 | 185 | wait_ms(waitTime); |
antbig | 9:d0042422d95a | 186 | doAction(115,0,0);//Fermeture porte arrière |
antbig | 12:14729d584500 | 187 | wait_ms(waitTime); |
antbig | 9:d0042422d95a | 188 | doAction(114,0,0);//Ouverture porte arrière |
antbig | 12:14729d584500 | 189 | wait_ms(waitTime); |
antbig | 12:14729d584500 | 190 | doAction(101,0,0);//Fermer les portes avant |
antbig | 12:14729d584500 | 191 | wait_ms(waitTime); |
antbig | 12:14729d584500 | 192 | doAction(100,0,0);//Ouvrir les portes avant |
antbig | 12:14729d584500 | 193 | wait_ms(waitTime); |
antbig | 12:14729d584500 | 194 | doAction(103,0,0);//Descendre le peigne |
antbig | 12:14729d584500 | 195 | wait_ms(waitTime); |
ClementBreteau | 18:cc5fec34ed9c | 196 | doAction(102,0,0);//Remonter le peigne*/ |
antbig | 0:ad97421fb1fb | 197 | } |
antbig | 3:19f2285a4757 | 198 | |
antbig | 4:88431b537477 | 199 | /****************************************************************************************/ |
antbig | 4:88431b537477 | 200 | /* FUNCTION NAME: SelectStrategy */ |
antbig | 4:88431b537477 | 201 | /* DESCRIPTION : Charger le fichier de stratégie correspondante à un id */ |
antbig | 4:88431b537477 | 202 | /* RETURN : 0=> Erreur, 1=> OK si le fichier existe */ |
antbig | 4:88431b537477 | 203 | /****************************************************************************************/ |
Sitkah | 29:41e02746041d | 204 | /*int SelectStrategy(unsigned char id) |
antbig | 4:88431b537477 | 205 | { |
antbig | 4:88431b537477 | 206 | switch(id) |
antbig | 4:88431b537477 | 207 | { |
ClementBreteau | 15:c2fc239e85df | 208 | // strat de match |
antbig | 4:88431b537477 | 209 | case 1: |
antbig | 11:ed13a480ddca | 210 | strcpy(cheminFileStart,"/local/strat1.txt"); |
antbig | 11:ed13a480ddca | 211 | return FileExists(cheminFileStart); |
antbig | 11:ed13a480ddca | 212 | case 2: |
antbig | 11:ed13a480ddca | 213 | strcpy(cheminFileStart,"/local/strat2.txt"); |
antbig | 11:ed13a480ddca | 214 | return FileExists(cheminFileStart); |
antbig | 11:ed13a480ddca | 215 | case 3: |
antbig | 11:ed13a480ddca | 216 | strcpy(cheminFileStart,"/local/strat3.txt"); |
antbig | 11:ed13a480ddca | 217 | return FileExists(cheminFileStart); |
antbig | 12:14729d584500 | 218 | case 4: |
antbig | 12:14729d584500 | 219 | strcpy(cheminFileStart,"/local/strat4.txt"); |
antbig | 12:14729d584500 | 220 | return FileExists(cheminFileStart); |
antbig | 12:14729d584500 | 221 | case 5: |
antbig | 12:14729d584500 | 222 | strcpy(cheminFileStart,"/local/strat5.txt"); |
antbig | 12:14729d584500 | 223 | return FileExists(cheminFileStart); |
ClementBreteau | 14:c8fc06c4887f | 224 | case 6: |
ClementBreteau | 14:c8fc06c4887f | 225 | strcpy(cheminFileStart,"/local/strat6.txt"); |
ClementBreteau | 14:c8fc06c4887f | 226 | return FileExists(cheminFileStart); |
ClementBreteau | 14:c8fc06c4887f | 227 | case 7: |
ClementBreteau | 14:c8fc06c4887f | 228 | strcpy(cheminFileStart,"/local/strat7.txt"); |
ClementBreteau | 14:c8fc06c4887f | 229 | return FileExists(cheminFileStart); |
ClementBreteau | 14:c8fc06c4887f | 230 | case 8: |
ClementBreteau | 14:c8fc06c4887f | 231 | strcpy(cheminFileStart,"/local/strat8.txt"); |
ClementBreteau | 14:c8fc06c4887f | 232 | return FileExists(cheminFileStart); |
ClementBreteau | 14:c8fc06c4887f | 233 | case 9: |
ClementBreteau | 14:c8fc06c4887f | 234 | strcpy(cheminFileStart,"/local/strat9.txt"); |
ClementBreteau | 14:c8fc06c4887f | 235 | return FileExists(cheminFileStart); |
ClementBreteau | 14:c8fc06c4887f | 236 | case 10: |
ClementBreteau | 14:c8fc06c4887f | 237 | strcpy(cheminFileStart,"/local/strat10.txt"); |
ClementBreteau | 14:c8fc06c4887f | 238 | return FileExists(cheminFileStart); |
ClementBreteau | 14:c8fc06c4887f | 239 | |
ClementBreteau | 15:c2fc239e85df | 240 | // strat de demo |
ClementBreteau | 14:c8fc06c4887f | 241 | case 0x10: |
ClementBreteau | 14:c8fc06c4887f | 242 | strcpy(cheminFileStart,"/local/moteur.txt"); |
ClementBreteau | 14:c8fc06c4887f | 243 | return FileExists(cheminFileStart); |
ClementBreteau | 14:c8fc06c4887f | 244 | case 0x11: |
ClementBreteau | 15:c2fc239e85df | 245 | #ifdef ROBOT_BIG |
ClementBreteau | 15:c2fc239e85df | 246 | strcpy(cheminFileStart,"/local/bras.txt"); |
ClementBreteau | 15:c2fc239e85df | 247 | #else |
ClementBreteau | 15:c2fc239e85df | 248 | strcpy(cheminFileStart,"/local/porteAvant.txt"); |
ClementBreteau | 15:c2fc239e85df | 249 | #endif |
ClementBreteau | 14:c8fc06c4887f | 250 | return FileExists(cheminFileStart); |
ClementBreteau | 15:c2fc239e85df | 251 | case 0x12: |
ClementBreteau | 15:c2fc239e85df | 252 | #ifdef ROBOT_BIG |
ClementBreteau | 15:c2fc239e85df | 253 | strcpy(cheminFileStart,"/local/balancier.txt"); |
ClementBreteau | 15:c2fc239e85df | 254 | #else |
ClementBreteau | 15:c2fc239e85df | 255 | strcpy(cheminFileStart,"/local/mainTourneuse.txt"); |
ClementBreteau | 15:c2fc239e85df | 256 | #endif |
ClementBreteau | 15:c2fc239e85df | 257 | return FileExists(cheminFileStart); |
antbig | 11:ed13a480ddca | 258 | default: |
antbig | 12:14729d584500 | 259 | strcpy(cheminFileStart,"/local/strat1.txt"); |
antbig | 11:ed13a480ddca | 260 | return 0; |
antbig | 4:88431b537477 | 261 | } |
Sitkah | 29:41e02746041d | 262 | }*/ |
antbig | 4:88431b537477 | 263 | |
antbig | 12:14729d584500 | 264 | /****************************************************************************************/ |
antbig | 12:14729d584500 | 265 | /* FUNCTION NAME: needToStop */ |
antbig | 12:14729d584500 | 266 | /* DESCRIPTION : Savoir si il faut autoriser le stop du robot via balise */ |
antbig | 12:14729d584500 | 267 | /****************************************************************************************/ |
antbig | 12:14729d584500 | 268 | unsigned char needToStop(void) |
antbig | 12:14729d584500 | 269 | { |
antbig | 12:14729d584500 | 270 | return isStopEnable; |
antbig | 12:14729d584500 | 271 | } |
antbig | 12:14729d584500 | 272 | |
antbig | 12:14729d584500 | 273 | /****************************************************************************************/ |
antbig | 12:14729d584500 | 274 | /* FUNCTION NAME: doBeforeEndAction */ |
antbig | 12:14729d584500 | 275 | /* DESCRIPTION : Terminer les actions du robot 1s avant la fin du match */ |
antbig | 12:14729d584500 | 276 | /****************************************************************************************/ |
antbig | 12:14729d584500 | 277 | void doBeforeEndAction(void) |
antbig | 12:14729d584500 | 278 | { |
antbig | 12:14729d584500 | 279 | doAction(110,0,0);//Ouverture pince arrière haute |
antbig | 12:14729d584500 | 280 | doAction(112,0,0);//Ouverture pince arrière basse |
antbig | 12:14729d584500 | 281 | doAction(114,0,0);//Ouverture porte arrière |
antbig | 12:14729d584500 | 282 | doAction(100,0,0);//Ouvrir les portes avant |
antbig | 12:14729d584500 | 283 | doAction(102,0,0);//Remonter le peigne |
antbig | 12:14729d584500 | 284 | } |
antbig | 12:14729d584500 | 285 | |
antbig | 3:19f2285a4757 | 286 | #endif |