Skip to content

Commit 9e7e68f

Browse files
committed
handling of some corner cases and World info function in datamanager
1 parent f50258c commit 9e7e68f

5 files changed

Lines changed: 185 additions & 17 deletions

File tree

CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ find_package(OpenCV 3 REQUIRED)
2626

2727

2828

29-
set(CMAKE_BUILD_TYPE "Release")
30-
#set(CMAKE_BUILD_TYPE Debug)
29+
#set(CMAKE_BUILD_TYPE "Release")
30+
set(CMAKE_BUILD_TYPE Debug)
3131
#set(CMAKE_BUILD_TYPE RelWithDebInfo)
3232
set( CMAKE_CXX_FLAGS "-fpermissive -std=c++11 -O3" )
3333
#-DEIGEN_USE_MKL_ALL")

src/NodeDataManager.cpp

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -996,3 +996,108 @@ int NodeDataManager::n_worlds() const
996996
// return kidnap_
997997
return kidnap_ends.size() + 1;
998998
}
999+
1000+
1001+
1002+
1003+
void NodeDataManager::print_worlds_info( int verbosity )
1004+
{
1005+
1006+
bool start_ends_u_of_worlds=false, rel_pose_between_worlds=false, kidnap_info=false, which_world_each_node_belong_to=false ;
1007+
1008+
switch( verbosity )
1009+
{
1010+
case 0:
1011+
start_ends_u_of_worlds=true;
1012+
rel_pose_between_worlds=false;
1013+
kidnap_info=false;
1014+
which_world_each_node_belong_to=false;
1015+
break;
1016+
case 1:
1017+
start_ends_u_of_worlds=true;
1018+
rel_pose_between_worlds=true;
1019+
kidnap_info=true;
1020+
which_world_each_node_belong_to=false;
1021+
break;
1022+
case 2:
1023+
start_ends_u_of_worlds=true;
1024+
rel_pose_between_worlds=true;
1025+
kidnap_info=true;
1026+
which_world_each_node_belong_to=true;
1027+
break;
1028+
default:
1029+
cout << "[NodeDataManager::print_worlds_info] ERROR invalid verbosity.\n";
1030+
exit(10);
1031+
}
1032+
1033+
cout << "---------------------!!!!! NodeDataManager::print_worlds_info verbosity = " << verbosity << "----------------\n";
1034+
1035+
if( start_ends_u_of_worlds ) {
1036+
//// Info on worlds
1037+
cout << TermColor::YELLOW() ;
1038+
cout << "Info on worlds start and end times from NodeDataManager\n";
1039+
cout << "#worlds = " << this->n_worlds() << "\t";
1040+
cout << "\tWorlds::n_worlds = " << this->getWorldsConstPtr()->n_worlds() << "\t";
1041+
cout << "\tWorlds::n_sets = " << this->getWorldsConstPtr()->n_sets() << "\t";
1042+
cout << endl;
1043+
for( int i=0 ; i<this->n_worlds() ; i++ ) {
1044+
cout << "world#" << std::setw(2) << i;
1045+
cout << " start_u=" << std::setw(5) << this->nodeidx_of_world_i_started(i);
1046+
cout << " end_u=" << std::setw(5) << this->nodeidx_of_world_i_ended(i);
1047+
// cout << " startstamp=" << manager->getNodeTimestamp( manager->nodeidx_of_world_i_started(i) );
1048+
// cout << " endstamp =" << manager->getNodeTimestamp( manager->nodeidx_of_world_i_ended(i) );
1049+
cout << " (" << this->getNodeTimestamp( this->nodeidx_of_world_i_started(i) );
1050+
cout << " to " << this->getNodeTimestamp( this->nodeidx_of_world_i_ended(i) ) << ")";
1051+
cout << " sec=" << this->getNodeTimestamp( this->nodeidx_of_world_i_ended(i) ) - this->getNodeTimestamp( this->nodeidx_of_world_i_started(i) );
1052+
cout << " setID=" << std::setw(2) << this->getWorldsConstPtr()->find_setID_of_world_i( i );
1053+
cout << endl;
1054+
}
1055+
cout << TermColor::RESET() << endl;
1056+
}
1057+
1058+
if( rel_pose_between_worlds ) {
1059+
//// Relative transforms between worlds
1060+
this->getWorldsPtr()->print_summary(2);
1061+
} else {
1062+
this->getWorldsPtr()->print_summary(0);
1063+
}
1064+
1065+
1066+
if( kidnap_info ) {
1067+
//// When was I kidnaped
1068+
cout << TermColor::BLUE();
1069+
cout << "Info on Kidnap starts and ends\n";
1070+
cout << "There were a total of " << this->n_kidnaps() << " kidnaps\n";
1071+
for( int i=0 ; i<this->n_kidnaps() ; i++ )
1072+
{
1073+
cout << "kidnap#" << std::setw(2) << i ;
1074+
cout << "\tstart=" << this->stamp_of_kidnap_i_started(i);
1075+
cout << "\tends =" << this->stamp_of_kidnap_i_ended(i);
1076+
cout << "\tduration=" << this->stamp_of_kidnap_i_ended(i) - this->stamp_of_kidnap_i_started(i) ;
1077+
cout << endl;
1078+
}
1079+
1080+
cout << " manager->last_kidnap_started() : " << this->last_kidnap_started() << endl;
1081+
cout << " manager->last_kidnap_ended() : " << this->last_kidnap_ended() << endl;
1082+
cout << TermColor::RESET();
1083+
}
1084+
1085+
1086+
1087+
if( which_world_each_node_belong_to ) {
1088+
//// Which world each of the nodes belong to
1089+
cout << "Info on all the Nodes\n";
1090+
int r=0;
1091+
for( int r=0 ; r<this->getNodeLen() ; r++ )
1092+
{
1093+
ros::Time _t = this->getNodeTimestamp(r);
1094+
cout << "node#" << std::setw(5) << r << " t=" << _t << " world=" << std::setw(3) << this->which_world_is_this( _t ) ;
1095+
1096+
if( r%3 == 0 )
1097+
cout << endl;
1098+
else
1099+
cout << "\t\t";
1100+
}
1101+
cout << endl;
1102+
}
1103+
}

