Skip to content

Commit 7358611

Browse files
committed
viz kidnap bug fix
1 parent e645359 commit 7358611

2 files changed

Lines changed: 47 additions & 30 deletions

File tree

src/PoseGraphSLAM.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1361,16 +1361,16 @@ bool PoseGraphSLAM::saveAsJSON(const string base_path)
13611361
#define __reinit_loopedge_cout( msg ) ;
13621362

13631363

1364-
#define __reint_gueses_short_info(msg) msg;
1365-
// #define __reint_gueses_short_info(msg) ;
1364+
// #define __reint_gueses_short_info(msg) msg;
1365+
#define __reint_gueses_short_info(msg) ;
13661366

13671367

13681368
// Print info on node regularization. I use node regularization to set
13691369
// the start of each worlds as constant. You can tune this as need be.
13701370
// The reason I do not use ceres::SetParameterBlockConstant() is that it cannot be
13711371
// set to not constant which hinders when the initial guess moves.
1372-
#define __reint_node_regularization_info( msg ) msg;
1373-
// #define __reint_node_regularization_info( msg ) ;
1372+
// #define __reint_node_regularization_info( msg ) msg;
1373+
#define __reint_node_regularization_info( msg ) ;
13741374

13751375

13761376
// Print Ceres Brief Report and other info on solving
@@ -1889,7 +1889,7 @@ void PoseGraphSLAM::reinit_ceres_problem_onnewloopedge_optimize6DOF()
18891889
// Functionally similar to marking it as constant
18901890
double regularization_weight = log( 1+ww_end - ww_start )/2.;
18911891

