CRAC Team / CRAC-Strat_2017

Fork of CRAC-Strat_copy by Clement Breteau

Files at this revision

API Documentation at this revision

Comitter:
antbig
Date:
Fri Apr 15 10:49:40 2016 +0000
Parent:
0:ad97421fb1fb
Child:
2:8d8e2cf798a3
Commit message:
Premier test fonctionnel avec le petit robot,

Changed in this revision

AX12-V2/AX12-V2.cpp Show annotated file Show diff for this revision Revisions of this file
AX12-V2/AX12-V2.h Show annotated file Show diff for this revision Revisions of this file
Asservissement/Asservissement.cpp Show annotated file Show diff for this revision Revisions of this file
Asservissement/Asservissement.h Show annotated file Show diff for this revision Revisions of this file
Debug/debug.cpp Show annotated file Show diff for this revision Revisions of this file
Debug/debug.h Show annotated file Show diff for this revision Revisions of this file
Globals/constantes.h Show annotated file Show diff for this revision Revisions of this file
Globals/global.h Show annotated file Show diff for this revision Revisions of this file
Globals/ident_crac.h Show annotated file Show diff for this revision Revisions of this file
Instruction/Instruction.cpp Show annotated file Show diff for this revision Revisions of this file
Robots/StrategieManager.h Show annotated file Show diff for this revision Revisions of this file
Robots/Strategie_big.cpp Show annotated file Show diff for this revision Revisions of this file
Robots/Strategie_big.h Show diff for this revision Revisions of this file
Robots/Strategie_small.cpp Show diff for this revision Revisions of this file
Robots/Strategie_small.h Show diff for this revision Revisions of this file
Strategie/Strategie.cpp Show annotated file Show diff for this revision Revisions of this file
Strategie/Strategie.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/AX12-V2/AX12-V2.cpp	Wed Apr 13 22:04:54 2016 +0000
+++ b/AX12-V2/AX12-V2.cpp	Fri Apr 15 10:49:40 2016 +0000
@@ -6,6 +6,8 @@
 
 int lastAX12Use = 0;
 
+FunctionPointer AX12_CallbackEnd;//Fonction de callback lors de la fin d'un mouvement d'un AX12
+
 /****************************************************************************************/
 /* FUNCTION NAME: AX12_register                                                         */
 /* DESCRIPTION  : Indiquer qu'un AX12 est connecté à la carte                           */
@@ -20,14 +22,14 @@
     if(speed > 0x3FF) speed = 0x3FF;//La vitesse ne doit pas depasser 1023
     
     AX12_data[lastAX12Use].speed = speed;
-    
+    /*
     data[0] = speed & 0xff; // bottom 8 bits
     data[1] = speed >> 8;   // top 8 bits
-    
+    */
     AX12_Serial.baud(1000000);//On indique la vitesse de transmission des AX12
-    
+    /*
     AX12_write(id,AX12_REG_MOVING_SPEED,2,data);
-    
+    */
     
 }
 
@@ -43,12 +45,12 @@
     AX12_data[localID].needToUpdate = 1;
     AX12_data[localID].goal = goal;
     if(speed > 0x3FF) speed = 0x3FF;//La vitesse ne doit pas depasser 1023
-    
-    AX12_data[localID].speed = speed;
+    if(speed != 0x3FF)
+        AX12_data[localID].speed = speed;
     
     if(AX12_data[localID].isUsingCAN != 0) {//Il faut envoyer la trame CAN car l'AX12 est sur une autre carte
         msgTx.id=SERVO_AX12_SETGOAL;
-        msgTx.len=3;
+        msgTx.len=5;
         msgTx.format=CANStandard;
         msgTx.type=CANData;
         // id de l'AX12 sur 1 octet
@@ -57,8 +59,8 @@
         msgTx.data[1]=(unsigned char)goal;
         msgTx.data[2]=(unsigned char)(goal>>8);
         //Vitesse de l'AX12 sur 2 octet
-        msgTx.data[3]=(unsigned char)speed;
-        msgTx.data[4]=(unsigned char)(speed>>8);
+        msgTx.data[3]=(unsigned char)AX12_data[localID].speed;
+        msgTx.data[4]=(unsigned char)(AX12_data[localID].speed>>8);
     
         can1.write(msgTx);
     }
@@ -102,12 +104,44 @@
 }
 
 /****************************************************************************************/
