Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot apply calibration (setParameterId) #670

Open
julia-sanchez-kitware opened this issue Mar 30, 2023 · 2 comments
Open

Cannot apply calibration (setParameterId) #670

julia-sanchez-kitware opened this issue Mar 30, 2023 · 2 comments

Comments

@julia-sanchez-kitware
Copy link

julia-sanchez-kitware commented Mar 30, 2023

Hello,

I am struggling with the behavior of the parameters. I want to add an offset calibration on an edge.
So I have added a ParameterSE3Offset to the optimizer containing the transform matrix as it is done in this example.
Then, I have used the function SetParameterId on the edge to link the edge to the calibration as it is done in the example.

However, it seems that SetParameterId always returns false because of this check. Indeed, the parameters vector is empty after the edge creation and setParameterId does not update it. I didn't find any other function updating _parameters in the examples making SetParameterId succeed...

I can make it work using this hack patch from master (warning it implies a memory leak for now):

diff --git a/g2o/core/optimizable_graph.cpp b/g2o/core/optimizable_graph.cpp
index 33ebbf89..2e635b96 100644
--- a/g2o/core/optimizable_graph.cpp
+++ b/g2o/core/optimizable_graph.cpp
@@ -132,9 +132,13 @@ const OptimizableGraph* OptimizableGraph::Edge::graph() const {
 }
 
 bool OptimizableGraph::Edge::setParameterId(int argNum, int paramId) {
-  if ((int)_parameters.size() <= argNum) return false;
   if (argNum < 0) return false;
-  *_parameters[argNum] = 0;
+  if ((int)_parameters.size() <= argNum)
+  {
+      _parameters.resize(argNum);
+      _parameterTypes.resize(argNum);
+      _parameterIds.resize(argNum);
+  }
   _parameterIds[argNum] = paramId;
   return true;
 }
@@ -150,6 +154,8 @@ bool OptimizableGraph::Edge::resolveParameters() {
   // parameters" << endl;
   for (size_t i = 0; i < _parameters.size(); i++) {
     int index = _parameterIds[i];
+    if (!_parameters[i])
+      _parameters[i] = new Parameter*;
     *_parameters[i] = graph()->parameter(index);
     auto& aux = **_parameters[i];
     if (typeid(aux).name() != _parameterTypes[i]) {

What am I doing wrong?

Thank you for your help!

@RainerKuemmerle
Copy link
Owner

Which edge are you using at the moment?
The c'tor of the edge should take care of the lines you patched in the base class, see for example
https://github.com/RainerKuemmerle/g2o/blob/master/g2o/types/slam3d/edge_se3_offset.cpp#L39:L48

@julia-sanchez-kitware
Copy link
Author

Thank you for your prompt response!
Oh yes, I am using a basic edge_se3 and it seems the constructor does not init the params... So edge_se3_offset seems closer to what I need. Is there a description of the available edges somewhere?
Can you confirm this setting will take care of rotating the covariance which is input?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants