Skip to content

Commit f75fe38

Browse files
committed
manager need to have camera pose in its world and not in its setID_of_world onstateload. Adjusted this part, looks like everything is correct now, try a few more test cases before merge with master
1 parent cc09c35 commit f75fe38

5 files changed

Lines changed: 93 additions & 20 deletions

File tree

src/Composer.cpp

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,14 @@ void Composer::pose_assember_thread( int looprate )
5454
for( int i=0 ; i<manager->getNodeLen() ; i++ )
5555
{
5656
int world_id = manager->which_world_is_this( manager->getNodeTimestamp(i) );
57+
int setID_of_worldID = manager->getWorldsConstPtr()->find_setID_of_world_i( world_id );
5758
__Composer__pose_assember_thread_posedebug(
58-
cout << "i=" << i << " world#" << world_id << endl;
59+
cout << "\t%% i=" << i << " world#" << world_id << " setID_of_worldID=" << setID_of_worldID << endl;
5960
)
6061

6162
if( i>=0 && i<= ____solvedUntil )
6263
{
64+
__Composer__pose_assember_thread_posedebug( cout << "in i>=0 && i<= ____solvedUntil\n" );
6365
Matrix4d w_T_c;
6466
// If the optimized pose exists use that else use the odometry pose
6567
int from_slam_or_from_odom = -1; // 1: from slam ; 2: from odom ; 3: kidnapped node
@@ -74,6 +76,9 @@ void Composer::pose_assember_thread( int looprate )
7476
w_T_c = manager->getNodePose( i );
7577
// cerr << "w_T_c=" << PoseManipUtils::prettyprintMatrix4d( w_T_c ) << endl;
7678
from_slam_or_from_odom = 2;
79+
80+
81+
7782
}
7883
}
7984
} else {
@@ -107,11 +112,19 @@ void Composer::pose_assember_thread( int looprate )
107112

108113
if( i>(____solvedUntil) )
109114
{
115+
__Composer__pose_assember_thread_posedebug( cout << "in i>(____solvedUntil)\n" );
116+
110117
int last_idx=-1;
111118
Matrix4d w_TM_i;
119+
#if 1 // added during loadStateFromDisk implementation
120+
int w_TM_i_from_mgr_or_from_slam = -1; // 0: mgr, 1: slam
121+
#endif
112122

113123
if( ____solvedUntil == 0 ) {
114124
w_TM_i = manager->getNodePose( i );
125+
#if 1 // added during loadStateFromDisk implementation
126+
w_TM_i_from_mgr_or_from_slam = 0;
127+
#endif
115128
} else {
116129
if( world_id >= 0 && ____solvedUntil_worldid == world_id ) {
117130
last_idx = ____solvedUntil;}
@@ -152,6 +165,29 @@ void Composer::pose_assember_thread( int looprate )
152165
}
153166

154167

168+
#if 1
169+
// added during loadStateFromDisk implementation
170+
// idea is always set ws_T_c and not the usual w_T_c
171+
// ws_T_c := ws_T_w * w_T_c
172+
if( world_id != setID_of_worldID && w_TM_i_from_mgr_or_from_slam==0 ) {
173+
__Composer__pose_assember_thread_posedebug(
174+
cout << "[world_id != setID_of_worldID]i=" << i << " world#" << world_id << " setID_of_worldID=" << setID_of_worldID << endl;
175+
);
176+
if( manager->getWorldsConstPtr()->is_exist(setID_of_worldID,world_id) ) {
177+
__Composer__pose_assember_thread_posedebug(
178+
cout << "[world_id != setID_of_worldID]relative pose exist beween these worlds.\n";
179+
);
180+
Matrix4d ws_T_w = manager->getWorldsConstPtr()->getPoseBetweenWorlds(setID_of_worldID,world_id);
181+
Matrix4d ws_T_c = ws_T_w * w_TM_i;
182+
w_TM_i = ws_T_c;
183+
} else {
184+
__Composer__pose_assember_thread_posedebug( cout << "[world_id != setID_of_worldID]relative pose doesnt exist beween these worlds.\n"; );
185+
}
186+
}
187+
188+
#endif // end of addition during oadStateFromDisk implementation
189+
190+
155191
if( jmb.count( world_id ) == 0 ) {
156192
__Composer__pose_assember_thread_posedebug(
157193
cout << "jmb[" << world_id << "] = vector<Matrix4d>() \n";

src/NodeDataManager.cpp

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -832,6 +832,23 @@ const ros::Time NodeDataManager::last_kidnap_started() const
832832
}
833833
}
834834

835+
836+
void NodeDataManager::mark_as_kidnapped_and_signal_end_of_world() //this is needed to be done when CTRL+C is called ie. when saveStateToDisk is to be performed
837+
{
838+
cout << "[NodeDataManager::mark_as_kidnapped_and_signal_end_of_world]" << endl;
839+
ros::Time last_ti_stamp = * ( node_timestamps.rbegin() );
840+
mark_as_kidnapped( last_ti_stamp );
841+
worlds_handle_raw_ptr->world_ends( last_ti_stamp );
842+
}
843+
844+
void NodeDataManager::mark_as_unkidnapped_and_signal_start_of_world( ros::Time _t_begin) //this is called when loading data from disk
845+
{
846+
cout << "[NodeDataManager::mark_as_unkidnapped_and_signal_start_of_world] _t_begin=" << _t_begin << endl;
847+
848+
mark_as_unkidnapped( _t_begin );
849+
worlds_handle_raw_ptr->world_starts( _t_begin );
850+
}
851+
835852
json NodeDataManager::kidnap_data_to_json() const
836853
{
837854
std::lock_guard<std::mutex> lk(mutex_kidnap);
@@ -993,14 +1010,44 @@ bool NodeDataManager::load_solved_posegraph_data_from_json( json obj )
9931010
int _worldID = obj.at("SolvedPoseGraph").at(i).at("worldID");
9941011
ros::Time _tnode = ros::Time().fromNSec( obj.at("SolvedPoseGraph").at(i).at("stampNSec") );
9951012

996-
Matrix4d ___w_T_c;
1013+
Matrix4d ___w_T_c; //< this is actually ws_T_cam (cam position in world-set-id, )
9971014
bool poseloadstatus=RawFileIO::read_eigen_matrix4d_fromjson( obj.at("SolvedPoseGraph").at(i).at("w_T_c"), ___w_T_c );
9981015
if( poseloadstatus == false )
9991016
{
10001017
cout << TermColor::RED() << "When loading SolvedPoseGraph[" << i << "], RawFileIO::read_eigen_matrix4d_fromjson returned false. This means, I cannot read the pose from json file\n" << TermColor::RESET() ;
10011018
return false;
10021019
}
10031020

1021+
1022+
if( i==0 || i==1 || i==2 || i==n_nodes-1 || i== n_nodes-2) {
1023+
cout << "i=" << i << "\t";
1024+
cout << "t=" << _tnode << "\t";
1025+
cout << "_worldID=" << _worldID << "\t";
1026+
cout << "_setID_of_worldID=" << _setID_of_worldID << "\t";
1027+
cout << "wset_T_cam=" << PoseManipUtils::prettyprintMatrix4d( ___w_T_c ) << endl;
1028+
}
1029+
if( i==3 ) {
1030+
cout << ".\n.\n.\n";
1031+
}
1032+
1033+
// For everything to be working correctly, I need to store the wTc and not wsTc
1034+
// w_T_c := w_T_ws * ws_T_c
1035+
if( _worldID >= 0 && _worldID != _setID_of_worldID )
1036+
{
1037+
Matrix4d wTws = Matrix4d::Identity();
1038+
if( getWorldsConstPtr()->is_exist(_worldID,_setID_of_worldID) )
1039+
wTws = getWorldsConstPtr()->getPoseBetweenWorlds( _worldID,_setID_of_worldID );
1040+
else {
1041+
cout << "[NodeDataManager::load_solved_posegraph_data_from_json] ERROR";
1042+
cout << "at i="<< i << "you requesting a pose between the worlds "<< _worldID << " and " << _setID_of_worldID << " that does not exist. This cannot be happening\n";
1043+
getWorldsConstPtr()->print_summary();
1044+
exit(1);
1045+
}
1046+
Matrix4d f_wTc = wTws * ___w_T_c;
1047+
___w_T_c = f_wTc;
1048+
}
1049+
1050+
10041051
// verify worldID and setID_of_worldID
10051052
#if 1
10061053
if( _worldID >= 0 && _setID_of_worldID>=0 ) {

src/NodeDataManager.h

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -159,22 +159,11 @@ class NodeDataManager
159159
ros::Time stamp_of_kidnap_i_started( int i ) const;
160160
ros::Time stamp_of_kidnap_i_ended( int i ) const;
161161
int n_kidnaps() const;
162+
163+
void mark_as_kidnapped_and_signal_end_of_world(); //this is needed to be done when CTRL+C is called ie. when saveStateToDisk is to be performed
164+
void mark_as_unkidnapped_and_signal_start_of_world( ros::Time _t_begin); //this is called when loading data from disk
165+
162166
json kidnap_data_to_json() const;
163-
void mark_as_kidnapped_and_signal_end_of_world() //this is needed to be done when CTRL+C is called ie. when saveStateToDisk is to be performed
164-
{
165-
cout << "[NodeDataManager::mark_as_kidnapped_and_signal_end_of_world]" << endl;
166-
ros::Time last_ti_stamp = * ( node_timestamps.rbegin() );
167-
mark_as_kidnapped( last_ti_stamp );
168-
worlds_handle_raw_ptr->world_ends( last_ti_stamp );
169-
}
170-
171-
void mark_as_unkidnapped_and_signal_start_of_world( ros::Time _t_begin) //this is called when loading data from disk
172-
{
173-
cout << "[NodeDataManager::mark_as_unkidnapped_and_signal_start_of_world] _t_begin=" << _t_begin << endl;
174-
175-
mark_as_unkidnapped( _t_begin );
176-
worlds_handle_raw_ptr->world_starts( _t_begin );
177-
}
178167
bool load_kidnap_data_from_json( json obj ); //< See comments in the implementation for json input format
179168
bool load_solved_posegraph_data_from_json( json obj ); //< See comments in the implementation for json input format
180169

src/Worlds.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -478,12 +478,13 @@ bool Worlds::loadStateFromDisk( json _objk )
478478
return false;
479479
}
480480

481-
481+
cout << "\t" << node_b << "_T_" << node_a ;
482482
rel_pose_between_worlds__wb_T_wa[ p ] = wb_T_wa;
483483
rel_pose_between_worlds__wb_T_wa___info_string[ p ] = info_wb_T_wa;
484484

485485

486486
}
487+
cout << endl;
487488
cout << "OK...rel_pose_between_worlds__wb_T_wa\n";
488489

489490

src/keyframe_pose_graph_slam_node.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ int main( int argc, char ** argv)
320320
//----Pose Composer---//
321321
Composer * cmpr = new Composer( manager, slam, viz , nh);
322322

323-
#define __LOAD_STATE__ 1 //set this to 1 to enable, 0 to disable
323+
#define __LOAD_STATE__ 0 //set this to 1 to enable, 0 to disable
324324
#if __LOAD_STATE__
325325
cmpr->loadStateFromDisk( "/Bulk_Data/chkpts_posegraph_solver" );
326326
// cout << "PREMATURE EXIT\n";
@@ -423,7 +423,7 @@ int main( int argc, char ** argv)
423423

424424

425425
//make this to 1 to save state to file upon exit, 0 to disable saving to file
426-
#define __SAVE_STATE__ 0
426+
#define __SAVE_STATE__ 1
427427
#if __SAVE_STATE__
428428
cmpr->saveStateToDisk( "/Bulk_Data/chkpts_posegraph_solver" );
429429
#endif

0 commit comments

Comments
 (0)