+/* FUNCTION NAME: AX12_notifyCANEnd                                                     */
+/* DESCRIPTION  : indiquer qu'un mouvement d'AX12 CAN est terminé                       */
+/****************************************************************************************/
+void AX12_notifyCANEnd(unsigned char id) 
+{
+    if(waitingAckFrom == SERVO_AX12_DONE) {
+        waitingAckFrom = 0;
+        waitingAckID = 0;
+    }
+}
+
+/****************************************************************************************/
 /* FUNCTION NAME: AX12_doLoop                                                           */
 /* DESCRIPTION  : Boucle de vérification de la position des AX12                        */
 /****************************************************************************************/
 void AX12_doLoop(void)
 {
-    //TODO
+    int i=0;
+    CANMessage msgTx=CANMessage();
+
+    for(i=0;i<MAX_AX12;i++)
+    {
+        if(AX12_data[i].isUsingCAN == 0 && AX12_data[i].needCheckMoving == 1)//Il faut vérifier si l'AX12 a terminé de bouger
+        {
+            if(AX12_isMoving(AX12_data[i].id) == 0) {//L'AX12 a terminé de bouger
+                AX12_data[i].needCheckMoving = 0;
+                
+                msgTx.id=SERVO_AX12_DONE;
+                msgTx.len=1;
+                msgTx.format=CANStandard;
+                msgTx.type=CANData;
+                // id de l'AX12 sur 1 octet
+                msgTx.data[0]=(unsigned char)AX12_data[i].id;
+                can1.write(msgTx);
+                AX12_notifyCANEnd(AX12_data[i].id);
+            }     
+        }
+    } 
 }
 
 /****************************************************************************************/
@@ -119,7 +153,7 @@
 {
     int i=0;
     int dataToSendLength = 0;
-    char dataToSend[50];
+    char dataToSend[100];
 
     
     for(i=0;i<MAX_AX12;i++)
@@ -129,10 +163,13 @@
             if(AX12_data[i].isUsingCAN == 0)//Il faut envoyer la trame en local
             {
                 if(dataToSendLength == 0)
-                    dataToSend[dataToSendLength++] = 2;//length data
+                    dataToSend[dataToSendLength++] = 4;//length data
                 dataToSend[dataToSendLength++] = AX12_data[i].id;//ID servo1
                 dataToSend[dataToSendLength++] = ((1023 * AX12_data[i].goal) / 300) & 0xff;// bottom 8 bits
-                dataToSend[dataToSendLength++] = ((1023 * AX12_data[i].goal) / 300) >> 8;  // top 8 bits                
+                dataToSend[dataToSendLength++] = ((1023 * AX12_data[i].goal) / 300) >> 8;  // top 8 bits      
+                dataToSend[dataToSendLength++] = (AX12_data[i].speed) & 0xff;// bottom 8 bits
+                dataToSend[dataToSendLength++] = (AX12_data[i].speed) >> 8;  // top 8 bits   
+                AX12_data[i].needCheckMoving = 1;         
             }
             AX12_data[i].needToUpdate = 0;//Remise à 0 de l'indicatif de mise à jour
         }
@@ -147,6 +184,17 @@
 }
 
 /****************************************************************************************/
+/* FUNCTION NAME: AX12_isMoving                                                         */
+/* DESCRIPTION  : Fonction pour savoir si un AX12 local est entrain de bouger           */
+/****************************************************************************************/
+int AX12_isMoving(unsigned char id)
+{
+    char data[1];
+    AX12_read(id,AX12_REG_MOVING,1,data);
+    return(data[0]);
+}
+
+/****************************************************************************************/
 /* FUNCTION NAME: AX12_syncWrite                                                        */
 /* DESCRIPTION  : Fonction pour envoyer des trames aux AX12 en mode syncWrite           */
 /****************************************************************************************/
@@ -397,3 +445,219 @@
 
     return(Status[4]); // retourne le code d'erreur ( octect 5 de la trame de retour )
 }
