Skip to content

Commit d77962d

Browse files
committed
a. save the poses in their own worlds when loading from disk. There some glitches and corner cases still remain, but is usually ok. also load and save can now be done with roslaunch params
1 parent f75fe38 commit d77962d

5 files changed

Lines changed: 83 additions & 5 deletions

File tree

src/Composer.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ void Composer::pose_assember_thread( int looprate )
124124
w_TM_i = manager->getNodePose( i );
125125
#if 1 // added during loadStateFromDisk implementation
126126
w_TM_i_from_mgr_or_from_slam = 0;
127-
#endif
127+
#endif
128128
} else {
129129
if( world_id >= 0 && ____solvedUntil_worldid == world_id ) {
130130
last_idx = ____solvedUntil;}
@@ -296,9 +296,11 @@ void Composer::bf_traj_publish_thread( int looprate ) const
296296
static thread_local std::mt19937 generator;
297297
std::uniform_int_distribution<int> distribution(0,100);
298298

299+
int x_loop_count = 0;
299300
while( b_bf_traj_publish )
300301
{
301302
rate.sleep();
303+
x_loop_count++;
302304
__Composer_bf_traj_publish_thread(
303305
cout << "[Composer::bf_traj_publish_thread] publish : global_lmb.size()=" << global_lmb.size() << "\t n_worlds aka. global_jmb.size()=" << global_jmb.size() << endl;
304306
)
@@ -313,7 +315,7 @@ void Composer::bf_traj_publish_thread( int looprate ) const
313315
continue;
314316
}
315317

316-
bool publish_all = (distribution(generator) < 5)?true:false;
318+
bool publish_all = (distribution(generator) < 5 || x_loop_count < 10 )?true:false;
317319

318320

319321
for( auto it=global_jmb.begin() ; it!=global_jmb.end() ; it++ )

src/NodeDataManager.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,9 @@ void NodeDataManager::loopclosure_pose_callback( const cerebro::LoopEdge::Const
179179
loopclosure_edges_timestamps.push_back( std::make_pair( t_a, t_b) );
180180
}
181181
else {
182-
cout << TermColor::YELLOW() << "[NodeDataManager::loopclosure_pose_callback] This edge's end points cannot be found in vector of nodes. This is not FATAL, I am ignoring this edge candidate as a fix.Ideally this should not be happening.\n" << TermColor::RESET() << endl;
182+
cout << TermColor::YELLOW() << "[NodeDataManager::loopclosure_pose_callback] This edge's end points( t_a=" << t_a << ", t_b=" << t_b << ") cannot be found in vector of nodes. This is not FATAL, I am ignoring this edge candidate as a fix.Ideally this should not be happening." << TermColor::RESET() << endl;
183+
cout << "t_a=" << t_a << " t_b=" << t_b << endl;
184+
cout << "index_t_a=" << index_t_a << " index_t_b=" << index_t_b << endl;
183185
}
184186

185187

@@ -1027,7 +1029,7 @@ bool NodeDataManager::load_solved_posegraph_data_from_json( json obj )
10271029
cout << "wset_T_cam=" << PoseManipUtils::prettyprintMatrix4d( ___w_T_c ) << endl;
10281030
}
10291031
if( i==3 ) {
1030-
cout << ".\n.\n.\n";
1032+
cout << "\t.\n\t.\n\t.\n";
10311033
}
10321034

10331035
// For everything to be working correctly, I need to store the wTc and not wsTc

src/keyframe_pose_graph_slam_node.cpp

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,51 @@ int main( int argc, char ** argv)
236236
ros::NodeHandle nh("~");
237237

238238

