Skip to content

Commit f50258c

Browse files
committed
fixes on the pose computation between the worlds. Helps the code base be stable. also fixed some asserts in debug mode
1 parent 39c5533 commit f50258c

3 files changed

Lines changed: 71 additions & 11 deletions

File tree

src/NodeDataManager.cpp

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,12 +469,14 @@ bool NodeDataManager::saveAsJSON( const string& base_path )
469469
json node;
470470
node["timestamp"] = getNodeTimestamp(i).toSec();
471471
node["idx"] = i;
472+
node["world_id"] = which_world_is_this( getNodeTimestamp(i) );
472473

473474
Matrix4d wTc;
474475
getNodePose(i, wTc );
475476
std::stringstream ss;
476477
ss << wTc.format(CSVFormat);
477478
node["wTc"] = ss.str();
479+
node["wTc_pretty"] = PoseManipUtils::prettyprintMatrix4d(wTc);
478480

479481
Matrix<double,6,6> cov;
480482
std::stringstream ss2;
@@ -503,11 +505,22 @@ bool NodeDataManager::saveAsJSON( const string& base_path )
503505
edge["timestamp0"] = getNodeTimestamp(p.first).toSec();
504506
edge["timestamp1"] = getNodeTimestamp(p.second).toSec();
505507

508+
edge["world0_id"] = which_world_is_this( getNodeTimestamp(p.first) );
509+
edge["world1_id"] = which_world_is_this( getNodeTimestamp(p.second) );
510+
if( edge["world0_id"] < 0 || edge["world1_id"] < 0 )
511+
edge["code"] = -1;
512+
else if( edge["world0_id"] == edge["world1_id"] ) {
513+
edge["code"] = 1;
514+
} else {
515+
edge["code"] = 2;
516+
}
517+
506518

507519
const Matrix4d b_T_a = getEdgePose(i);
508520
std::stringstream ss;
509521
ss << b_T_a.format(CSVFormat);
510522
edge["b_T_a"] = ss.str();
523+
edge["b_T_a_pretty"] = PoseManipUtils::prettyprintMatrix4d(b_T_a);
511524

512525
edge["weight"] = getEdgeWeight( i );
513526
edge["description"] = getEdgeDescriptionString(i);
@@ -518,6 +531,35 @@ bool NodeDataManager::saveAsJSON( const string& base_path )
518531

519532
}
520533

534+
// World Info
535+
json all_world;
536+
all_info["meta_data"]["n_worlds"] = n_worlds();
537+
for( int i=0 ; i<n_worlds() ; i++ ) {
538+
json xworld;
539+
xworld["id"] = i;
540+
xworld["nodeidx_of_world_i_started"] = nodeidx_of_world_i_started( i );
541+
xworld["nodeidx_of_world_i_ended"] = nodeidx_of_world_i_ended( i );
542+
543+
all_world.push_back( xworld );
544+
}
545+
all_info[ "world_info"] = all_world;
546+
547+
// Kidnap Info
548+
json all_kidnaps;
549+
all_info["meta_data"]["n_worlds"] = n_kidnaps();
550+
for( int i=0 ; i<n_kidnaps() ; i++ ) {
551+
json kidnap;
552+
kidnap["idx"] = i;
553+
kidnap["stamp_of_kidnap_i_started"] = stamp_of_kidnap_i_started(i).toSec();
554+
kidnap["stamp_of_kidnap_i_ended"] = stamp_of_kidnap_i_ended(i).toSec();
555+
556+
all_kidnaps.push_back( kidnap );
557+
}
558+
all_info[ "kidnap_info"] = all_kidnaps;
559+
all_info["disjoint_set_status"] = getWorldsConstPtr()->disjoint_set_status();
560+
561+
562+
521563

522564
// Save file
523565
cout << TermColor::GREEN() << "[NodeDataManager::saveAsJSON]\n" << all_info["meta_data"] << endl;
@@ -695,6 +737,8 @@ void NodeDataManager::rcvd_kidnap_indicator_callback( const std_msgs::HeaderCons
695737
}
696738

697739
ROS_ERROR( "[posegraph solver NodeDataManager::rcvd_kidnap_indicator_callback] rcvd_header is something other than `kidnapped` or `unkidnapped`. This should not be happening and is a fatal error.");
740+
exit(2);
741+
698742
}
699743

700744

src/PoseGraphSLAM.cpp

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1369,8 +1369,8 @@ bool PoseGraphSLAM::saveAsJSON(const string base_path)
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
@@ -1570,37 +1570,52 @@ void PoseGraphSLAM::reinit_ceres_problem_onnewloopedge_optimize6DOF()
15701570

15711571
)
15721572
// compute the relative transforms between the 2 worlds
1573-
Matrix4d wa_T_a = this->getNodePose( _a );
1574-
Matrix4d wb_T_b = this->getNodePose( _b );
1573+
Matrix4d wa_T_a = manager->getNodePose( _a );
1574+
Matrix4d wb_T_b = manager->getNodePose( _b );
15751575
Matrix4d b_T_a_observed = manager->getEdgePose(e);
15761576

