PINOUT à jour, trame CAN OK
Dependencies: mbed ident_crac
Code carte pompe
main.cpp@4:82c90657da4a, 2019-05-08 (annotated)
- Committer:
- marwanesaich
- Date:
- Wed May 08 17:46:13 2019 +0000
- Revision:
- 4:82c90657da4a
- Parent:
- 2:4cc8fa2f64be
- Child:
- 5:176e7353ba1c
changement pinout sans surcharge constructeur
Who changed what in which revision?
User | Revision | Line number | New 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 | 2:4cc8fa2f64be | 64 | ventouse[AR_GAUCHE]->action(1);; |
marwanesaich | 2:4cc8fa2f64be | 65 | ventouse[AR_CENTRE]->action(1);; |
marwanesaich | 2:4cc8fa2f64be | 66 | ventouse[AR_DROIT]->action(1);; |
marwanesaich | 0:84a8c24e29ae | 67 | break; |
marwanesaich | 0:84a8c24e29ae | 68 | |
marwanesaich | 1:8a55f1d5cb26 | 69 | case HACHEUR_GET_PRESENTOIR_AV : |
marwanesaich | 2:4cc8fa2f64be | 70 | ventouse[AV_GAUCHE]->action(1);; |
marwanesaich | 2:4cc8fa2f64be | 71 | ventouse[AV_CENTRE]->action(1);; |
marwanesaich | 2:4cc8fa2f64be | 72 | ventouse[AV_DROIT]->action(1);; |
marwanesaich | 0:84a8c24e29ae | 73 | break; |
marwanesaich | 0:84a8c24e29ae | 74 | |
marwanesaich | 0:84a8c24e29ae | 75 | case HACHEUR_STATUT_VENTOUSES: |
marwanesaich | 0:84a8c24e29ae | 76 | get_etat_ventouses(); |
marwanesaich | 0:84a8c24e29ae | 77 | break; |
marwanesaich | 0:84a8c24e29ae | 78 | |
marwanesaich | 0:84a8c24e29ae | 79 | case GLOBAL_GAME_END: |
marwanesaich | 0:84a8c24e29ae | 80 | end_game = 1; |
marwanesaich | 0:84a8c24e29ae | 81 | break; |
marwanesaich | 0:84a8c24e29ae | 82 | #endif |
marwanesaich | 0:84a8c24e29ae | 83 | |
marwanesaich | 0:84a8c24e29ae | 84 | #ifdef ROBOT_BIG |
marwanesaich | 0:84a8c24e29ae | 85 | |
marwanesaich | 0:84a8c24e29ae | 86 | #endif |
marwanesaich | 0:84a8c24e29ae | 87 | } |
marwanesaich | 0:84a8c24e29ae | 88 | FIFO_lecture=(FIFO_lecture+1)%SIZE_FIFO; |
marwanesaich | 0:84a8c24e29ae | 89 | } |
marwanesaich | 0:84a8c24e29ae | 90 | } |
marwanesaich | 0:84a8c24e29ae | 91 | |
marwanesaich | 0:84a8c24e29ae | 92 | int main() { |
marwanesaich | 0:84a8c24e29ae | 93 | |
marwanesaich | 0:84a8c24e29ae | 94 | can.attach(&canRx_ISR); // création de l'interrupt attachée à la réception sur le CAN |
marwanesaich | 0:84a8c24e29ae | 95 | wait(1); |
marwanesaich | 1:8a55f1d5cb26 | 96 | #ifdef ROBOT_SMALL |
marwanesaich | 2:4cc8fa2f64be | 97 | ventouse[AR_CENTRE] = new Ventouse(PC_9, PA_8, PB_0, AR_CENTRE); |
marwanesaich | 2:4cc8fa2f64be | 98 | ventouse[AR_DROIT] = new Ventouse(PA_9, PA_10, PB_1, AR_DROIT); |
marwanesaich | 2:4cc8fa2f64be | 99 | ventouse[AR_BAS] = new Ventouse(PA_11, PA_15, PC_1, AR_BAS); |
marwanesaich | 2:4cc8fa2f64be | 100 | ventouse[AV_GAUCHE] = new Ventouse(PB_7, PB_6, PC_0, AV_GAUCHE); |
marwanesaich | 0:84a8c24e29ae | 101 | |
marwanesaich | 2:4cc8fa2f64be | 102 | ventouse[AV_CENTRE] = new Ventouse(PC_7,PC_8 , PC_5, AV_CENTRE); |
marwanesaich | 4:82c90657da4a | 103 | ventouse[AR_GAUCHE] = new Ventouse(PB_10, PB_2, PC_4, AR_GAUCHE); |
marwanesaich | 4:82c90657da4a | 104 | ventouse[AV_BAS] = new Ventouse(PA_6, PA_5, PA_7, AV_BAS); |
marwanesaich | 2:4cc8fa2f64be | 105 | ventouse[AV_DROIT] = new Ventouse(PA_0, PA_1, PA_4, AV_DROIT); |
marwanesaich | 0:84a8c24e29ae | 106 | |
marwanesaich | 4:82c90657da4a | 107 | |
marwanesaich | 1:8a55f1d5cb26 | 108 | #endif |
marwanesaich | 1:8a55f1d5cb26 | 109 | pc.printf("LAUNCHED"); |
marwanesaich | 0:84a8c24e29ae | 110 | while(1) { |
marwanesaich | 0:84a8c24e29ae | 111 | canProcessRx(); |
marwanesaich | 2:4cc8fa2f64be | 112 | for(int i=0; i<8; i++){ |
marwanesaich | 2:4cc8fa2f64be | 113 | ventouse[i]->automate(); |
marwanesaich | 2:4cc8fa2f64be | 114 | } |
marwanesaich | 0:84a8c24e29ae | 115 | if(end_game){ |
marwanesaich | 0:84a8c24e29ae | 116 | for(int i=0; i<8;i++){ |
marwanesaich | 0:84a8c24e29ae | 117 | ventouse[i]->setPompe(0.0); |
marwanesaich | 0:84a8c24e29ae | 118 | ventouse[i]->setElectrovanne(0.0); |
marwanesaich | 0:84a8c24e29ae | 119 | } |
marwanesaich | 0:84a8c24e29ae | 120 | while(1){;} |
marwanesaich | 0:84a8c24e29ae | 121 | } |
marwanesaich | 0:84a8c24e29ae | 122 | } |
marwanesaich | 0:84a8c24e29ae | 123 | } |
marwanesaich | 0:84a8c24e29ae | 124 | |
marwanesaich | 0:84a8c24e29ae | 125 | |
marwanesaich | 0:84a8c24e29ae | 126 | void get_etat_ventouses() |
marwanesaich | 0:84a8c24e29ae | 127 | { |
marwanesaich | 0:84a8c24e29ae | 128 | CANMessage etat_ventouses = CANMessage(); |
marwanesaich | 0:84a8c24e29ae | 129 | etat_ventouses.id=HACHEUR_STATUT_VENTOUSES; |
marwanesaich | 0:84a8c24e29ae | 130 | etat_ventouses.len=2; |
marwanesaich | 0:84a8c24e29ae | 131 | etat_ventouses.format=CANStandard; |
marwanesaich | 0:84a8c24e29ae | 132 | etat_ventouses.type=CANData; |
marwanesaich | 2:4cc8fa2f64be | 133 | etat_ventouses.data[0]=0; |
marwanesaich | 2:4cc8fa2f64be | 134 | etat_ventouses.data[0]=1; |
marwanesaich | 0:84a8c24e29ae | 135 | for(int i=7; i>=0; i--){ |
marwanesaich | 0:84a8c24e29ae | 136 | etat_ventouses.data[0] = (etat_ventouses.data[0]<<1) + ventouse[i]->getPompe(); |
marwanesaich | 0:84a8c24e29ae | 137 | etat_ventouses.data[1] = (etat_ventouses.data[1]<<1) + ventouse[i]->getPression(); |
marwanesaich | 0:84a8c24e29ae | 138 | } |
marwanesaich | 0:84a8c24e29ae | 139 | can.write(etat_ventouses); |
marwanesaich | 0:84a8c24e29ae | 140 | |
marwanesaich | 0:84a8c24e29ae | 141 | } |