1892-
for( int s=0; s<2 ; s++ )
1892+
for( int s=0; s<1 ; s++ )
18931893
{
18941894
__reint_node_regularization_info( cout << "s="<< s << " "; )
18951895
Matrix4d ww_start_pose = this->getNodePose(ww_start+s);

src/keyframe_pose_graph_slam_node.cpp

Lines changed: 42 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,7 @@ void opt_traj_publisher_colored_by_world( const NodeDataManager * manager, const
345345
{
346346

347347
ros::Rate loop_rate(20);
348+
// ros::Rate loop_rate(5);
348349
map<int, vector<Matrix4d> > jmb;
349350
vector< Vector3d > lbm; // a corrected poses. Same index as the node. These are used for loopedges.
350351
while( ros::ok() )
@@ -365,31 +366,57 @@ void opt_traj_publisher_colored_by_world( const NodeDataManager * manager, const
365366
int ____solvedUntil = slam->solvedUntil(); //note: solvedUntil is the index until which posegraph was solved
366367
int ____solvedUntil_worldid = manager->which_world_is_this( manager->getNodeTimestamp(____solvedUntil) );
367368
bool ____solvedUntil_worldid_is_neg = false;
368-
if( ____solvedUntil_worldid < 0 ) { ____solvedUntil_worldid = -____solvedUntil_worldid - 1; ____solvedUntil_worldid_is_neg=true; }
369+
if( ____solvedUntil_worldid < 0 ) { /*____solvedUntil_worldid = -____solvedUntil_worldid - 1;*/ ____solvedUntil_worldid_is_neg=true; }
369370
// cerr << "\t[opt_traj_publisher_colored_by_world] slam->solvedUntil=" << ____solvedUntil << " ____solvedUntil_worldid" << ____solvedUntil_worldid << endl;
370371

372+
// cout << "[opt_traj_publisher_colored_by_world] i=0" << " i<"<<manager->getNodeLen() ;
373+
// cout << "____solvedUntil=" << ____solvedUntil << " ____solvedUntil_worldid=" << ____solvedUntil_worldid << endl;
371374
for( int i=0 ; i<manager->getNodeLen() ; i++ )
372375
{
373376
int world_id = manager->which_world_is_this( manager->getNodeTimestamp(i) );
377+
// cout << "i=" << i << " world#" << world_id << endl;// << " w_TM_i=" << PoseManipUtils::prettyprintMatrix4d( w_TM_i ) << endl;
374378

375379
// i>=0 and i<solvedUntil()
376380
if( i>=0 && i<= ____solvedUntil ) {
377-
Matrix4d w_T_c_optimized, w_T_c;
381+
// Matrix4d w_T_c_optimized;
382+
Matrix4d w_T_c;
378383

379384
// cerr << "world_id=" << world_id << " ";
380385
// cerr << "slam->nodePoseExists("<< i << ") " << slam->nodePoseExists(i) << " ";
381386
// cerr << "manager->nodePoseExists(" << i << ") " << manager->nodePoseExists(i ) << " \n";
382387

383388

384389
// If the optimized pose exists use that else use the odometry pose
385-
if( slam->nodePoseExists(i) ) {
386-
w_T_c = slam->getNodePose( i );
387-
// cerr << "w_T_c_optimized=" << PoseManipUtils::prettyprintMatrix4d( w_T_c ) << endl;
388-
} else {
389-
if( manager->nodePoseExists(i ) ) {
390-
w_T_c = manager->getNodePose( i );
391-
// cerr << "w_T_c=" << PoseManipUtils::prettyprintMatrix4d( w_T_c ) << endl;
390+
int from_slam_or_from_odom = -1;
391+
if( world_id >= 0 ) {
392+
if( slam->nodePoseExists(i) ) {
393+
w_T_c = slam->getNodePose( i );
394+
// cerr << "w_T_c_optimized=" << PoseManipUtils::prettyprintMatrix4d( w_T_c ) << endl;
395+
from_slam_or_from_odom = 1;
396+
} else {
397+
if( manager->nodePoseExists(i ) ) {
398+
w_T_c = manager->getNodePose( i );
399+
// cerr << "w_T_c=" << PoseManipUtils::prettyprintMatrix4d( w_T_c ) << endl;
400+
from_slam_or_from_odom = 2;
401+
}
392402
}
403+
} else {
404+
// kidnapped worlds viz, -1, -2 etc.
405+
// use the last pose and add the odometry to it
406+
// TODO
407+
from_slam_or_from_odom = 3;
408+
409+
int last_idx = manager->nodeidx_of_world_i_ended( -world_id - 1 );
410+
Matrix4d w_T_last;
411+
// if( slam->nodePoseExists(i) )
412+
// w_T_last = slam->getNodePose(last_idx );
413+
// else
414+
// w_T_last = manager->getNodePose(last_idx );
415+
w_T_last = *(jmb.at( -world_id - 1 ).rbegin());
416+
Matrix4d last_M_i = manager->getNodePose( last_idx ).inverse() * manager->getNodePose( i );
417+
w_T_c = w_T_last * last_M_i;
418+
419+
393420
}
394421

395422

@@ -399,6 +426,7 @@ void opt_traj_publisher_colored_by_world( const NodeDataManager * manager, const
399426
jmb[ world_id ].push_back( w_T_c );
400427
lbm.push_back( w_T_c.col(3).topRows(3) );
401428
latest_pose_worldid = world_id;
429+
// cout << " (from_slam_or_from_odom=" << from_slam_or_from_odom << " w_T_c=" << PoseManipUtils::prettyprintMatrix4d( w_T_c ) << endl;
402430

403431
}
404432

@@ -409,21 +437,7 @@ void opt_traj_publisher_colored_by_world( const NodeDataManager * manager, const
409437
int last_idx=-1;
410438
Matrix4d w_TM_i;
411439

412-
/*
413-
if( ____solvedUntil == 0 ) {
414-
w_TM_i = manager->getNodePose( i );
415-
} else if( world_id < 0 ) {
416-
last_idx = manager->nodeidx_of_world_i_ended( -world_id-1 );
417-
} else if(world_id == ____solvedUntil_worldid && ____solvedUntil_worldid_is_neg==false) {
418-
last_idx = ____solvedUntil;
419-
}
420-
else if(world_id == ____solvedUntil_worldid && ____solvedUntil_worldid_is_neg==true) {
421-
last_idx = ____solvedUntil;
422-
} else {
423-
// last_idx = manager->nodeidx_of_world_i_started( world_id );
424-
w_TM_i = manager->getNodePose( i );
425-
}
426-
*/
440+
427441

428442
if( ____solvedUntil == 0 ) {
429443
w_TM_i = manager->getNodePose( i );
@@ -437,7 +451,7 @@ void opt_traj_publisher_colored_by_world( const NodeDataManager * manager, const
437451
last_idx = manager->nodeidx_of_world_i_ended( -world_id - 1 );
438452
// cout << "last_idx=" << last_idx << endl;
439453
} else {
440-
cout << "opt_traj_publisher_colored_by_world impossivle";
454+
cout << "\nopt_traj_publisher_colored_by_world impossivle\n";
441455
exit(2);
442456
}
443457

@@ -459,9 +473,12 @@ void opt_traj_publisher_colored_by_world( const NodeDataManager * manager, const
459473
if( jmb.count( world_id ) == 0 )
460474
jmb[ world_id ] = vector<Matrix4d>();
461475

476+
477+
462478
jmb[ world_id ].push_back( w_TM_i );
463479
lbm.push_back( w_TM_i.col(3).topRows(3) );
464480
latest_pose_worldid = world_id;
481+
// cout << " w_TM_i=" << PoseManipUtils::prettyprintMatrix4d( w_TM_i ) << " last_idx="<< last_idx << endl;
465482
}
466483

467484

0 commit comments

Comments
 (0)