carte esclave pompe 2020 V1

Dependencies:   mbed ident_crac

Revision:
1:8a55f1d5cb26
Parent:
0:84a8c24e29ae
Child:
2:4cc8fa2f64be
--- a/main.cpp	Mon May 06 07:53:34 2019 +0000
+++ b/main.cpp	Tue May 07 08:33:42 2019 +0000
@@ -1,13 +1,14 @@
 #include "mbed.h"
 #include "class_ventouse.h"
 #include "ident_CRAC.h"
-#include "def.h"
+
+#define ROBOT_SMALL
 
 #define SIZE_FIFO 50
 
 CAN can(PB_8,PB_9,1000000);
 Serial pc(USBTX,USBRX);
-Ticker tick;
+
 
 CANMessage msgRxBuffer[SIZE_FIFO];
 unsigned char FIFO_ecriture=0; //Position du fifo pour la reception CAN
@@ -18,9 +19,7 @@
 
 
 void get_etat_ventouses();
-void isr_pression();
 
-//ajouter ticker pour isr_presison
 
 /*********************************************************************************************************/
 /* FUNCTION NAME: canRx_ISR                                                                              */
@@ -47,29 +46,31 @@
         FIFO_max_occupation=FIFO_occupation;
     if(FIFO_occupation!=0) {
     int identifiant=msgRxBuffer[FIFO_lecture].id;
-    int BRAS = msgRxBuffer[FIFO_lecture].data[0];
+    char BRAS = 0;
+    
         switch(identifiant){
             
             #ifdef ROBOT_SMALL
             case HACHEUR_GET_ATOM:
-                pc.printf("HACHEUR_GET_ATOM bras %d\n", int(BRAS));
+                BRAS = msgRxBuffer[FIFO_lecture].data[0];
+                pc.printf("HACHEUR_GET_ATOM bras %d\n", BRAS);
                 ventouse[BRAS]->attraper();
                 break;
             
             case HACHEUR_RELEASE_ATOM:
-                pc.printf("HACHEUR_RELEASE_ATOM\n");
+                BRAS = msgRxBuffer[FIFO_lecture].data[0];
+                pc.printf("HACHEUR_RELEASE_ATOM bras %d\n", BRAS);
                 ventouse[BRAS]->relacher(); 
                 break;              
             
-            case HACHEUR_GET_DISTRIB_AR:
+            case HACHEUR_GET_PRESENTOIR_AR:
                 pc.printf("HACHEUR_GET_DISTRIB_AR\n");            
                 ventouse[AR_GAUCHE]->attraper();
                 ventouse[AR_CENTRE]->attraper();
                 ventouse[AR_DROIT]->attraper();
                 break;
             
-            case HACHEUR_GET_DISTRIB_AV:
-                //SendAck();
+            case HACHEUR_GET_PRESENTOIR_AV :
                 pc.printf("HACHEUR_GET_DISTRIB_AV\n"); 
                 ventouse[AV_GAUCHE]->relacher();
                 ventouse[AV_CENTRE]->relacher();
@@ -96,33 +97,23 @@
 
 int main() {
     
-    char i =0;
-
-    pc.printf("Hello World");
     can.attach(&canRx_ISR); // création de l'interrupt attachée à la réception sur le CAN
-    //tick.attach(&isr_pression, 0.5);
     wait(1);
-   // #ifdef ROBOT_SMALL
-    //DEFINITION DES VENTOUSES
-    ventouse[AV_GAUCHE] = new Ventouse(PC_9, PA_8, PB_0);
-    ventouse[AV_CENTRE] = new Ventouse(PA_9, PA_10,  PB_1);
-    ventouse[AV_DROIT]  = new Ventouse(PA_11, PA_15, PC_1);
-    ventouse[AV_BAS]    = new Ventouse(PB_7, PB_6, PC_0);
+    #ifdef ROBOT_SMALL
+    ventouse[AR_CENTRE] = new Ventouse(PC_9, PA_8, PB_0);
+    ventouse[AR_DROIT] = new Ventouse(PA_9, PA_10,  PB_1);
+    ventouse[AR_BAS] = new Ventouse(PA_11, PA_15, PC_1);
+    ventouse[AV_GAUCHE] = new Ventouse(PB_7, PB_6, PC_0);
     
-    ventouse[AR_GAUCHE] = new Ventouse(PC_7,PC_8 , PC_5);
-    ventouse[AR_CENTRE] = new Ventouse(PB_10, PB_2, PC_4);
-    ventouse[AR_DROIT]  = new Ventouse(PA_6, PA_5, PA_7);
-    ventouse[AR_BAS]    = new Ventouse(PA_0, PA_1, PA_4);
-    
+    ventouse[AV_CENTRE] = new Ventouse(PC_7,PC_8 , PC_5);
+    ventouse[AV_BAS] = new Ventouse(PB_10, PB_2, PC_4);
+    ventouse[AR_GAUCHE] = new Ventouse(PA_6, PA_5, PA_7);
+    ventouse[AV_DROIT] = new Ventouse(PA_0, PA_1, PA_4);
 
-   // #endif
-    
+    #endif
+    pc.printf("LAUNCHED");
     while(1) {
         canProcessRx();
-        pc.printf("%d\n",i);
-        i++;
-        wait_ms(10);
-        //isr_pression();
         if(end_game){
             for(int i=0; i<8;i++){
                 ventouse[i]->setPompe(0.0);
@@ -134,8 +125,6 @@
 }
 
 
-
-
 void get_etat_ventouses()
 {   
     CANMessage etat_ventouses = CANMessage();
@@ -150,33 +139,3 @@
     can.write(etat_ventouses);
 
 }
-
-void isr_pression()
-{   
-    static char i = 1;
-    can.write(CANMessage(100,&i,1));
-    i++;
-    /*
-    static char new_pression = 0;
-    static char old_pression = 0;
-    
-    for(int i=7; i>=0; i--){
-        new_pression = (new_pression<<1) + ventouse[i]->getPression();
-    }
-    
-    if(old_pression^new_pression){
-        CANMessage chgt_pression = CANMessage();
-        chgt_pression.id=HACHEUR_ISR_PRESSION ;      
-        chgt_pression.len=2;
-        chgt_pression.format=CANStandard;
-        chgt_pression.type=CANData;
-        chgt_pression.data[0] = old_pression^new_pression ;
-        chgt_pression.data[1] = new_pression;
-        can.write(chgt_pression);
-    }
-    
-    new_pression = old_pression; 
-    */
-    
-
-}
\ No newline at end of file