Skip to content

Commit c405046

Browse files
committed
added a path publisher with details on co-ordinate systems
1 parent c132678 commit c405046

5 files changed

Lines changed: 184 additions & 6 deletions

File tree

src/Composer.cpp

Lines changed: 117 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ void Composer::bf_traj_publish_thread( int looprate ) const
283283
{
284284
//--- Options
285285
const int options_line_color_style = 10; // should be either 10 or 12. 10:color by WorldID; 12: //color by world setID
286-
const float options_linewidth_multiplier = 3; // thickness of the line
286+
const float options_linewidth_multiplier = 1; // thickness of the line
287287

288288
//---
289289

@@ -396,7 +396,7 @@ void Composer::bf_traj_publish_thread( int looprate ) const
396396
void Composer::cam_visual_publish_thread( int looprate ) const
397397
{
398398
//--- Options
399-
const int options_linewidth_multiplier = 3; //default 3
399+
const int options_linewidth_multiplier = 1; //default 3
400400
//---
401401

402402

@@ -448,7 +448,7 @@ void Composer::path_publish_thread( int looprate )
448448
nav_msgs::Path path_msg;
449449

450450
string path_topic = string( "adhoc/xpath" );
451-
ROS_INFO( "[Composer::setup_200hz_publishers] Publish to %s", path_topic.c_str() );
451+
ROS_INFO( "[Composer::path_publish_thread] Publish to %s", path_topic.c_str() );
452452
pub_hz200_marker = nh.advertise<nav_msgs::Path>( path_topic , 1000 );
453453

454454
ros::Publisher pub___path = nh.advertise<nav_msgs::Path>( path_topic , 1000 );
@@ -519,6 +519,83 @@ void Composer::path_publish_thread( int looprate )
519519
cout << TermColor::RED() << "Finished `Composer::path_publish_thread`\n" << TermColor::RESET() << endl;
520520
}
521521

522+
523+
// #define __Composer__detailed_path_publish_thread__(msg) msg;
524+
#define __Composer__detailed_path_publish_thread__(msg) ;
525+
void Composer::detailed_path_publish_thread( int looprate=30 )
526+
{
527+
cout << TermColor::GREEN() << "start `Composer::detailed_path_publish_thread` @" << looprate << " hz" << TermColor::RESET() << endl;
528+
cout << "[Composer::detailed_path_publish_thread]will use `b_cam_visual_publish` for terminating this thread\n";
529+
assert( looprate > 0 && looprate < 50 );
530+
531+
532+
int n, prev_n = 0;
533+
nav_msgs::Path path_msg;
534+
535+
string path_topic = string( "adhoc/xpath_detailed" );
536+
ROS_INFO( "[Composer::detailed_path_publish_thread] Publish to %s", path_topic.c_str() );
537+
ros::Publisher pub___path = nh.advertise<nav_msgs::Path>( path_topic , 1000 );
538+
539+
ros::Rate rate(looprate);
540+
Matrix4d imu_T_cam = Matrix4d::Identity(); bool flag_imu_T_cam = false;
541+
542+
while( b_cam_visual_publish )
543+
{
544+
rate.sleep();
545+
{
546+
std::lock_guard<std::mutex> lk(mx);
547+
548+
nav_msgs::Path path_msg;
549+
path_msg.poses.clear();
550+
__Composer__detailed_path_publish_thread__( cout << "---\n"; )
551+
for( int i=0 ; i<global_lmb.size() ; i++ )
552+
{
553+
if( flag_imu_T_cam == false)
554+
{
555+
imu_T_cam = manager->get_imu_T_cam();
556+
flag_imu_T_cam = true;
557+
}
558+
559+
if( flag_imu_T_cam == false ) {
560+
cout << "FATAIL.....This cannot be happening.....\n";
561+
exit(1);
562+
}
563+
Matrix4d wTc = global_lmb[i]; // this is pose of camera in the co-ordinate system of setID_of_worldID
564+
Matrix4d w_T_imu = wTc * imu_T_cam.inverse();
565+
566+
567+
ros::Time stamp = manager->getNodeTimestamp(i);
568+
int worldID = manager->which_world_is_this( stamp );
569+
570+
571+
if( worldID < 0 )
572+
continue;
573+
int setID_of_worldID = manager->getWorldsConstPtr()->find_setID_of_world_i( worldID );
574+
575+
__Composer__detailed_path_publish_thread__(
576+
cout << "[Composer::detailed_path_publish_thread]worldID:" << worldID << "\tsetID_of_worldID:" << setID_of_worldID << "\t" << PoseManipUtils::prettyprintMatrix4d(wTc) << endl;
577+
);
578+
579+
geometry_msgs::PoseStamped pose_i;
580+
pose_i.header.stamp = stamp;
581+
pose_i.header.frame_id = "worldID:" + to_string( worldID )+":"+"setID_of_worldID:"+to_string(setID_of_worldID);
582+
583+
// PoseManipUtils::eigenmat_to_geometry_msgs_Pose( wTc, pose_i.pose );
584+
PoseManipUtils::eigenmat_to_geometry_msgs_Pose( w_T_imu, pose_i.pose );
585+
586+
587+
path_msg.poses.push_back( pose_i );
588+
}
589+
__Composer__detailed_path_publish_thread__(
590+
cout << "[Composer::detailed_path_publish_thread]PUBLISH....path_msg.poses.size=" << path_msg.poses.size() << endl;
591+
)
592+
pub___path.publish( path_msg );
593+
}
594+
}
595+
596+
}
597+
598+
522599
#define __Composer__w0_T_w1_publish_thread( msg ) msg;
523600
// #define __Composer__w0_T_w1_publish_thread( msg ) ;
524601
void Composer::w0_T_w1_publish_thread( int looprate )
@@ -698,8 +775,45 @@ void Composer::disjointset_statusimage_publish_thread( int looprate ) const
698775
cout << TermColor::RED() << "Finished `Composer::disjointset_statusimage_publish_thread`\n" << TermColor::RESET() << endl;
699776
}
700777

