1

I am currently trying to optimize a multi constraints function for SLAM. Classic optimization function minimize reprojection errors with g2o like proposed in https://fzheng.me/2016/03/15/g2o-demo/.

My problem is that I do not know how to modify this g2o sample code to jointly optimize two constraints (for example : 1 constraint for reprojection error and 1 constraint for inertial error).

Regards,

sa.l_dev
  • 189
  • 1
  • 10

1 Answers1

0

To include a custom constraint, you must to implement a specification of one BaseEdge<> subclasses.

There are 3 subclasses of BaseEdge<> that are BaseUnaryEdge<> (for self-constraints), BaseBinaryEdge<> (between 2 nodes) and BaseMultiEdge<> (arbitrary number of nodes).

Inertial error is a self-constraint, so you must specify an implementation of BaseUnaryEdge.

It is mandatory to implement just the computeError() method in your custom class, but you can also implement linearizeOplus() to set the jacobian by hand.

Then you can follow the sample code you posted. Instantiate the optimizer, create vertices, add reprojection constraints and add your custom inertial constraints.

  • Thanks a lot for the information! How do you define if a constraint is a self-constraint ? – sa.l_dev Dec 16 '19 at 13:54
  • self-constraint constraints the measurement itself, not a relation between measurements. – Douglas Oliveira Dec 16 '19 at 14:02
  • Can we add weights to constraints ? I mean if I jointly optimize c1 and c2 (two different constraints), can I assign them a weight ? Like alpha*c1 and beta * c2. – sa.l_dev Mar 20 '20 at 14:39
  • @sa.l_dev Yeah, you decide the way to compute the error in your custom computeError() method. You can put the weights as attributes of your derived edge class. – Douglas Oliveira Mar 23 '20 at 12:05