Skip to content

Commit 3e3caf9

Browse files
committed
new co-ordinate system an offset away, viz only
1 parent 7a6440d commit 3e3caf9

4 files changed

Lines changed: 144 additions & 25 deletions

File tree

src/PoseGraphSLAM.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1103,8 +1103,8 @@ bool PoseGraphSLAM::saveAsJSON(const string base_path)
11031103

11041104
// This thread wakes up when there are new loopedges. This flag controls the printing on trigger.
11051105
// When debugging you want to keep the headers 'on'.
1106-
#define ___trigger_header( msg ) msg;
1107-
// #define ___trigger_header( msg ) ;
1106+
// #define ___trigger_header( msg ) msg;
1107+
#define ___trigger_header( msg ) ;
11081108

11091109
void PoseGraphSLAM::reinit_ceres_problem_onnewloopedge_optimize6DOF()
11101110
{

src/VizPoseGraph.cpp

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ void VizPoseGraph::publishLastNNodes( int n )
6565

6666

6767
void VizPoseGraph::publishNodesAsLineStrip( const vector<Matrix4d>& w_T_ci,
68-
const string& ns, float r, float g, float b, float linewidth_multiplier ) const
68+
const string& ns, float r, float g, float b, float linewidth_multiplier,
69+
float offset_x, float offset_y, float offset_z ) const
6970
{
7071
// this is a cost effective way to visualize camera path
7172
visualization_msgs::Marker marker;
@@ -84,9 +85,9 @@ void VizPoseGraph::publishNodesAsLineStrip( const vector<Matrix4d>& w_T_ci,
8485
for( int i=0 ; i<w_T_ci.size() ; i++ )
8586
{
8687
geometry_msgs::Point pt;
87-
pt.x = (w_T_ci[i])(0,3);
88-
pt.y = (w_T_ci[i])(1,3);
89-
pt.z = (w_T_ci[i])(2,3);
88+
pt.x = (w_T_ci[i])(0,3) + offset_x;
89+
pt.y = (w_T_ci[i])(1,3) + offset_y;
90+
pt.z = (w_T_ci[i])(2,3) + offset_z;
9091

9192
marker.points.push_back( pt );
9293
marker.colors.push_back( C1 );
@@ -445,34 +446,39 @@ void VizPoseGraph::publishSlamResidueVisual( int n ) const
445446

446447

447448

448-
void VizPoseGraph::publishCameraVisualMarker( const Matrix4d& wTc, const string& ns, float r, float g, float b, float linewidth_multiplier, float camera_size_multiplier )
449+
void VizPoseGraph::publishCameraVisualMarker( const Matrix4d& wTc, const string& ns, float r, float g, float b,
450+
float linewidth_multiplier, float camera_size_multiplier,
451+
float offset_x, float offset_y, float offset_z )
449452
{
450453
visualization_msgs::Marker marker2 ;
451454
RosMarkerUtils::init_camera_marker( marker2, camera_size_multiplier );
452455
RosMarkerUtils::setpose_to_marker( wTc, marker2 );
453456
RosMarkerUtils::setcolor_to_marker( r,g,b, marker2 );
457+
marker2.pose.position.x += offset_x;
458+
marker2.pose.position.y += offset_y;
459+
marker2.pose.position.z += offset_z;
454460
marker2.scale.x = 0.08*linewidth_multiplier;
455461
marker2.id = 0;
456462
marker2.ns = ns+string("_cam_visual");
457463
pub_pgraph.publish( marker2 );
458464
}
459465

460-
void VizPoseGraph::publishXYZAxis( const Matrix4d& wT_axis, const string ns, int id )
466+
void VizPoseGraph::publishXYZAxis( const Matrix4d& wT_axis, const string ns, int id, float scale )
461467
{
462468
visualization_msgs::Marker axis;
463469
RosMarkerUtils::init_line_marker( axis );
464-
axis.id = 0;
470+
axis.id = id;
465471
axis.ns = ns.c_str();
466472
axis.scale.x = 0.2;
467473

468-
474+
float f = scale;
469475
// Add pts
470476
RosMarkerUtils::add_point_to_marker( 0,0,0, axis, true );
471-
RosMarkerUtils::add_point_to_marker( 1,0,0, axis, false );
477+
RosMarkerUtils::add_point_to_marker( f,0,0, axis, false );
472478
RosMarkerUtils::add_point_to_marker( 0,0,0, axis, false );
473-
RosMarkerUtils::add_point_to_marker( 0,1,0, axis, false );
479+
RosMarkerUtils::add_point_to_marker( 0,f,0, axis, false );
474480
RosMarkerUtils::add_point_to_marker( 0,0,0, axis, false );
475-
RosMarkerUtils::add_point_to_marker( 0,0,1, axis, false );
481+
RosMarkerUtils::add_point_to_marker( 0,0,f, axis, false );
476482

477483
// Add colors to each pt
478484
RosMarkerUtils::add_colors_to_marker( 1.0,0,0, axis, true );

src/VizPoseGraph.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,10 @@ class VizPoseGraph
4646
void setOdometryPublisher( const ros::Publisher& pub );
4747

4848
// void publishLastNNodes( int n ); //< Removal
49-
void publishNodesAsLineStrip( const vector<Matrix4d>& w_T_ci, const string& ns, float r, float g, float b, float linewidth_multiplier=1.0 ) const;
49+
void publishNodesAsLineStrip( const vector<Matrix4d>& w_T_ci, const string& ns,
50+
float r, float g, float b,
51+
float linewidth_multiplier=1.0,
52+
float offset_x=0., float offset_y=0., float offset_z=0. ) const;
5053
void publishNodesAsLineStrip( const vector<Matrix4d>& w_T_ci, const string& ns,
5154
float r, float g, float b,
5255
int idx_partition,
@@ -60,9 +63,11 @@ class VizPoseGraph
6063
void publishLastNEdges( int n ) const;
6164

6265
void publishSlamResidueVisual( int n ) const;
63-
void publishCameraVisualMarker( const Matrix4d& wTc, const string& ns, float r, float g, float b, float linewidth_multiplier=1.0, float camera_size_multiplier=10. );
66+
void publishCameraVisualMarker( const Matrix4d& wTc, const string& ns, float r, float g, float b,
67+
float linewidth_multiplier=1.0, float camera_size_multiplier=10.,
68+
float offset_x=0.0, float offset_y=0.0, float offset_z=0.0 );
6469

65-
void publishXYZAxis( const Matrix4d& wT_axis, const string ns, int id );
70+
void publishXYZAxis( const Matrix4d& wT_axis, const string ns, int id, float scale=1.0 );
6671
void publishThisVisualMarker( const visualization_msgs::Marker& the_marker );
6772
void publishImage( const cv::Mat& im );
6873

src/keyframe_pose_graph_slam_node.cpp

Lines changed: 117 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,10 @@ struct opt_traj_publisher_options
396396

397397
// The thickness of the lines
398398
float linewidth_multiplier=1.0;
399+
400+
401+
// Udumbe offset_y. When multiple co-ordinates exist, the offset for plotting on rviz. keep it 30.0
402+
float udumbe_offset_y = 30.0;
399403
};
400404

401405
// comment the following #define to remove the code which checks file's exisitance before printing.
@@ -1017,9 +1021,45 @@ void opt_traj_publisher_colored_by_world( const NodeDataManager * manager, const
10171021

10181022
}
10191023

1024+
//-----------------------------------------------------------------------------------------------//
1025+
//------------------------- After this only uses jmb and lmb to publish -------------------------//
1026+
//-----------------------------------------------------------------------------------------------//
1027+
1028+
//---
1029+
//--- Decide offset's (for plotting) different co-ordinate systems
1030+
//---
1031+
#if 1
1032+
map< int, int > setids_to_udumbes;
1033+
if( jmb.size() > 0 )
1034+
{
1035+
int h=0;
1036+
for( auto it=jmb.begin() ; it!=jmb.end() ; it++ ) {
1037+
int setid = manager->getWorldsConstPtr()->find_setID_of_world_i( it->first );
1038+
if( setid < 0 ) //ignore negative setids
1039+
continue;
1040+
if( setids_to_udumbes.count(setid) == 0 ) {
1041+
setids_to_udumbes[ setid ] = h;
1042+
h++;
1043+
}
1044+
}
1045+
1046+
#if 0
1047+
cout << TermColor::MAGENTA() << "---\n";
1048+
for( auto it=setids_to_udumbes.begin() ; it!=setids_to_udumbes.end() ; it++ ) {
1049+
cout << "setid=" << it->first << "\tudumbe=" << it->second << endl;
1050+
}
1051+
cout << TermColor::RESET();
1052+
#endif
1053+
1054+
}
1055+
#endif
1056+
1057+
1058+
10201059

10211060
//---
1022-
//--- Publish jmb
1061+
//--- Publish jmb.
1062+
// Note: jmb's keys are `worldIDs` and jmb's values are `vector<Matrix4d>& w_T_ci`
10231063
//---
10241064
if( jmb.size() == 0 )
10251065
{
@@ -1037,6 +1077,7 @@ void opt_traj_publisher_colored_by_world( const NodeDataManager * manager, const
10371077

10381078
float c_r=0., c_g=0., c_b=0.;
10391079
int rng=-1;
1080+
10401081
if( options.line_color_style == 10 )
10411082
rng = it->first; //color by world id WorldID
10421083
else if( options.line_color_style == 12 )
@@ -1060,7 +1101,21 @@ void opt_traj_publisher_colored_by_world( const NodeDataManager * manager, const
10601101
c_b = color[0]/255.;
10611102
}
10621103

1063-
viz->publishNodesAsLineStrip( it->second, ns.c_str(), c_r, c_g, c_b, options.linewidth_multiplier );
1104+
int curr_set_id = manager->getWorldsConstPtr()->find_setID_of_world_i( it->first );
1105+
float offset_x=0., offset_y=0., offset_z=0.;
1106+
if( curr_set_id >= 0 ) {
1107+
if ( setids_to_udumbes.count(curr_set_id) > 0 ) {
1108+
// cout << "rng=" << rng << "setids_to_udumbes"<< setids_to_udumbes.at( rng ) << endl;
1109+
offset_y = setids_to_udumbes.at( curr_set_id )*options.udumbe_offset_y;
1110+
}
1111+
} else {
1112+
curr_set_id = manager->getWorldsConstPtr()->find_setID_of_world_i( -it->first-1);
1113+
if ( setids_to_udumbes.count(curr_set_id) > 0 ) {
1114+
offset_y = setids_to_udumbes.at( curr_set_id )*options.udumbe_offset_y;
1115+
}
1116+
}
1117+
1118+
viz->publishNodesAsLineStrip( it->second, ns.c_str(), c_r, c_g, c_b, options.linewidth_multiplier, offset_x, offset_y, offset_z );
10641119
}
10651120
// #endif
10661121

@@ -1091,7 +1146,25 @@ void opt_traj_publisher_colored_by_world( const NodeDataManager * manager, const
10911146
c_g = color[1]/255.;
10921147
c_b = color[0]/255.;
10931148
}
1094-
viz->publishCameraVisualMarker( wi_T_latest, "world##", c_r, c_g, c_b, options.linewidth_multiplier, 20 );
1149+
1150+
1151+
int curr_set_id = manager->getWorldsConstPtr()->find_setID_of_world_i( latest_pose_worldid );
1152+
float offset_x=0., offset_y=0., offset_z=0.;
1153+
if( curr_set_id >= 0 ) {
1154+
if ( setids_to_udumbes.count(curr_set_id) > 0 ) {
1155+
// cout << "rng=" << rng << "setids_to_udumbes"<< setids_to_udumbes.at( rng ) << endl;
1156+
offset_y = setids_to_udumbes.at( curr_set_id )*options.udumbe_offset_y;
1157+
}
1158+
} else {
1159+
curr_set_id = manager->getWorldsConstPtr()->find_setID_of_world_i( -latest_pose_worldid-1 );
1160+
if ( setids_to_udumbes.count(curr_set_id) > 0 ) {
1161+
offset_y = setids_to_udumbes.at( curr_set_id )*options.udumbe_offset_y;
1162+
}
1163+
}
1164+
1165+
viz->publishCameraVisualMarker( wi_T_latest, "world##", c_r, c_g, c_b,
1166+
options.linewidth_multiplier, 20,
1167+
offset_x, offset_y, offset_z );
10951168

10961169

10971170
// Publish loop edges
@@ -1107,19 +1180,53 @@ void opt_traj_publisher_colored_by_world( const NodeDataManager * manager, const
11071180
auto pair = manager->getEdgeIdxInfo( it );
11081181
int __a = pair.first;
11091182
int __b = pair.second;
1110-
Vector3d ____apose = lbm[__a];
1111-
Vector3d ____bpose = lbm[__b];
1183+
1184+
int __a_worldid = manager->which_world_is_this( manager->getNodeTimestamp(__a) );
1185+
int __a_setid = manager->getWorldsConstPtr()->find_setID_of_world_i( __a_worldid );
1186+
int __b_worldid = manager->which_world_is_this( manager->getNodeTimestamp(__b) );
1187+
int __b_setid = manager->getWorldsConstPtr()->find_setID_of_world_i( __b_worldid );
1188+
#if 0
1189+
cout << TermColor::CYAN() ;
1190+
cout << "it=" << it;
1191+
cout << "__a=" << __a << " __a_worldid=" << __a_worldid << " __a_setid=" << __a_setid << "\t|";
1192+
cout << "__b=" << __b << " __b_worldid=" << __b_worldid << " __b_setid=" << __b_setid << "\n";
1193+
cout << TermColor::RESET();
1194+
#endif
1195+
1196+
int __a_udumbe = 0, __b_udumbe=0;
1197+
if( setids_to_udumbes.count(__a_setid) > 0 )
1198+
__a_udumbe = setids_to_udumbes.at( __a_setid );
1199+
if( setids_to_udumbes.count(__b_setid) > 0 )
1200+
int __b_udumbe = setids_to_udumbes.at( __b_setid );
1201+
1202+
Vector3d ____apose = lbm[__a] + Vector3d( 0., options.udumbe_offset_y*__a_udumbe , 0.0 );
1203+
Vector3d ____bpose = lbm[__b] + Vector3d( 0., options.udumbe_offset_y*__a_udumbe , 0.0 );
11121204

11131205
RosMarkerUtils::add_point_to_marker( ____apose, linelist_marker, false );
11141206
RosMarkerUtils::add_point_to_marker( ____bpose, linelist_marker, false );
11151207
}
11161208
viz->publishThisVisualMarker( linelist_marker );
11171209

11181210

1211+
// if( published_axis || rand() % 100 == 0 ) {
11191212
if( published_axis || rand() % 100 == 0 ) {
1120-
Matrix4d _axis_pose = Matrix4d::Identity();
11211213
// odm_axis_pose(0,3) += offset_x; odm_axis_pose(1,3) += offset_y; odm_axis_pose(2,3) += offset_z;
1122-
viz->publishXYZAxis( _axis_pose, "opt_traj_axis", 0 );
1214+
// viz->publishXYZAxis( _axis_pose, "opt_traj_axis", 0 );
1215+
1216+
for( int p=0 ; p<setids_to_udumbes.size() ; p++ ) {
1217+
Matrix4d _axis_pose = Matrix4d::Identity();
1218+
_axis_pose(0,3) += 0.0; _axis_pose(1,3) += p*options.udumbe_offset_y; _axis_pose(2,3) += 0.0;
1219+
viz->publishXYZAxis( _axis_pose, "opt_traj_axis", p, 2.0 );
1220+
}
1221+
1222+
if( rand() %1000 == 0 ) {
1223+
// once in a while flush the unused co-ordinates
1224+
Matrix4d _axis_pose = Matrix4d::Identity();
1225+
for( int p=setids_to_udumbes.size() ; p<20; p++ ) {
1226+
viz->publishXYZAxis( _axis_pose, "opt_traj_axis", 0, 0.0 );
1227+
}
1228+
}
1229+
11231230
published_axis = false;
11241231
}
11251232

@@ -1355,7 +1462,8 @@ int main( int argc, char ** argv)
13551462
// 10 //< color the line with worldID
13561463
// 12 //< color the line with setID( worldID )
13571464
options.line_color_style = 10;
1358-
options.linewidth_multiplier = 0.25;
1465+
options.linewidth_multiplier = 3; //0.25; //8
1466+
options.udumbe_offset_y = 30.0;
13591467
std::thread th6( opt_traj_publisher_colored_by_world, manager, slam, viz, options );
13601468

13611469

@@ -1384,7 +1492,7 @@ int main( int argc, char ** argv)
13841492

13851493

13861494

1387-
#define __LOGGING__ 1 // make this 1 to enable logging. 0 to disable logging. rememeber to catkin_make after this change
1495+
#define __LOGGING__ 0 // make this 1 to enable logging. 0 to disable logging. rememeber to catkin_make after this change
13881496
#if __LOGGING__
13891497
// Note: If using roslaunch to launch this node and when LOGGING is enabled,
13901498
// roslaunch sends a sigterm and kills this thread when ros::ok() returns false ie.

0 commit comments

Comments
 (0)