Skip to content

Commit 39c5533

Browse files
committed
fixed some more corner cases in node_idx_of_worldi_starts function and some more viz related corner cases
1 parent ecdfc1e commit 39c5533

6 files changed

Lines changed: 62 additions & 16 deletions

File tree

CMakeLists.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,11 @@ find_package(Ceres REQUIRED)
2424
find_package(OpenCV 3 REQUIRED)
2525
#find_package( ZLIB REQUIRED ) # Needed for cnpy (c++ support for writing .npy and .npz files). Remove this and in target if you dont need it.
2626

27-
#set(CMAKE_BUILD_TYPE "Release")
27+
28+
29+
set(CMAKE_BUILD_TYPE "Release")
30+
#set(CMAKE_BUILD_TYPE Debug)
31+
#set(CMAKE_BUILD_TYPE RelWithDebInfo)
2832
set( CMAKE_CXX_FLAGS "-fpermissive -std=c++11 -O3" )
2933
#-DEIGEN_USE_MKL_ALL")
3034

src/NodeDataManager.cpp

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -356,10 +356,14 @@ bool NodeDataManager::getNodeTimestamp( int i, ros::Time& stamp ) const
356356
return status;
357357
}
358358

359+
360+
#define __MY_ASSERT__(condition, to_print) { if(!(condition)){ std::cerr << "ASSERT FAILED: " << #condition << " @ " << __FILE__ << " (" << __LINE__ << ")" << "msg=" << to_print << std::endl; } }
359361
const ros::Time NodeDataManager::getNodeTimestamp( int i ) const
360362
{
361363
std::lock_guard<std::mutex> lk(node_mutex);
362-
assert( i>=0 && i< node_timestamps.size() );
364+
// cout << string( "you requested timestamp at i="+to_string(i)+", but node_timestamps.size="+to_string( node_timestamps.size()) ).c_str() << endl;
365+
// assert( i>=0 && i< node_timestamps.size() && string( "you requested timestamp at i="+to_string(i)+", but node_timestamps.size="+to_string( node_timestamps.size()) ).c_str() );
366+
__MY_ASSERT__( (i>=0 && i< node_timestamps.size()), "you requested timestamp at i="+to_string(i)+", but node_timestamps.size="+to_string( node_timestamps.size()) );
363367
return node_timestamps[i];
364368
}
365369

@@ -753,6 +757,7 @@ ros::Time NodeDataManager::stamp_of_kidnap_i_started( int i ) const
753757
return kidnap_starts[i];
754758
}
755759

760+
assert( false && "[NodeDataManager::stamp_of_kidnap_i_started]no such kidnap" );
756761
__KIDNAP_START_ENDS___debug( cout << "[NodeDataManager::stamp_of_kidnap_i_started]no such kidnap" << i << " kidnap_starts.size()=" << kidnap_starts.size() << endl; )
757762
return ros::Time();
758763
}
@@ -764,6 +769,7 @@ ros::Time NodeDataManager::stamp_of_kidnap_i_ended( int i ) const
764769
return kidnap_ends[i];
765770
}
766771

772+
assert( false && "[NodeDataManager::stamp_of_kidnap_i_ended]no such kidnap" );
767773
__KIDNAP_START_ENDS___debug( cout << "[NodeDataManager::stamp_of_kidnap_i_ended]no such kidnap" << i << " kidnap_ends.size()=" << kidnap_ends.size() << endl; )
768774
return ros::Time();
769775
}
@@ -850,15 +856,16 @@ int NodeDataManager::which_world_is_this( int i ) //given the node idx, gets the
850856
}
851857
*/
852858

853-
854859
// #define __WORLD_START_ENDS___debug( msg ) msg;
855860
#define __WORLD_START_ENDS___debug( msg ) ;
861+
862+
#define __WORLD_START____errors( msg ) msg;
856863
int NodeDataManager::nodeidx_of_world_i_started( int i ) const
857864
{
858865

859866
if( i<0 )
860867
{
861-
__WORLD_START_ENDS___debug( cout << "[NodeDataManager::nodeidx_of_world_i_started] i cant be negative. no such world " << i << " exists\n"; )
868+
__WORLD_START____errors( cout << TermColor::RED() << "[NodeDataManager::nodeidx_of_world_i_started] ERROR i cant be negative. no such world " << i << " exists" << TermColor::RESET() << endl; )
862869
return -3;
863870
}
864871
if( i==0 ) {
@@ -876,7 +883,7 @@ int NodeDataManager::nodeidx_of_world_i_started( int i ) const
876883
}
877884

878885
if( i>=1 && (i-1) <n ) {
879-
__WORLD_START_ENDS___debug( cout << "[NodeDataManager::nodeidx_of_world_i_started] return nodeidx of kidnap_ends["<<i-1 <<"] as the start of world" << i << "\n"; )
886+
__WORLD_START_ENDS___debug( cout << "[NodeDataManager::nodeidx_of_world_i_started] return nodeidx of kidnap_ends["<<i-1 <<"] as the start of world" << i << "\n"; )
880887
std::lock_guard<std::mutex> lk(node_mutex);
881888

882889
int r=0;
@@ -890,10 +897,14 @@ int NodeDataManager::nodeidx_of_world_i_started( int i ) const
890897
}
891898

892899

893-
__WORLD_START_ENDS___debug( cout << "[NodeDataManager::nodeidx_of_world_i_started] no such world " << i << " exists\n"; )
900+
__WORLD_START____errors( cout << TermColor::RED() << "[NodeDataManager::nodeidx_of_world_i_started] ERROR no such world " << i << " exists" << TermColor::RESET() << endl; )
894901
return -4;
895902
}
896903

