carte esclave pompe 2020 V1
Dependencies: mbed ident_crac
Diff: main.cpp
- Revision:
- 17:fcfdd7de9039
- Parent:
- 16:5e00af31ae8a
- Child:
- 18:972d29c668a5
--- a/main.cpp Thu May 23 10:36:35 2019 +0000 +++ b/main.cpp Sat May 25 00:56:34 2019 +0000 @@ -5,7 +5,6 @@ - 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 @@ -13,17 +12,30 @@ Ventouse* ventouse[NB_VENTOUSES]; +BusIn contacts(PC_11, PC_12, PB_4, PB_5, PC_13, PC_14, PC_2, PC_3); +DigitalIn Contact1(PC_11, PullNone); +DigitalIn Contact2(PC_12, PullNone); +DigitalIn Contact3(PB_4, PullNone); +DigitalIn Contact4(PB_5, PullNone); +DigitalIn Contact5(PC_13, PullNone); +DigitalIn Contact6(PC_14, PullNone); +DigitalIn Contact7(PC_2, PullNone); +DigitalIn Contact8(PC_3, PullNone); + +void lecture_contacts(void); + #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 +#define VIT_COURROIE_V 0.6 +#define VIT_COURROIE_L 0.5 void set_ascensseur(int allume); #endif @@ -82,6 +94,11 @@ case GLOBAL_GAME_END: end_game = 1; break; + + case HACHEUR_ETAT_CONTACTS: + char contacts_tmp = contacts; + can.write(CANMessage(HACHEUR_ETAT_CONTACTS,&contacts_tmp,1)); + break; #ifdef ROBOT_SMALL @@ -110,7 +127,6 @@ ventouse[AV_DROIT]->action(0); break; - #endif @@ -183,31 +199,56 @@ canProcessRx(); for(int i=0; i<NB_VENTOUSES; i++){ ventouse[i]->automate(); - } + } + lecture_contacts(); + + if(end_game){ for(int i=0; i<NB_VENTOUSES;i++){ ventouse[i]->setPompe(0.0); ventouse[i]->setElectrovanne(0); } - #ifdef ROBOT_BIG +#ifdef ROBOT_BIG set_ascensseur(0); - #endif +#endif while(1){;} } } } - - +void lecture_contacts(void) +{ + static char prev_contacts = contacts; + + if(contacts != prev_contacts) + { + prev_contacts = contacts; + can.write(CANMessage(HACHEUR_ETAT_CONTACTS,&prev_contacts,1)); + } +} #ifdef ROBOT_BIG void set_ascensseur(int allume){ - float vit = VIT_D*allume; - for (int i=0; i<4; i++){ - ascenseur_D[i] = vit; + float vitG, vitD; + + switch(allume){ + case 1: + vitG = VIT_COURROIE_V; + vitD = VIT_COURROIE_L; + break; + case 2: + vitG = VIT_COURROIE_L; + vitD = VIT_COURROIE_V; + break; + default: + vitG = 0; + vitD = 0; + break; } - vit = VIT_G*allume; - for (int i=0; i<4; i++){ - ascenseur_G[i] = vit; + + for (int i=0; i<4; i++) + { + ascenseur_D[i] = vitD; + ascenseur_G[i] = vitG; } } #endif