+
+
+/****************************************************************************************/
+/* FUNCTION NAME: AX12_read                                                             */
+/* DESCRIPTION  : Lire des données dans un registre de l'AX12                           */
+/****************************************************************************************/
+int AX12_read(int ID, int start, int bytes, char* data)
+{
+
+
+    char PacketLength = 0x3;
+    char TxBuf[16];
+    char sum = 0;
+    char Status[16];
+
+    int timeout = 0;
+    int plen = 0;
+    int flag_out = 0;
+    int timeout_transmit = 0;
+    int i = 0;
+    int enable = 0;
+//    int poubelle = 0;
+//    int count = 0;
+//    char vidage[50];
+
+    typedef enum {Header1, Header2, ident, length, erreur, reception, checksum} type_etat;
+    type_etat etat = Header1;
+
+    Status[4] = 0xFE; // return code
+
+
+
+
+
+    /*********************************** CREATION DE LA TRAME A EVOYER *****************************************/
+
+
+    // Build the TxPacket first in RAM, then we'll send in one go
+
+    TxBuf[0] = 0xff;
+    TxBuf[1] = 0xff;
+
+    // ID
+    TxBuf[2] = ID;
+    sum += TxBuf[2];
+
+    // Packet Length
+    TxBuf[3] = PacketLength+bytes;    // Length = 4 ; 2 + 1 (start) = 1 (bytes)
+    sum += TxBuf[3];            // Accululate the packet sum
+
+
+    // Instruction - Read
+    TxBuf[4] = 0x2;
+    sum += TxBuf[4];
+
+    // Start Address
+    TxBuf[5] = start;
+    sum += TxBuf[5];
+
+    // Bytes to read
+    TxBuf[6] = bytes;
+    sum += TxBuf[6];
+
+    // Checksum
+    TxBuf[7] = 0xFF - sum;
+
+    /********************************************TRAME CONSTRUITE DANS TxBuf***************************************/
+
+
+
+
+    /* Transmission de la trame construite precedemment dans le tableau TxBuf
+    */
+    while ((timeout_transmit<1000) && (i < (7+bytes))) {
+        if (AX12_Serial.writeable()) {
+            AX12_Serial.putc(TxBuf[i]);
+            i++;
+            timeout_transmit = 0;
+        } else timeout_transmit++;
+    }
+
+    if (timeout_transmit == 1000 ) { // dans le cas d'une sortie en timeout pour ne pas rester bloquer !
+        return(-1);
+    }
+    /* Transmission effectuée on va ensuite récuperer la trame de retour renvoyer par le servomoteur
+    */
+    // Wait for the bytes to be transmitted
+    wait (0.001);
+
+    // Skip if the read was to the broadcast address
+    if (ID != 0xFE) {
+
+        /* Partie de reception de la trame de retour
+        */
+        while ((flag_out != 1) && (timeout < (1000*bytes))) {
+            // Les differents etats de l'automate on été créés au debut de la fonction write !
+            switch (etat) {
+                case Header1:
+                    if (AX12_Serial.readable()) {     // reception du premier Header ( 0xFF )
+                        Status[plen] = AX12_Serial.getc();
+                        timeout = 0;
+                        if (Status[plen] == 0xFF ) {
+                            etat = Header2;
+                            plen++;
+
+                        } else etat = Header1;
+                    } else timeout++;
+                    break;
+
+
+                case Header2:
+                    if (AX12_Serial.readable()) {     // reception du second Header ( 0xFF )
+                        Status[plen] = AX12_Serial.getc();
+                        timeout = 0;
+                        if (Status[plen] == 0xFF ) {
+                            etat = ident;
+                            plen++;
+
+                        } else if (Status[plen] == ID ) { // PERMET D'EVITER CERTAINES ERREUR LORSQU'ON LIT PLUSIEURS REGISTRES !!!!
+                            Status[plen] = 0;
+                            plen++;
+                            Status[plen] = ID;
+                            etat = length;
+                            plen++;
+
+                        } else {
+
+                            etat = Header1;
+                            plen = 0;
+                        }
+                    } else timeout++;
+                    break;
+
+                case ident:
+                    if (AX12_Serial.readable()) {     // reception de l'octet correspondant à l'ID du servomoteur
+                        Status[plen] = AX12_Serial.getc();
+                        timeout = 0;
+                        if (Status[plen] == ID ) {
+                            etat = length;
+                            plen++;
+
+                        } else {
+                            etat = Header1;
+                            plen = 0;
+                        }
+                    } else timeout++;
+                    break;
+
+                case length:
+                    if (AX12_Serial.readable()) {        // reception de l'octet correspondant à la taille ( taille = 2 + nombre de paramètres )
+                        Status[plen] = AX12_Serial.getc();
+                        timeout = 0;
+                        if (Status[plen] == (bytes+2) ) {
+                            etat = erreur;
+                            plen++;
+
+                        } else {
+                            etat = Header1;
+                            plen = 0;
+                        }
+                    } else timeout++;
+                    break;
+
+                case erreur:
+                    if (AX12_Serial.readable()) {     //reception de l'octet correspondant au code d'erreurs eventuels ( 0 = pas d'erreur )
+                        Status[plen] = AX12_Serial.getc();
+                        timeout = 0;
+                        plen++;
+
+                        etat = reception;
+                    } else timeout++;
+
+                case reception:
+                    while ( enable < bytes ) {     // reception du ou des octect(s) de donnés ( suivant la valeur de la variable length )
+                        if (AX12_Serial.readable()) {
+                            Status[plen] = AX12_Serial.getc();
+                            timeout = 0;
+                            plen++;
+                            enable++;
+
+                        } else timeout++;
+                    }
+                    etat = checksum;
+                    break;
+
+                case checksum:
+                    if (AX12_Serial.readable()) { // reception du dernier octet ( Checksum ) >>> checksum = NOT ( ID + length + somme des données ) >>>> dans le cas d'un retour d'un read!!
+                        Status[plen] = AX12_Serial.getc();
+                        timeout = 0;
+                        flag_out = 1;
+                        etat = Header1;
+                    } else timeout++;
+                    break;
+
+                default:
+                    break;
+            }
+        }
+
+
+        if (timeout == (1000*bytes) ) { // permet d'afficher si il y a une erreur de timeout et de ne pas rester bloquer si il y a des erreurs de trames
+            return(-1);
+        }
+
+
+        // copie des données dans le tableau data
+        for (int i=0; i < Status[3]-2 ; i++) {
+            data[i] = Status[5+i];
+        }
+
+    } // toute la partie precedente ne s'effectue pas dans le cas d'un appel avec un broadcast ID (ID!=0xFE)
+
+    return(Status[4]);    // retourne le code d'erreur ( octect 5 de la trame de retour )
+}
+
+
--- a/AX12-V2/AX12-V2.h	Wed Apr 13 22:04:54 2016 +0000
+++ b/AX12-V2/AX12-V2.h	Fri Apr 15 10:49:40 2016 +0000
@@ -71,6 +71,7 @@
     unsigned short speed;//La vitesse de déplacement du bras    
     unsigned char isUsingCAN;//Indique si il faut envoyer les information via CAN (0=>non | autre=>oui)
     unsigned char needToUpdate;//Indique qu'il faut mettre à jour la position