15771577
Matrix4d wb_T_a = wb_T_b * b_T_a_observed;
15781578
Matrix4d wb_T_wa = wb_T_a * wa_T_a.inverse();
15791579
__reinit_loopedge_cout(
15801580
cout << "I just computed the rel pose between 2 worlds, wb_T_wa=" << TermColor::iBLUE() << PoseManipUtils::prettyprintMatrix4d(wb_T_wa) << TermColor::RESET() << endl;
15811581
)
1582+
// Done...!
15821583

1584+
1585+
// The following bit of code, records the setID states before `setPoseBetweenWorlds` and after `setPoseBetweenWorlds`
1586+
// This is done so that we know which world's base changed. This is used later to initialize/reinitialize the guesses for optimization
1587+
1588+
//---- get setID (before)
15831589
std::map<int,int> mipmap_before_union, mipmap_after_union;
15841590
__reinit_loopedge_cout(
15851591
cout << "CURRENT STATUS OF WORLDS (disjoint set) before:\n";
1586-
15871592
manager->getWorldsPtr()->print_summary();
15881593
)
15891594
manager->getWorldsPtr()->getWorld2SetIDMap( mipmap_before_union );
15901595

1596+
1597+
1598+
//---- setPoseBetweenWorlds()
15911599
__reinit_loopedge_cout(
15921600
cout << "setting var rel_pose_between_worlds__wb_T_wa[ " << __b_world_is << "," << __a_world_is << " ] = " << PoseManipUtils::prettyprintMatrix4d(wb_T_wa) << endl;
15931601
)
15941602
string info_string = "this pose computed from edge "+ std::to_string(_a) + " <--> " + std::to_string(_b);
15951603
// THIS IS THE ONLY PLACE WHERE THE 2 SETS CAN MERGE AND THE SETID OF THE WORLDS CAN CHANGE.
15961604
manager->getWorldsPtr()->setPoseBetweenWorlds( __b_world_is, __a_world_is, wb_T_wa, info_string );
15971605

1606+
1607+
1608+
1609+
//---- get setID (after)
15981610
__reinit_loopedge_cout(
15991611
cout << "CURRENT STATUS OF WORLDS (disjoint set) after:\n";
16001612
manager->getWorldsPtr()->print_summary();
16011613
)
16021614
manager->getWorldsPtr()->getWorld2SetIDMap( mipmap_after_union );
16031615

1616+
1617+
1618+
//---- findout the changes from `mipmap_before_union` to `mipmap_after_union`
16041619
__reinit_loopedge_cout(
16051620
cout << TermColor::iWHITE();
16061621
cout << "Changes in the setID of the worlds\n";
@@ -1889,13 +1904,13 @@ void PoseGraphSLAM::reinit_ceres_problem_onnewloopedge_optimize6DOF()
18891904

18901905
// Matrix4d ww_start_pose = manager->getNodePose(ww_start);
18911906
// Functionally similar to marking it as constant
1892-
double regularization_weight = max( 1.1, log( 1+ww_end - ww_start )/2. );
1907+
double regularization_weight = max( 2.1, log( 1+ww_end - ww_start )/2. );
18931908

1894-
for( int s=0; s<1 ; s++ )
1909+
for( int s=0; s<3 ; s++ )
18951910
{
18961911
__reint_node_regularization_info( cout << "s="<< s << " "; )
1897-
// Matrix4d ww_start_pose = this->getNodePose(ww_start+s);
1898-
Matrix4d ww_start_pose = manager->getNodePose(ww_start+s);
1912+
Matrix4d ww_start_pose = this->getNodePose(ww_start+s);
1913+
// Matrix4d ww_start_pose = manager->getNodePose(ww_start+s);
18991914
__reint_node_regularization_info( cout << "regularization_weight=" << regularization_weight << " ww_start_pose : " << PoseManipUtils::prettyprintMatrix4d( ww_start_pose ) << endl; )
19001915
ceres::CostFunction * regularixa_cost = NodePoseRegularization::Create( ww_start_pose, regularization_weight );
19011916
ceres::ResidualBlockId resi_id = reint_problem.AddResidualBlock( regularixa_cost, NULL, get_raw_ptr_to_opt_variable_q(ww_start+s), get_raw_ptr_to_opt_variable_t(ww_start+s) );

src/keyframe_pose_graph_slam_node.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -713,6 +713,9 @@ int main( int argc, char ** argv)
713713
th_slam.join();
714714

715715

716+
717+
#define __LOGGING__ 1 // make this 1 to enable logging. 0 to disable logging. rememeber to catkin_make after this change
718+
#if __LOGGING__
716719
///// Save Pose Graph for Debugging
717720
const string DATA_PATH = "/Bulk_Data/_tmp_posegraph/";
718721

@@ -728,8 +731,6 @@ int main( int argc, char ** argv)
728731
std::system( cmd_mkdir.c_str() );
729732

730733

731-
#define __LOGGING__ 1 // make this 1 to enable logging. 0 to disable logging. rememeber to catkin_make after this change
732-
#if __LOGGING__
733734
// save
734735
// manager->saveForDebug( DATA_PATH );
735736
manager->saveAsJSON( DATA_PATH );

0 commit comments

Comments
 (0)