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