Skip to content

Commit 619029f

Browse files
committed
added pose graph loading in as constant, adhoc publishers for teach-repeat demo
1 parent d77962d commit 619029f

7 files changed

Lines changed: 411 additions & 39 deletions

File tree

src/Composer.cpp

Lines changed: 185 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,133 @@ void Composer::cam_visual_publish_thread( int looprate ) const
436436
cout << TermColor::RED() << "Finished `Composer::cam_visual_publish_thread`\n" << TermColor::RESET() << endl;
437437
}
438438

439+
// #define __Composer__path_publish_thread__(msg) msg;
440+
#define __Composer__path_publish_thread__(msg) ;
441+
void Composer::path_publish_thread( int looprate )
442+
{
443+
cout << TermColor::GREEN() << "start `Composer::path_publish_thread` @" << looprate << " hz" << TermColor::RESET() << endl;
444+
cout << "[Composer::path_publish_thread]will use `b_cam_visual_publish` for terminating this thread\n";
445+
assert( looprate > 0 && looprate < 50 );
446+
447+
int n, prev_n = 0;
448+
nav_msgs::Path path_msg;
449+
450+
string path_topic = string( "adhoc/xpath" );
451+
ROS_INFO( "[Composer::setup_200hz_publishers] Publish to %s", path_topic.c_str() );
452+
pub_hz200_marker = nh.advertise<nav_msgs::Path>( path_topic , 1000 );
453+
454+
ros::Publisher pub___path = nh.advertise<nav_msgs::Path>( path_topic , 1000 );
455+
456+
ros::Rate rate(looprate);
457+
while( b_cam_visual_publish )
458+
{
459+
rate.sleep();
460+
461+
{
462+
__Composer__path_publish_thread__( "---\n");
463+
std::lock_guard<std::mutex> lk(mx);
464+
if( global_latest_pose_worldid < 0 ) {
465+
__Composer__path_publish_thread__( cout << "global_latest_pose_worldid is negative, so, continue...\n"; )
466+
continue;
467+
}
468+
469+
n = global_lmb.size();
470+
if( prev_n == n || n == 0 ) {
471+
__Composer__path_publish_thread__(
472+
cout << "[Composer::path_publish_thread] nothing new, n same as prev_n=" << n << "\n";
473+
)
474+
continue;
475+
}
476+
Matrix4d wi_T_latest = global_lmb.at( n-1 );
477+
478+
if( rand()%100 > 2 ) {
479+
//add to msg
480+
ros::Time stamp_of_it = manager->getNodeTimestamp( n-1 );
481+
path_msg.header.stamp = stamp_of_it;
482+
path_msg.header.frame_id = "world";
483+
geometry_msgs::PoseStamped pxl;
484+
pxl.header.stamp = stamp_of_it;
485+
PoseManipUtils::eigenmat_to_geometry_msgs_Pose( wi_T_latest, pxl.pose );
486+
path_msg.poses.push_back( pxl );
487+
__Composer__path_publish_thread__(
488+
cout << "[Composer::path_publish_thread]push_back " << stamp_of_it<< endl;
489+
)
490+
}
491+
else {
492+
// reset and set all again
493+
__Composer__path_publish_thread__(
494+
cout << TermColor::iRED() << "[Composer::path_publish_thread]reset and then for h=[0:" << n << ")" << TermColor::RESET() << endl;
495+
)
496+
path_msg.poses.clear();
497+
for( int h=0 ; h<n ; h++ )
498+
{
499+
ros::Time stamp_of_it = manager->getNodeTimestamp( h );
500+
path_msg.header.stamp = stamp_of_it;
501+
path_msg.header.frame_id = "world";
502+
geometry_msgs::PoseStamped pxl;
503+
pxl.header.stamp = stamp_of_it;
504+
auto ___wi_T_c = global_lmb.at( h );
505+
PoseManipUtils::eigenmat_to_geometry_msgs_Pose( ___wi_T_c, pxl.pose );
506+
path_msg.poses.push_back( pxl );
507+
}
508+
}
509+
}
510+
511+
prev_n = n;
512+
__Composer__path_publish_thread__( cout << "[Composer::path_publish_thread]publish path, contains: " << path_msg.poses.size() << " poses\n"; )
513+
pub___path.publish( path_msg );
514+
515+
516+
}
517+
cout << TermColor::RED() << "Finished `Composer::path_publish_thread`\n" << TermColor::RESET() << endl;
518+
}
519+
520+
#define __Composer__w0_T_w1_publish_thread( msg ) msg;
521+
// #define __Composer__w0_T_w1_publish_thread( msg ) ;
522+
void Composer::w0_T_w1_publish_thread( int looprate )
523+
{
524+
cout << TermColor::GREEN() << "start `Composer::w0_T_w1_publish_thread` @" << looprate << " hz" << TermColor::RESET() << endl;
525+
assert( looprate > 0 && looprate < 5 );
526+
527+
string w0_T_w1_topic = string( "adhoc/w0_T_w1");
528+
ROS_INFO( "[Composer::setup_200hz_publishers] Publish to %s", w0_T_w1_topic.c_str() );
529+
ros::Publisher pub_w0_T_w1 = nh.advertise<geometry_msgs::PoseStamped>( w0_T_w1_topic , 1000 );
530+
531+
532+
ros::Rate rate(looprate);
533+
while( b_cam_visual_publish )
534+
{
535+
rate.sleep();
536+
537+
__Composer__w0_T_w1_publish_thread( cout << "----w0_T_w1_publish_thread---\n"; )
538+
539+
540+
// w0_T_w1 if available
541+
if( manager->getWorldsConstPtr()->is_exist( 0, 1 ) )
542+
{
543+
// publish.
544+
__Composer__w0_T_w1_publish_thread( cout << "[Composer::w0_T_w1_publish_thread]w0_T_w1 exist...pubnlish/....\n"; )
545+
Matrix4d w0_T_w1 = manager->getWorldsConstPtr()->getPoseBetweenWorlds( 0, 1);
546+
__Composer__w0_T_w1_publish_thread( cout << "w0_T_w1=" << PoseManipUtils::prettyprintMatrix4d( w0_T_w1 ) << endl; )
547+
548+
549+
geometry_msgs::PoseStamped msg;
550+
PoseManipUtils::eigenmat_to_geometry_msgs_Pose( w0_T_w1, msg.pose );
551+
msg.header.stamp = ros::Time();
552+
msg.header.frame_id = "w0_T_w1";
553+
554+
pub_w0_T_w1.publish( msg );
555+
}
556+
else {
557+
__Composer__w0_T_w1_publish_thread( cout << "[Composer::w0_T_w1_publish_thread]w0_T_w1 doesnt exist, so dont publish anything\n"; )
558+
}
559+
560+
561+
}
562+
563+
cout << TermColor::RED() << "Finished `Composer::w0_T_w1_publish_thread`\n" << TermColor::RESET() << endl;
564+
565+
}
439566

