PINOUT à jour, trame CAN OK
Dependencies: mbed ident_crac
Code carte pompe
Diff: main.cpp
- Revision:
- 8:a25a9c22ba91
- Parent:
- 7:43d9c70b6689
- Child:
- 9:8193c05bd0a0
diff -r 43d9c70b6689 -r a25a9c22ba91 main.cpp --- a/main.cpp Tue May 21 14:17:12 2019 +0000 +++ b/main.cpp Wed May 22 09:52:47 2019 +0000 @@ -1,22 +1,40 @@ #include "mbed.h" #include "class_ventouse.h" -#include "ident_CRAC.h" +#include "ident_crac.h" #include "extern.h" +#define SIZE_FIFO 50 -#define ROBOT_SMALL + -#define SIZE_FIFO 50 + CANMessage msgRxBuffer[SIZE_FIFO]; unsigned char FIFO_ecriture=0; //Position du fifo pour la reception CAN signed char FIFO_lecture=0;//Position du fifo de lecture des messages CAN +char end_game = 0; -Ventouse* ventouse[8]; -char end_game = 0; +Ventouse* ventouse[NB_VENTOUSES]; + +#ifdef ROBOT_SMALL + +#endif + +#ifdef ROBOT_BIG +PwmOut ascenseur[8] = {PC_9, PA_8, PA_9, PA_10, PC_7, PC_8, PB_10 ,PB_2}; +PwmOut* ascenseur_D; +PwmOut* ascenseur_G; + +#define VIT_G 0.7 +#define VIT_D 0.65 + +void set_ascensseur(int allume); +#endif + void get_etat_ventouses(); + CAN can(PB_8,PB_9,1000000); Serial pc(USBTX,USBRX); @@ -49,16 +67,26 @@ switch(identifiant){ - #ifdef ROBOT_SMALL case HACHEUR_GET_ATOM: BRAS = msgRxBuffer[FIFO_lecture].data[0]; ventouse[BRAS]->action(1); break; - + case HACHEUR_RELEASE_ATOM: BRAS = msgRxBuffer[FIFO_lecture].data[0]; ventouse[BRAS]->action(0); - break; + break; + + case HACHEUR_STATUT_VENTOUSES: + get_etat_ventouses(); + break; + + case GLOBAL_GAME_END: + end_game = 1; + break; + + #ifdef ROBOT_SMALL + case HACHEUR_GET_PRESENTOIR_AR: ventouse[AR_GAUCHE]->action(1); @@ -84,16 +112,28 @@ ventouse[AV_DROIT]->action(0); break; - case HACHEUR_STATUT_VENTOUSES: - get_etat_ventouses(); + + + + #endif + + #ifdef ROBOT_BIG + + case HACHEUR_GET_PRESENTOIR_AV : + ventouse[PGR_GAUCHE]->action(1); + ventouse[PGR_CENTRE]->action(1); + ventouse[PGR_DROIT]->action(1); break; - case GLOBAL_GAME_END: - end_game = 1; + case HACHEUR_RELEASE_AV : + ventouse[PGR_GAUCHE]->action(0); + ventouse[PGR_CENTRE]->action(0); + ventouse[PGR_DROIT]->action(0); break; - #endif - - #ifdef ROBOT_BIG + + case ETAT_COUROIES : + set_ascensseur(msgRxBuffer[FIFO_lecture].data[0]); + break; #endif } @@ -117,21 +157,40 @@ //ventouse[AV_BAS] = new Ventouse(PA_6, PA_5, PA_7, AV_BAS); ventouse[AV_BAS] = new Ventouse(PA_6, PA_7, AV_BAS); ventouse[AV_DROIT] = new Ventouse(PA_0, PA_1, PA_4, AV_DROIT); - + + #endif + + #ifdef ROBOT_BIG + ventouse[PGR_GAUCHE] = new Ventouse(PA_6, PA_5, PA_7, PGR_GAUCHE); + ventouse[PGR_CENTRE] = new Ventouse(PA_0, PA_1, PA_4, PGR_CENTRE); + ventouse[PGR_DROIT] = new Ventouse(PA_11, PA_15, PC_1, PGR_DROIT); + + for (int i=0; i<8; i++){ + ascenseur[i].period_us(50); + } + + ascenseur_D = ascenseur; + ascenseur_G = ascenseur + 4; + + + set_ascensseur(0); + wait(1); + set_ascensseur(1); + wait(2); + set_ascensseur(0); #endif + pc.printf("LAUNCHED"); while(1) { canProcessRx(); - for(int i=0; i<8; i++){ + for(int i=0; i<NB_VENTOUSES; i++){ ventouse[i]->automate(); } - //ventouse[1]->getPression(); - //ventouse[4]->getPression(); if(end_game){ - for(int i=0; i<8;i++){ + for(int i=0; i<NB_VENTOUSES;i++){ ventouse[i]->setPompe(0.0); - ventouse[i]->setElectrovanne(0.0); + ventouse[i]->setElectrovanne(0); } while(1){;} } @@ -139,6 +198,20 @@ } + +#ifdef ROBOT_BIG +void set_ascensseur(int allume){ + float vit = VIT_D*allume; + for (int i=0; i<4; i++){ + ascenseur_D[i] = vit; + } + vit = VIT_G*allume; + for (int i=0; i<4; i++){ + ascenseur_G[i] = vit; + } +} +#endif + void get_etat_ventouses() { CANMessage etat_ventouses = CANMessage(); @@ -148,7 +221,7 @@ etat_ventouses.type=CANData; etat_ventouses.data[0]=0; etat_ventouses.data[0]=1; - for(int i=7; i>=0; i--){ + for(int i=NB_VENTOUSES; i>=0; i--){ etat_ventouses.data[0] = (etat_ventouses.data[0]<<1) + ventouse[i]->getPompe(); etat_ventouses.data[1] = (etat_ventouses.data[1]<<1) + ventouse[i]->getPression(); }