PINOUT à jour, trame CAN OK

Dependencies:   mbed ident_crac

Code carte pompe

Committer:
marwanesaich
Date:
Mon May 20 09:40:21 2019 +0000
Revision:
6:fda992188a2f
Parent:
5:176e7353ba1c
Child:
7:43d9c70b6689
seuil par capteur pression

Who changed what in which revision?

UserRevisionLine numberNew contents of line
marwanesaich 0:84a8c24e29ae 1 #include "mbed.h"
marwanesaich 0:84a8c24e29ae 2 #include "class_ventouse.h"
marwanesaich 0:84a8c24e29ae 3 #include "ident_CRAC.h"
marwanesaich 4:82c90657da4a 4 #include "extern.h"
marwanesaich 1:8a55f1d5cb26 5
marwanesaich 1:8a55f1d5cb26 6 #define ROBOT_SMALL
marwanesaich 0:84a8c24e29ae 7
marwanesaich 0:84a8c24e29ae 8 #define SIZE_FIFO 50
marwanesaich 0:84a8c24e29ae 9
marwanesaich 0:84a8c24e29ae 10 CANMessage msgRxBuffer[SIZE_FIFO];
marwanesaich 0:84a8c24e29ae 11 unsigned char FIFO_ecriture=0; //Position du fifo pour la reception CAN
marwanesaich 0:84a8c24e29ae 12 signed char FIFO_lecture=0;//Position du fifo de lecture des messages CAN
marwanesaich 0:84a8c24e29ae 13
marwanesaich 0:84a8c24e29ae 14 Ventouse* ventouse[8];
marwanesaich 0:84a8c24e29ae 15 char end_game = 0;
marwanesaich 0:84a8c24e29ae 16
marwanesaich 0:84a8c24e29ae 17
marwanesaich 0:84a8c24e29ae 18 void get_etat_ventouses();
marwanesaich 0:84a8c24e29ae 19
marwanesaich 2:4cc8fa2f64be 20 CAN can(PB_8,PB_9,1000000);
marwanesaich 2:4cc8fa2f64be 21 Serial pc(USBTX,USBRX);
marwanesaich 0:84a8c24e29ae 22
marwanesaich 0:84a8c24e29ae 23 /*********************************************************************************************************/
marwanesaich 0:84a8c24e29ae 24 /* FUNCTION NAME: canRx_ISR */
marwanesaich 0:84a8c24e29ae 25 /* DESCRIPTION : lit les messages sur le can et les stocke dans la FIFO */
marwanesaich 0:84a8c24e29ae 26 /*********************************************************************************************************/
marwanesaich 0:84a8c24e29ae 27 void canRx_ISR (void)
marwanesaich 0:84a8c24e29ae 28 {
marwanesaich 0:84a8c24e29ae 29 if (can.read(msgRxBuffer[FIFO_ecriture]))
marwanesaich 0:84a8c24e29ae 30 FIFO_ecriture=(FIFO_ecriture+1)%SIZE_FIFO;
marwanesaich 0:84a8c24e29ae 31 }
marwanesaich 0:84a8c24e29ae 32
marwanesaich 0:84a8c24e29ae 33
marwanesaich 0:84a8c24e29ae 34 /*********************************************************************************************************/
marwanesaich 0:84a8c24e29ae 35 /* FUNCTION NAME: canProcessRx */
marwanesaich 0:84a8c24e29ae 36 /* DESCRIPTION : Fonction de traitement des messages CAN */
marwanesaich 0:84a8c24e29ae 37 /*********************************************************************************************************/
marwanesaich 0:84a8c24e29ae 38 void canProcessRx(void){
marwanesaich 0:84a8c24e29ae 39 static signed char FIFO_occupation=0,FIFO_max_occupation=0;
marwanesaich 0:84a8c24e29ae 40 CANMessage msgTx=CANMessage();
marwanesaich 0:84a8c24e29ae 41 FIFO_occupation=FIFO_ecriture-FIFO_lecture;
marwanesaich 0:84a8c24e29ae 42 if(FIFO_occupation<0)
marwanesaich 0:84a8c24e29ae 43 FIFO_occupation=FIFO_occupation+SIZE_FIFO;
marwanesaich 0:84a8c24e29ae 44 if(FIFO_max_occupation<FIFO_occupation)
marwanesaich 0:84a8c24e29ae 45 FIFO_max_occupation=FIFO_occupation;
marwanesaich 0:84a8c24e29ae 46 if(FIFO_occupation!=0) {
marwanesaich 0:84a8c24e29ae 47 int identifiant=msgRxBuffer[FIFO_lecture].id;
marwanesaich 1:8a55f1d5cb26 48 char BRAS = 0;
marwanesaich 1:8a55f1d5cb26 49
marwanesaich 0:84a8c24e29ae 50 switch(identifiant){
marwanesaich 0:84a8c24e29ae 51
marwanesaich 0:84a8c24e29ae 52 #ifdef ROBOT_SMALL
marwanesaich 0:84a8c24e29ae 53 case HACHEUR_GET_ATOM:
marwanesaich 1:8a55f1d5cb26 54 BRAS = msgRxBuffer[FIFO_lecture].data[0];
marwanesaich 2:4cc8fa2f64be 55 ventouse[BRAS]->action(1);
marwanesaich 0:84a8c24e29ae 56 break;
marwanesaich 0:84a8c24e29ae 57
marwanesaich 0:84a8c24e29ae 58 case HACHEUR_RELEASE_ATOM:
marwanesaich 1:8a55f1d5cb26 59 BRAS = msgRxBuffer[FIFO_lecture].data[0];
marwanesaich 2:4cc8fa2f64be 60 ventouse[BRAS]->action(0);
marwanesaich 0:84a8c24e29ae 61 break;
marwanesaich 0:84a8c24e29ae 62
marwanesaich 4:82c90657da4a 63 case HACHEUR_GET_PRESENTOIR_AR:
marwanesaich 5:176e7353ba1c 64 ventouse[AR_GAUCHE]->action(1);
marwanesaich 5:176e7353ba1c 65 ventouse[AR_CENTRE]->action(1);
marwanesaich 5:176e7353ba1c 66 ventouse[AR_DROIT]->action(1);
marwanesaich 0:84a8c24e29ae 67 break;
marwanesaich 0:84a8c24e29ae 68
marwanesaich 5:176e7353ba1c 69 case HACHEUR_RELEASE_AR:
marwanesaich 5:176e7353ba1c 70 ventouse[AR_GAUCHE]->action(0);
marwanesaich 5:176e7353ba1c 71 ventouse[AR_CENTRE]->action(0);
marwanesaich 5:176e7353ba1c 72 ventouse[AR_DROIT]->action(0);
marwanesaich 5:176e7353ba1c 73 break;
marwanesaich 5:176e7353ba1c 74
marwanesaich 1:8a55f1d5cb26 75 case HACHEUR_GET_PRESENTOIR_AV :
marwanesaich 5:176e7353ba1c 76 ventouse[AV_GAUCHE]->action(1);
marwanesaich 5:176e7353ba1c 77 ventouse[AV_CENTRE]->action(1);
marwanesaich 5:176e7353ba1c 78 ventouse[AV_DROIT]->action(1);
marwanesaich 0:84a8c24e29ae 79 break;
marwanesaich 0:84a8c24e29ae 80
marwanesaich 5:176e7353ba1c 81 case HACHEUR_RELEASE_AV :
marwanesaich 5:176e7353ba1c 82 ventouse[AV_GAUCHE]->action(0);
marwanesaich 5:176e7353ba1c 83 ventouse[AV_CENTRE]->action(0);
marwanesaich 5:176e7353ba1c 84 ventouse[AV_DROIT]->action(0);
marwanesaich 5:176e7353ba1c 85 break;
marwanesaich 5:176e7353ba1c 86
marwanesaich 0:84a8c24e29ae 87 case HACHEUR_STATUT_VENTOUSES:
marwanesaich 0:84a8c24e29ae 88 get_etat_ventouses();
marwanesaich 0:84a8c24e29ae 89 break;
marwanesaich 0:84a8c24e29ae 90
marwanesaich 0:84a8c24e29ae 91 case GLOBAL_GAME_END:
marwanesaich 0:84a8c24e29ae 92 end_game = 1;
marwanesaich 0:84a8c24e29ae 93 break;
marwanesaich 0:84a8c24e29ae 94 #endif
marwanesaich 0:84a8c24e29ae 95
marwanesaich 0:84a8c24e29ae 96 #ifdef ROBOT_BIG
marwanesaich 0:84a8c24e29ae 97
marwanesaich 0:84a8c24e29ae 98 #endif
marwanesaich 0:84a8c24e29ae 99 }
marwanesaich 0:84a8c24e29ae 100 FIFO_lecture=(FIFO_lecture+1)%SIZE_FIFO;
marwanesaich 0:84a8c24e29ae 101 }
marwanesaich 0:84a8c24e29ae 102 }
marwanesaich 0:84a8c24e29ae 103
marwanesaich 0:84a8c24e29ae 104 int main() {
marwanesaich 0:84a8c24e29ae 105
marwanesaich 0:84a8c24e29ae 106 can.attach(&canRx_ISR); // création de l'interrupt attachée à la réception sur le CAN
marwanesaich 0:84a8c24e29ae 107 wait(1);
marwanesaich 1:8a55f1d5cb26 108 #ifdef ROBOT_SMALL
marwanesaich 2:4cc8fa2f64be 109 ventouse[AR_CENTRE] = new Ventouse(PC_9, PA_8, PB_0, AR_CENTRE);
marwanesaich 2:4cc8fa2f64be 110 ventouse[AR_DROIT] = new Ventouse(PA_9, PA_10, PB_1, AR_DROIT);
marwanesaich 5:176e7353ba1c 111 //ventouse[AR_BAS] = new Ventouse(PA_11, PA_15, PC_1, AR_BAS);
marwanesaich 5:176e7353ba1c 112 ventouse[AR_BAS] = new Ventouse(PA_11, PC_1, AR_BAS);
marwanesaich 2:4cc8fa2f64be 113 ventouse[AV_GAUCHE] = new Ventouse(PB_7, PB_6, PC_0, AV_GAUCHE);
marwanesaich 0:84a8c24e29ae 114
marwanesaich 2:4cc8fa2f64be 115 ventouse[AV_CENTRE] = new Ventouse(PC_7,PC_8 , PC_5, AV_CENTRE);
marwanesaich 4:82c90657da4a 116 ventouse[AR_GAUCHE] = new Ventouse(PB_10, PB_2, PC_4, AR_GAUCHE);
marwanesaich 5:176e7353ba1c 117 //ventouse[AV_BAS] = new Ventouse(PA_6, PA_5, PA_7, AV_BAS);
marwanesaich 5:176e7353ba1c 118 ventouse[AV_BAS] = new Ventouse(PA_6, PA_7, AV_BAS);
marwanesaich 2:4cc8fa2f64be 119 ventouse[AV_DROIT] = new Ventouse(PA_0, PA_1, PA_4, AV_DROIT);
marwanesaich 0:84a8c24e29ae 120
marwanesaich 4:82c90657da4a 121
marwanesaich 1:8a55f1d5cb26 122 #endif
marwanesaich 1:8a55f1d5cb26 123 pc.printf("LAUNCHED");
marwanesaich 0:84a8c24e29ae 124 while(1) {
marwanesaich 0:84a8c24e29ae 125 canProcessRx();
marwanesaich 2:4cc8fa2f64be 126 for(int i=0; i<8; i++){
marwanesaich 2:4cc8fa2f64be 127 ventouse[i]->automate();
marwanesaich 2:4cc8fa2f64be 128 }
marwanesaich 6:fda992188a2f 129 //ventouse[0]->getPression();
marwanesaich 6:fda992188a2f 130 //ventouse[4]->getPression();
marwanesaich 0:84a8c24e29ae 131 if(end_game){
marwanesaich 0:84a8c24e29ae 132 for(int i=0; i<8;i++){
marwanesaich 0:84a8c24e29ae 133 ventouse[i]->setPompe(0.0);
marwanesaich 0:84a8c24e29ae 134 ventouse[i]->setElectrovanne(0.0);
marwanesaich 0:84a8c24e29ae 135 }
marwanesaich 0:84a8c24e29ae 136 while(1){;}
marwanesaich 0:84a8c24e29ae 137 }
marwanesaich 0:84a8c24e29ae 138 }
marwanesaich 0:84a8c24e29ae 139 }
marwanesaich 0:84a8c24e29ae 140
marwanesaich 0:84a8c24e29ae 141
marwanesaich 0:84a8c24e29ae 142 void get_etat_ventouses()
marwanesaich 0:84a8c24e29ae 143 {
marwanesaich 0:84a8c24e29ae 144 CANMessage etat_ventouses = CANMessage();
marwanesaich 0:84a8c24e29ae 145 etat_ventouses.id=HACHEUR_STATUT_VENTOUSES;
marwanesaich 0:84a8c24e29ae 146 etat_ventouses.len=2;
marwanesaich 0:84a8c24e29ae 147 etat_ventouses.format=CANStandard;
marwanesaich 0:84a8c24e29ae 148 etat_ventouses.type=CANData;
marwanesaich 2:4cc8fa2f64be 149 etat_ventouses.data[0]=0;
marwanesaich 2:4cc8fa2f64be 150 etat_ventouses.data[0]=1;
marwanesaich 0:84a8c24e29ae 151 for(int i=7; i>=0; i--){
marwanesaich 0:84a8c24e29ae 152 etat_ventouses.data[0] = (etat_ventouses.data[0]<<1) + ventouse[i]->getPompe();
marwanesaich 0:84a8c24e29ae 153 etat_ventouses.data[1] = (etat_ventouses.data[1]<<1) + ventouse[i]->getPression();
marwanesaich 0:84a8c24e29ae 154 }
marwanesaich 0:84a8c24e29ae 155 can.write(etat_ventouses);
marwanesaich 0:84a8c24e29ae 156
marwanesaich 0:84a8c24e29ae 157 }