440567

441568
// #define __Composer__loopedge_publish_thread(msg) msg;
@@ -583,8 +710,20 @@ void Composer::setup_200hz_publishers()
583710
pub_hz200_marker = nh.advertise<visualization_msgs::Marker>( marker_topic , 1000 );
584711

585712

586-
// puby =
587-
// cmpr->set_200hz_odom_pub( puby )
713+
// geometry_msgs::Pose
714+
string pose_topic = string( "hz200/pose");
715+
ROS_INFO( "[Composer::setup_200hz_publishers] Publish to %s", pose_topic.c_str() );
716+
pub_hz200_pose = nh.advertise<geometry_msgs::Pose>( pose_topic , 1000 );
717+
718+
// geometry_msgs::PoseStamped
719+
string posestamped_topic = string( "hz200/posestamped");
720+
ROS_INFO( "[Composer::setup_200hz_publishers] Publish to %s", posestamped_topic.c_str() );
721+
pub_hz200_posestamped = nh.advertise<geometry_msgs::PoseStamped>( posestamped_topic , 1000 );
722+
723+
724+
// path
725+
726+
588727
}
589728

590729

@@ -640,25 +779,48 @@ void Composer::imu_propagate_callback( const nav_msgs::Odometry::ConstPtr& msg )
640779
Matrix4d wf_T_imucurr = ( wf_T_camlast * imu_T_cam.inverse() ) * imulast_T_imucurr;
641780

642781

782+
//==============================================================//
783+
//--------------------done computation....now publixh-----------//
784+
//==============================================================//
785+
bool publish_marker = true;
786+
bool publish_txt_marker = false;
787+
643788

644789
//
645790
// Make viz marker and publish
646-
visualization_msgs::Marker imu_m;
647-
RosMarkerUtils::init_XYZ_axis_marker( imu_m, 1.0 );
648-
imu_m.ns = "hz100_imu";
649-
imu_m.id = 0;
650-
RosMarkerUtils::setpose_to_marker( wf_T_imucurr, imu_m );
651-
pub_hz200_marker.publish( imu_m );
791+
if( publish_marker ) {
792+
visualization_msgs::Marker imu_m;
793+
RosMarkerUtils::init_XYZ_axis_marker( imu_m, 1.0 );
794+
imu_m.ns = "hz100_imu";
795+
imu_m.id = 0;
796+
RosMarkerUtils::setpose_to_marker( wf_T_imucurr, imu_m );
797+
pub_hz200_marker.publish( imu_m );
798+
}
652799

