code petit robot pour homologation

Fork of CRAC-Strat_2017_V2 by CRAC Team

Robots/Strategie_small.cpp

Committer:
antbig
Date:
2016-04-26
Revision:
7:dcce34c7e06e
Parent:
5:dcd817534b57
Child:
9:d0042422d95a

File content as of revision 7:dcce34c7e06e:

#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 {
                AX12_setGoal(AX12_ID_BRAS_BASE,140,0x0FF);
                AX12_processChange();
            }
        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,220,0x0FF);
                AX12_processChange();
            } else {
                AX12_setGoal(AX12_ID_BRAS_BASE,100,0x0FF);
                AX12_processChange();
            }
        break;
        case 103://Lacher les poissons
            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://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 {
                AX12_setGoal(AX12_ID_BRAS_BASE,55,0x0FF);
                AX12_setGoal(AX12_ID_BRAS_RELACHEUR,200);//fermer le bras
                AX12_processChange();
            }
        break;
        case 105:
            //AX12_setGoal(AX12_ID_BRAS_RELACHEUR_INV,160);//fermer le bras
            //AX12_processChange();
        break;
        case 106:
            //AX12_setGoal(AX12_ID_BRAS_RELACHEUR_INV,160);//fermer le bras
            //AX12_processChange();
        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: 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