carte esclave petit robot

Dependencies:   mbed Herkulex_Library_2019 actions_Gr ident_crac actions_Pr

Committer:
Artiom
Date:
Thu May 23 14:18:03 2019 +0000
Revision:
35:04c3ad41064d
Parent:
32:e9947815c4d7
Child:
38:9295a9721acb
symetrisation;

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