Programme carte strategie (disco)

Dependencies:   mbed SerialHalfDuplex SDFileSystem DISCO-F469NI_portrait liaison_Bluetooth ident_crac

Robots/Strategie_small.cpp

Committer:
Sitkah
Date:
2018-04-20
Revision:
30:a1e37af4bbde
Parent:
29:41e02746041d
Child:
34:6aa4b46b102e

File content as of revision 30:a1e37af4bbde:

#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) {
    
    
}
//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 cote, short arg2) {
    int retour = 1;
    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
            SendRawId(LANCEMENT_MOTEUR_TIR_ON);
            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 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(speed,(unsigned short)angle);
            wait_us(200);
            waitingAckFrom = 0;
            waitingAckID = 0;
        break;
        
        case 19: // CHANGER LA VITESSE + DECELERATION 
            SendSpeedDecel(speed,(unsigned short) angle);
            wait_us(200);
            waitingAckFrom = 0;
            waitingAckID =0;
        break;
        
        case 30://Action tempo
            wait_ms(speed);
        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