Skip to content

Commit 5b6006c

Browse files
committed
added a regularization penalty which will ask as mark_as_constant
1 parent b71e405 commit 5b6006c

2 files changed

Lines changed: 45 additions & 17 deletions

File tree

src/PoseGraphSLAM.cpp

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1383,11 +1383,13 @@ void PoseGraphSLAM::reinit_ceres_problem_onnewloopedge_optimize6DOF()
13831383
reint_options.linear_solver_type = ceres::SPARSE_NORMAL_CHOLESKY;
13841384
reint_options.minimizer_progress_to_stdout = false;
13851385
reint_options.max_num_iterations = 50;
1386+
// reint_options.enable_fast_removal = true;
13861387
eigenquaternion_parameterization = new ceres::EigenQuaternionParameterization;
13871388
// robust_norm = new ceres::CauchyLoss(1.0);
13881389
robust_norm = new ceres::HuberLoss(0.1);
13891390

13901391
std::map< int , std::tuple<int,int> > changes_to_setid_on_set_union; // key:= worldID, value:= (prev setID of this world, new setID of this world).
1392+
vector<ceres::ResidualBlockId> regularization_terms_list;
13911393

13921394

13931395
while( reinit_ceres_problem_onnewloopedge_optimize6DOF_isEnabled )
@@ -1855,19 +1857,43 @@ void PoseGraphSLAM::reinit_ceres_problem_onnewloopedge_optimize6DOF()
18551857

18561858

18571859
//-----------------------------
1858-
// Mark nodes as constant. Possibly also need to mark starts of each worlds as constants.
1860+
// Mark nodes as constant. Possibly also need to mark starts of each worlds as constants. Can also try setting each sets 1st node as constant.
18591861
//------------------------------
1862+
for( int v=0 ; v<regularization_terms_list.size() ; v++ ) {
1863+
reint_problem.RemoveResidualBlock( regularization_terms_list[v] );
1864+
cout << "Remove " << v << " th regularization term\n";
1865+
}
1866+
regularization_terms_list.clear();
1867+
18601868
std::map< int, bool > mark_as_constant;
18611869
// mark_as_constant[0] = true;
18621870
mark_as_constant[1] = true;
18631871
for( int ww=0 ; ww<manager->n_worlds(); ww++ ) {
1864-
if( mark_as_constant.count(ww) ==0 )
1865-
continue;
1872+
// if( mark_as_constant.count(ww) ==0 )
1873+
// continue;
1874+
int ww_setid = manager->getWorldsConstPtr()->find_setID_of_world_i(ww);
1875+
cout << "&&&&&&&&&&&&world#" << ww << " is in setID=" << ww_setid << endl;
1876+
if( ww_setid >= 0 && ww_setid==ww ) {
1877+
1878+
18661879
int ww_start = manager->nodeidx_of_world_i_started( ww );
1867-
reint_problem.SetParameterBlockConstant( get_raw_ptr_to_opt_variable_q(ww_start) );
1868-
reint_problem.SetParameterBlockConstant( get_raw_ptr_to_opt_variable_t(ww_start) );
1869-
cout << "Mark node#" << ww_start << " as constant\n";
1880+
// reint_problem.SetParameterBlockConstant( get_raw_ptr_to_opt_variable_q(ww_start) );
1881+
// reint_problem.SetParameterBlockConstant( get_raw_ptr_to_opt_variable_t(ww_start) );
1882+
1883+
ceres::CostFunction * regularixa_cost = NodePoseRegularization::Create( getNodePose(ww_start), 1.2 );
1884+
ceres::ResidualBlockId resi_id = reint_problem.AddResidualBlock( regularixa_cost, NULL, get_raw_ptr_to_opt_variable_q(ww_start), get_raw_ptr_to_opt_variable_t(ww_start) );
1885+
regularization_terms_list.push_back( resi_id );
1886+
1887+
cout << "node#" << ww_start << " is in world#" << ww << " which has setID as " << ww_setid << endl;
1888+
cout << "Mark node#" << ww_start << " as constant. \n";
1889+
}
1890+
else
1891+
cout << "skip\n";
18701892
}
1893+
cout << "Total elements in `regularization_terms_list` = " << regularization_terms_list.size() << endl;
1894+
1895+
1896+
18711897

18721898

18731899
//-----------------------

src/PoseGraphSLAM.h

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -293,26 +293,28 @@ class NodePoseRegularization
293293
npose.col(3).topRows(3) = p_1;
294294

295295
// nodepose --> T
296-
Matrix<T,4,4> f = nodepose.cast<float> ();
296+
Matrix<T,4,4> f = nodepose.cast<T> ();
297297

298298
Matrix<T,4,4> delta = f.inverse() * npose ;
299-
Quaternion<T> delta_q( delta.topLeftCorner(3,3) );
299+
Matrix<T,3,3> R = delta.topLeftCorner(3,3);
300+
Quaternion<T> delta_q( R );
301+
300302

301303
Eigen::Map<Matrix<T,6,1> > residuals( residue_ptr );
302304
residuals.block(0,0, 3,1) = T(weight) * delta.col(3).topRows(3);
303305
residuals.block(3,0, 3,1) = T(weight) * T(2.0) * delta_q.vec();
304-
306+
305307
return true;
306308
}
307309

308-
// static ceres::CostFunction* Create( const Matrix4d& _observed_node_pose, const double xweight )
309-
// {
310-
// return ( new ceres::AutoDiffCostFunction<NodePoseRegularization,6,4,3>
311-
// (
312-
// new NodePoseRegularization(_observed_node_pose, xweight )
313-
// )
314-
// );
315-
// }
310+
static ceres::CostFunction* Create( const Matrix4d& _observed_node_pose, const double xweight )
311+
{
312+
return ( new ceres::AutoDiffCostFunction<NodePoseRegularization,6,4,3>
313+
(
314+
new NodePoseRegularization(_observed_node_pose, xweight )
315+
)
316+
);
317+
}
316318

317319
private:
318320
const Matrix4d& nodepose;

0 commit comments

Comments
 (0)