src/NodeDataManager.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ class NodeDataManager
166166
const Worlds * getWorldsConstPtr() const { return (const Worlds*) worlds_handle_raw_ptr; }
167167
// int worlds__n_worlds() const { return worlds_handle.n_worlds(); }
168168

169+
void print_worlds_info( int verbosity );
169170

170171
private:
171172
mutable std::mutex mutex_kidnap;

src/PoseGraphSLAM.cpp

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1357,12 +1357,12 @@ bool PoseGraphSLAM::saveAsJSON(const string base_path)
13571357
// #define __reint_odom_cout(msg) msg;
13581358
#define __reint_odom_cout(msg) ;
13591359

1360-
// #define __reinit_loopedge_cout( msg ) msg;
1361-
#define __reinit_loopedge_cout( msg ) ;
1360+
#define __reinit_loopedge_cout( msg ) msg;
1361+
// #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
@@ -1374,8 +1374,9 @@ bool PoseGraphSLAM::saveAsJSON(const string base_path)
13741374

13751375

13761376
// Print Ceres Brief Report and other info on solving
1377-
// #define __reint_ceres_solve_info( msg ) msg;
1378-
#define __reint_ceres_solve_info( msg ) ;
1377+
#define __reint_ceres_solve_info( msg ) msg;
1378+
// #define __reint_ceres_solve_info( msg ) ;
1379+
13791380

13801381