+    unsigned char needCheckMoving;//Permet d'indiquer que l'on doit verifier si l'AX12 bouge
 };
 
 /****************************************************************************************/
@@ -92,6 +93,12 @@
 unsigned char AX12_isLocal(unsigned char id);
 
 /****************************************************************************************/
+/* FUNCTION NAME: AX12_notifyCANEnd                                                     */
+/* DESCRIPTION  : indiquer qu'un mouvement d'AX12 CAN est terminé                       */
+/****************************************************************************************/
+void AX12_notifyCANEnd(unsigned char id);
+
+/****************************************************************************************/
 /* FUNCTION NAME: AX12_getLocalID                                                       */
 /* DESCRIPTION  : Obtenir les info sur un AX12 ou l'initialiser si non présent          */
 /****************************************************************************************/
@@ -103,7 +110,6 @@
 /****************************************************************************************/
 void AX12_doLoop(void);
 
-
 /****************************************************************************************/
 /* FUNCTION NAME: AX12_processChange                                                    */
 /* DESCRIPTION  : Permet de prendre en compte les changement d'instruction des AX12     */
@@ -112,6 +118,12 @@
 void AX12_processChange(void);
 
 /****************************************************************************************/
+/* FUNCTION NAME: AX12_isMoving                                                         */
+/* DESCRIPTION  : Fonction pour savoir si un AX12 local est entrain de bouger           */
+/****************************************************************************************/
+int AX12_isMoving(unsigned char id);
+
+/****************************************************************************************/
 /* FUNCTION NAME: AX12_syncWrite                                                        */
 /* DESCRIPTION  : Fonction pour envoyer des trames aux AX12 en mode syncWrite           */
 /****************************************************************************************/
@@ -123,5 +135,11 @@
 /****************************************************************************************/
 int AX12_write(int ID, int start, int bytes, char* data, int flag=0);
 
+/****************************************************************************************/
+/* FUNCTION NAME: AX12_read                                                             */
+/* DESCRIPTION  : Lire des données dans un registre de l'AX12                           */
+/****************************************************************************************/
+int AX12_read(int ID, int start, int bytes, char* data);
+
 #endif
 
--- a/Asservissement/Asservissement.cpp	Wed Apr 13 22:04:54 2016 +0000
+++ b/Asservissement/Asservissement.cpp	Fri Apr 15 10:49:40 2016 +0000
@@ -51,7 +51,7 @@
 {
     CANMessage msgTx=CANMessage();
     msgTx.id=ASSERVISSEMENT_ROTATION;  // Tx rotation autour du centre du robot
-    msgTx.len=1;
+    msgTx.len=2;
     msgTx.format=CANStandard;
     msgTx.type=CANData;
     //  Angle signé sur 2 octets
@@ -59,4 +59,37 @@
     msgTx.data[1]=(unsigned char)(angle>>8);
 
     can1.write(msgTx);
+}
+
+
+/*********************************************************************************************/
+/* FUNCTION NAME: GoStraight                                                                 */
+/* DESCRIPTION  : Transmission CAN correspondant à une ligne droite, avec ou sans recalage   */
+/*  recalage : 0 => pas de recalage                                                          */
+/*             1 => recalage en X                                                            */
+/*             2 => Recalage en Y                                                            */
+/*  newValue : Uniquement en cas de recalage, indique la nouvelle valeur de l'odo            */
+/*  isEnchainement : Indique si il faut executer l'instruction en enchainement               */
+/*                   0 => non                                                                */
+/*                   1 => oui                                                                */
+/*********************************************************************************************/
+void GoStraight (signed short distance,unsigned char recalage, unsigned short newValue, unsigned char isEnchainement)
+{
+    CANMessage msgTx=CANMessage();
+    msgTx.id=ASSERVISSEMENT_RECALAGE;
+    msgTx.len=6;
+    msgTx.format=CANStandard;
+    msgTx.type=CANData;
+    // x sur 2 octets
+    msgTx.data[0]=(unsigned char)distance;
+    msgTx.data[1]=(unsigned char)(distance>>8);
+    //Recalage sur 1 octet
+    msgTx.data[2]=recalage;
+    //Valeur du recalage sur 2 octets
+    msgTx.data[3]=(unsigned char)newValue;
+    msgTx.data[4]=(unsigned char)(newValue>>8);
+    //Enchainement sur 1 octet
+    msgTx.data[5]=isEnchainement;
+
+    can1.write(msgTx);
 }
\ No newline at end of file
--- a/Asservissement/Asservissement.h	Wed Apr 13 22:04:54 2016 +0000
+++ b/Asservissement/Asservissement.h	Fri Apr 15 10:49:40 2016 +0000
@@ -24,4 +24,17 @@
 
 void Rotate (signed short angle);
 
