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 SerialHalfDuplex SDFileSystem DISCO-F469NI_portrait liaison_Bluetooth ident_crac
Robots/Strategie_small.cpp@36:6dd30780bd8e, 2018-05-02 (annotated)
- Committer:
- Sitkah
- Date:
- Wed May 02 20:40:57 2018 +0000
- Revision:
- 36:6dd30780bd8e
- Parent:
- 34:6aa4b46b102e
- Child:
- 38:76f886a1c8e6
Recalage en une fois
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Sitkah | 29:41e02746041d | 1 | #include "global.h" |
antbig | 3:19f2285a4757 | 2 | #ifdef ROBOT_SMALL |
Sitkah | 29:41e02746041d | 3 | |
antbig | 3:19f2285a4757 | 4 | |
antbig | 12:14729d584500 | 5 | unsigned char isStopEnable = 1;//Permet de savoir si il faut autoriser le stop via les balises |
ClementBreteau | 21:590cdacb6a35 | 6 | //unsigned short telemetreDistance; |
ClementBreteau | 18:cc5fec34ed9c | 7 | |
antbig | 12:14729d584500 | 8 | |
antbig | 3:19f2285a4757 | 9 | /****************************************************************************************/ |
antbig | 3:19f2285a4757 | 10 | /* FUNCTION NAME: doFunnyAction */ |
antbig | 3:19f2285a4757 | 11 | /* DESCRIPTION : Permet de faire la funny action en fin de partie */ |
antbig | 3:19f2285a4757 | 12 | /****************************************************************************************/ |
antbig | 3:19f2285a4757 | 13 | void doFunnyAction(void) { |
antbig | 3:19f2285a4757 | 14 | |
antbig | 3:19f2285a4757 | 15 | |
antbig | 3:19f2285a4757 | 16 | } |
antbig | 3:19f2285a4757 | 17 | |
ClementBreteau | 18:cc5fec34ed9c | 18 | |
antbig | 3:19f2285a4757 | 19 | /****************************************************************************************/ |
antbig | 3:19f2285a4757 | 20 | /* FUNCTION NAME: doAction */ |
antbig | 3:19f2285a4757 | 21 | /* DESCRIPTION : Effectuer une action specifique */ |
antbig | 3:19f2285a4757 | 22 | /****************************************************************************************/ |
Sitkah | 34:6aa4b46b102e | 23 | unsigned char doAction(unsigned char id, unsigned short arg1, short arg2) { |
ClementBreteau | 18:cc5fec34ed9c | 24 | int retour = 1; |
Sitkah | 34:6aa4b46b102e | 25 | CANMessage msgTx=CANMessage(); |
Sitkah | 34:6aa4b46b102e | 26 | msgTx.format=CANStandard; |
Sitkah | 34:6aa4b46b102e | 27 | msgTx.type=CANData; |
antbig | 3:19f2285a4757 | 28 | switch(id) { |
Sitkah | 30:a1e37af4bbde | 29 | case 101: //baisser attrape bloc avant |
Sitkah | 30:a1e37af4bbde | 30 | SendRawId(BAISSER_ATTRAPE_BLOC); |
Sitkah | 30:a1e37af4bbde | 31 | break; |
Sitkah | 30:a1e37af4bbde | 32 | case 102: //Relever attrape bloc avant |
Sitkah | 30:a1e37af4bbde | 33 | SendRawId(RELEVER_ATTRAPE_BLOC); |
Sitkah | 30:a1e37af4bbde | 34 | break; |
Sitkah | 30:a1e37af4bbde | 35 | case 115: //allumer panneau |
Sitkah | 30:a1e37af4bbde | 36 | SendRawId(ALLUMER_PANNEAU_UP); |
Sitkah | 30:a1e37af4bbde | 37 | break; |
Sitkah | 30:a1e37af4bbde | 38 | case 116: //range le bras qui allume le panneau |
Sitkah | 30:a1e37af4bbde | 39 | SendRawId(ALLUMER_PANNEAU_DOWN); |
Sitkah | 30:a1e37af4bbde | 40 | break; |
Sitkah | 30:a1e37af4bbde | 41 | case 117: //lève le bras pour pousser l'abeille |
Sitkah | 30:a1e37af4bbde | 42 | SendRawId(BRAS_ABEILLE_UP); |
Sitkah | 30:a1e37af4bbde | 43 | break; |
Sitkah | 30:a1e37af4bbde | 44 | case 118: //abaisse le bras qui pousse l'abeille |
Sitkah | 30:a1e37af4bbde | 45 | SendRawId(BRAS_ABEILLE_DOWN); |
Sitkah | 30:a1e37af4bbde | 46 | break; |
Sitkah | 30:a1e37af4bbde | 47 | case 130: //Inclinaison pour viser le chateau d'eau |
Sitkah | 30:a1e37af4bbde | 48 | SendRawId(INCLINAISON_CHATEAU); |
Sitkah | 30:a1e37af4bbde | 49 | break; |
Sitkah | 30:a1e37af4bbde | 50 | case 131: //inclinaison pour deverser les balles sales |
Sitkah | 30:a1e37af4bbde | 51 | SendRawId(INCLINAISON_EPURATION); |
Sitkah | 30:a1e37af4bbde | 52 | break; |
Sitkah | 30:a1e37af4bbde | 53 | case 132: //blocage des balles |
Sitkah | 30:a1e37af4bbde | 54 | SendRawId(BLOCAGE_BALLE); |
Sitkah | 30:a1e37af4bbde | 55 | break; |
Sitkah | 30:a1e37af4bbde | 56 | case 133: //lance le pwm de tir |
Sitkah | 34:6aa4b46b102e | 57 | msgTx.id=LANCEMENT_MOTEUR_TIR_ON; |
Sitkah | 34:6aa4b46b102e | 58 | |
Sitkah | 34:6aa4b46b102e | 59 | msgTx.len=1; |
Sitkah | 34:6aa4b46b102e | 60 | msgTx.data[0]=arg1; |
Sitkah | 34:6aa4b46b102e | 61 | can2.write(msgTx); |
Sitkah | 30:a1e37af4bbde | 62 | break; |
Sitkah | 30:a1e37af4bbde | 63 | case 134: ///Arrete le pwm de tir |
Sitkah | 30:a1e37af4bbde | 64 | SendRawId(LANCEMENT_MOTEUR_TIR_OFF); |
Sitkah | 30:a1e37af4bbde | 65 | break; |
Sitkah | 30:a1e37af4bbde | 66 | case 135://position aiguilleur au centre |
Sitkah | 30:a1e37af4bbde | 67 | SendRawId(AIGUILLEUR_CENTRE); |
Sitkah | 30:a1e37af4bbde | 68 | break; |
Sitkah | 30:a1e37af4bbde | 69 | case 136://position aiguilleur à gauche |
Sitkah | 30:a1e37af4bbde | 70 | SendRawId(AIGUILLEUR_GAUCHE); |
Sitkah | 30:a1e37af4bbde | 71 | break; |
Sitkah | 30:a1e37af4bbde | 72 | case 137://position aiguilleur à droite |
Sitkah | 30:a1e37af4bbde | 73 | SendRawId(AIGUILLEUR_DROITE); |
Sitkah | 30:a1e37af4bbde | 74 | break; |
Sitkah | 30:a1e37af4bbde | 75 | case 138://position aiguilleur au centre |
Sitkah | 30:a1e37af4bbde | 76 | SendRawId(TRI_BALLE); |
Sitkah | 30:a1e37af4bbde | 77 | break; |
Sitkah | 34:6aa4b46b102e | 78 | case 139: |
Sitkah | 34:6aa4b46b102e | 79 | SendRawId(VIBRO); |
Sitkah | 34:6aa4b46b102e | 80 | break; |
Sitkah | 34:6aa4b46b102e | 81 | |
ClementBreteau | 18:cc5fec34ed9c | 82 | |
ClementBreteau | 16:7321fb3bb396 | 83 | |
ClementBreteau | 18:cc5fec34ed9c | 84 | case 200 : |
Sitkah | 30:a1e37af4bbde | 85 | SendRawId(DATA_TELEMETRE); |
Sitkah | 30:a1e37af4bbde | 86 | /*telemetreDistance = dataTelemetre(); |
ClementBreteau | 18:cc5fec34ed9c | 87 | wait_ms(1); |
ClementBreteau | 18:cc5fec34ed9c | 88 | telemetreDistance = dataTelemetre(); |
Sitkah | 30:a1e37af4bbde | 89 | telemetreDistance = telemetreDistance - 170;*/ |
ClementBreteau | 18:cc5fec34ed9c | 90 | break; |
ClementBreteau | 18:cc5fec34ed9c | 91 | |
ClementBreteau | 18:cc5fec34ed9c | 92 | case 201 : |
Sitkah | 30:a1e37af4bbde | 93 | SendRawId(0x99); |
ClementBreteau | 18:cc5fec34ed9c | 94 | retour = 2; |
antbig | 10:a788d9cf60f2 | 95 | break; |
ClementBreteau | 15:c2fc239e85df | 96 | |
antbig | 12:14729d584500 | 97 | case 10://Désactiver le stop |
antbig | 12:14729d584500 | 98 | isStopEnable = 0; |
antbig | 12:14729d584500 | 99 | break; |
antbig | 12:14729d584500 | 100 | case 11://Activer le stop |
antbig | 12:14729d584500 | 101 | isStopEnable = 1; |
antbig | 12:14729d584500 | 102 | break; |
antbig | 12:14729d584500 | 103 | case 20://Désactiver l'asservissement |
antbig | 12:14729d584500 | 104 | setAsservissementEtat(0); |
antbig | 12:14729d584500 | 105 | break; |
antbig | 12:14729d584500 | 106 | case 21://Activer l'asservissement |
antbig | 12:14729d584500 | 107 | setAsservissementEtat(1); |
ClementBreteau | 16:7321fb3bb396 | 108 | break; |
ClementBreteau | 16:7321fb3bb396 | 109 | |
Sitkah | 34:6aa4b46b102e | 110 | case 22://Changer la vitesse du robot |
Sitkah | 34:6aa4b46b102e | 111 | SendSpeed(arg1,(unsigned short)arg2); |
ClementBreteau | 18:cc5fec34ed9c | 112 | wait_us(200); |
antbig | 28:acd18776ed2d | 113 | waitingAckFrom = 0; |
antbig | 28:acd18776ed2d | 114 | waitingAckID = 0; |
antbig | 28:acd18776ed2d | 115 | break; |
antbig | 28:acd18776ed2d | 116 | |
antbig | 28:acd18776ed2d | 117 | case 19: // CHANGER LA VITESSE + DECELERATION |
Sitkah | 34:6aa4b46b102e | 118 | SendSpeedDecel(arg1,(unsigned short) arg2); |
antbig | 28:acd18776ed2d | 119 | wait_us(200); |
antbig | 28:acd18776ed2d | 120 | waitingAckFrom = 0; |
antbig | 28:acd18776ed2d | 121 | waitingAckID =0; |
ClementBreteau | 16:7321fb3bb396 | 122 | break; |
ClementBreteau | 16:7321fb3bb396 | 123 | |
ClementBreteau | 16:7321fb3bb396 | 124 | case 30://Action tempo |
Sitkah | 34:6aa4b46b102e | 125 | wait_ms(arg1); |
antbig | 12:14729d584500 | 126 | break; |
Sitkah | 34:6aa4b46b102e | 127 | |
antbig | 3:19f2285a4757 | 128 | default: |
ClementBreteau | 18:cc5fec34ed9c | 129 | retour = 0;//L'action n'existe pas, il faut utiliser le CAN |
antbig | 3:19f2285a4757 | 130 | |
antbig | 3:19f2285a4757 | 131 | } |
ClementBreteau | 18:cc5fec34ed9c | 132 | return retour;//L'action est spécifique. |
antbig | 3:19f2285a4757 | 133 | |
antbig | 3:19f2285a4757 | 134 | } |
antbig | 3:19f2285a4757 | 135 | |
antbig | 3:19f2285a4757 | 136 | /****************************************************************************************/ |
antbig | 3:19f2285a4757 | 137 | /* FUNCTION NAME: initRobot */ |
antbig | 3:19f2285a4757 | 138 | /* DESCRIPTION : initialiser le robot */ |
antbig | 3:19f2285a4757 | 139 | /****************************************************************************************/ |
Sitkah | 30:a1e37af4bbde | 140 | //void initRobot(void) { |
antbig | 3:19f2285a4757 | 141 | /** |
antbig | 3:19f2285a4757 | 142 | On enregistre les id des AX12 présent sur la carte |
antbig | 3:19f2285a4757 | 143 | **/ |
ClementBreteau | 15:c2fc239e85df | 144 | /*AX12_register(1,AX12_SERIAL1,0x0FF); |
antbig | 5:dcd817534b57 | 145 | AX12_register(2,AX12_SERIAL1); |
antbig | 5:dcd817534b57 | 146 | AX12_register(18,AX12_SERIAL1); |
antbig | 5:dcd817534b57 | 147 | AX12_register(4,AX12_SERIAL2); |
antbig | 5:dcd817534b57 | 148 | AX12_register(16,AX12_SERIAL2); |
ClementBreteau | 15:c2fc239e85df | 149 | AX12_register(17,AX12_SERIAL2,0x0FF);*/ |
antbig | 12:14729d584500 | 150 | |
antbig | 12:14729d584500 | 151 | //runRobotTest(); |
antbig | 12:14729d584500 | 152 | |
antbig | 5:dcd817534b57 | 153 | /* |
antbig | 5:dcd817534b57 | 154 | AX12_setGoal(AX12_ID_BRAS_BASE_INV,278,0x0FF); |
antbig | 5:dcd817534b57 | 155 | AX12_setGoal(AX12_ID_BRAS_RELACHEUR_INV,160);//fermer le bras |
antbig | 5:dcd817534b57 | 156 | AX12_setGoal(AX12_ID_BRAS_BASE,278,0x0FF); |
antbig | 5:dcd817534b57 | 157 | AX12_setGoal(AX12_ID_BRAS_RELACHEUR,160);//fermer le bras |
antbig | 5:dcd817534b57 | 158 | AX12_processChange();*/ |
ClementBreteau | 16:7321fb3bb396 | 159 | |
Sitkah | 30:a1e37af4bbde | 160 | //initialisation_AX12(); |
ClementBreteau | 18:cc5fec34ed9c | 161 | |
Sitkah | 30:a1e37af4bbde | 162 | //} |
antbig | 3:19f2285a4757 | 163 | |
antbig | 4:88431b537477 | 164 | /****************************************************************************************/ |
antbig | 12:14729d584500 | 165 | /* FUNCTION NAME: initRobotActionneur */ |
antbig | 12:14729d584500 | 166 | /* DESCRIPTION : Initialiser la position des actionneurs du robot */ |
antbig | 12:14729d584500 | 167 | /****************************************************************************************/ |
Sitkah | 30:a1e37af4bbde | 168 | /*void initRobotActionneur(void) |
antbig | 12:14729d584500 | 169 | { |
ClementBreteau | 18:cc5fec34ed9c | 170 | moteurGauchePWM(0); |
ClementBreteau | 18:cc5fec34ed9c | 171 | moteurDroitPWM(0); |
ClementBreteau | 18:cc5fec34ed9c | 172 | AX12_automate(AX12_PINCE_CENTRALE_POSITION_INITIALE); |
ClementBreteau | 18:cc5fec34ed9c | 173 | AX12_automate(AX12_GAUCHE_CROC_INITIALE); |
ClementBreteau | 18:cc5fec34ed9c | 174 | AX12_automate(AX12_DROIT_CROC_INITIALE); |
ClementBreteau | 18:cc5fec34ed9c | 175 | AX12_automate(AX12_TOURNANTE_GAUCHE_POSITION_INITIALE); |
ClementBreteau | 18:cc5fec34ed9c | 176 | AX12_automate(AX12_TOURNANTE_DROIT_POSITION_INITIALE); |
antbig | 12:14729d584500 | 177 | } |
Sitkah | 30:a1e37af4bbde | 178 | */ |
antbig | 12:14729d584500 | 179 | /****************************************************************************************/ |
antbig | 9:d0042422d95a | 180 | /* FUNCTION NAME: runTest */ |
antbig | 9:d0042422d95a | 181 | /* DESCRIPTION : tester l'ensemble des actionneurs du robot */ |
antbig | 9:d0042422d95a | 182 | /****************************************************************************************/ |
antbig | 9:d0042422d95a | 183 | void runRobotTest(void) |
antbig | 9:d0042422d95a | 184 | { |
ClementBreteau | 18:cc5fec34ed9c | 185 | |
antbig | 9:d0042422d95a | 186 | } |
antbig | 9:d0042422d95a | 187 | |
antbig | 9:d0042422d95a | 188 | /****************************************************************************************/ |
antbig | 4:88431b537477 | 189 | /* FUNCTION NAME: SelectStrategy */ |
antbig | 4:88431b537477 | 190 | /* DESCRIPTION : Charger le fichier de stratégie correspondante à un id */ |
antbig | 4:88431b537477 | 191 | /* RETURN : 0=> Erreur, 1=> OK si le fichier existe */ |
antbig | 4:88431b537477 | 192 | /****************************************************************************************/ |
antbig | 4:88431b537477 | 193 | int SelectStrategy(unsigned char id) |
antbig | 4:88431b537477 | 194 | { |
antbig | 12:14729d584500 | 195 | |
antbig | 4:88431b537477 | 196 | switch(id) |
antbig | 4:88431b537477 | 197 | { |
antbig | 4:88431b537477 | 198 | case 1: |
Sitkah | 29:41e02746041d | 199 | strcpy(cheminFileStart,"/sd/strat1.txt"); |
antbig | 4:88431b537477 | 200 | return FileExists(cheminFileStart); |
antbig | 4:88431b537477 | 201 | case 2: |
Sitkah | 29:41e02746041d | 202 | strcpy(cheminFileStart,"/sd/strat2.txt"); |
antbig | 4:88431b537477 | 203 | return FileExists(cheminFileStart); |
antbig | 7:dcce34c7e06e | 204 | case 3: |
Sitkah | 29:41e02746041d | 205 | strcpy(cheminFileStart,"/sd/strat3.txt"); |
antbig | 7:dcce34c7e06e | 206 | return FileExists(cheminFileStart); |
antbig | 11:ed13a480ddca | 207 | case 4: |
Sitkah | 29:41e02746041d | 208 | strcpy(cheminFileStart,"/sd/strat4.txt"); |
antbig | 11:ed13a480ddca | 209 | return FileExists(cheminFileStart); |
antbig | 11:ed13a480ddca | 210 | case 5: |
Sitkah | 29:41e02746041d | 211 | strcpy(cheminFileStart,"/sd/strat5.txt"); |
antbig | 11:ed13a480ddca | 212 | return FileExists(cheminFileStart); |
antbig | 12:14729d584500 | 213 | case 6: |
Sitkah | 29:41e02746041d | 214 | strcpy(cheminFileStart,"/sd/strat6.txt"); |
antbig | 12:14729d584500 | 215 | return FileExists(cheminFileStart); |
ClementBreteau | 16:7321fb3bb396 | 216 | case 7: |
Sitkah | 29:41e02746041d | 217 | strcpy(cheminFileStart,"/sd/strat7.txt"); |
ClementBreteau | 16:7321fb3bb396 | 218 | return FileExists(cheminFileStart); |
ClementBreteau | 16:7321fb3bb396 | 219 | case 8: |
Sitkah | 29:41e02746041d | 220 | strcpy(cheminFileStart,"/sd/strat8.txt"); |
ClementBreteau | 16:7321fb3bb396 | 221 | return FileExists(cheminFileStart); |
ClementBreteau | 16:7321fb3bb396 | 222 | case 9: |
Sitkah | 29:41e02746041d | 223 | strcpy(cheminFileStart,"/sd/strat9.txt"); |
ClementBreteau | 16:7321fb3bb396 | 224 | return FileExists(cheminFileStart); |
antbig | 12:14729d584500 | 225 | case 10: |
Sitkah | 29:41e02746041d | 226 | strcpy(cheminFileStart,"/sd/strat10.txt"); |
ClementBreteau | 16:7321fb3bb396 | 227 | return FileExists(cheminFileStart); |
ClementBreteau | 16:7321fb3bb396 | 228 | case 11: |
Sitkah | 29:41e02746041d | 229 | strcpy(cheminFileStart,"/sd/grand_8.txt"); |
antbig | 12:14729d584500 | 230 | return FileExists(cheminFileStart); |
ClementBreteau | 16:7321fb3bb396 | 231 | |
ClementBreteau | 16:7321fb3bb396 | 232 | case 0x10: |
Sitkah | 29:41e02746041d | 233 | strcpy(cheminFileStart,"/sd/demoBras.txt"); |
ClementBreteau | 16:7321fb3bb396 | 234 | return FileExists(cheminFileStart); |
ClementBreteau | 16:7321fb3bb396 | 235 | |
antbig | 4:88431b537477 | 236 | default: |
Sitkah | 29:41e02746041d | 237 | strcpy(cheminFileStart,"/sd/strat1.txt"); |
ClementBreteau | 16:7321fb3bb396 | 238 | SendRawId(0x258); |
antbig | 4:88431b537477 | 239 | return 0; |
antbig | 4:88431b537477 | 240 | } |
antbig | 4:88431b537477 | 241 | } |
antbig | 4:88431b537477 | 242 | |
antbig | 12:14729d584500 | 243 | /****************************************************************************************/ |
antbig | 12:14729d584500 | 244 | /* FUNCTION NAME: needToStop */ |
antbig | 12:14729d584500 | 245 | /* DESCRIPTION : Savoir si il faut autoriser le stop du robot via balise */ |
antbig | 12:14729d584500 | 246 | /****************************************************************************************/ |
antbig | 12:14729d584500 | 247 | unsigned char needToStop(void) |
antbig | 12:14729d584500 | 248 | { |
antbig | 12:14729d584500 | 249 | return isStopEnable; |
antbig | 12:14729d584500 | 250 | } |
antbig | 12:14729d584500 | 251 | |
antbig | 12:14729d584500 | 252 | /****************************************************************************************/ |
antbig | 12:14729d584500 | 253 | /* FUNCTION NAME: doBeforeEndAction */ |
antbig | 12:14729d584500 | 254 | /* DESCRIPTION : Terminer les actions du robot 1s avant la fin du match */ |
antbig | 12:14729d584500 | 255 | /****************************************************************************************/ |
antbig | 12:14729d584500 | 256 | void doBeforeEndAction(void) |
antbig | 12:14729d584500 | 257 | { |
antbig | 12:14729d584500 | 258 | |
antbig | 12:14729d584500 | 259 | } |
antbig | 12:14729d584500 | 260 | |
antbig | 3:19f2285a4757 | 261 | #endif |