653-
visualization_msgs::Marker imu_txt;
654-
RosMarkerUtils::init_text_marker( imu_txt );
655-
imu_txt.ns = "hz100_imu_txt";
656-
imu_txt.text = "IMU@200hz";
657-
imu_txt.scale.z = 0.5;
658-
RosMarkerUtils::setcolor_to_marker( 1.0, 1.0, 1.0, imu_txt );
659-
RosMarkerUtils::setpose_to_marker( wf_T_imucurr, imu_txt );
660-
pub_hz200_marker.publish( imu_txt );
800+
if( publish_txt_marker ) {
801+
visualization_msgs::Marker imu_txt;
802+
RosMarkerUtils::init_text_marker( imu_txt );
803+
imu_txt.ns = "hz100_imu_txt";
804+
imu_txt.text = "IMU@200hz";
805+
imu_txt.scale.z = 0.5;
806+
RosMarkerUtils::setcolor_to_marker( 1.0, 1.0, 1.0, imu_txt );
807+
RosMarkerUtils::setpose_to_marker( wf_T_imucurr, imu_txt );
808+
pub_hz200_marker.publish( imu_txt );
809+
}
810+
811+
812+
geometry_msgs::Pose posex;
813+
PoseManipUtils::eigenmat_to_geometry_msgs_Pose( wf_T_imucurr, posex );
661814

815+
geometry_msgs::PoseStamped posexstamped;
816+
posexstamped.header.stamp = msg->header.stamp;
817+
int _worldID = manager->which_world_is_this( cam_t );
818+
int _setID_of_worldID = manager->getWorldsConstPtr()->find_setID_of_world_i( _worldID );
819+
posexstamped.header.frame_id = "pose_in_world#" + std::to_string( _setID_of_worldID );
820+
posexstamped.pose = posex;
821+
822+
pub_hz200_pose.publish( posex );
823+
pub_hz200_posestamped.publish( posexstamped );
662824

663825

664826

@@ -886,8 +1048,14 @@ bool Composer::loadStateFromDisk( string save_dir_path )
8861048

8871049
//---
8881050
// Adjust variables in object slam (in PoseGraphSLAM), especially the solved_until
1051+
bool status_slamsolver = slam->load_state( ); //< this will build up a constant pose graph until this point.
1052+
if( status_slamsolver == false )
1053+
{
1054+
cout << TermColor::RED() << "[Composer::loadStateFromDisk]slam->load_state( ); returned false\nFATAL ERROR..." << TermColor::RESET() << endl;
1055+
exit(1);
1056+
}
8891057

8901058

891-
1059+
return true;
8921060

8931061
}

src/Composer.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ using namespace std;
3535
using json = nlohmann::json;
3636
#include "utils/RawFileIO.h"
3737

38+
#include <nav_msgs/Path.h>
39+
3840
class Composer
3941
{
4042
public:
@@ -107,6 +109,9 @@ class Composer
107109
// makes use of global_jmb and publish last cam
108110
public:
109111
void cam_visual_publish_thread( int looprate = 30 ) const;
112+
// vvvv I am publishing just as it is, this might need work when having multiple co-ordinate systems
113+
void path_publish_thread( int looprate=30 );
114+
void w0_T_w1_publish_thread( int looprate=3 ); //if world exists(0,1) will publish else nothing
110115
void cam_visual_publish_enable() { b_cam_visual_publish = true;}
111116
void cam_visual_publish_disable() {b_cam_visual_publish = false; }
112117

@@ -153,6 +158,8 @@ class Composer
153158

154159
private:
155160
ros::Publisher pub_hz200_marker;
161+
ros::Publisher pub_hz200_pose, pub_hz200_posestamped;
162+
156163

157164

158165
/////////////// Save State ////////////////////

src/NodeDataManager.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1032,7 +1032,8 @@ bool NodeDataManager::load_solved_posegraph_data_from_json( json obj )
10321032
cout << "\t.\n\t.\n\t.\n";
10331033
}
10341034

1035-
// For everything to be working correctly, I need to store the wTc and not wsTc
1035+
// For everything to be working correctly, I need to store (in NodeDataManager)
1036+
// the wTc and not wsTc
10361037
// w_T_c := w_T_ws * ws_T_c
10371038
if( _worldID >= 0 && _worldID != _setID_of_worldID )
10381039
{
@@ -1047,6 +1048,11 @@ bool NodeDataManager::load_solved_posegraph_data_from_json( json obj )
10471048
}
10481049
Matrix4d f_wTc = wTws * ___w_T_c;
10491050
___w_T_c = f_wTc;
1051+
} else if( _worldID < 0 && _worldID != _setID_of_worldID )
1052+
{
1053+
// TODO: the kidnapped sections need to be shifted from setID_of_worldID of their world's to worldIDs of their worlds
1054+
// Also note, the worlds of kidnap will be -worldid +1. For example, for worldID=-1 the worldid is actually 0, ie. -1 is adjacent to the world0.
1055+
10501056
}
10511057

10521058

0 commit comments

Comments
 (0)