+/*********************************************************************************************/
+/* FUNCTION NAME: GoStraight                                                                 */
+/* DESCRIPTION  : Transmission CAN correspondant à une ligne droite, avec ou sans recalage   */
+/*  recalage : 0 => pas de recalage                                                          */
+/*             1 => recalage en X                                                            */
+/*             2 => Recalage en Y                                                            */
+/*  newValue : Uniquement en cas de recalage, indique la nouvelle valeur de l'odo            */
+/*  isEnchainement : Indique si il faut executer l'instruction en enchainement               */
+/*                   0 => non                                                                */
+/*                   1 => oui                                                                */
+/*********************************************************************************************/
+void GoStraight (signed short distance,unsigned char recalage, unsigned short newValue, unsigned char isEnchainement);
+
 #endif
\ No newline at end of file
--- a/Debug/debug.cpp	Wed Apr 13 22:04:54 2016 +0000
+++ b/Debug/debug.cpp	Fri Apr 15 10:49:40 2016 +0000
@@ -87,6 +87,15 @@
     }
 }
 
+void errorInstructionLoop(void) {
+    while(true) {
+        led2 = 1;
+        wait(0.2);
+        led2 = 0;
+        wait(0.2);
+    }
+}
+
 /****************************************************************************************/
 /* FUNCTION NAME: sendStratEtat                                                         */
 /* DESCRIPTION  : permet le debug de l'etat de l'automate de stratégie                  */
--- a/Debug/debug.h	Wed Apr 13 22:04:54 2016 +0000
+++ b/Debug/debug.h	Fri Apr 15 10:49:40 2016 +0000
@@ -19,6 +19,10 @@
 Boucle d'erreur
 ***/
 void errorLoop(void);
+/***
+Boucle d'erreur si une instruction n'est pas lue correctement
+***/
+void errorInstructionLoop(void);
 
 /****************************************************************************************/
 /* FUNCTION NAME: sendStratEtat                                                         */
--- a/Globals/constantes.h	Wed Apr 13 22:04:54 2016 +0000
+++ b/Globals/constantes.h	Fri Apr 15 10:49:40 2016 +0000
@@ -1,9 +1,10 @@
+#ifndef CRAC_CONSTANTES
+#define CRAC_CONSTANTES
 // ****************************************************************************************
 // * CONSTANTES SYMBOLIQUES                                                               *
 // ****************************************************************************************
 
-#define ROBOT_BIG 1
-#define ROBOT_SMALL 2
+
 
 #define SIZE_FIFO               10 //Taille du buffer pour le bus CAN
 
@@ -12,10 +13,12 @@
 
 #define NOMBRE_CARTES           2 //Le nombre de carte présente sur le robot
 
-#define ROBOT_BIG               1//Le gros robot
-#define ROBOT_SMALL             2//Le petit robot
-
 /****
 ** Variable à modifier en fonction du robot
 ***/
-#define ROBOT_TYPE ROBOT_BIG
\ No newline at end of file
+//#define ROBOT_BIG//Indique que l'on va compiler pour le gros robot
+#define ROBOT_SMALL
+
+
+
+#endif
\ No newline at end of file
--- a/Globals/global.h	Wed Apr 13 22:04:54 2016 +0000
+++ b/Globals/global.h	Fri Apr 15 10:49:40 2016 +0000
@@ -13,10 +13,14 @@
 extern CANMessage msgRxBuffer[SIZE_FIFO];
 extern unsigned char FIFO_ecriture;
 
-extern DigitalOut led1;
+extern DigitalOut led1,led2;
 
 extern char cheminFileStart[SIZE+8]; //Le chemin du fichier de strat, utiliser strcpy(cheminFileStart,"/local/strat.txt");
 extern struct S_Instruction strat_instructions[SIZE_BUFFER_FILE]; //La liste des instruction chargé en mémoire
 extern unsigned char nb_instructions; //Le nombre d'instruction dans le fichier de strategie
 extern unsigned char actual_instruction;//La ligne de l'instruction en cours d'execution
 
+extern unsigned char InversStrat;//Si à 1, indique que l'on part de l'autre cote de la table(inversion des Y)
+
+extern unsigned short waitingAckID;//L'id du ack attendu
+extern unsigned short waitingAckFrom;//La provenance du ack attendu
--- a/Globals/ident_crac.h	Wed Apr 13 22:04:54 2016 +0000
+++ b/Globals/ident_crac.h	Fri Apr 15 10:49:40 2016 +0000
@@ -73,7 +73,10 @@
 #define ERROR_STRATEGIE 0x789  // Bug stratégie
 
 #define DEBUG_STRATEGIE_AUTOMATE 0x760  // Etat automate stratégie  (Permet de savoir l'etat de l'automate)
+#define DEBUG_FAKE_JAKE 0x761  // Fake jack  (Permet d'outre passerr le JACk du robot)
 
 #define SERVO_AX12_SETGOAL 0x090  // AX12 setGoal  (Indiquer la nouvelle position de l'AX12 !! Ne bouge pas)
 #define SERVO_AX12_PROCESS 0x091  // AX12 processChange  (Lancer le déplacement des AX12)
