Programme carte strategie (disco)
Dependencies: mbed SerialHalfDuplex SDFileSystem DISCO-F469NI_portrait liaison_Bluetooth ident_crac
Robots/Strategie_small.cpp
- Committer:
- Sitkah
- Date:
- 2018-05-09
- Revision:
- 38:76f886a1c8e6
- Parent:
- 36:6dd30780bd8e
- Child:
- 42:657b6a573e11
File content as of revision 38:76f886a1c8e6:
#include "global.h" #ifdef ROBOT_SMALL unsigned char isStopEnable = 1;//Permet de savoir si il faut autoriser le stop via les balises //unsigned short telemetreDistance; /****************************************************************************************/ /* FUNCTION NAME: doFunnyAction */ /* DESCRIPTION : Permet de faire la funny action en fin de partie */ /****************************************************************************************/ void doFunnyAction(void) { } /****************************************************************************************/ /* FUNCTION NAME: doAction */ /* DESCRIPTION : Effectuer une action specifique */ /****************************************************************************************/ unsigned char doAction(unsigned char id, unsigned short arg1, short arg2) { int retour = 1; CANMessage msgTx=CANMessage(); msgTx.format=CANStandard; msgTx.type=CANData; switch(id) { case 101: //baisser attrape bloc avant SendRawId(BAISSER_ATTRAPE_BLOC); break; case 102: //Relever attrape bloc avant SendRawId(RELEVER_ATTRAPE_BLOC); break; case 115: //allumer panneau SendRawId(ALLUMER_PANNEAU_UP); break; case 116: //range le bras qui allume le panneau SendRawId(ALLUMER_PANNEAU_DOWN); break; case 117: //lève le bras pour pousser l'abeille SendRawId(BRAS_ABEILLE_UP); break; case 118: //abaisse le bras qui pousse l'abeille SendRawId(BRAS_ABEILLE_DOWN); break; case 130: //Inclinaison pour viser le chateau d'eau SendRawId(INCLINAISON_CHATEAU); break; case 131: //inclinaison pour deverser les balles sales SendRawId(INCLINAISON_EPURATION); break; case 132: //blocage des balles SendRawId(BLOCAGE_BALLE); break; case 133: //lance le pwm de tir msgTx.id=LANCEMENT_MOTEUR_TIR_ON; msgTx.len=1; msgTx.data[0]=arg1; can2.write(msgTx); break; case 134: ///Arrete le pwm de tir SendRawId(LANCEMENT_MOTEUR_TIR_OFF); break; case 135://position aiguilleur au centre SendRawId(AIGUILLEUR_CENTRE); break; case 136://position aiguilleur à gauche SendRawId(AIGUILLEUR_GAUCHE); break; case 137://position aiguilleur à droite SendRawId(AIGUILLEUR_DROITE); break; case 138://position aiguilleur au centre SendRawId(TRI_BALLE); break; case 139: SendRawId(VIBRO); break; case 150: SCORE_PR+=arg1; liaison_Tx.envoyer_short(0x30,SCORE_PR); waitingAckFrom = 0; waitingAckID = 0; break; case 200 : SendRawId(DATA_TELEMETRE); /*telemetreDistance = dataTelemetre(); wait_ms(1); telemetreDistance = dataTelemetre(); telemetreDistance = telemetreDistance - 170;*/ break; case 201 : SendRawId(0x99); retour = 2; break; case 10://Désactiver le stop isStopEnable = 0; break; case 11://Activer le stop isStopEnable = 1; break; case 20://Désactiver l'asservissement setAsservissementEtat(0); break; case 21://Activer l'asservissement setAsservissementEtat(1); break; case 22://Changer la vitesse du robot SendSpeed(arg1,(unsigned short)arg2); wait_us(200); waitingAckFrom = 0; waitingAckID = 0; break; case 19: // CHANGER LA VITESSE + DECELERATION SendSpeedDecel(arg1,(unsigned short) arg2); wait_us(200); waitingAckFrom = 0; waitingAckID =0; break; case 30://Action tempo wait_ms(arg1); break; default: retour = 0;//L'action n'existe pas, il faut utiliser le CAN } return retour;//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);*/ //runRobotTest(); /* 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();*/ //initialisation_AX12(); //} /****************************************************************************************/ /* FUNCTION NAME: initRobotActionneur */ /* DESCRIPTION : Initialiser la position des actionneurs du robot */ /****************************************************************************************/ /*void initRobotActionneur(void) { moteurGauchePWM(0); moteurDroitPWM(0); AX12_automate(AX12_PINCE_CENTRALE_POSITION_INITIALE); AX12_automate(AX12_GAUCHE_CROC_INITIALE); AX12_automate(AX12_DROIT_CROC_INITIALE); AX12_automate(AX12_TOURNANTE_GAUCHE_POSITION_INITIALE); AX12_automate(AX12_TOURNANTE_DROIT_POSITION_INITIALE); } */ /****************************************************************************************/ /* 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,"/sd/strat1.txt"); return FileExists(cheminFileStart); case 2: strcpy(cheminFileStart,"/sd/strat2.txt"); return FileExists(cheminFileStart); case 3: strcpy(cheminFileStart,"/sd/strat3.txt"); return FileExists(cheminFileStart); case 4: strcpy(cheminFileStart,"/sd/strat4.txt"); return FileExists(cheminFileStart); case 5: strcpy(cheminFileStart,"/sd/strat5.txt"); return FileExists(cheminFileStart); case 6: strcpy(cheminFileStart,"/sd/strat6.txt"); return FileExists(cheminFileStart); case 7: strcpy(cheminFileStart,"/sd/strat7.txt"); return FileExists(cheminFileStart); case 8: strcpy(cheminFileStart,"/sd/strat8.txt"); return FileExists(cheminFileStart); case 9: strcpy(cheminFileStart,"/sd/strat9.txt"); return FileExists(cheminFileStart); case 10: strcpy(cheminFileStart,"/sd/strat10.txt"); return FileExists(cheminFileStart); case 11: strcpy(cheminFileStart,"/sd/grand_8.txt"); return FileExists(cheminFileStart); case 0x10: strcpy(cheminFileStart,"/sd/demoBras.txt"); return FileExists(cheminFileStart); default: strcpy(cheminFileStart,"/sd/strat1.txt"); SendRawId(0x258); return 0; } } /****************************************************************************************/ /* FUNCTION NAME: needToStop */ /* DESCRIPTION : Savoir si il faut autoriser le stop du robot via balise */ /****************************************************************************************/ unsigned char needToStop(void) { return isStopEnable; } /****************************************************************************************/ /* FUNCTION NAME: doBeforeEndAction */ /* DESCRIPTION : Terminer les actions du robot 1s avant la fin du match */ /****************************************************************************************/ void doBeforeEndAction(void) { } #endif