carte esclave petit robot

Dependencies:   mbed Herkulex_Library_2019 actions_Gr ident_crac actions_Pr

Committer:
kyxstark
Date:
Wed May 22 20:56:42 2019 +0000
Revision:
27:9627700d989f
Parent:
26:33c7ff467bd9
Child:
30:d034f469359e
pour theo

Who changed what in which revision?

UserRevisionLine numberNew contents of line
kyxstark 27:9627700d989f 1
Artiom 1:568955af8c2b 2 #include "main.h"
Artiom 0:bc74da1c502f 3
Artiom 0:bc74da1c502f 4 #define SIZE_FIFO 50
Artiom 0:bc74da1c502f 5
Artiom 0:bc74da1c502f 6 CAN can(PB_8,PB_9,1000000); // Rx&Tx pour le CAN
Artiom 0:bc74da1c502f 7
kyxstark 22:9e92a2b941ba 8 Serial pc(USBTX,USBRX);
Artiom 0:bc74da1c502f 9
Artiom 0:bc74da1c502f 10 CANMessage msgRxBuffer[SIZE_FIFO];
Artiom 0:bc74da1c502f 11 unsigned char FIFO_ecriture=0; //Position du fifo pour la reception CAN
Artiom 0:bc74da1c502f 12 signed char FIFO_lecture=0;//Position du fifo de lecture des messages CAN
Artiom 0:bc74da1c502f 13 unsigned char EtatGameEnd=0;
Artiom 0:bc74da1c502f 14
kyxstark 21:edf6d03fdb20 15 void canProcessRx(void);
Artiom 12:191486ba5118 16
Artiom 12:191486ba5118 17
Artiom 0:bc74da1c502f 18 /*********************************************************************************************/
Artiom 0:bc74da1c502f 19 /* FUNCTION NAME: canRx_ISR */
Artiom 0:bc74da1c502f 20 /* DESCRIPTION : lit les messages sur le can et les stocke dans la FIFO */
Artiom 0:bc74da1c502f 21 /*********************************************************************************************/
Artiom 0:bc74da1c502f 22 void canRx_ISR (void)
Artiom 0:bc74da1c502f 23 {
Artiom 0:bc74da1c502f 24 if (can.read(msgRxBuffer[FIFO_ecriture])) {
Artiom 0:bc74da1c502f 25 if (msgRxBuffer[FIFO_ecriture].id==GLOBAL_GAME_END) {
Artiom 0:bc74da1c502f 26
Artiom 0:bc74da1c502f 27 }
Artiom 0:bc74da1c502f 28 FIFO_ecriture=(FIFO_ecriture+1)%SIZE_FIFO;
Artiom 0:bc74da1c502f 29
Artiom 0:bc74da1c502f 30 }
Artiom 0:bc74da1c502f 31
Artiom 0:bc74da1c502f 32 }
Artiom 0:bc74da1c502f 33
Artiom 0:bc74da1c502f 34 int main()
Artiom 0:bc74da1c502f 35 {
Artiom 0:bc74da1c502f 36 can.attach(&canRx_ISR); // création de l'interrupt attachée à la réception sur le CAN
Artiom 0:bc74da1c502f 37 servo_interrupt_en(); //permettre les interuptions
Artiom 11:6c11c081c855 38
Artiom 0:bc74da1c502f 39 wait(1);//attente servo boot
kyxstark 21:edf6d03fdb20 40
kyxstark 21:edf6d03fdb20 41
kyxstark 21:edf6d03fdb20 42 #ifdef ROBOT_SMALL
kyxstark 22:9e92a2b941ba 43 pc.printf("\nPetit robot\n\n");
Artiom 2:9e63099cca99 44 gabarit_petit_robot();
kyxstark 21:edf6d03fdb20 45 #endif
kyxstark 21:edf6d03fdb20 46
kyxstark 21:edf6d03fdb20 47
kyxstark 21:edf6d03fdb20 48
kyxstark 21:edf6d03fdb20 49 #ifdef ROBOT_BIG
kyxstark 22:9e92a2b941ba 50 pc.printf("\nGros robot\n\n");
kyxstark 21:edf6d03fdb20 51 clear(doigt,2);
kyxstark 21:edf6d03fdb20 52 setTorque(doigt, TORQUE_ON,2);
kyxstark 21:edf6d03fdb20 53 positionControl(doigt,384,100,BLED_ON,2);
kyxstark 21:edf6d03fdb20 54 wait(1.0);
kyxstark 21:edf6d03fdb20 55 #endif
kyxstark 21:edf6d03fdb20 56
kyxstark 21:edf6d03fdb20 57
kyxstark 22:9e92a2b941ba 58 pc.printf("\nLAUNCHED");
Artiom 0:bc74da1c502f 59 while(1) {
Artiom 0:bc74da1c502f 60 canProcessRx();
Artiom 10:48c0d1b8aed9 61 f_mesure();//dt35
Artiom 11:6c11c081c855 62
kyxstark 21:edf6d03fdb20 63
kyxstark 21:edf6d03fdb20 64 #ifdef ROBOT_SMALL
Artiom 5:6e198cdd99ad 65 automate_ventouse_presentoir_arriere();
kyxstark 26:33c7ff467bd9 66 automate_ventouse_presentoir_avant();
Artiom 7:553f3f1c2c53 67
Artiom 6:45f9cf44718a 68 automate_ventouse_goldenium_arriere();
kyxstark 26:33c7ff467bd9 69 automate_ventouse_goldenium_avant();
kyxstark 26:33c7ff467bd9 70
Artiom 6:45f9cf44718a 71 automate_ventouse_sol_avant();
Artiom 7:553f3f1c2c53 72 automate_ventouse_sol_arriere();
Artiom 7:553f3f1c2c53 73
kyxstark 26:33c7ff467bd9 74 automate_ventouse_balance_avant();
Artiom 12:191486ba5118 75 automate_ventouse_balance_arriere();
Artiom 12:191486ba5118 76
Artiom 12:191486ba5118 77 automate_ventouse_relache_arriere();
kyxstark 26:33c7ff467bd9 78 automate_ventouse_relache_avant();
Artiom 14:b1abd2f6df75 79
Artiom 13:9e19048eb065 80 automate_ventouse_sol_avant_relache();
Artiom 14:b1abd2f6df75 81 automate_ventouse_sol_arriere_relache();
Artiom 14:b1abd2f6df75 82
Artiom 14:b1abd2f6df75 83 automate_ventouse_accelerateur_arriere();
kyxstark 26:33c7ff467bd9 84 automate_ventouse_accelerateur_avant();
kyxstark 21:edf6d03fdb20 85 #endif
kyxstark 21:edf6d03fdb20 86
kyxstark 21:edf6d03fdb20 87 #ifdef ROBOT_BIG
kyxstark 27:9627700d989f 88 /*automate_ventouse_presentoir_avant();
kyxstark 26:33c7ff467bd9 89 automate_ventouse_goldenium_avant();
kyxstark 26:33c7ff467bd9 90 automate_ventouse_relache_avant();
kyxstark 27:9627700d989f 91 automate_ventouse_accelerateur_avant();*/
kyxstark 26:33c7ff467bd9 92
kyxstark 21:edf6d03fdb20 93 fifo_couleur();
kyxstark 21:edf6d03fdb20 94 ascenseur();
kyxstark 21:edf6d03fdb20 95
kyxstark 21:edf6d03fdb20 96 #endif
Artiom 13:9e19048eb065 97
Artiom 0:bc74da1c502f 98 if(EtatGameEnd==1) {
Artiom 0:bc74da1c502f 99 while(1);
Artiom 0:bc74da1c502f 100 }
Artiom 0:bc74da1c502f 101
Artiom 0:bc74da1c502f 102 }
Artiom 0:bc74da1c502f 103 }
Artiom 0:bc74da1c502f 104
Artiom 0:bc74da1c502f 105 /****************************************************************************************/
Artiom 0:bc74da1c502f 106 /* FUNCTION NAME: canProcessRx */
Artiom 0:bc74da1c502f 107 /* DESCRIPTION : Fonction de traitement des messages CAN */
Artiom 0:bc74da1c502f 108 /****************************************************************************************/
Artiom 0:bc74da1c502f 109 void canProcessRx(void)
Artiom 0:bc74da1c502f 110 {
Artiom 0:bc74da1c502f 111 static signed char FIFO_occupation=0,FIFO_max_occupation=0;
Artiom 0:bc74da1c502f 112 CANMessage msgTx=CANMessage();
Artiom 0:bc74da1c502f 113 FIFO_occupation=FIFO_ecriture-FIFO_lecture;
Artiom 0:bc74da1c502f 114 if(FIFO_occupation<0)
Artiom 0:bc74da1c502f 115 FIFO_occupation=FIFO_occupation+SIZE_FIFO;
Artiom 0:bc74da1c502f 116 if(FIFO_max_occupation<FIFO_occupation)
Artiom 0:bc74da1c502f 117 FIFO_max_occupation=FIFO_occupation;
Artiom 0:bc74da1c502f 118 if(FIFO_occupation!=0) {
Artiom 0:bc74da1c502f 119 int identifiant=msgRxBuffer[FIFO_lecture].id;
Artiom 0:bc74da1c502f 120
Artiom 0:bc74da1c502f 121 switch(identifiant) {
Artiom 0:bc74da1c502f 122
Artiom 0:bc74da1c502f 123 case GLOBAL_GAME_END:
Artiom 0:bc74da1c502f 124 EtatGameEnd = 1;
Artiom 0:bc74da1c502f 125 break;
Artiom 0:bc74da1c502f 126
Artiom 0:bc74da1c502f 127 case DATA_TELEMETRE: //Lit le telemetre N°X suivant la data dans le CAN
Artiom 0:bc74da1c502f 128 char numero_telemetre=msgRxBuffer[FIFO_lecture].data[0];
Artiom 0:bc74da1c502f 129 short distance=lecture_telemetre(numero_telemetre);
Artiom 0:bc74da1c502f 130
Artiom 0:bc74da1c502f 131
Artiom 0:bc74da1c502f 132 msgTx.id=RECEPTION_DATA; // tx Valeur Telemetre1
Artiom 0:bc74da1c502f 133 msgTx.len=2;
Artiom 0:bc74da1c502f 134 msgTx.format=CANStandard;
Artiom 0:bc74da1c502f 135 msgTx.type=CANData;
Artiom 0:bc74da1c502f 136 // Rayon sur 2 octets
Artiom 0:bc74da1c502f 137 msgTx.data[0]=(unsigned char)distance;
Artiom 0:bc74da1c502f 138 msgTx.data[1]=(unsigned char)(distance>>8);
Artiom 0:bc74da1c502f 139
Artiom 0:bc74da1c502f 140 can.write(msgTx);
Artiom 0:bc74da1c502f 141 SendAck(ACKNOWLEDGE_TELEMETRE,RECEPTION_DATA);
Artiom 0:bc74da1c502f 142 break;
Artiom 0:bc74da1c502f 143
Artiom 0:bc74da1c502f 144 case DATA_RECALAGE:
Artiom 0:bc74da1c502f 145 short distance1=lecture_telemetre(1);
Artiom 0:bc74da1c502f 146 short distance2=lecture_telemetre(2);
Artiom 0:bc74da1c502f 147 short distance3=lecture_telemetre(3);
Artiom 0:bc74da1c502f 148 short distance4=lecture_telemetre(4);
Artiom 0:bc74da1c502f 149
Artiom 0:bc74da1c502f 150 msgTx.id=RECEPTION_RECALAGE; // tx Valeur Telemetre1
Artiom 0:bc74da1c502f 151 msgTx.len=8;
Artiom 0:bc74da1c502f 152 msgTx.format=CANStandard;
Artiom 0:bc74da1c502f 153 msgTx.type=CANData;
Artiom 0:bc74da1c502f 154 // Rayon sur 2 octets
Artiom 0:bc74da1c502f 155 msgTx.data[0]=(unsigned char)distance1;
Artiom 0:bc74da1c502f 156 msgTx.data[1]=(unsigned char)(distance1>>8);
Artiom 0:bc74da1c502f 157 msgTx.data[2]=(unsigned char)distance2;
Artiom 0:bc74da1c502f 158 msgTx.data[3]=(unsigned char)(distance2>>8);
Artiom 0:bc74da1c502f 159 msgTx.data[4]=(unsigned char)distance3;
Artiom 0:bc74da1c502f 160 msgTx.data[5]=(unsigned char)(distance3>>8);
Artiom 0:bc74da1c502f 161 msgTx.data[6]=(unsigned char)distance4;
Artiom 0:bc74da1c502f 162 msgTx.data[7]=(unsigned char)(distance4>>8);
Artiom 0:bc74da1c502f 163 can.write(msgTx);
Artiom 0:bc74da1c502f 164 SendAck(ACKNOWLEDGE_TELEMETRE,RECEPTION_RECALAGE);
Artiom 0:bc74da1c502f 165 break;
kyxstark 23:93a427b242ce 166
kyxstark 27:9627700d989f 167
kyxstark 27:9627700d989f 168
kyxstark 27:9627700d989f 169 //--------------------------------------------------------------------------ACK carte pompe----------------------------------------------
kyxstark 27:9627700d989f 170
kyxstark 27:9627700d989f 171
kyxstark 27:9627700d989f 172 case HACHEUR_STATUT_VENTOUSES:
kyxstark 27:9627700d989f 173 status_pompe = msgRxBuffer[FIFO_lecture].data[1];
kyxstark 27:9627700d989f 174 //can.write(CANMessage(0x529, &status_pompe,1));
kyxstark 27:9627700d989f 175 break;
kyxstark 27:9627700d989f 176
kyxstark 27:9627700d989f 177 case HACHEUR_GET_ATOM_ACK:
kyxstark 27:9627700d989f 178 status_pompe |= (0x01 << msgRxBuffer[FIFO_lecture].data[0]);
kyxstark 27:9627700d989f 179 //can.write(CANMessage(0x529, &status_pompe,1));
kyxstark 27:9627700d989f 180 break;
kyxstark 27:9627700d989f 181
kyxstark 27:9627700d989f 182 case HACHEUR_RELEASE_ATOM_ACK :
kyxstark 27:9627700d989f 183 status_pompe &= ~(0x01 << msgRxBuffer[FIFO_lecture].data[0]);
kyxstark 27:9627700d989f 184 break;
kyxstark 27:9627700d989f 185
kyxstark 27:9627700d989f 186 //-------------------------------------------------------------------------------------------------------------------------------------------
kyxstark 27:9627700d989f 187
kyxstark 27:9627700d989f 188
kyxstark 27:9627700d989f 189
kyxstark 27:9627700d989f 190 #ifdef ROBOT_SMALL
kyxstark 23:93a427b242ce 191 case PRESENTOIR_AVANT:
kyxstark 23:93a427b242ce 192 fpresentoir_avant=1;
kyxstark 23:93a427b242ce 193 break;
kyxstark 23:93a427b242ce 194
kyxstark 23:93a427b242ce 195 case BALANCE_AVANT:
kyxstark 23:93a427b242ce 196 fbalance_avant=1;
kyxstark 23:93a427b242ce 197 break;
kyxstark 23:93a427b242ce 198
kyxstark 23:93a427b242ce 199 case ACCELERATEUR_AVANT:
kyxstark 23:93a427b242ce 200 faccelerateur_avant=1;
kyxstark 23:93a427b242ce 201 break;
kyxstark 23:93a427b242ce 202
kyxstark 23:93a427b242ce 203 case GOLDENIUM_AVANT:
kyxstark 23:93a427b242ce 204 fgoldenium_avant=1;
kyxstark 23:93a427b242ce 205 break;
kyxstark 23:93a427b242ce 206
kyxstark 23:93a427b242ce 207 case VENTOUSE_AV_CENTRE_BALANCE:
kyxstark 23:93a427b242ce 208 SendAck(ACKNOWLEDGE_HERKULEX, ACK_ACTION);
kyxstark 23:93a427b242ce 209 goldenium_avant();
kyxstark 23:93a427b242ce 210 verification();
kyxstark 23:93a427b242ce 211 SendAck(ACKNOWLEDGE_HERKULEX, ACK_FIN_ACTION);
kyxstark 23:93a427b242ce 212 break;
kyxstark 23:93a427b242ce 213
kyxstark 23:93a427b242ce 214 case AVANT_RELACHE:
kyxstark 23:93a427b242ce 215 favant_relache=1;
kyxstark 23:93a427b242ce 216 break;
Artiom 4:4a79942713fa 217 //-------------------------------------------------------------------------Actions petit robot----------------------------------------------
Artiom 2:9e63099cca99 218 case GABARIT_PETIT_ROBOT:
Artiom 2:9e63099cca99 219 SendAck(ACKNOWLEDGE_HERKULEX, ACK_ACTION);
Artiom 2:9e63099cca99 220 gabarit_petit_robot();
Artiom 2:9e63099cca99 221 SendAck(ACKNOWLEDGE_HERKULEX, ACK_FIN_ACTION);
Artiom 0:bc74da1c502f 222 break;
Artiom 0:bc74da1c502f 223
Artiom 0:bc74da1c502f 224 case PRESENTOIR_ARRIERE:
Artiom 5:6e198cdd99ad 225 fpresentoir_arriere=1;
Artiom 0:bc74da1c502f 226 break;
Artiom 0:bc74da1c502f 227
Artiom 0:bc74da1c502f 228 case BALANCE_ARRIERE:
Artiom 12:191486ba5118 229 fbalance_arriere=1;
Artiom 2:9e63099cca99 230 break;
Artiom 2:9e63099cca99 231
Artiom 2:9e63099cca99 232 case ACCELERATEUR_ARRIERE:
Artiom 14:b1abd2f6df75 233 faccelerateur_arriere=1;
Artiom 2:9e63099cca99 234 break;
Artiom 6:45f9cf44718a 235
Artiom 2:9e63099cca99 236 case GOLDENIUM_ARRIERE:
Artiom 6:45f9cf44718a 237 fgoldenium_arriere=1;
Artiom 2:9e63099cca99 238 break;
Artiom 6:45f9cf44718a 239
Artiom 2:9e63099cca99 240 case SOL_AVANT:
Artiom 6:45f9cf44718a 241 fsol_avant=1;
Artiom 2:9e63099cca99 242 break;
Artiom 2:9e63099cca99 243
Artiom 2:9e63099cca99 244 case SOL_ARRIERE:
Artiom 6:45f9cf44718a 245 fsol_arriere=1;
Artiom 2:9e63099cca99 246 break;
Artiom 2:9e63099cca99 247
Artiom 2:9e63099cca99 248 case SOL_AVANT_RELACHE:
Artiom 7:553f3f1c2c53 249 fsol_avant_relache=1;
Artiom 2:9e63099cca99 250 break;
Artiom 2:9e63099cca99 251
Artiom 2:9e63099cca99 252 case SOL_ARRIERE_RELACHE:
Artiom 7:553f3f1c2c53 253 fsol_arriere_relache=1;
Artiom 0:bc74da1c502f 254 break;
Artiom 12:191486ba5118 255
Artiom 12:191486ba5118 256 case ARRIERE_RELACHE:
Artiom 12:191486ba5118 257 farriere_relache=1;
Artiom 12:191486ba5118 258 break;
Artiom 14:b1abd2f6df75 259 case RECROQUEVILLER:
Artiom 14:b1abd2f6df75 260 SendAck(ACKNOWLEDGE_HERKULEX, ACK_ACTION);
Artiom 14:b1abd2f6df75 261 recroqueviller_avant();
Artiom 14:b1abd2f6df75 262 recroqueviller_arriere();
Artiom 14:b1abd2f6df75 263 verification();
Artiom 14:b1abd2f6df75 264 SendAck(ACKNOWLEDGE_HERKULEX, ACK_FIN_ACTION);
Artiom 14:b1abd2f6df75 265 break;
Artiom 13:9e19048eb065 266
Artiom 20:42f8ec726ac8 267 case VENTOUSE_AR_CENTRE_BALANCE:
Artiom 20:42f8ec726ac8 268 SendAck(ACKNOWLEDGE_HERKULEX, ACK_ACTION);
Artiom 20:42f8ec726ac8 269 goldenium_arriere();
Artiom 20:42f8ec726ac8 270 positionControl(AR_poigne_D, 200,1,BLED_ON,3);//actionneur
Artiom 20:42f8ec726ac8 271 verification();
Artiom 20:42f8ec726ac8 272 SendAck(ACKNOWLEDGE_HERKULEX, ACK_FIN_ACTION);
Artiom 20:42f8ec726ac8 273 break;
Artiom 13:9e19048eb065 274
Artiom 0:bc74da1c502f 275
Artiom 0:bc74da1c502f 276 #endif
kyxstark 23:93a427b242ce 277
Artiom 0:bc74da1c502f 278 #ifdef ROBOT_BIG
kyxstark 21:edf6d03fdb20 279 case ASCENSEUR:
kyxstark 22:9e92a2b941ba 280 flag_ascenseur = msgRxBuffer[FIFO_lecture].data[0];
Artiom 0:bc74da1c502f 281 break;
Artiom 0:bc74da1c502f 282
Artiom 0:bc74da1c502f 283 #endif
Artiom 0:bc74da1c502f 284 }
Artiom 0:bc74da1c502f 285 FIFO_lecture=(FIFO_lecture+1)%SIZE_FIFO;
Artiom 0:bc74da1c502f 286
Artiom 0:bc74da1c502f 287 }
Artiom 4:4a79942713fa 288
Artiom 4:4a79942713fa 289
Artiom 4:4a79942713fa 290 }
Artiom 4:4a79942713fa 291
Artiom 4:4a79942713fa 292
Artiom 4:4a79942713fa 293
Artiom 11:6c11c081c855 294