@@ -227,10 +227,23 @@ void Composer::pose_assember_thread( int looprate )
227227}
228228
229229
230+ int Composer::get_last_known_camerapose ( Matrix4d& w_T_lastcam, ros::Time& stamp_of_it )
231+ {
232+ std::lock_guard<std::mutex> lk (mx);
233+ const int sz = global_lmb.size ();
234+ if ( sz == 0 )
235+ return -1 ;
236+
237+ auto it = global_lmb.rbegin ();
238+ w_T_lastcam = *(it);
239+
240+ stamp_of_it = manager->getNodeTimestamp ( sz-1 );
241+ return sz-1 ;
242+ }
230243
231244// #define __Composer_bf_traj_publish_thread( msg ) msg;
232245#define __Composer_bf_traj_publish_thread ( msg ) ;
233- void Composer::bf_traj_publish_thread ( int looprate )
246+ void Composer::bf_traj_publish_thread ( int looprate ) const
234247{
235248 // --- Options
236249 const int options_line_color_style = 10 ; // should be either 10 or 12. 10:color by WorldID; 12: //color by world setID
@@ -242,6 +255,7 @@ void Composer::bf_traj_publish_thread( int looprate )
242255 cout << TermColor::GREEN () << " start `Composer::bf_traj_publish_thread` @ " << looprate << " hz" << TermColor::RESET () << endl;
243256 assert ( looprate > 0 && looprate < 50 );
244257 ros::Rate rate (looprate);
258+ bool published_axis = false ;
245259
246260 static thread_local std::mt19937 generator;
247261 std::uniform_int_distribution<int > distribution (0 ,100 );
@@ -327,14 +341,20 @@ void Composer::bf_traj_publish_thread( int looprate )
327341
328342 }
329343
344+ if ( published_axis==false || rand () % 100 == 0 ) {
345+ // Publish Axis - publish infrequently
346+ Matrix4d _axis_pose = Matrix4d::Identity ();
347+ viz->publishXYZAxis ( _axis_pose, " opt_traj_axis" , 0 );
348+ published_axis = true ;
349+ }
330350 }
331351
332352 cout << TermColor::RED () << " Finished `Composer::bf_traj_publish_thread`\n " << TermColor::RESET () << endl;
333353}
334354
335355
336356
337- void Composer::cam_visual_publish_thread ( int looprate )
357+ void Composer::cam_visual_publish_thread ( int looprate ) const
338358{
339359 // --- Options
340360 const int options_linewidth_multiplier = 3 ; // default 3
@@ -381,7 +401,7 @@ void Composer::cam_visual_publish_thread( int looprate )
381401
382402// #define __Composer__loopedge_publish_thread(msg) msg;
383403#define __Composer__loopedge_publish_thread (msg ) ;
384- void Composer::loopedge_publish_thread ( int looprate )
404+ void Composer::loopedge_publish_thread ( int looprate ) const
385405{
386406 cout << TermColor::GREEN () << " start `Composer::loopedge_publish_thread` @" << looprate << " hz" << TermColor::RESET () << endl;
387407 assert ( looprate > 0 && looprate < 50 );
@@ -468,7 +488,7 @@ void Composer::loopedge_publish_thread( int looprate )
468488
469489// #define __Composer__disjointset_statusimage_publish_thread(msg) msg;
470490#define __Composer__disjointset_statusimage_publish_thread (msg ) ;
471- void Composer::disjointset_statusimage_publish_thread ( int looprate )
491+ void Composer::disjointset_statusimage_publish_thread ( int looprate ) const
472492{
473493 cout << TermColor::GREEN () << " start `Composer::disjointset_statusimage_publish_thread` @" << looprate << " hz" << TermColor::RESET () << endl;
474494 assert ( looprate > 0 && looprate < 50 );
@@ -509,3 +529,101 @@ void Composer::disjointset_statusimage_publish_thread( int looprate )
509529
510530 cout << TermColor::RED () << " Finished `Composer::disjointset_statusimage_publish_thread`\n " << TermColor::RESET () << endl;
511531}
532+
533+
534+
535+
536+ // ------ Publish body pose @200Hz ------//
537+
538+ void Composer::setup_200hz_publishers ()
539+ {
540+ // pubx =
541+ // cmpr->set_200hz_marker_pub( pubx )
542+ string marker_topic = string ( " hz200/visualization_marker" );
543+ ROS_INFO ( " [Composer::setup_200hz_publishers] Publish to %s" , marker_topic.c_str () );
544+ pub_hz200_marker = nh.advertise <visualization_msgs::Marker>( marker_topic , 1000 );
545+
546+
547+ // puby =
548+ // cmpr->set_200hz_odom_pub( puby )
549+ }
550+
551+
552+ // #define _Composer__imu_propagate_callback_( msg ) msg;
553+ #define _Composer__imu_propagate_callback_ ( msg ) ;
554+ void Composer::imu_propagate_callback ( const nav_msgs::Odometry::ConstPtr& msg )
555+ {
556+ _Composer__imu_propagate_callback_ (
557+ cout << TermColor::iBLUE () << " [Composer::imu_propagate_callback] t=" << msg->header .stamp << TermColor::RESET () << endl;
558+ )
559+
560+ Matrix4d w_T_imucurr; // = pose from msg
561+ PoseManipUtils::geometry_msgs_Pose_to_eigenmat ( msg->pose .pose , w_T_imucurr );
562+
563+
564+
565+
566+ //
567+ // Last Known camera-pose? - after pose graph solver
568+ Matrix4d wf_T_camlast;
569+ ros::Time cam_t ;
570+ int posegraph_nodeidx = get_last_known_camerapose ( wf_T_camlast, cam_t );
571+ if ( posegraph_nodeidx < 0 ) {
572+ _Composer__imu_propagate_callback_ (
573+ cout << TermColor::iYELLOW () << " posegraph_nodeidx was neg, meaning non existant last known cam pose\n " << TermColor::RESET ();
574+ )
575+ return ;
576+ }
577+
578+ _Composer__imu_propagate_callback_ (
579+ cout << " \t Last known camera-pose is at posegraphnode postion=" << posegraph_nodeidx << " is at t=" << cam_t << " which is " << msg->header .stamp - cam_t << " behind current imu_prop msg\n " ;
580+ )
581+
582+
583+ //
584+ // extrinsic-calibration value: imu_T_cam
585+ if ( manager->is_imu_T_cam_available () == false ) {
586+ _Composer__imu_propagate_callback_ (
587+ cout << TermColor::iYELLOW () << " imu-cam extrinsic is not yet available\n " << TermColor::RESET () << endl;
588+ )
589+ return ;
590+ }
591+ Matrix4d imu_T_cam = manager->get_imu_T_cam ();
592+
593+ //
594+ // relative pose between when imu at t=now_t and when imu was at t=last_known_t
595+ Matrix4d w_T_imulast = manager->getNodePose (posegraph_nodeidx) * imu_T_cam.inverse ();
596+ Matrix4d imulast_T_imucurr = w_T_imulast.inverse () * w_T_imucurr;
597+
598+
599+ //
600+ // Add this relative pose to `wf_T_camlast`
601+ Matrix4d wf_T_imucurr = ( wf_T_camlast * imu_T_cam.inverse () ) * imulast_T_imucurr;
602+
603+
604+
605+ //
606+ // Make viz marker and publish
607+ visualization_msgs::Marker imu_m;
608+ RosMarkerUtils::init_XYZ_axis_marker ( imu_m, 1.0 );
609+ imu_m.ns = " hz100_imu" ;
610+ imu_m.id = 0 ;
611+ RosMarkerUtils::setpose_to_marker ( wf_T_imucurr, imu_m );
612+ pub_hz200_marker.publish ( imu_m );
613+
614+ visualization_msgs::Marker imu_txt;
615+ RosMarkerUtils::init_text_marker ( imu_txt );
616+ imu_txt.ns = " hz100_imu_txt" ;
617+ imu_txt.text = " IMU@200hz" ;
618+ imu_txt.scale .z = 0.5 ;
619+ RosMarkerUtils::setcolor_to_marker ( 1.0 , 1.0 , 1.0 , imu_txt );
620+ RosMarkerUtils::setpose_to_marker ( wf_T_imucurr, imu_txt );
621+ pub_hz200_marker.publish ( imu_txt );
622+
623+
624+
625+
626+ }
627+
628+
629+ // ------ END Publish body pose @200Hz ------//
0 commit comments