From c36b220308c08147a6c995fbb6082aa5ab0a0a21 Mon Sep 17 00:00:00 2001 From: cnlohr Date: Thu, 15 Dec 2016 22:36:16 -0500 Subject: Get working plane tester --- tools/planetest2/Makefile | 2 +- tools/planetest2/camfind.c | 277 +++++++++++++++++++++++++++------------------ 2 files changed, 165 insertions(+), 114 deletions(-) (limited to 'tools/planetest2') diff --git a/tools/planetest2/Makefile b/tools/planetest2/Makefile index dd19480..b48b099 100644 --- a/tools/planetest2/Makefile +++ b/tools/planetest2/Makefile @@ -1,6 +1,6 @@ all : camfind -CFLAGS:=-g -O4 -DFLT=float -ffast-math -I../../redist -flto +CFLAGS:=-g -O4 -DFLT=float -I../../redist -flto LDFLAGS:=$(CFLAGS) -lm camfind : camfind.o ../../redist/linmath.c diff --git a/tools/planetest2/camfind.c b/tools/planetest2/camfind.c index 54fd8a1..6caee1a 100644 --- a/tools/planetest2/camfind.c +++ b/tools/planetest2/camfind.c @@ -18,8 +18,6 @@ int LoadData( char Camera ); //Values used for RunTest() FLT LighthousePos[3] = { 0, 0, 0 }; FLT LighthouseQuat[4] = { 1, 0, 0, 0 }; -FLT BarrelRotate[4]; //XXX TODO: Concatenate these. - FLT RunOpti( int print ); FLT RunTest( int print ); @@ -41,6 +39,17 @@ int main() FLT bestxyz[3]; memcpy( bestxyz, LighthousePos, sizeof( LighthousePos ) ); + if( 0 ) + { + LighthousePos[0] = .0531311; + LighthousePos[1] = 1.2911; + LighthousePos[2] = 2.902; + RunOpti(1); + FLT ft = RunTest(1); + printf( "Final RMS: %f\n", ft ); + return 0; + } + //STAGE1 1: Detemine vectoral position from lighthouse to target. Does not determine lighthouse-target distance. //This also is constantly optimizing the lighthouse quaternion for optimal spotting. FLT fullrange = 5; //Maximum search space for positions. (Relative to HMD) @@ -52,10 +61,14 @@ int main() FLT bestxyzrunning[3]; FLT beste = 1e20; - FLT splits = 2; - if( cycle == 0 ) splits = 25; - //XXX TODO: Switch to polar coordinate search + FLT splits = 4; + if( cycle == 0 ) splits = 24; + if( cycle == 1 ) splits = 13; + if( cycle == 2 ) splits = 10; + if( cycle == 3 ) splits = 8; + if( cycle == 4 ) splits = 5; + for( dz = 0; dz <= fullrange; dz += fullrange/splits ) for( dy = -fullrange; dy <= fullrange; dy += fullrange/splits ) for( dx = -fullrange; dx <= fullrange; dx += fullrange/splits ) @@ -70,8 +83,6 @@ int main() //Try refining the search for the best orientation several times. ft = RunOpti(0); if( ft < beste ) { beste = ft; memcpy( bestxyzrunning, LighthousePos, sizeof( LighthousePos ) ); } - - //printf( " %f %f %f %f\n", LighthousePos[0], LighthousePos[1], LighthousePos[2], ft ); } memcpy( bestxyz, bestxyzrunning, sizeof( bestxyz ) ); @@ -81,7 +92,7 @@ int main() } //Every cycle, tighten up the search area. - fullrange *= 0.6; + fullrange *= 0.25; } //Use bestxyz @@ -90,29 +101,7 @@ int main() //Optimize the quaternion for lighthouse rotation RunOpti(1); - //STAGE 2: Determine optimal distance from target - { - FLT dist = 0.1; - FLT best_dist = 0; - FLT best_err = 1e20; - for( ; dist < 10; dist+=0.01 ) - { - FLT nrmvect[3]; - normalize3d( nrmvect, bestxyz ); - scale3d( LighthousePos, nrmvect, dist ); - FLT res = RunTest( 0 ); - if( res < best_err ) - { - best_dist = dist; - best_err = res; - } - } - - //Apply the best res. - normalize3d( LighthousePos, bestxyz ); - scale3d( LighthousePos, LighthousePos, best_dist ); - printf( "Best distance: %f\n", best_dist ); - } + printf( "Best Quat: %f %f %f %f\n", PFFOUR( LighthouseQuat ) ); //Print out plane accuracies with these settings. FLT ft = RunTest(1); @@ -121,97 +110,131 @@ int main() FLT RunOpti( int print ) { - int i; + int i, p; FLT UsToTarget[3]; + FLT LastUsToTarget[3]; + FLT mux = .9; + quatsetnone( LighthouseQuat ); - { - //XXX TODO: We should use several points to determine initial rotation optimization to object. - //By using only one point the "best" we could be rotating somewhere wrong. We do use - //several points for the rotate-about-this-vector rotation in stage 2. + int first = 1, second = 0; - //Find out where our ray shoots forth from. - FLT ax = hmd_point_angles[best_hmd_target*2+0]; - FLT ay = hmd_point_angles[best_hmd_target*2+1]; + //First check to see if this is a valid viewpoint. - //NOTE: Inputs may never be output with cross product. - //Create a fictitious normalized ray. Imagine the lighthouse is pointed - //straight in the +z direction, this is the lighthouse ray to the point. - FLT RayShootOut[3] = { sin(ax), sin(ay), 0 }; - RayShootOut[2] = sqrt( 1 - (RayShootOut[0]*RayShootOut[0] + RayShootOut[1]*RayShootOut[1]) ); - - //Find a ray from us to the target point. - sub3d( UsToTarget, &hmd_points[best_hmd_target*3], LighthousePos ); - normalize3d( UsToTarget, UsToTarget ); - - FLT AxisToRotate[3]; - cross3d( AxisToRotate, RayShootOut, UsToTarget ); - //Rotate the lighthouse around this axis to point at the HMD. - - FLT RotateAmount = -acos( dot3d( RayShootOut, UsToTarget ) ); //XXX TODO How to determine if negative. - quatfromaxisangle( LighthouseQuat, AxisToRotate, RotateAmount ); //Tested, working! + for( p = 0; p < 32; p++ ) + { + if( hmd_point_counts[p*2+0] < MIN_HITS_FOR_VALID || hmd_point_counts[p*2+1] < MIN_HITS_FOR_VALID ) continue; + FLT me_to_dot[3]; + sub3d( me_to_dot, LighthousePos, &hmd_points[p*3] ); + float dot = dot3d( &hmd_norms[p*3], me_to_dot ); + if( dot < -.01 ) { return 1000; } } - //Now our lighthouse's ray is pointed at the HMD's dot, but, we need to - //rotate the lighthouse such that it is oriented optimally. We do this - //by finding what the optimal rotation aroud our face would be for all - //remaining points. - FLT rotate_radians = 0; - int points_found_to_rotate = 0; + int iters = 6; - float rots[PTS]; - for( i = 0; i < PTS; i++ ) + for( i = 0; i < iters; i++ ) { - if( i == best_hmd_target ) continue; - int xhits = hmd_point_counts[i*2+0]; - int yhits = hmd_point_counts[i*2+1]; - int xyhits = (xhits Date: Fri, 16 Dec 2016 00:41:28 -0500 Subject: Remove dependency on Xinerama Improve camfinder a little Add data_recorder.c Closes #1 making libsurvive much more pluggable. --- tools/planetest2/camfind.c | 27 ++++++--------------------- 1 file changed, 6 insertions(+), 21 deletions(-) (limited to 'tools/planetest2') diff --git a/tools/planetest2/camfind.c b/tools/planetest2/camfind.c index 6caee1a..c987e46 100644 --- a/tools/planetest2/camfind.c +++ b/tools/planetest2/camfind.c @@ -5,7 +5,7 @@ #include #define PTS 32 -#define MAX_CHECKS 20000 +#define MAX_CHECKS 30000 #define MIN_HITS_FOR_VALID 10 FLT hmd_points[PTS*3]; @@ -28,7 +28,7 @@ int main() int i; //Load either 'L' (LH1) or 'R' (LH2) data. - if( LoadData( 'R' ) ) return 5; + if( LoadData( 'L' ) ) return 5; int opti = 0; int cycle = 0; @@ -39,17 +39,6 @@ int main() FLT bestxyz[3]; memcpy( bestxyz, LighthousePos, sizeof( LighthousePos ) ); - if( 0 ) - { - LighthousePos[0] = .0531311; - LighthousePos[1] = 1.2911; - LighthousePos[2] = 2.902; - RunOpti(1); - FLT ft = RunTest(1); - printf( "Final RMS: %f\n", ft ); - return 0; - } - //STAGE1 1: Detemine vectoral position from lighthouse to target. Does not determine lighthouse-target distance. //This also is constantly optimizing the lighthouse quaternion for optimal spotting. FLT fullrange = 5; //Maximum search space for positions. (Relative to HMD) @@ -231,7 +220,7 @@ FLT RunOpti( int print ) cross3d( xproduct, UsToTarget, RayShootOut ); FLT dist = magnitude3d( xproduct ); errorsq += dist*dist; - if( print ) printf( "%f (%d) ", dist, p ); + if( print ) printf( "%f (%d(%d/%d))\n", dist, p, hmd_point_counts[p*2+0], hmd_point_counts[p*2+1] ); } if( print ) printf( " = %f\n", sqrt( errorsq ) ); return sqrt(errorsq); @@ -270,11 +259,6 @@ FLT RunTest( int print ) //plane_normal is our normal / LighthousePos is our point. FLT w0[] = { hmd_points[pt*3+0], hmd_points[pt*3+1], hmd_points[pt*3+2] }; - -//May be able to remove this. -// FLT w0[] = { hmd_points[pt*3+0], hmd_points[pt*3+2],-hmd_points[pt*3+1] }; //XXX WRONG Why does this produce the right answers? - - //FLT w0[] = { 0, 0, 0 }; FLT d = -(plane_normal[0] * LighthousePos[0] + plane_normal[1] * LighthousePos[1] + plane_normal[2] * LighthousePos[2]); FLT D = plane_normal[0] * w0[0] + plane_normal[1] * w0[1] + plane_normal[2] * w0[2] + d; //Point line distance assuming ||normal|| = 1. @@ -291,8 +275,9 @@ FLT RunTest( int print ) if( print ) { int p; - printf( "Imagespace comparison:\n" ); + printf( "POS: %f %f %f %f\n", PFFOUR(LighthousePos ) ); printf( "QUAT: %f %f %f %f\n", PFFOUR(LighthouseQuat ) ); + printf( "Imagespace comparison:\n" ); for( p = 0; p < 32; p++ ) { if( hmd_point_counts[p*2+0] < MIN_HITS_FOR_VALID || hmd_point_counts[p*2+1] < MIN_HITS_FOR_VALID ) continue; @@ -381,7 +366,7 @@ int LoadData( char Camera ) int xck = 0; - f = fopen( "third_test_with_time_lengths.csv", "r" ); + f = fopen( "testfive.csv", "r" ); if( !f ) { fprintf( stderr, "Error: can't open two lighthouses test data.\n" ); return -11; } while( !feof(f) && !ferror(f) ) { -- cgit v1.2.3