13811382
// This thread wakes up when there are new loopedges. This flag controls the printing on trigger.
@@ -1893,6 +1894,10 @@ void PoseGraphSLAM::reinit_ceres_problem_onnewloopedge_optimize6DOF()
18931894
int ww_setid = manager->getWorldsConstPtr()->find_setID_of_world_i(ww);
18941895
int ww_start = manager->nodeidx_of_world_i_started( ww );
18951896
int ww_end = manager->nodeidx_of_world_i_ended( ww );
1897+
if( ww_start < 0 ) {
1898+
__reint_node_regularization_info( cout << TermColor::RED() << "ignore this world since ww_start is negative. Shouldnt be happening but..:(\n" );
1899+
continue;
1900+
}
18961901
__reint_node_regularization_info( cout << TermColor::CYAN() << "&&&&&&&&&&&&world#" << ww << " is in setID=" << ww_setid << " with ww_start=" << ww_start << " ww_end=" << ww_end << TermColor::RESET() << endl; )
18971902
if( (ww_setid >= 0 && ww_setid==ww) )
18981903
{
@@ -1904,7 +1909,7 @@ void PoseGraphSLAM::reinit_ceres_problem_onnewloopedge_optimize6DOF()
19041909

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

19091914
for( int s=0; s<3 ; s++ )
19101915
{

src/keyframe_pose_graph_slam_node.cpp

Lines changed: 65 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ void periodic_publish_odoms( const NodeDataManager * manager, const VizPoseGraph
9797
break;
9898

9999
cout << "[periodic_publish_odoms] sleep() for 100milis. This is done just as a precaution because next world may not be immediately available after unkidnap. It takes usually upto 500milisec for vins to reinitialize. This warning is not very critial." << endl;
100-
std::this_thread::sleep_for (std::chrono::milliseconds(100));
100+
std::this_thread::sleep_for (std::chrono::milliseconds(200));
101101
__i__start = manager->nodeidx_of_world_i_started(manager->n_worlds()-1); //0;
102102
}
103103

@@ -364,13 +364,32 @@ struct opt_traj_publisher_options
364364
int line_color_style=10;
365365
};
366366

367+
// #define __opt_traj_publisher_colored_by_world___print_on_file_exist
368+
369+
#ifdef __opt_traj_publisher_colored_by_world___print_on_file_exist
370+
#include <sys/stat.h>
371+
#include <unistd.h>
372+
#include <string>
373+
#include <fstream>
374+
inline bool exists_test3 (const std::string& name) {
375+
struct stat buffer;
376+
return (stat (name.c_str(), &buffer) == 0);
377+
}
378+
#endif
379+
367380
void opt_traj_publisher_colored_by_world( const NodeDataManager * manager, const PoseGraphSLAM * slam, const VizPoseGraph * viz, const opt_traj_publisher_options& options )
368381
{
382+
#ifdef __opt_traj_publisher_colored_by_world___print_on_file_exist
383+
bool enable_cout = false;
384+
#endif
385+
386+
369387

370388
ros::Rate loop_rate(20);
371389
// ros::Rate loop_rate(5);
372390
map<int, vector<Matrix4d> > jmb;
373391
vector< Vector3d > lbm; // a corrected poses. Same index as the node. These are used for loopedges.
392+
bool published_axis = true;
374393
while( ros::ok() )
375394
{
376395
// cout << "[opt_traj_publisher_colored_by_world]---\n";
@@ -392,8 +411,19 @@ void opt_traj_publisher_colored_by_world( const NodeDataManager * manager, const
392411
if( ____solvedUntil_worldid < 0 ) { /*____solvedUntil_worldid = -____solvedUntil_worldid - 1;*/ ____solvedUntil_worldid_is_neg=true; }
393412
// cerr << "\t[opt_traj_publisher_colored_by_world] slam->solvedUntil=" << ____solvedUntil << " ____solvedUntil_worldid" << ____solvedUntil_worldid << endl;
394413

414+
#ifdef __opt_traj_publisher_colored_by_world___print_on_file_exist
415+
if( exists_test3( "/app/xxx") )
416+
enable_cout = true;
417+
else
418+
enable_cout = false;
419+
420+
if( enable_cout ) {
395421
// cout << "[opt_traj_publisher_colored_by_world] i=0" << " i<"<<manager->getNodeLen() ;
396-
// cout << "____solvedUntil=" << ____solvedUntil << " ____solvedUntil_worldid=" << ____solvedUntil_worldid << endl;
422+
cout << "____solvedUntil=" << ____solvedUntil << " ____solvedUntil_worldid=" << ____solvedUntil_worldid << endl;
423+
}
424+
#endif
425+
426+
397427
for( int i=0 ; i<manager->getNodeLen() ; i++ )
398428
{
399429
int world_id = manager->which_world_is_this( manager->getNodeTimestamp(i) );
@@ -449,7 +479,11 @@ void opt_traj_publisher_colored_by_world( const NodeDataManager * manager, const
449479
jmb[ world_id ].push_back( w_T_c );
450480
lbm.push_back( w_T_c.col(3).topRows(3) );
451481
latest_pose_worldid = world_id;
452-
// cout << " (from_slam_or_from_odom=" << from_slam_or_from_odom << " w_T_c=" << PoseManipUtils::prettyprintMatrix4d( w_T_c ) << endl;
482+
483+
#ifdef __opt_traj_publisher_colored_by_world___print_on_file_exist
484+
if( enable_cout )
485+
cout << i << ":" << world_id << " (from_slam_or_from_odom=" << from_slam_or_from_odom << " w_T_c=" << PoseManipUtils::prettyprintMatrix4d( w_T_c ) << endl;
486+
#endif
453487

454488
}
455489

@@ -468,11 +502,22 @@ void opt_traj_publisher_colored_by_world( const NodeDataManager * manager, const
468502
if( world_id >= 0 && ____solvedUntil_worldid == world_id ) {
469503
last_idx = ____solvedUntil;}
470504
else if( world_id >=0 && ____solvedUntil_worldid != world_id ) {
471-
w_TM_i = manager->getNodePose( i );}
505+
w_TM_i = manager->getNodePose( i );
506+
}
472507
else if( world_id < 0 ) {
473-
// last_idx = ____solvedUntil;
474-
last_idx = manager->nodeidx_of_world_i_ended( -world_id - 1 );
475-
// cout << "last_idx=" << last_idx << endl;
508+
// this is the kidnaped node
509+
last_idx = manager->nodeidx_of_world_i_ended( -world_id - 1 ); // only this in working code
510+
511+
if( !( last_idx >= 0 && last_idx < manager->getNodeLen() && i >=0 && i<manager->getNodeLen()) ) {
512+
cout << "ERROR. last_idx=" << last_idx << endl;
513+
manager->getWorldsConstPtr()->print_summary( 2);
514+
manager->print_worlds_info(2);
515+
assert( last_idx >= 0 && last_idx < manager->getNodeLen() && i >=0 && i<manager->getNodeLen() );
516+
}
517+
518+
w_TM_i = *(jmb[ -world_id-1 ].rbegin()) * ( manager->getNodePose( last_idx ).inverse() * manager->getNodePose( i ) ) ;
519+
last_idx = -1;
520+
476521
} else {
477522
cout << "\nopt_traj_publisher_colored_by_world impossivle\n";
478523
exit(2);
@@ -501,7 +546,11 @@ void opt_traj_publisher_colored_by_world( const NodeDataManager * manager, const
501546
jmb[ world_id ].push_back( w_TM_i );
502547
lbm.push_back( w_TM_i.col(3).topRows(3) );
503548
latest_pose_worldid = world_id;
504-
// cout << " w_TM_i=" << PoseManipUtils::prettyprintMatrix4d( w_TM_i ) << " last_idx="<< last_idx << endl;
549+
550+
#ifdef __opt_traj_publisher_colored_by_world___print_on_file_exist
551+
if( enable_cout )
552+
cout << i << ":" << world_id << " w_TM_i=" << PoseManipUtils::prettyprintMatrix4d( w_TM_i ) << " last_idx="<< last_idx << endl;
553+
#endif
505554
}
506555

507556

@@ -598,6 +647,14 @@ void opt_traj_publisher_colored_by_world( const NodeDataManager * manager, const
598647
viz->publishThisVisualMarker( linelist_marker );
599648

600649

650+
if( published_axis || rand() % 100 == 0 ) {
651+
Matrix4d _axis_pose = Matrix4d::Identity();
652+
// odm_axis_pose(0,3) += offset_x; odm_axis_pose(1,3) += offset_y; odm_axis_pose(2,3) += offset_z;
653+
viz->publishXYZAxis( _axis_pose, "opt_traj_axis", 0 );
654+
published_axis = false;
655+
}
656+
657+
601658
// book keeping
602659
// cerr << "\nSLEEP\n";
603660
loop_rate.sleep();

0 commit comments

Comments
 (0)