carte esclave Petit Robot

Dependencies:   mbed Herkulex_Library_2019 actions_Gr ident_crac actions_Pr

Committer:
kyxstark
Date:
Wed May 22 15:46:40 2019 +0000
Revision:
22:9e92a2b941ba
Parent:
21:edf6d03fdb20
Child:
23:93a427b242ce
flag ascensseur;

Who changed what in which revision?

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