AresENSEA-CDF2020
/
AresCDFMainCode_us2
Test
captUS.cpp
- Committer:
- Nanaud
- Date:
- 2020-10-28
- Revision:
- 23:a74135a0271d
- Parent:
- 22:f891c2bce091
- Child:
- 24:be2b2be6907b
File content as of revision 23:a74135a0271d:
/* #include */ #include "pins.h" /* Variables globales */ Timer TimUS; Ticker TickUS_actu; const float DISTLIM = 450; double us_high[6]= {0}; double us_low[6]= {0}; double us_diff[6]= {0}; bool us_verif[6]= {0}; double distt[6]; bool rebooted = 0; bool wtt = 0; //int sptt = 0; /* void captUS_init() { ::distance = new double(6); //équivalent au malloc() tps.reset(); tps.start(); } */ void captUS_trig() { convertToDistance(); if((objRecule[indice]==0) && (fnc == 2)) { //if ((distt[5] >= DISTLIM) && (distt[0] >= DISTLIM) && (distt[1] >= DISTLIM)) { if (((distt[5] >= DISTLIM) && (distt[0] >= DISTLIM) && (distt[1] >= DISTLIM)) || ((distt[5] < 0) && (distt[0] < 0) && (distt[1] < 0))) { wtt = 1; } else { mot_dis(); rebooted = 1; wtt=0; } } else if((objRecule[indice]==1) && (fnc == 2)) { //if ((distt[2] >= DISTLIM) && (distt[3] >= DISTLIM) && (distt[4] >= DISTLIM)) { if (((distt[2] >= DISTLIM) && (distt[3] >= DISTLIM) && (distt[4] >= DISTLIM)) || ((distt[2] < 0) && (distt[3] < 0) && (distt[4] < 0))) { wtt=1; } else { mot_dis(); rebooted = 1; wtt=0; } } /* pc.printf("US1 = %5.0lf uS\n\r", us_out[0]); pc.printf("US2 = %5.0lf uS\n\r", us_out[1]); //pc.printf("US3 = %5.0lf uS\n\r", us_out[2]); //pc.printf("US4 = %5.0lf uS\n\r", us_out[3]); //pc.printf("US5 = %5.0lf uS\n\r", us_out[4]); pc.printf("US6 = %5.0lf uS\n\r", us_out[5]); pc.printf("\n\r"); */ /* pc.printf("Dist1 = %5.0lf mm\n\r", ::distance[0]); pc.printf("Dist2 = %5.0lf mm\n\r", ::distance[1]); pc.printf("Dist3 = %5.0lf mm\n\r", ::distance[2]); pc.printf("Dist4 = %5.0lf mm\n\r", ::distance[3]); pc.printf("Dist5 = %5.0lf mm\n\r", ::distance[4]); pc.printf("Dist6 = %5.0lf mm\n\r", ::distance[5]); pc.printf("\n\r"); */ pc.printf("distance[1] = %lf\n\r", distt[0]); pc.printf("distance[2] = %lf\n\r", distt[1]); pc.printf("distance[3] = %lf\n\r", distt[2]); pc.printf("distance[4] = %lf\n\r", distt[3]); pc.printf("distance[5] = %lf\n\r", distt[4]); pc.printf("distance[6] = %lf\n\r", distt[5]); pc.printf("\n\r"); TimUS.reset(); trigger=1; wait(0.00002); trigger=0; } void echoRise1() { if(us_verif[0] == 0) { us_high[0]=TimUS.read_us(); us_verif[0] = 1; } } void echoFall1() { if(us_verif[0] == 1) { us_low[0]=TimUS.read_us(); us_diff[0]=us_low[0]-us_high[0]; us_verif[0] = 0; } } void echoRise2() { if(us_verif[1] == 0) { us_high[1]=TimUS.read_us(); us_verif[1] = 1; } } void echoFall2() { if(us_verif[1] == 1) { us_low[1]=TimUS.read_us(); us_diff[1]=us_low[1]-us_high[1]; us_verif[1] = 0; } } void echoRise3() { if(us_verif[2] == 0) { us_high[2]=TimUS.read_us(); us_verif[2] = 1; } } void echoFall3() { if(us_verif[2] == 1) { us_low[2]=TimUS.read_us(); us_diff[2]=us_low[2]-us_high[2]; us_verif[2] = 0; } } void echoRise4() { if(us_verif[3] == 0) { us_high[3]=TimUS.read_us(); us_verif[3] = 1; } } void echoFall4() { if(us_verif[3] == 1) { us_low[3]=TimUS.read_us(); us_diff[3]=us_low[3]-us_high[3]; us_verif[3] = 0; } } void echoRise5() { if(us_verif[4] == 0) { us_high[4]=TimUS.read_us(); us_verif[4] = 1; } } void echoFall5() { if(us_verif[4] == 1) { us_low[4]=TimUS.read_us(); us_diff[4]=us_low[4]-us_high[4]; us_verif[4] = 0; } } void echoRise6() { if(us_verif[5] == 0) { us_high[5]=TimUS.read_us(); us_verif[5] = 1; } } void echoFall6() { if(us_verif[5] == 1) { us_low[5]=TimUS.read_us(); us_diff[5]=us_low[5]-us_high[5]; us_verif[5] = 0; } } void convertToDistance() { /************************************** * Nous convertisons grâce au valeur * * qui sont retournées par echoRiseX * * et echoFallx * **************************************/ for(int i = 0; i<6; i++) { distt[i] = ((us_diff[i]*340)/1000); //conversion en distance(mm) } /**************************************** * nous retournons l'adresse du tableau * ****************************************/ //return ::distance; }