code de la carte IHM avant les bugs et avant le travail effectué avec Melchior

Dependencies:   mbed SerialHalfDuplex SDFileSystem liaison_Bluetooth ident_crac DISCO-F469NI_portrait

Committer:
goldmas
Date:
Fri May 21 16:19:18 2021 +0000
Revision:
35:2a745eeb7922
Child:
36:c37dbe2be916
comptage point marche avant ok mais pas marche arriere

Who changed what in which revision?

UserRevisionLine numberNew contents of line
goldmas 35:2a745eeb7922 1 #include "global.h"
goldmas 35:2a745eeb7922 2
goldmas 35:2a745eeb7922 3 #define M_PI 3.14159265358979323846
goldmas 35:2a745eeb7922 4 #define DEMI_GOBELET 30
goldmas 35:2a745eeb7922 5
goldmas 35:2a745eeb7922 6 int Ventouse_coord[6][2]={{145,-75},{145,0},{145,75},{-145,75},{-145,0},{-145,-75}};
goldmas 35:2a745eeb7922 7 int Bras_coord[6][2];
goldmas 35:2a745eeb7922 8 int Manche_air_coord[6][2];
goldmas 35:2a745eeb7922 9
goldmas 35:2a745eeb7922 10 int score_final=0;
goldmas 35:2a745eeb7922 11 int score_ventouse=0,gobelet_vert=0,gobelet_rouge=0,gobelet_port=0;
goldmas 35:2a745eeb7922 12 int score_manche=0,manche_releve=0;
goldmas 35:2a745eeb7922 13 int score_bon_port=0;
goldmas 35:2a745eeb7922 14 int score_phare=0;
goldmas 35:2a745eeb7922 15 int score_pavillon=0;
goldmas 35:2a745eeb7922 16
goldmas 35:2a745eeb7922 17 int etat_groupe, gobelet_en_place=0, old_gobelet=0;
goldmas 35:2a745eeb7922 18 unsigned char num_groupe;
goldmas 35:2a745eeb7922 19
goldmas 35:2a745eeb7922 20 CompteurGameEtat VentEtat[6] = {ETAT_ATTENDRE, ETAT_ATTENDRE, ETAT_ATTENDRE, ETAT_ATTENDRE, ETAT_ATTENDRE, ETAT_ATTENDRE};
goldmas 35:2a745eeb7922 21 int deja_compter[6] = {0, 0, 0, 0, 0, 0};
goldmas 35:2a745eeb7922 22
goldmas 35:2a745eeb7922 23 /********************************************************************************************************************/
goldmas 35:2a745eeb7922 24 /* FUNCTION NAME: gestion_Message_CAN */
goldmas 35:2a745eeb7922 25 /* DESCRIPTION : Récupère message CAN et appelle la fonction correspondante à l'action rapportant des points */
goldmas 35:2a745eeb7922 26 /********************************************************************************************************************/
goldmas 35:2a745eeb7922 27 void gestion_Message_CAN(void)
goldmas 35:2a745eeb7922 28 {
goldmas 35:2a745eeb7922 29 int identifiant = msgRxBuffer[FIFO_ecriture].id;
goldmas 35:2a745eeb7922 30
goldmas 35:2a745eeb7922 31 switch(identifiant)
goldmas 35:2a745eeb7922 32 {
goldmas 35:2a745eeb7922 33 case 0x220:
goldmas 35:2a745eeb7922 34 for(int num_vent=0;num_vent<6;num_vent++)
goldmas 35:2a745eeb7922 35 {
goldmas 35:2a745eeb7922 36 switch(VentEtat[num_vent])
goldmas 35:2a745eeb7922 37 {
goldmas 35:2a745eeb7922 38 case ETAT_ATTENDRE:
goldmas 35:2a745eeb7922 39 etat_groupe = msgRxBuffer[FIFO_ecriture].data[num_vent];
goldmas 35:2a745eeb7922 40 if(etat_groupe == 5) //Pompe et capteur
goldmas 35:2a745eeb7922 41 {
goldmas 35:2a745eeb7922 42 VentEtat[num_vent] = ETAT_RECUP;
goldmas 35:2a745eeb7922 43 }
goldmas 35:2a745eeb7922 44 break;
goldmas 35:2a745eeb7922 45
goldmas 35:2a745eeb7922 46 case ETAT_RECUP:
goldmas 35:2a745eeb7922 47 etat_groupe = msgRxBuffer[FIFO_ecriture].data[num_vent];
goldmas 35:2a745eeb7922 48 if(etat_groupe == 2) //Electrovane
goldmas 35:2a745eeb7922 49 {
goldmas 35:2a745eeb7922 50 VentEtat[num_vent] = ETAT_COMPTER;
goldmas 35:2a745eeb7922 51 }
goldmas 35:2a745eeb7922 52 break;
goldmas 35:2a745eeb7922 53
goldmas 35:2a745eeb7922 54 case ETAT_COMPTER:
goldmas 35:2a745eeb7922 55 verif_position_ventouse(num_vent);
goldmas 35:2a745eeb7922 56 compteur_de_points();
goldmas 35:2a745eeb7922 57 VentEtat[num_vent] = ETAT_ATTENDRE;
goldmas 35:2a745eeb7922 58 break;
goldmas 35:2a745eeb7922 59 }
goldmas 35:2a745eeb7922 60 }
goldmas 35:2a745eeb7922 61 break;
goldmas 35:2a745eeb7922 62
goldmas 35:2a745eeb7922 63 case BRAS_RE:
goldmas 35:2a745eeb7922 64 num_groupe = msgRxBuffer[FIFO_ecriture].data[0];
goldmas 35:2a745eeb7922 65 verif_position_bras(num_groupe);
goldmas 35:2a745eeb7922 66 compteur_de_points();
goldmas 35:2a745eeb7922 67 break;
goldmas 35:2a745eeb7922 68
goldmas 35:2a745eeb7922 69 case AUTOMATE_MANCHE_BAS:
goldmas 35:2a745eeb7922 70 num_groupe = msgRxBuffer[FIFO_ecriture].data[0];
goldmas 35:2a745eeb7922 71 verif_position_manche(num_groupe);
goldmas 35:2a745eeb7922 72 compteur_de_points();
goldmas 35:2a745eeb7922 73 break;
goldmas 35:2a745eeb7922 74 }
goldmas 35:2a745eeb7922 75 }
goldmas 35:2a745eeb7922 76
goldmas 35:2a745eeb7922 77 void compteur_de_points(void)
goldmas 35:2a745eeb7922 78 {
goldmas 35:2a745eeb7922 79 int paire_ventouse = abs(gobelet_vert - gobelet_rouge);
goldmas 35:2a745eeb7922 80
goldmas 35:2a745eeb7922 81 //Points gobelets
goldmas 35:2a745eeb7922 82 score_ventouse = (gobelet_vert*2 + gobelet_rouge*2)*2 - (paire_ventouse)*2 + gobelet_port;
goldmas 35:2a745eeb7922 83
goldmas 35:2a745eeb7922 84 //Points manche à air
goldmas 35:2a745eeb7922 85 if(manche_releve == 1) score_manche = 5;
goldmas 35:2a745eeb7922 86 else if(manche_releve == 2) score_manche = 15;
goldmas 35:2a745eeb7922 87
goldmas 35:2a745eeb7922 88 //Points phare
goldmas 35:2a745eeb7922 89
goldmas 35:2a745eeb7922 90 //Points pavillons
goldmas 35:2a745eeb7922 91
goldmas 35:2a745eeb7922 92 //Points d'arrivée à bon port
goldmas 35:2a745eeb7922 93
goldmas 35:2a745eeb7922 94 //Points totaux
goldmas 35:2a745eeb7922 95 score_final = score_ventouse; //+ score_manche + score_phare + score_pavillon + score_bon_port;
goldmas 35:2a745eeb7922 96 }
goldmas 35:2a745eeb7922 97
goldmas 35:2a745eeb7922 98
goldmas 35:2a745eeb7922 99
goldmas 35:2a745eeb7922 100
goldmas 35:2a745eeb7922 101 /********************************************************************************************************************/
goldmas 35:2a745eeb7922 102 /* FUNCTION NAME: verif_position_ventouse */
goldmas 35:2a745eeb7922 103 /* DESCRIPTION : Vérifie si les gobelets posés par les ventouses sont dans un chenal/un port et augmente le score */
goldmas 35:2a745eeb7922 104 /********************************************************************************************************************/
goldmas 35:2a745eeb7922 105 void verif_position_ventouse(int num_groupe)
goldmas 35:2a745eeb7922 106 {
goldmas 35:2a745eeb7922 107 int x_offset = Ventouse_coord[num_groupe][0]*cos(theta_robot*M_PI/1800) - Ventouse_coord[num_groupe][1]*sin(theta_robot*M_PI*1800);
goldmas 35:2a745eeb7922 108 int y_offset = Ventouse_coord[num_groupe][0]*sin(theta_robot*M_PI/1800) + Ventouse_coord[num_groupe][1]*cos(theta_robot*M_PI*1800);
goldmas 35:2a745eeb7922 109
goldmas 35:2a745eeb7922 110 //chenal vert port départ bleu
goldmas 35:2a745eeb7922 111 if((x_robot+x_offset <= 530+DEMI_GOBELET)&&(x_robot+x_offset >= 500-DEMI_GOBELET)
goldmas 35:2a745eeb7922 112 && (y_robot+y_offset <= 400+DEMI_GOBELET)&&(y_robot+y_offset >= 0)) gobelet_vert++;
goldmas 35:2a745eeb7922 113 //chenal rouge port départ bleu
goldmas 35:2a745eeb7922 114 else if((x_robot+x_offset <= 1100+DEMI_GOBELET)&&(x_robot+x_offset >= 1070-DEMI_GOBELET)
goldmas 35:2a745eeb7922 115 && (y_robot+y_offset <= 400+DEMI_GOBELET)&&(y_robot+y_offset >= 0)) gobelet_rouge++;
goldmas 35:2a745eeb7922 116 //port départ bleu
goldmas 35:2a745eeb7922 117 else if((x_robot+x_offset > 530+DEMI_GOBELET)&&(x_robot+x_offset < 1070-DEMI_GOBELET)
goldmas 35:2a745eeb7922 118 && (y_robot+y_offset <= 400+DEMI_GOBELET)&&(y_robot+y_offset >= 0)) gobelet_port++;
goldmas 35:2a745eeb7922 119
goldmas 35:2a745eeb7922 120 //chenal vert port ext bleu
goldmas 35:2a745eeb7922 121 else if((x_robot+x_offset >= 1700-DEMI_GOBELET)&&(x_robot+x_offset <= 2000+DEMI_GOBELET)
goldmas 35:2a745eeb7922 122 && (y_robot+y_offset >= 1650-DEMI_GOBELET)&&(y_robot+y_offset <= 1750+DEMI_GOBELET)) gobelet_vert++;
goldmas 35:2a745eeb7922 123 //chenal rouge port ext bleu
goldmas 35:2a745eeb7922 124 else if((x_robot+x_offset >= 1700-DEMI_GOBELET)&&(x_robot+x_offset <= 2000+DEMI_GOBELET)
goldmas 35:2a745eeb7922 125 && (y_robot+y_offset >= 1850-DEMI_GOBELET)&&(y_robot+y_offset <= 1950+DEMI_GOBELET)) gobelet_rouge++;
goldmas 35:2a745eeb7922 126 //port ext bleu
goldmas 35:2a745eeb7922 127 else if((x_robot+x_offset >= 1700-DEMI_GOBELET)&&(x_robot+x_offset <= 2000+DEMI_GOBELET)
goldmas 35:2a745eeb7922 128 && (y_robot+y_offset > 1750+DEMI_GOBELET)&&(y_robot+y_offset < 1850-DEMI_GOBELET)) gobelet_port++;
goldmas 35:2a745eeb7922 129
goldmas 35:2a745eeb7922 130
goldmas 35:2a745eeb7922 131 //chenal vert port départ jaune
goldmas 35:2a745eeb7922 132 else if((x_robot+x_offset <= 530+DEMI_GOBELET)&&(x_robot+x_offset >= 500-DEMI_GOBELET)
goldmas 35:2a745eeb7922 133 && (y_robot+y_offset <= 3000+DEMI_GOBELET)&&(y_robot+y_offset >= 2600-DEMI_GOBELET)) gobelet_vert++;
goldmas 35:2a745eeb7922 134 //chenal rouge port départ jaune
goldmas 35:2a745eeb7922 135 else if((x_robot+x_offset <= 1100+DEMI_GOBELET)&&(x_robot+x_offset >= 1070-DEMI_GOBELET)
goldmas 35:2a745eeb7922 136 && (y_robot+y_offset <= 3000+DEMI_GOBELET)&&(y_robot+y_offset >= 2600-DEMI_GOBELET)) gobelet_rouge++;
goldmas 35:2a745eeb7922 137 //port départ jaune
goldmas 35:2a745eeb7922 138 else if((x_robot+x_offset > 530+DEMI_GOBELET)&&(x_robot+x_offset < 1070-DEMI_GOBELET)
goldmas 35:2a745eeb7922 139 && (y_robot+y_offset <= 3000+DEMI_GOBELET)&&(y_robot+y_offset >= 2600-DEMI_GOBELET)) gobelet_port++;
goldmas 35:2a745eeb7922 140
goldmas 35:2a745eeb7922 141 //chenal vert port ext jaune
goldmas 35:2a745eeb7922 142 else if((x_robot+x_offset >= 1700-DEMI_GOBELET)&&(x_robot+x_offset <= 2000+DEMI_GOBELET)
goldmas 35:2a745eeb7922 143 && (y_robot+y_offset >= 1050-DEMI_GOBELET)&&(y_robot+y_offset <= 1150+DEMI_GOBELET)) gobelet_vert++;
goldmas 35:2a745eeb7922 144 //chenal rouge port ext jaune
goldmas 35:2a745eeb7922 145 else if((x_robot+x_offset >= 1700-DEMI_GOBELET)&&(x_robot+x_offset <= 2000+DEMI_GOBELET)
goldmas 35:2a745eeb7922 146 && (y_robot+y_offset >= 1250-DEMI_GOBELET)&&(y_robot+y_offset <= 1350+DEMI_GOBELET)) gobelet_rouge++;
goldmas 35:2a745eeb7922 147 //port ext jaune
goldmas 35:2a745eeb7922 148 else if((x_robot+x_offset >= 1700-DEMI_GOBELET)&&(x_robot+x_offset <= 2000+DEMI_GOBELET)
goldmas 35:2a745eeb7922 149 && (y_robot+y_offset > 1150+DEMI_GOBELET)&&(y_robot+y_offset < 1250-DEMI_GOBELET)) gobelet_port++;
goldmas 35:2a745eeb7922 150 }
goldmas 35:2a745eeb7922 151
goldmas 35:2a745eeb7922 152 void verif_position_bras(int num_groupe)
goldmas 35:2a745eeb7922 153 {
goldmas 35:2a745eeb7922 154
goldmas 35:2a745eeb7922 155 }
goldmas 35:2a745eeb7922 156
goldmas 35:2a745eeb7922 157 void verif_position_manche(int num_groupe)
goldmas 35:2a745eeb7922 158 {
goldmas 35:2a745eeb7922 159
goldmas 35:2a745eeb7922 160 }