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') 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