@@ -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+
367380void 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 << " \n opt_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