v2019

Dependencies:   CRAC-Strat_2019 SerialHalfDuplex SDFileSystem DISCO-F469NI_portrait liaison_Bluetooth ident_crac

Dependents:   Codeprincipal_2019 CRAC-Strat_2019

Robots/Strategie_big.cpp

Committer:
antbig
Date:
2016-05-02
Revision:
11:ed13a480ddca
Parent:
9:d0042422d95a
Child:
12:14729d584500

File content as of revision 11:ed13a480ddca:

#include "StrategieManager.h"
#ifdef ROBOT_BIG
#include "Config_big.h"

/****************************************************************************************/
/* FUNCTION NAME: doFunnyAction                                                         */
/* DESCRIPTION  : Permet de faire la funny action en fin de partie                      */
/****************************************************************************************/
void doFunnyAction(void) {
    AX12_setGoal(AX12_ID_FUNNY_ACTION, 275);
    AX12_setGoal(AX12_ID_FUNNY_ACTION, 180);
    AX12_processChange();
    
}

/****************************************************************************************/
/* FUNCTION NAME: doAction                                                              */
/* DESCRIPTION  : Effectuer une action specifique                                       */
/****************************************************************************************/
unsigned char doAction(unsigned char id, unsigned short speed, short angle) {
    switch(id) {
        
        case 110://Ouvrir la pince arrière haute
            AX12_setGoal(AX12_ID_PINCE_ARRIERE_HAUTE_GAUCHE, 205);
            AX12_setGoal(AX12_ID_PINCE_ARRIERE_HAUTE_DROITE, 95);
            AX12_processChange();
        break;
        case 111://Fermer la pince arrière haute
            AX12_setGoal(AX12_ID_PINCE_ARRIERE_HAUTE_GAUCHE, 145);
            AX12_setGoal(AX12_ID_PINCE_ARRIERE_HAUTE_DROITE, 155);
            AX12_processChange();
        break;
        
        case 112://Ouvrir la pince arrière basse
            AX12_setGoal(AX12_ID_PINCE_ARRIERE_BASSE_GAUCHE, 205);
            AX12_setGoal(AX12_ID_PINCE_ARRIERE_BASSE_DROITE, 95);
            AX12_processChange();
        break;
        case 113://Fermer la pince arrière basse
            AX12_setGoal(AX12_ID_PINCE_ARRIERE_BASSE_GAUCHE, 145);
            AX12_setGoal(AX12_ID_PINCE_ARRIERE_BASSE_DROITE, 155);
            AX12_processChange();
        break;
        
        case 114://Ouvrir les portes arrières
            AX12_setGoal(AX12_ID_PORTE_ARRIERE_GAUCHE, 250);
            AX12_setGoal(AX12_ID_PORTE_ARRIERE_DROITE, 50);
            AX12_processChange();
        break;
        case 115://Fermer les portes arrière
            AX12_setGoal(AX12_ID_PORTE_ARRIERE_GAUCHE, 145);
            AX12_setGoal(AX12_ID_PORTE_ARRIERE_DROITE, 155);
            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) 
{
    //Enregistrement de tous les AX12 présent sur la carte
    AX12_register(4,  AX12_SERIAL1);
    AX12_register(14, AX12_SERIAL1);
    AX12_register(15, AX12_SERIAL1);
    AX12_register(5,  AX12_SERIAL2);
    AX12_register(18, AX12_SERIAL2);
    AX12_register(13, AX12_SERIAL2);
    AX12_register(1,  AX12_SERIAL2);
    
    //runRobotTest();
}

/****************************************************************************************/
/* FUNCTION NAME: runTest                                                               */
/* DESCRIPTION  : tester l'ensemble des actionneurs du robot                            */
/****************************************************************************************/
void runRobotTest(void) 
{
    //Test des AX12 dans l'ordre
    doAction(111,0,0);//Fermeture pince arrière haute
    wait_ms(500);
    doAction(110,0,0);//Ouverture pince arrière haute
    wait_ms(500);
    doAction(113,0,0);//Fermeture pince arrière basse
    wait_ms(500);
    doAction(112,0,0);//Ouverture pince arrière basse
    wait_ms(500);
    doAction(115,0,0);//Fermeture porte arrière
    wait_ms(500);
    doAction(114,0,0);//Ouverture porte arrière
}

/****************************************************************************************/
/* 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