Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: captUS.cpp
- Revision:
- 24:be2b2be6907b
- Parent:
- 23:a74135a0271d
- Child:
- 25:869b1c1f51a7
--- a/captUS.cpp Wed Oct 28 16:27:05 2020 +0000 +++ b/captUS.cpp Wed Oct 28 20:08:39 2020 +0000 @@ -1,22 +1,55 @@ /* #include */ #include "pins.h" +/* #define */ +#define DISTLIM 600 +#define MAXMOY 3 + /* Variables globales */ Timer TimUS; Ticker TickUS_actu; -const float DISTLIM = 450; +//const float DISTLIM = 600; -double us_high[6]= {0}; -double us_low[6]= {0}; -double us_diff[6]= {0}; +unsigned int us_high[6]= {0}; +unsigned int us_low[6]= {0}; +unsigned int us_diff[6]= {0}; bool us_verif[6]= {0}; -double distt[6]; +unsigned int distt[6]; bool rebooted = 0; bool wtt = 0; -//int sptt = 0; +int indix = 0; +unsigned int total[6] = {0}; +unsigned int ttt[6] = {0}; + +void calculTotal() +{ + if(indix < MAXMOY) { + for(int j=0; j<6 ; j++) { + total[j]+=distt[j]; + } + indix++; + } else { + for(int j=0; j<6 ; j++) { + ttt[j]=total[j]/MAXMOY; + total[j]=0; + } + + /* + pc.printf("ttt[1] = %d\n\r", ttt[0]); + pc.printf("ttt[2] = %d\n\r", ttt[1]); + pc.printf("ttt[3] = %d\n\r", ttt[2]); + pc.printf("ttt[4] = %d\n\r", ttt[3]); + pc.printf("ttt[5] = %d\n\r", ttt[4]); + pc.printf("ttt[6] = %d\n\r", ttt[5]); + pc.printf("\n\r"); + */ + + indix=0; + } +} /* void captUS_init() @@ -31,9 +64,12 @@ { convertToDistance(); + calculTotal(); + 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))) { + //if (((distt[5] >= DISTLIM) && (distt[0] >= DISTLIM) && (distt[1] >= DISTLIM)) /*|| ((distt[5] < 0) && (distt[0] < 0) && (distt[1] < 0))*/) { + if ((ttt[5] >= DISTLIM) && (ttt[0] >= DISTLIM) && (ttt[1] >= DISTLIM)) { wtt = 1; } @@ -46,7 +82,8 @@ 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))) { + //if (((distt[2] >= DISTLIM) && (distt[3] >= DISTLIM) && (distt[4] >= DISTLIM)) /*|| ((distt[2] < 0) && (distt[3] < 0) && (distt[4] < 0))*/) { + if ((ttt[2] >= DISTLIM) && (ttt[3] >= DISTLIM) && (ttt[4] >= DISTLIM)) { wtt=1; } @@ -76,14 +113,18 @@ pc.printf("Dist6 = %5.0lf mm\n\r", ::distance[5]); pc.printf("\n\r"); */ + + /* + pc.printf("ttt[1] = %d\n\r", ttt[0]); + pc.printf("ttt[2] = %d\n\r", ttt[1]); + pc.printf("ttt[3] = %d\n\r", ttt[2]); + pc.printf("ttt[4] = %d\n\r", ttt[3]); + pc.printf("ttt[5] = %d\n\r", ttt[4]); + pc.printf("ttt[6] = %d\n\r", ttt[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"); + //calculTotal(); TimUS.reset(); trigger=1; @@ -203,7 +244,7 @@ **************************************/ for(int i = 0; i<6; i++) { - distt[i] = ((us_diff[i]*340)/1000); //conversion en distance(mm) + distt[i] = (int) ((us_diff[i]*340)/1000); //conversion en distance(mm) } /****************************************