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: main.cpp
- Revision:
- 3:814cb36d0f90
- Parent:
- 2:fed59450f2ed
- Child:
- 4:00ac3d093b24
--- a/main.cpp Thu Sep 22 14:10:56 2016 +0000 +++ b/main.cpp Thu Sep 22 16:18:08 2016 +0000 @@ -22,7 +22,7 @@ int main() { - float avg1,avg2,timeavg1,timeavg2; + float avg1,avg2,timeavg1,timeavg2,deltat,a,b,v,argv; pc.baud(115200); while (1) { long duration1, duration2,USSDistance1, USSDistance2, cm1, cm2, time1,time2; @@ -96,7 +96,7 @@ cm2 = microsecondsToCentimeters(USSDistance2); if(15<cm2&&cm2<40) { time2=tmr.read_ms(); - printf(" 2: %d %d[ms]",cm2,time2); + printf(" 2: %d %d[ms]",cm2,time2); count2++; timecount2++; @@ -108,6 +108,18 @@ timesum2=timesum2+time2; //time2を合計する timeavg2=timesum2/timecount2; //time2の平均 printf(" timeavg2:%4.2f[ms]\n",timeavg2); + + deltat=timeavg2-timeavg1; //Δtを求める + printf("\ndeltat: %4.2f\n",deltat); + + a=pow((avg2-avg1)/deltat,2); + b=pow(10/deltat,2); + v=sqrt(a+b); //|v|を求める + + argv=atan(10/(avg2-avg1)); //θを求める + + printf("\n|v|: %lf theta: %lf\n",v,argv); + } wait_ms(10);