-#define SERVO_XL320 0x092  // XL320
+#define SERVO_AX12_DONE 0x092  // AX12 done  (Indique q'un AX12 a terminé son déplacement)
+#define SERVO_XL320 0x093  // XL320
+
--- a/Instruction/Instruction.cpp	Wed Apr 13 22:04:54 2016 +0000
+++ b/Instruction/Instruction.cpp	Fri Apr 15 10:49:40 2016 +0000
@@ -75,14 +75,14 @@
     char instructionPrecision;
     char instructionNextActionType;
     char instructionJumpAction;
-    
+    int errorCode = 0;
     /*
     Info sur la fonction sscanf
     %d -> Entier signé
     %u -> Entié non signé
     %c -> char
     */
-    sscanf(line, "%d,%c,%c,%u,%u,%d,%c,%c,%c,%u,%u,%d,%d",
+    errorCode = sscanf(line, "%d,%c,%c,%u,%u,%d,%c,%c,%c,%u,%u,%d,%d",
         &instruction.lineNumber,
         &instructionOrder,
         &instructionDirection,
@@ -97,6 +97,10 @@
         &instruction.nextLineOK,
         &instruction.nextLineError
     );
+    /*
+    if(errorCode != 13) {
+        errorInstructionLoop();//L'instruction est pas bonne !!  
+    }*/
     
     instruction.order           = charToInstructionType(instructionOrder);
     instruction.direction       = charToInstructionDirection(instructionDirection);
@@ -121,6 +125,9 @@
     while (fgets(LineBuffer, SIZE, testFile) != NULL)  {
         instruction = stringToInstruction(LineBuffer);
         strat_instructions[nb_instructions] = instruction;
+        if(strat_instructions[nb_instructions].order == UNKNOWN) {
+            errorInstructionLoop();//L'instruction est pas bonne !!   
+        }
         //printf(LineBuffer);
         //debug_Instruction(instruction);
         nb_instructions++;
--- a/Robots/StrategieManager.h	Wed Apr 13 22:04:54 2016 +0000
+++ b/Robots/StrategieManager.h	Fri Apr 15 10:49:40 2016 +0000
@@ -1,12 +1,24 @@
-#ifndef CRAC_STRATEGIE_MANAGER
-#define CRAC_STRATEGIE_MANAGER
+#ifndef CRAC_STRATEGIE_BIG
+#define CRAC_STRATEGIE_BIG
 
 #include "global.h"
 
-#if ROBOT_TYPE == ROBOT_BIG
-    #include "Strategie_big.h"
-#else
-    #include "Strategie_small.h"
-#endif
+/****************************************************************************************/
+/* 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);
+
+/****************************************************************************************/
+/* FUNCTION NAME: initRobot                                                             */
+/* DESCRIPTION  : initialiser le robot                                                  */
+/****************************************************************************************/
+void initRobot(void);
 
 #endif
\ No newline at end of file
--- a/Robots/Strategie_big.cpp	Wed Apr 13 22:04:54 2016 +0000
+++ b/Robots/Strategie_big.cpp	Fri Apr 15 10:49:40 2016 +0000
@@ -1,4 +1,4 @@
-#include "Strategie_big.h"
+#include "StrategieManager.h"
 
 /****************************************************************************************/
 /* FUNCTION NAME: doFunnyAction                                                         */
@@ -15,9 +15,26 @@
 /****************************************************************************************/
 unsigned char doAction(unsigned char id, unsigned short speed, short angle) {
     
+    led1 = 1;
+    led2 = 1;
     switch(id) {
-        case 20:
-            
+        case 101://Descendre le bras pour les poissons
+            AX12_setGoal(1,190,0x0FF);
+            AX12_processChange();
+        break;
+        case 102://Remonter bras moiter
+            AX12_setGoal(1,260,0x0FF);
+            AX12_processChange();
+        break;
+        case 103://Lacher les poissons
+            AX12_setGoal(1,230,0x0FF);
+            AX12_setGoal(2,60);//Ouverture du bras
+            AX12_processChange();
+        break;
+        case 104://Rentrer le bras
+            AX12_setGoal(1,280,0x0FF);
+            AX12_setGoal(2,160);//fermer le bras
+            AX12_processChange();
         break;
         default:
             return 0;//L'action n'existe pas, il faut utiliser le CAN
--- a/Robots/Strategie_big.h	Wed Apr 13 22:04:54 2016 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,24 +0,0 @@
-#ifndef CRAC_STRATEGIE_BIG
-#define CRAC_STRATEGIE_BIG
-
-#include "global.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);
-
-/****************************************************************************************/
-/* FUNCTION NAME: initRobot                                                             */
-/* DESCRIPTION  : initialiser le robot                                                  */
-/****************************************************************************************/
-void initRobot(void);
-
-#endif
\ No newline at end of file
--- a/Robots/Strategie_small.cpp	Wed Apr 13 22:04:54 2016 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,28 +0,0 @@
-#include "Strategie_small.h"
-
-
-/****************************************************************************************/
-/* FUNCTION NAME: doAction                                                              */
-/* DESCRIPTION  : Effectuer une action specifique                                       */
-/****************************************************************************************/
-unsigned char doAction(unsigned char id, unsigned short speed, short angle) {
-    
-    switch(id) {
-        case 20:
-            
-        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) {
-    
-}
\ No newline at end of file
--- a/Robots/Strategie_small.h	Wed Apr 13 22:04:54 2016 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,18 +0,0 @@
-#ifndef CRAC_STRATEGIE_SMALL
-#define CRAC_STRATEGIE_SMALL
-
-#include "global.h"
-
-/****************************************************************************************/
-/* FUNCTION NAME: doAction                                                              */
-/* DESCRIPTION  : Effectuer une action specifique                                       */
-/****************************************************************************************/
-unsigned char doAction(unsigned char id, unsigned short speed, short angle);
-
-/****************************************************************************************/
-/* FUNCTION NAME: initRobot                                                             */
-/* DESCRIPTION  : initialiser le robot                                                  */
-/****************************************************************************************/
-void initRobot(void);
-
-#endif
\ No newline at end of file
--- a/Strategie/Strategie.cpp	Wed Apr 13 22:04:54 2016 +0000
+++ b/Strategie/Strategie.cpp	Fri Apr 15 10:49:40 2016 +0000
@@ -21,6 +21,8 @@
 unsigned char checkCurrent = 0;
 unsigned char countAliveCard = 0; 
 
+unsigned char InversStrat = 0;//Si à 1, indique que l'on part de l'autre cote de la table(inversion des Y)
+
 
 void chronometre_ISR (void)
 {
@@ -28,20 +30,23 @@
     SendRawId(GLOBAL_GAME_END);//Indication fin de match
     gameTimer.stop();//Arret du timer
 
-#if ROBOT_TYPE == ROBOT_BIG
+#ifdef ROBOT_BIG
     doFunnyAction();
 #endif
     
-    gameEtat = ETAT_END_LOOP;
+    while(1);//On bloque la programme dans l'interruption
 }
 
 void automate_process(void)
 {
     static struct S_Instruction instruction;
+    static unsigned char AX12_enchainement = 0;
+    static unsigned char MV_enchainement = 0;
     signed char localData1 = 0;
     signed short localData2 = 0;
     unsigned short localData3 = 0;
     signed short localData4 = 0;
+    unsigned char localData5 = 0;
     
     if(gameTimer.read_ms() >= 88000) {//Fin du match (On autorise 2s pour déposer des éléments
         gameTimer.stop();
@@ -160,25 +165,22 @@
             Il est aussi possible d'envoyer les ordres de debug
             */
         break;
-        case ETAT_GAME_START:
+        case ETAT_GAME_INIT:
             //On charge la liste des instructions
             strcpy(cheminFileStart,"/local/test.txt");//On ouvre le fichier test.txt
             loadAllInstruction();//Mise en cache de toute les instructions
-            fakeJack.reset();//Utiliser pour simuler le jack
-            fakeJack.start();//Utiliser pour simuler le jack
             gameEtat = ETAT_GAME_WAIT_FOR_JACK;
             SendRawId(ECRAN_ACK_START_MATCH);
             tactile_printf("Attente du JACK.");
         break;
         case ETAT_GAME_WAIT_FOR_JACK:
             //TODO Attendre le jack
-            if(fakeJack.read_ms() > 3000) {//Utiliser pour simuler le jack
-                fakeJack.stop();
-                gameEtat = ETAT_GAME_LOAD_NEXT_INSTRUCTION;
-                gameTimer.reset();
-                gameTimer.start();
-                chronoEnd.attach(&chronometre_ISR,90);
-            }
+        break;
+        case ETAT_GAME_START:
+            gameEtat = ETAT_GAME_LOAD_NEXT_INSTRUCTION;
+            gameTimer.reset();
+            gameTimer.start();
+            chronoEnd.attach(&chronometre_ISR,90);
         break;
         case ETAT_GAME_LOAD_NEXT_INSTRUCTION:
             /*
@@ -195,6 +197,7 @@
                 //actual_instruction++;
             }
             screenChecktry = 0;
+            wait_ms(100);
         break;
         case ETAT_GAME_PROCESS_INSTRUCTION:
             /*
@@ -213,9 +216,18 @@
                     waitingAckID = ASSERVISSEMENT_RECALAGE;
                     waitingAckFrom = ACKNOWLEDGE_MOTEUR;
                     if(instruction.nextActionType == ENCHAINEMENT) {
-                        //TODO - flag dans le trame pour indiquer l'enchainement  
-                        
+                        MV_enchainement++;
+                        localData5 = 1;
+                    } else {
+                        if(MV_enchainement > 0) {
+                            localData5 = 2;
+                            MV_enchainement = 0;
+                        } else {
+                            localData5 = 0;
+                        }
                     }
+                    localData2 = (((instruction.direction == FORWARD)?1:-1)*instruction.arg1);
+                    GoStraight(localData2, 0, 0, localData5);
                 break;
                 case MV_TURN:
                     if(instruction.direction == RELATIVE) {
@@ -251,12 +263,11 @@
                         //L'action est spécifique
                     } else {
                         //C'est un AX12 qu'il faut bouger
+                        AX12_setGoal(instruction.arg1,instruction.arg3,instruction.arg2);
+                        AX12_enchainement++;
                     }
-                
-                    //TODO - mettre l'ACK à jour
-                    if(instruction.nextActionType == ENCHAINEMENT) {
-                        //TODO - flag dans le trame pour indiquer l'enchainement    
-                    }
+                    waitingAckFrom = 0;
+                    waitingAckID = 0;
                 break;
                 default:
                     //Instruction inconnue, on l'ignore
@@ -270,6 +281,10 @@
                 screenChecktry++;//On incrèment le conteur de tentative de 1
                 cartesCheker.reset();//On reset le timeOut
                 cartesCheker.start();
+                if(AX12_enchainement > 0) {
+                    AX12_processChange();//Il faut lancer le déplacement des AX12
+                    AX12_enchainement = 0;
+                }
             } else {//C'est un enchainement
                 actual_instruction = instruction.nextLineOK;//On indique que l'on va charger l'instruction suivante
                 gameEtat = ETAT_GAME_LOAD_NEXT_INSTRUCTION;//C'est un enchainement, on charge directement l'instruction suivante
@@ -318,7 +333,8 @@
                             waitingAckFrom = INSTRUCTION_END_MOTEUR;
                         break;
                         case ACTION:
-                            //TODO 
+                            waitingAckFrom = SERVO_AX12_DONE;
+                            waitingAckID = instruction.arg1;
                         break;
                         default:
                         break;
@@ -385,6 +401,13 @@
             case ASSERVISSEMENT_STOP:
                 
             break;
+            
+            case DEBUG_FAKE_JAKE:
+                if(gameEtat == ETAT_GAME_WAIT_FOR_JACK) {
+                    gameEtat = ETAT_GAME_START;
+                }
+            break;
+            
             case ALIVE_BALISE:
             case ALIVE_MOTEUR:
             case ALIVE_IHM:
@@ -405,7 +428,7 @@
                     waitingAckID = 0;
                 }
             break;
-#if ROBOT_TYPE == ROBOT_BIG
+#ifdef ROBOT_BIG
             case ODOMETRIE_BIG_POSITION:
 #else
             case ODOMETRIE_SMALL_POSITION:
@@ -417,7 +440,7 @@
             
             case ECRAN_START_MATCH:
                 if(gameEtat == ETAT_CONFIG) {
-                    gameEtat = ETAT_GAME_START;
+                    gameEtat = ETAT_GAME_INIT;
                 }
             break;
             case SERVO_AX12_SETGOAL:
@@ -428,6 +451,9 @@
             case SERVO_AX12_PROCESS:
                 AX12_processChange();
             break;
+            case SERVO_AX12_DONE:
+                AX12_notifyCANEnd(((unsigned short)(msgRxBuffer[FIFO_lecture].data[0])));
+            break;
         }        
         
         FIFO_lecture=(FIFO_lecture+1)%SIZE_FIFO;
--- a/Strategie/Strategie.h	Wed Apr 13 22:04:54 2016 +0000
+++ b/Strategie/Strategie.h	Fri Apr 15 10:49:40 2016 +0000
@@ -12,8 +12,9 @@
     ETAT_WAIT_FORCE,//Attente du forçage du lancement
     ETAT_CONFIG, //attente reception du choix du mode( debug ou game)
     
+    ETAT_GAME_INIT,//Mise en mémoire du fichier de stratégie
+    ETAT_GAME_WAIT_FOR_JACK,
     ETAT_GAME_START,
-    ETAT_GAME_WAIT_FOR_JACK,
     ETAT_GAME_LOAD_NEXT_INSTRUCTION,
     ETAT_GAME_PROCESS_INSTRUCTION,
     ETAT_GAME_WAIT_ACK,
--- a/main.cpp	Wed Apr 13 22:04:54 2016 +0000
+++ b/main.cpp	Fri Apr 15 10:49:40 2016 +0000
@@ -7,6 +7,7 @@
 extern "C" void mbed_reset();//Pour pouvoir reset la carte
 
 DigitalOut led1(LED1);//Led d'indication de problème, si elle clignote, c'est pas bon
+DigitalOut led2(LED2);//Led d'indication de problème, si elle clignote, c'est pas bon
 
 /****************************************************************************************/
 /* FUNCTION NAME: canRx_ISR                                                             */
@@ -36,12 +37,11 @@
     AX12_register(2);
     
     wait_ms(1000);
-    
+    tactile_printf("Initialisation cartes...");
     initRobot();//Initialisation du robot
     
     wait_ms(9000);//Attente pour que toutes les cartes se lancent et surtout le CANBlue
-    tactile_printf("Initialisation cartes...");
-
+    
     /**
     A retirer lors de l'utilisation avec selecteur de stratégie sur IHM
     **/
@@ -50,7 +50,7 @@
     
     
     while(true) {
-        //automate_process();//Boucle dans l'automate principal
+        automate_process();//Boucle dans l'automate principal
         canProcessRx();//Traitement des trames CAN en attente  
         AX12_doLoop();//Vérification de la position des AX12
     }