-
Notifications
You must be signed in to change notification settings - Fork 768
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
Fixing the EKF example and change linearization point initialization #848
Open
ProfFan
wants to merge
3
commits into
develop
Choose a base branch
from
fix/ekf
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -64,11 +64,12 @@ namespace gtsam { | |
template <class VALUE> | ||
ExtendedKalmanFilter<VALUE>::ExtendedKalmanFilter( | ||
Key key_initial, T x_initial, noiseModel::Gaussian::shared_ptr P_initial) | ||
: x_(x_initial) // Set the initial linearization point | ||
: x_(x_initial), lastLinearization(nullptr) // Set the initial linearization point | ||
{ | ||
// Create a Jacobian Prior Factor directly P_initial. | ||
// Since x0 is set to the provided mean, the b vector in the prior will be zero | ||
// TODO(Frank): is there a reason why noiseModel is not simply P_initial? | ||
// The reason why noiseModel is not simply P_initial is that a JacobianFactor only | ||
// accepts Diagonal noise models. | ||
int n = traits<T>::GetDimension(x_initial); | ||
priorFactor_ = JacobianFactor::shared_ptr( | ||
new JacobianFactor(key_initial, P_initial->R(), Vector::Zero(n), | ||
|
@@ -82,20 +83,38 @@ namespace gtsam { | |
const auto keys = motionFactor.keys(); | ||
|
||
// Create a Gaussian Factor Graph | ||
GaussianFactorGraph linearFactorGraph; | ||
GaussianFactorGraph::shared_ptr linearFactorGraph = boost::make_shared<GaussianFactorGraph>(); | ||
|
||
// Add in previous posterior as prior on the first state | ||
linearFactorGraph.push_back(priorFactor_); | ||
linearFactorGraph->push_back(priorFactor_); | ||
|
||
// Linearize motion model and add it to the Kalman Filter graph | ||
Values linearizationPoint; | ||
linearizationPoint.insert(keys[0], x_); | ||
linearizationPoint.insert(keys[1], x_); // TODO should this really be x_ ? | ||
linearFactorGraph.push_back(motionFactor.linearize(linearizationPoint)); | ||
|
||
if (lastLinearization != nullptr) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. document! What's happening? |
||
auto new_prior = boost::make_shared<JacobianFactor>(*priorFactor_); | ||
new_prior->keys()[0] = lastLinearizationPointKey; | ||
|
||
Values lastLinearizationPoint; | ||
lastLinearizationPoint.insert(lastLinearizationPointKey, x_); | ||
lastLinearizationPoint.insert(keys[0], x_); | ||
T linearEstimate = solve_(*lastLinearization, lastLinearizationPoint, keys[0], &new_prior); | ||
|
||
linearizationPoint.insert(keys[0], x_); | ||
linearizationPoint.insert(keys[1], linearEstimate); | ||
} else { | ||
linearizationPoint.insert(keys[0], x_); | ||
linearizationPoint.insert(keys[1], x_); | ||
} | ||
|
||
linearFactorGraph->push_back(motionFactor.linearize(linearizationPoint)); | ||
|
||
// Solve the factor graph and update the current state estimate | ||
// and the posterior for the next iteration. | ||
x_ = solve_(linearFactorGraph, linearizationPoint, keys[1], &priorFactor_); | ||
x_ = solve_(*linearFactorGraph, linearizationPoint, keys[1], &priorFactor_); | ||
|
||
lastLinearization.swap(linearFactorGraph); | ||
lastLinearizationPointKey = keys[0]; | ||
|
||
return x_; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,7 @@ | |
|
||
#include <gtsam/nonlinear/NonlinearFactorGraph.h> | ||
#include <gtsam/nonlinear/NonlinearFactor.h> | ||
#include <gtsam/linear/GaussianFactorGraph.h> | ||
|
||
namespace gtsam { | ||
|
||
|
@@ -58,6 +59,8 @@ class ExtendedKalmanFilter { | |
protected: | ||
T x_; // linearization point | ||
JacobianFactor::shared_ptr priorFactor_; // Gaussian density on x_ | ||
GaussianFactorGraph::shared_ptr lastLinearization; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. docs: what are these things? |
||
Key lastLinearizationPointKey; | ||
|
||
static T solve_(const GaussianFactorGraph& linearFactorGraph, const Values& linearizationPoints, | ||
Key x, JacobianFactor::shared_ptr* newPrior); | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Why did you change this to a pointer?