239+
//--- loadStateFromDisk, saveStateToDisk ---//
240+
string loadStateFromDisk = "";
241+
if( nh.getParam( "loadStateFromDisk", loadStateFromDisk ) == true )
242+
{
243+
if( loadStateFromDisk.compare("") == 0 ) {
244+
ROS_WARN( "[keyframe_pose_graph_slam_node] loadStateFromDisk cmdline parameter was found, but with a empty string, so I will not loadStateFromDisk()");
245+
} else {
246+
// now make sure it is a directory
247+
if( RawFileIO::is_path_a_directory(loadStateFromDisk) ) {
248+
ROS_INFO( "[keyframe_pose_graph_slam_node] loadStateFromDisk=%s, Directory exists...OK!", loadStateFromDisk.c_str() );
249+
cout << TermColor::GREEN() << "[keyframe_pose_graph_slam_node] loadStateFromDisk=" << loadStateFromDisk << ", Directory exists...OK!" << TermColor::RESET() << endl;
250+
}
251+
else {
252+
ROS_ERROR( "[keyframe_pose_graph_slam_node] You specified a directory for loadStateFromDisk=`%s`, This path need to exist\n...EXIT\n", loadStateFromDisk.c_str());
253+
exit(1);
254+
}
255+
}
256+
} else {
257+
ROS_WARN( "[keyframe_pose_graph_slam_node] loadStateFromDisk cmdline parameter was not found, so I will not loadStateFromDisk()");
258+
}
259+
260+
string saveStateToDisk = "";
261+
if( nh.getParam( "saveStateToDisk", saveStateToDisk ) == true )
262+
{
263+
if( saveStateToDisk.compare("") == 0 ) {
264+
ROS_WARN( "[keyframe_pose_graph_slam_node] saveStateToDisk cmdline parameter was found, but with a empty string, so I will not saveStateToDisk()");
265+
} else {
266+
// now make sure it is a directory
267+
if( RawFileIO::is_path_a_directory(saveStateToDisk) ) {
268+
ROS_INFO( "[keyframe_pose_graph_slam_node] saveStateToDisk=%s, Directory exists...OK!", saveStateToDisk.c_str() );
269+
cout << TermColor::GREEN() << "[keyframe_pose_graph_slam_node] saveStateToDisk=" << saveStateToDisk << ", Directory exists...OK!" << TermColor::RESET() << endl;
270+
}
271+
else {
272+
ROS_ERROR( "[keyframe_pose_graph_slam_node] You specified a directory for saveStateToDisk=`%s`, This path need to exist and be writable\n...EXIT\n", saveStateToDisk.c_str());
273+
exit(1);
274+
}
275+
}
276+
} else {
277+
ROS_WARN( "[keyframe_pose_graph_slam_node] saveStateToDisk cmdline parameter was not found, so I will not saveStateToDisk()");
278+
}
279+
280+
//--- END loadStateFromDisk, saveStateToDisk ---//
281+
282+
283+
239284
// Setup subscribers and callbacks
240285
NodeDataManager * manager = new NodeDataManager(nh);
241286

@@ -327,6 +372,11 @@ int main( int argc, char ** argv)
327372
// exit(1);
328373
#endif
329374

375+
if( loadStateFromDisk.compare("") != 0 )
376+
{
377+
cmpr->loadStateFromDisk( loadStateFromDisk );
378+
}
379+
330380

331381
// ++ start the pose assember thread - This is needed for the following publish threads
332382
// It queries data from manager, slam and assembles the upto date data. This is threadsafe.
@@ -423,11 +473,16 @@ int main( int argc, char ** argv)
423473

424474

425475
//make this to 1 to save state to file upon exit, 0 to disable saving to file
426-
#define __SAVE_STATE__ 1
476+
#define __SAVE_STATE__ 0
427477
#if __SAVE_STATE__
428478
cmpr->saveStateToDisk( "/Bulk_Data/chkpts_posegraph_solver" );
429479
#endif
430480

481+
if( saveStateToDisk.compare("") != 0 )
482+
{
483+
cmpr->saveStateToDisk( saveStateToDisk );
484+
}
485+
431486
#define __LOGGING__ 0 // make this 1 to enable logging. 0 to disable logging. rememeber to catkin_make after this change
432487
#if __LOGGING__
433488
// Note: If using roslaunch to launch this node and when LOGGING is enabled,

src/utils/RawFileIO.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,18 @@ bool RawFileIO::read_eigen_vector_fromjson( const json str, VectorXd& output )
456456

457457

458458

459+
460+
bool RawFileIO::is_path_a_directory(const char* path)
461+
{
462+
struct stat buf;
463+
stat(path, &buf);
464+
return S_ISDIR(buf.st_mode);
465+
}
466+
467+
bool RawFileIO::is_path_a_directory(const string path) { return is_path_a_directory(path.c_str() ); }
468+
469+
470+
459471
std::vector<std::string>
460472
RawFileIO::split( std::string const& original, char separator )
461473
{

src/utils/RawFileIO.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ using json = nlohmann::json;
3333

3434
#define __RawFileIO__write_image_debug_dm( msg ) msg;
3535

36+
#include <sys/stat.h> // for is_directory
37+
38+
3639
class RawFileIO
3740
{
3841
public:
@@ -101,6 +104,10 @@ class RawFileIO
101104

102105
static bool if_file_exist( char * fname );
103106
static bool if_file_exist( string fname );
107+
108+
static bool is_path_a_directory(const char* path);
109+
static bool is_path_a_directory(const string path);
110+
104111
static int exec_cmd( const string& cmd ); //< Executes a unix command.
105112

106113

0 commit comments

Comments
 (0)