778+
void Composer::disjointset_statusjson_publish_thread( int looprate )
779+
{
780+
cout << TermColor::GREEN() << "start `Composer::disjointset_statusjson_publish_thread` @" << looprate << " hz" << TermColor::RESET() << endl;
781+
assert( looprate > 0 && looprate < 50 );
782+
783+
string jsonstring_topic = string( "adhoc/disjoint_set_status_jsonstring" );
784+
ROS_INFO( "[Composer::disjointset_statusjson_publish_thread] Publish to %s", jsonstring_topic.c_str() );
785+
ros::Publisher pub_jsonstring = nh.advertise<std_msgs::String>( jsonstring_topic , 1000 );
786+
787+
701788

702789

790+
ros::Rate rate(looprate);
791+
string prev_status_str = "";
792+
while( b_disjointset_statusimage_publish )
793+
{
794+
rate.sleep();
795+
796+
string curr_status_str = manager->getWorldsConstPtr()->disjoint_set_status_json().dump(4);
797+
if( prev_status_str.compare(curr_status_str) == 0 ) {
798+
// same as old, no point publishing
799+
__Composer__disjointset_statusimage_publish_thread(
800+
cout << "[Composer::disjointset_statusjson_publish_thread] No change in status, so dont publish image." << endl;
801+
)
802+
continue;
803+
}
804+
805+
// publish only when changed, modify as need be.
806+
std_msgs::String msg;
807+
msg.data = curr_status_str;
808+
pub_jsonstring.publish( msg );
809+
810+
811+
812+
prev_status_str = curr_status_str;
813+
}
814+
815+
cout << TermColor::RED() << "Finished `Composer::disjointset_statusjson_publish_thread`\n" << TermColor::RESET() << endl;
816+
}
703817

704818
//------ Publish body pose @200Hz ------//
705819

src/Composer.h

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

3838
#include <nav_msgs/Path.h>
39+
#include <std_msgs/String.h>
3940

4041
class Composer
4142
{
@@ -111,6 +112,7 @@ class Composer
111112
void cam_visual_publish_thread( int looprate = 30 ) const;
112113
// vvvv I am publishing just as it is, this might need work when having multiple co-ordinate systems
113114
void path_publish_thread( int looprate=30 );
115+
void detailed_path_publish_thread( int looprate=30 );
114116
void w0_T_w1_publish_thread( int looprate=3 ); //if world exists(0,1) will publish else nothing
115117
void cam_visual_publish_enable() { b_cam_visual_publish = true;}
116118
void cam_visual_publish_disable() {b_cam_visual_publish = false; }
@@ -141,6 +143,7 @@ class Composer
141143
// makes use of manager->getEdgeLen() and global_lmb and publish edges.
142144
public:
143145
void disjointset_statusimage_publish_thread( int looprate = 10 ) const;
146+
void disjointset_statusjson_publish_thread( int looprate = 10 ) ; //since i define the ros::Publisher inside this thread, I cannot set this as const. :(
144147
void disjointset_statusimage_publish_enable() { b_disjointset_statusimage_publish = true;}
145148
void disjointset_statusimage_publish_disable() {b_disjointset_statusimage_publish = false; }
146149

src/Worlds.cpp

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,61 @@ int Worlds::n_sets() const //< number of sets
275275
return disjoint_set.set_count();
276276
}
277277