904+
905+
906+
// #define __WORLD__ENDS___error( msg ) msg;
907+
#define __WORLD__ENDS___error( msg ) ;
897908
int NodeDataManager::nodeidx_of_world_i_ended( int i ) const
898909
{
899910
// returns a large number if the world i never ended
@@ -904,12 +915,12 @@ int NodeDataManager::nodeidx_of_world_i_ended( int i ) const
904915
}
905916

906917
if( i<0 ) {
907-
__WORLD_START_ENDS___debug( cout << "[NodeDataManager::nodeidx_of_world_i_ended] i cannot be negative. no such world\n");
918+
__WORLD__ENDS___error( cout << TermColor::RED() << "[NodeDataManager::nodeidx_of_world_i_ended] ERROR i cannot be negative. no such world" << TermColor::RESET() << endl; );
908919
return -1;
909920
}
910921

911922
if( i>n_kidnap_ends ) {
912-
__WORLD_START_ENDS___debug( cout << "[NodeDataManager::nodeidx_of_world_i_ended] no such world" << i << "\n"; )
923+
__WORLD__ENDS___error( cout << TermColor::RED() << "[NodeDataManager::nodeidx_of_world_i_ended] ERROR no such world" << i << TermColor::RESET() << endl; )
913924
return -1;
914925
}
915926
else {
@@ -937,5 +948,7 @@ int NodeDataManager::nodeidx_of_world_i_ended( int i ) const
937948
int NodeDataManager::n_worlds() const
938949
{
939950
std::lock_guard<std::mutex> lk(mutex_kidnap);
951+
// if( current_kidnap_status == true )
952+
// return kidnap_
940953
return kidnap_ends.size() + 1;
941954
}

src/PoseGraphSLAM.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1656,7 +1656,9 @@ void PoseGraphSLAM::reinit_ceres_problem_onnewloopedge_optimize6DOF()
16561656

16571657
// --------------> add odometry residue : u <---> u-f
16581658
for( int f=1 ; f<5 ; f++ ){
1659-
int world_of_u_m_f = manager->which_world_is_this( manager->getNodeTimestamp(u-f) );
1659+
int world_of_u_m_f=-1;
1660+
if( u-f >= 0 )
1661+
world_of_u_m_f = manager->which_world_is_this( manager->getNodeTimestamp(u-f) );
16601662
int setID_of__world_of_u_m_f = manager->getWorldsConstPtr()->find_setID_of_world_i( world_of_u_m_f );
16611663

16621664
if( setID_of__world_of_u < 0 || setID_of__world_of_u_m_f < 0 ) {
@@ -1887,12 +1889,13 @@ void PoseGraphSLAM::reinit_ceres_problem_onnewloopedge_optimize6DOF()
18871889

18881890
// Matrix4d ww_start_pose = manager->getNodePose(ww_start);
18891891
// Functionally similar to marking it as constant
1890-
double regularization_weight = log( 1+ww_end - ww_start )/2.;
1892+
double regularization_weight = max( 1.1, log( 1+ww_end - ww_start )/2. );
18911893

18921894
for( int s=0; s<1 ; s++ )
18931895
{
18941896
__reint_node_regularization_info( cout << "s="<< s << " "; )
1895-
Matrix4d ww_start_pose = this->getNodePose(ww_start+s);
1897+
// Matrix4d ww_start_pose = this->getNodePose(ww_start+s);
1898+
Matrix4d ww_start_pose = manager->getNodePose(ww_start+s);
18961899
__reint_node_regularization_info( cout << "regularization_weight=" << regularization_weight << " ww_start_pose : " << PoseManipUtils::prettyprintMatrix4d( ww_start_pose ) << endl; )
18971900
ceres::CostFunction * regularixa_cost = NodePoseRegularization::Create( ww_start_pose, regularization_weight );
18981901
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) );
@@ -1953,6 +1956,8 @@ void PoseGraphSLAM::reinit_ceres_problem_onnewloopedge_optimize6DOF()
19531956
n_solve_convergences++;
19541957
}
19551958
// cout << reint_summary.FullReport() << endl;
1959+
___trigger_header( cout << TermColor::iGREEN() << "Solve() took (milli-sec) : " << eta.toc_milli() << "\n" << TermColor::RESET() ; )
1960+
19561961

19571962
__reint_ceres_solve_info(
19581963
cout << "Solve() took (milli-sec) : " << eta.toc_milli() << endl;

src/Worlds.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,8 @@ bool Worlds::setPoseBetweenWorlds( int m, int n, const Matrix4d m_T_n, const str
161161
rel_pose_between_worlds__wb_T_wa___info_string[ make_pair(m,n) ] += ";" + info_string;
162162

163163
// union_sets()
164-
assert( disjoint_set.exist( m ) && disjoint_set.exist( n ) && "Either of m of n doesn't seem to exist in the disjoint set. m="+to_string(m)+" n="+to_string(n) );
164+
// assert( (disjoint_set.exists( m ) && disjoint_set.exists( n )) && "Either of m of n doesn't seem to exist in the disjoint set. m="+to_string(m)+" n="+to_string(n) );
165+
assert( (disjoint_set.exists( m ) && disjoint_set.exists( n )) );
165166

166167
// ideally, disjoint_set.union_sets( m, n ), but doing the min max trick to retain the id of earliest sample.
167168
disjoint_set.union_sets( max(m,n), min(m,n) );

src/keyframe_pose_graph_slam_node.cpp

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,30 @@ void periodic_publish_odoms( const NodeDataManager * manager, const VizPoseGraph
8888
jmb.clear();
8989

9090
// collect all
91+
int __i__start = manager->nodeidx_of_world_i_started(manager->n_worlds()-1); //0;
92+
//
93+
// try maximum 5 times. mili-seconds after unkidnapped the next world is not available
94+
// which causes a seg fault. This little fix will sleep for say 5ms and try again
95+
for( int _j=0 ; _j<25 ; _j++ ) {
96+
if( __i__start>=0 )
97+
break;
98+
99+
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));
101+
__i__start = manager->nodeidx_of_world_i_started(manager->n_worlds()-1); //0;
102+
}
103+
104+
// cout << "__i__start=" << __i__start << endl;
105+
91106
// for( int i=0 ; i<manager->getNodeLen() ; i++ )
92-
for( int i=manager->nodeidx_of_world_i_started(manager->n_worlds()-1) ; i<manager->getNodeLen() ; i++ )
107+
for( int i=__i__start ; i<manager->getNodeLen() ; i++ )
93108
{
109+
if( i==-3 || i==-4 ) {
110+
cout << "break" << endl;
111+
break;
112+
}
113+
if( i< 0 )
114+
cout << TermColor::iCYAN() << "manager->getNodeTimestamp(" << i << ")" << TermColor::RESET() << endl;
94115
int world_id = manager->which_world_is_this( manager->getNodeTimestamp(i) );
95116
if( manager->nodePoseExists(i ) ) {
96117
auto w_T_c = manager->getNodePose( i );
@@ -103,6 +124,7 @@ void periodic_publish_odoms( const NodeDataManager * manager, const VizPoseGraph
103124
jmb[ world_id ].push_back( w_T_c );
104125
}
105126
}
127+
// cout << "Done collecting\n";
106128

107129

108130

@@ -142,7 +164,8 @@ void periodic_publish_odoms( const NodeDataManager * manager, const VizPoseGraph
142164
if( it->first > to_publish_key && it->first >=0 )
143165
to_publish_key = it->first;
144166
}
145-
viz->publishNodesAsLineStrip( jmb[to_publish_key] , "latest_odometry", 0.0, 0.7, 0.0 );
167+
if( to_publish_key >= 0 )
168+
viz->publishNodesAsLineStrip( jmb[to_publish_key] , "latest_odometry", 0.0, 0.7, 0.0 );
146169

147170
// Publish Camera visual
148171
Matrix4d wi_T_latest = *( jmb.at( to_publish_key ).rbegin() );

src/utils/RosMarkerUtils.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ void RosMarkerUtils::add_points_to_marker( const MatrixXd& X, visualization_msgs
318318

319319
void RosMarkerUtils::add_colors_to_marker( const Vector3d& color_rgb, visualization_msgs::Marker& marker, bool clear_prev_colors )
320320
{
321-
assert( (X.rows() == 3) && "[RosMarkerUtils::add_colors_to_marker] X need to of size 3xN representing rgb colors of the points\n" );
321+
// assert( (X.rows() == 3) && "[RosMarkerUtils::add_colors_to_marker] X need to of size 3xN representing rgb colors of the points\n" );
322322
// geometry_msgs::Point pt;
323323
std_msgs::ColorRGBA pt_color;
324324

@@ -334,7 +334,7 @@ void RosMarkerUtils::add_colors_to_marker( const Vector3d& color_rgb, visualizat
334334

335335
void RosMarkerUtils::add_colors_to_marker( float c_r, float c_g, float c_b, visualization_msgs::Marker& marker, bool clear_prev_colors )
336336
{
337-
assert( (X.rows() == 3) && "[RosMarkerUtils::add_colors_to_marker] X need to of size 3xN representing rgb colors of the points\n" );
337+
// assert( (X.rows() == 3) && "[RosMarkerUtils::add_colors_to_marker] X need to of size 3xN representing rgb colors of the points\n" );
338338
// geometry_msgs::Point pt;
339339
std_msgs::ColorRGBA pt_color;
340340

0 commit comments

Comments
 (0)