Strategie_13h30

Fork of CRAC-Strat_2017_homologation_gros_rob by CRAC Team

Robots/Strategie_small.cpp

Committer:
antbig
Date:
2016-04-17
Revision:
4:88431b537477
Parent:
3:19f2285a4757
Child:
5:dcd817534b57

File content as of revision 4:88431b537477:

#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) {
    
    
}

/****************************************************************************************/
/* 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 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 {
                
            }
        break;
        case 102://Remonter bras moiter
            if(InversStrat == 1) {//Si c'est inversé, On utilise le bras coté gauche
                AX12_setGoal(AX12_ID_BRAS_BASE_INV,270,0x0FF);
                AX12_processChange();
            } else {
                
            }
        break;
        case 103://Lacher les poissons
            if(InversStrat == 1) {//Si c'est inversé, On utilise le bras coté gauche
                AX12_setGoal(AX12_ID_BRAS_BASE_INV,210,0x0FF);
                AX12_processChange();
                wait_ms(500);//TODO ajouter une action pour remplacer l'attente bloquante
                AX12_setGoal(AX12_ID_BRAS_RELACHEUR_INV,90);//Ouverture du bras
                AX12_processChange();
            } else {
                
            }
        break;
        case 104://Rentrer le bras
            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 {
                
            }
        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,0x0FF);
    AX12_register(2);
}

/****************************************************************************************/
/* 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);
        default:
            strcpy(cheminFileStart,"/local/strat.txt");
            return 0;
    }
}

#endif