278+
const json Worlds::disjoint_set_status_json() const
279+
{
280+
json obj;
281+
282+
std::lock_guard<std::mutex> lk(mutex_world);
283+
284+
obj["Global"]["n_worlds"] = disjoint_set.element_count();
285+
obj["Global"]["set_count"] = disjoint_set.set_count();
286+
287+
//loop thru all elements
288+
for( int i=0 ; i<disjoint_set.element_count() ; i++ )
289+
{
290+
int setID = disjoint_set.find_set( i ) ;
291+
292+
json this_obj;
293+
this_obj["worldID"] = i;
294+
this_obj["setID_of_worldID"] = setID;
295+
296+
if( i>=0 && i< vec_world_starts.size() )
297+
this_obj["start_stamp"] = vec_world_starts.at(i).toNSec();
298+
else
299+
this_obj["start_stamp"] = ros::Time().toNSec();
300+
301+
if( i>=0 && i< vec_world_ends.size() )
302+
this_obj["end_stamp"] = vec_world_ends.at(i).toNSec();
303+
else
304+
this_obj["end_stamp"] = ros::Time().toNSec();
305+
306+
obj["WorldInfo"].push_back( this_obj );
307+
}
308+
309+
310+
#if 0
311+
// all between world poses worlds
312+
obj["BetweenWorldsRelPose"] = {};
313+
for( auto it=rel_pose_between_worlds__wb_T_wa.begin() ; it!=rel_pose_between_worlds__wb_T_wa.end() ; it++ )
314+
{
315+
auto key = it->first; //this is std::pair<m,n>
316+
Matrix4d wb_T_wa = it->second;
317+
string info_wb_T_wa = rel_pose_between_worlds__wb_T_wa___info_string.at( key );
318+
319+
json iterm;
320+
iterm["world_b"] = std::get<0>(it->first);
321+
iterm["world_a"] = std::get<1>(it->first);
322+
iterm["wb_T_wa"] = RawFileIO::eigen_matrix_to_json( wb_T_wa );
323+
iterm["wb_T_wa"]["data_pretty"] = PoseManipUtils::prettyprintMatrix4d(wb_T_wa);
324+
iterm["info_wb_T_wa"] = info_wb_T_wa;
325+
obj["BetweenWorldsRelPose"].push_back( iterm );
326+
}
327+
#endif
328+
329+
330+
return obj;
331+
}
332+
278333
const string Worlds::disjoint_set_status() const
279334
{
280335
std::lock_guard<std::mutex> lk(mutex_world);

src/Worlds.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ class Worlds
6060

6161
void print_summary( int verbosity = 1) const;
6262
const string disjoint_set_status() const ;
63+
const json disjoint_set_status_json() const;
6364
void disjoint_set_status_image(cv::Mat& outIm, bool enable_bubbles=true, bool enable_text=true ) const;
6465
json saveStateToDisk() const;
6566
bool loadStateFromDisk( json _objk );

src/keyframe_pose_graph_slam_node.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -422,11 +422,14 @@ int main( int argc, char ** argv)
422422
}
423423
}
424424

425-
if( adhoc_pubpath )
426-
path_pub_th = std::thread{ &Composer::path_publish_thread, cmpr, 30 };
425+
if( adhoc_pubpath ) {
426+
// path_pub_th = std::thread{ &Composer::path_publish_thread, cmpr, 30 };
427+
path_pub_th = std::thread{ &Composer::detailed_path_publish_thread, cmpr, 10 };
428+
}
427429

428-
if( adhoc_pubw0_T_w1 )
430+
if( adhoc_pubw0_T_w1 ) {
429431
w0_T_w1_pub_th = std::thread{ &Composer::w0_T_w1_publish_thread, cmpr, 3 };
432+
}
430433
#endif //adhoc
431434

432435
// ++ loop edge publish thread
@@ -438,6 +441,7 @@ int main( int argc, char ** argv)
438441
cmpr->disjointset_statusimage_publish_enable();
439442
// cmpr->disjointset_statusimage_publish_disable();
440443
std::thread disjointset_monitor_pub_th( &Composer::disjointset_statusimage_publish_thread, cmpr, 1 );
444+
std::thread disjointset_monitortxt_pub_th( &Composer::disjointset_statusjson_publish_thread, cmpr, 1 );
441445

442446

443447
// TODO
@@ -504,6 +508,7 @@ int main( int argc, char ** argv)
504508
cam_visual_pub_th.join();
505509
loopedge_pub_th.join();
506510
disjointset_monitor_pub_th.join();
511+
disjointset_monitortxt_pub_th.join();
507512

508513
#ifdef __main__adhoc__
509514
if( adhoc_pubpath )

0 commit comments

Comments
 (0)