code strat avant match 2, strat inversée OK normalement
Fork of CRAC-Strat_2017_fin_premier_match by
Robots/Strategie_small.cpp
- Committer:
- antbig
- Date:
- 2016-04-29
- Revision:
- 10:a788d9cf60f2
- Parent:
- 9:d0042422d95a
- Child:
- 11:ed13a480ddca
File content as of revision 10:a788d9cf60f2:
#include "StrategieManager.h" #ifdef ROBOT_SMALL #include "Config_small.h" /****************************************************************************************/ /* FUNCTION NAME: doFunnyAction */ /* DESCRIPTION : Permet de faire la funny action en fin de partie */ /****************************************************************************************/ void doFunnyAction(void) { } //L'angle est entre 0 et 1023 void XL320_setGoal(unsigned char id, unsigned short angle); void XL320_setGoal(unsigned char id, unsigned short angle) { CANMessage msgTx=CANMessage(); msgTx.id=SERVO_XL320; msgTx.len=3; msgTx.format=CANStandard; msgTx.type=CANData; msgTx.data[0]=(unsigned char)id; // from sur 2 octets msgTx.data[1]=(unsigned char)angle; msgTx.data[2]=(unsigned char)(angle>>8); can1.write(msgTx); } /****************************************************************************************/ /* FUNCTION NAME: doAction */ /* DESCRIPTION : Effectuer une action specifique */ /****************************************************************************************/ unsigned char doAction(unsigned char id, unsigned short speed, short angle) { switch(id) { case 101://Descendre le bras pour pecher les poissons if(InversStrat == 1) {//Si c'est inversé, On utilise le bras coté gauche AX12_setGoal(AX12_ID_BRAS_BASE_INV,200,0x0FF); AX12_processChange(); } else { AX12_setGoal(AX12_ID_BRAS_BASE,140,0x0FF); AX12_processChange(); } break; case 102://Remonter le bras avec les poissons dessus if(InversStrat == 1) {//Si c'est inversé, On utilise le bras coté gauche AX12_setGoal(AX12_ID_BRAS_BASE_INV,220,0x0FF); AX12_processChange(); } else { AX12_setGoal(AX12_ID_BRAS_BASE,100,0x0FF); AX12_processChange(); } break; case 103://Decendre à 30° if(InversStrat == 1) {//Si c'est inversé, On utilise le bras coté gauche AX12_setGoal(AX12_ID_BRAS_RELACHEUR_INV,90);//Ouverture du bras AX12_processChange(); } else { AX12_setGoal(AX12_ID_BRAS_RELACHEUR,250);//Ouverture du bras AX12_processChange(); } break; case 104://ouvrir séparateur if(InversStrat == 1) {//Si c'est inversé, On utilise le bras coté gauche AX12_setGoal(AX12_ID_BRAS_BASE_INV,278,0x0FF); AX12_setGoal(AX12_ID_BRAS_RELACHEUR_INV,160);//fermer le bras AX12_processChange(); } else { AX12_setGoal(AX12_ID_BRAS_BASE,55,0x0FF); AX12_setGoal(AX12_ID_BRAS_RELACHEUR,200);//fermer le bras AX12_processChange(); } break; case 105://Rentrer le bras dans le robot, fermer le séparateur //AX12_setGoal(AX12_ID_BRAS_RELACHEUR_INV,160);//fermer le bras //AX12_processChange(); break; case 106://descendre l'atrape coquillages gauche si non inversé, droit si inversé //AX12_setGoal(AX12_ID_BRAS_RELACHEUR_INV,160);//fermer le bras //AX12_processChange(); break; case 200://ouvir la pince gauche XL320_setGoal(XL320_ID_PINCE_GAUCHE, 350); break; case 205://Sécuriser le palet gauche XL320_setGoal(XL320_ID_PINCE_GAUCHE, 400); break; case 202://fermer pince gauche XL320_setGoal(XL320_ID_PINCE_GAUCHE, 650); break; case 201://ouvir la pince droite XL320_setGoal(XL320_ID_PINCE_DROITE, 400); break; case 204://Sécuriser le palet droit XL320_setGoal(XL320_ID_PINCE_DROITE, 300); break; case 203://fermer pince droite XL320_setGoal(XL320_ID_PINCE_DROITE, 70); break; default: return 0;//L'action n'existe pas, il faut utiliser le CAN } //return 1;//L'action est spécifique. } /****************************************************************************************/ /* FUNCTION NAME: initRobot */ /* DESCRIPTION : initialiser le robot */ /****************************************************************************************/ void initRobot(void) { /** On enregistre les id des AX12 présent sur la carte **/ AX12_register(1,AX12_SERIAL1,0x0FF); AX12_register(2,AX12_SERIAL1); AX12_register(18,AX12_SERIAL1); AX12_register(4,AX12_SERIAL2); AX12_register(16,AX12_SERIAL2); AX12_register(17,AX12_SERIAL2,0x0FF); /* AX12_setGoal(AX12_ID_BRAS_BASE_INV,278,0x0FF); AX12_setGoal(AX12_ID_BRAS_RELACHEUR_INV,160);//fermer le bras AX12_setGoal(AX12_ID_BRAS_BASE,278,0x0FF); AX12_setGoal(AX12_ID_BRAS_RELACHEUR,160);//fermer le bras AX12_processChange();*/ } /****************************************************************************************/ /* FUNCTION NAME: runTest */ /* DESCRIPTION : tester l'ensemble des actionneurs du robot */ /****************************************************************************************/ void runRobotTest(void) { } /****************************************************************************************/ /* FUNCTION NAME: SelectStrategy */ /* DESCRIPTION : Charger le fichier de stratégie correspondante à un id */ /* RETURN : 0=> Erreur, 1=> OK si le fichier existe */ /****************************************************************************************/ int SelectStrategy(unsigned char id) { switch(id) { case 1: strcpy(cheminFileStart,"/local/strat1.txt"); return FileExists(cheminFileStart); case 2: strcpy(cheminFileStart,"/local/strat2.txt"); return FileExists(cheminFileStart); case 3: strcpy(cheminFileStart,"/local/strat3.txt"); return FileExists(cheminFileStart); default: strcpy(cheminFileStart,"/local/strat.txt"); return 0; } } #endif