-
Notifications
You must be signed in to change notification settings - Fork 856
Updated elaboratePoint2KalmanFilter.cpp example and easyPoint2KF bugfix #2031
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome. I left a bunch of comments with recommendations, and it would be nice to include the output in the Pr comment, but I am approving. I trust you to implement comments where you agree with them.
@@ -55,17 +55,21 @@ int main() { | |||
|
|||
// Create new state variable | |||
Symbol x0('x',0); | |||
ordering->insert(x0, 0); | |||
ordering->push_back(x0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe use X(k) everywhere.
using symbol_shorthand::X;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, I mean: kill x0, x1, x2 variables. Use X(k) in-place everywhere. Slightly less efficient but good practice for copy/paste in other code.
|
||
// Initialize state x0 (2D point) at origin by adding a prior factor, i.e., Bayes net P(x0) | ||
// This is equivalent to x_0 and P_0 | ||
Point2 x_initial(0,0); | ||
SharedDiagonal P_initial = noiseModel::Diagonal::Sigmas((Vec(2) << 0.1, 0.1)); | ||
PriorFactor<Point2> factor1(x0, x_initial, P_initial); | ||
SharedDiagonal P_initial = noiseModel::Diagonal::Sigmas((gtsam::Vector2() << 0.1, 0.1).finished()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use Isotropic
// Create a JacobianFactor directly - this represents the prior constraint on x0 | ||
JacobianFactor::shared_ptr factor1( | ||
new JacobianFactor(x0, P_initial->R(), Vector::Zero(2), | ||
noiseModel::Unit::Create(2))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure but you might even omit noise model if Unit
// Linearize the factor and add it to the linear factor graph | ||
linearizationPoints.insert(x0, x_initial); | ||
linearFactorGraph->push_back(factor1.linearize(linearizationPoints, *ordering)); | ||
|
||
linearFactorGraph->push_back(factor1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Try to use emplace_shared if you’re creating the shared pointer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-> emplace_shared(args)
OR
-> add(args)
so make_shared above is no longer needed.
|
||
Point2 difference(1,0); | ||
SharedDiagonal Q = noiseModel::Diagonal::Sigmas((Vec(2) << 0.1, 0.1)); | ||
SharedDiagonal Q = noiseModel::Diagonal::Sigmas((gtsam::Vector2() << 0.1, 0.1).finished()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isotropic
@@ -88,14 +92,14 @@ int main() { | |||
// = (F - I)*x_{t} + B*u_{t} | |||
// = B*u_{t} (for our example) | |||
Symbol x1('x',1); | |||
ordering->insert(x1, 1); | |||
ordering->push_back(x1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
X(1)
SharedDiagonal P_initial = noiseModel::Diagonal::Sigmas((gtsam::Vector2() << 0.1, 0.1).finished()); | ||
|
||
// Create a JacobianFactor directly - this represents the prior constraint on x0 | ||
JacobianFactor::shared_ptr factor1( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
auto factor1 = std::make_shared….
@@ -169,10 +183,10 @@ int main() { | |||
// = (x_{t} - z_{t}) * R^-1 * (x_{t} - z_{t})^T | |||
// This can be modeled using the PriorFactor, where the mean is z_{t} and the covariance is R. | |||
Point2 z1(1.0, 0.0); | |||
SharedDiagonal R1 = noiseModel::Diagonal::Sigmas((Vec(2) << 0.25, 0.25)); | |||
SharedDiagonal R1 = noiseModel::Diagonal::Sigmas((gtsam::Vector2() << 0.25, 0.25).finished()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isotropic
assert(cg1->nrParents() == 0); | ||
JacobianFactor tmpPrior1 = JacobianFactor(*cg1); | ||
linearFactorGraph->add(0, tmpPrior1.getA(tmpPrior1.begin()), tmpPrior1.getb() - tmpPrior1.getA(tmpPrior1.begin()) * result[ordering->at(x1)], tmpPrior1.get_model()); | ||
JacobianFactor::shared_ptr updatedPrior(new JacobianFactor( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
auto make_shared is the recommended style now
Point2 x3_update = linearizationPoints.at<Point2>(x3).retract(result[ordering->at(x3)]); | ||
x3_update.print("X3 Update"); | ||
VectorValues updatedResult3 = updatedBayesNet3->optimize(); | ||
Point2 x3_update = linearizationPoints.at<Point2>(x3) + Point2(updatedResult3[x3]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don’t think you need the Point2()
Thanks! I've added your suggestions. Waiting for CI checks to complete. |
Adding for reference, expected output is: X1 Predict[ |
Two more comments. And, request: update the PR comment with the actual output in a |
Added |
Very cool, I will merge after CI passes! Next, Python version? We are moving to have Python examples as notebooks, so maybe immediately make a notebook? Will require exposing in wrapper of course. |
Great, and yes- working on this! |
Congrats on first PR :-) |
Fixed the elaboratePoint2KalmanFilter.cpp with:
Additionally fixed minor bug in easyPoint2KalmanFilter which predicted with wrong factor.