gtsam
Loading...
Searching...
No Matches
WnoaInterpolator.h
Go to the documentation of this file.
1/* ----------------------------------------------------------------------------
2
3 * GTSAM Copyright 2010, Georgia Tech Research Corporation,
4 * Atlanta, Georgia 30332-0415
5 * All Rights Reserved
6 * Authors: Frank Dellaert, et al. (see THANKS for the full author list)
7
8 * See LICENSE for the license information
9
10 * -------------------------------------------------------------------------- */
11
22#pragma once
23
27
28#include <functional>
29#include <map>
30#include <optional>
31#include <set>
32#include <utility>
33#include <vector>
34
35namespace gtsam {
36
46 std::pair<std::optional<StateData>, std::optional<StateData>>;
47
56template <typename PoseType>
58 PoseType pose;
60
62 std::pair<PoseType, typename traits<PoseType>::TangentVector> asPair() const {
63 return std::make_pair(pose, vel);
64 }
65};
66
75template <typename PoseType>
76struct TimestampedPoseVelocity {
78 double timestamp;
79
80 TimestampedPoseVelocity(PoseType pose,
82 double time)
83 : poseVel{pose, vel}, timestamp(time) {}
84
85 TimestampedPoseVelocity(PoseVelocity<PoseType> pv, double time)
86 : poseVel(pv), timestamp(time) {}
87};
88
92typedef std::map<Key, Matrix> InterpCovarianceMap;
93
105template <typename PoseType>
106class GTSAM_EXPORT Interpolator {
107 protected:
108 static constexpr int dim = traits<PoseType>::dimension;
109 using VelocityType = typename traits<PoseType>::TangentVector;
110 using MatrixN = Eigen::Matrix<double, dim, dim>;
111 using VectorN = Eigen::Matrix<double, dim, 1>;
112 using Matrix2N = Eigen::Matrix<double, 2 * dim, 2 * dim>;
113 using Vector2N = Eigen::Matrix<double, 2 * dim, 1>;
114 using MatrixNx2N = Eigen::Matrix<double, dim, 2 * dim>;
115
116 VectorN q_psd_diag_; // Diagonal power Spectral Density for WNOA
117 std::function<Matrix(double dt)> transitionFunction_;
118 std::function<Matrix(double dt, const VectorN& q_psd_diag)>
119 covarianceFunction_;
120 std::function<Matrix(double dt, const VectorN& q_psd_diag)>
121 inverseCovarianceFunction_;
122 // Todo: need to make the below two functions generalize to cases with no
123 // velocities, e.g. WNOV
124 std::function<Matrix(const std::pair<PoseType, VelocityType>&,
125 const std::pair<PoseType, VelocityType>&, double)>
126 computeJacobianPrev_;
127 std::function<Matrix(const std::pair<PoseType, VelocityType>&,
128 const std::pair<PoseType, VelocityType>&, double)>
129 computeJacobianNext_;
130
131 public:
132 // Type aliases
133 using StateDataSet = std::set<StateData>;
134 using PoseVel = PoseVelocity<PoseType>;
135 using TimestampedPoseVel = TimestampedPoseVelocity<PoseType>;
136 using LambdaPsiMats = std::pair<Matrix2N, Matrix2N>;
137 using LocalStateVecs = std::pair<VectorN, VectorN>;
139 MatrixN dxi_dTk;
140 MatrixN dxi_dTkp1;
141 MatrixN dxidot_dTk;
142 MatrixN dxidot_dTkp1;
143 MatrixN dxidotkp1_dvarpikp1;
144 };
145
146
147 Interpolator() = delete;
148
164 Interpolator(
165 const VectorN& q_psd_diag,
166 std::function<Matrix(double dt)> transitionFunction,
167 std::function<Matrix(double dt, const VectorN& q_psd_diag)>
168 covarianceFunction,
169 std::function<Matrix(double dt, const VectorN& q_psd_diag)>
170 inverseCovarianceFunction,
171 std::function<Matrix(const std::pair<PoseType, VelocityType>&,
172 const std::pair<PoseType, VelocityType>&, double)>
173 computeJacobianPrev,
174 std::function<Matrix(const std::pair<PoseType, VelocityType>&,
175 const std::pair<PoseType, VelocityType>&, double)>
176 computeJacobianNext);
177
184 Interpolator(const VectorN& q_psd_diag);
185
217 const std::optional<TimestampedPoseVel>& Tvarpi_k,
218 const std::optional<TimestampedPoseVel>& Tvarpi_kp1, double t_tau,
219 OptionalMatrixVecType H = nullptr,
220 const std::shared_ptr<Matrix>& mainSolveMarginalMatrix = nullptr,
221 Matrix* covarianceOut = nullptr,
222 const std::shared_ptr<const LambdaPsiMats>& LambdaPsiPreComp = nullptr,
223 const std::shared_ptr<const LocalStateVecs>& localStateVecsPreComp =
224 nullptr,
225 const std::shared_ptr<const StateJacobians>& stateJacobiansPreComp =
226 nullptr) const;
227
251 const NonlinearFactorGraph& mainSolveGraph,
252 const Values& mainSolveSolution, const StateDataSet& mainSolveStates,
253 const StateDataSet& interpolatedStates,
254 std::shared_ptr<InterpCovarianceMap> covarianceMapOut = nullptr) const;
255
271 Matrix2N computeConditionalCov(const TimestampedPoseVel& pvk,
272 const TimestampedPoseVel& pvkp1,
273 const TimestampedPoseVel& pvtau,
274 OptionalMatrixType Lambda = nullptr,
275 OptionalMatrixType Psi = nullptr) const;
276
289 std::pair<Matrix, Matrix> getLambdaPsi(double t_k, double t_kp1,
290 double t_tau) const;
291
305 std::pair<Matrix, Matrix> getLambdaPsiGeneral(double t_k, double t_kp1,
306 double t_tau) const;
320 LocalStateVecs computeLocalStateVecs(const TimestampedPoseVel& pvk,
321 const TimestampedPoseVel& pvkp1,
322 StateJacobians* jacs = nullptr) const;
323
324 protected:
343 const PoseVelocity<PoseType>& poseVel_k,
344 OptionalMatrixVecType H = nullptr,
345 const std::shared_ptr<Matrix>& mainSolveMarginalMatrix = nullptr,
346 Matrix* covarianceOut = nullptr) const;
347
366 const PoseVelocity<PoseType>& poseVel_kp1,
367 OptionalMatrixVecType H = nullptr,
368 const std::shared_ptr<Matrix>& mainSolveMarginalMatrix = nullptr,
369 Matrix* covarianceOut = nullptr) const;
370
389 const PoseVelocity<PoseType>& poseVel, double t_diff,
390 OptionalMatrixVecType H = nullptr,
391 const std::shared_ptr<Matrix>& mainSolveMarginalMatrix = nullptr,
392 Matrix* covarianceOut = nullptr) const;
393
424 const TimestampedPoseVel& tPoseVel_k,
425 const TimestampedPoseVel& tPoseVel_kp1, double t_tau,
426 OptionalMatrixVecType H = nullptr,
427 const std::shared_ptr<Matrix>& mainSolveMarginalMatrix = nullptr,
428 Matrix* covarianceOut = nullptr,
429 const std::shared_ptr<const LambdaPsiMats>& LambdaPsiPreComp = nullptr,
430 const std::shared_ptr<const LocalStateVecs>& localStateVecsPreComp =
431 nullptr,
432 const std::shared_ptr<const StateJacobians>& stateJacobiansPreComp =
433 nullptr) const;
434
456 const TimestampedPoseVel& tPoseVel_k,
457 const TimestampedPoseVel& tPoseVel_kp1,
458 const std::shared_ptr<const LocalStateVecs>& localStateVecsPreComp,
459 const std::shared_ptr<const StateJacobians>& stateJacobiansPreComp,
460 VectorN* xi_dot_k, VectorN* xi_kp1, VectorN* xi_dot_kp1,
461 StateJacobians* jacs = nullptr) const;
462
484 double t_k, double t_kp1, double t_tau, const VectorN& xi_dot_k,
485 const VectorN& xi_kp1, const VectorN& xi_dot_kp1,
486 const std::shared_ptr<const LambdaPsiMats>& LambdaPsiPreComp,
487 Matrix2N* Lambda, Matrix2N* Psi, VectorN* xi_tau,
488 VectorN* xidot_tau) const;
489
506 PoseVel mapLocalStateToManifold_(const PoseType& T_k, const VectorN& xi_tau,
507 const VectorN& xidot_tau,
508 MatrixN* right_jac_tau,
509 MatrixN* dTtau_dTk = nullptr,
510 MatrixN* dTtau_dxitau = nullptr) const;
511
526 void computeCompleteJacobians_(const Matrix2N& Lambda, const Matrix2N& Psi,
527 const VectorN& xidot_tau,
528 const MatrixN& right_jac_tau,
529 const MatrixN& dTtau_dTk,
530 const MatrixN& dTtau_dxitau,
531 const StateJacobians& jacs,
532 OptionalMatrixVecType H) const;
533
549 const TimestampedPoseVel& tPoseVel_k,
550 const TimestampedPoseVel& tPoseVel_kp1, const PoseVel& poseVel_tau,
551 double t_tau, const Matrix2N& Lambda, const Matrix2N& Psi,
552 const std::shared_ptr<Matrix>& mainSolveMarginalMatrix,
553 Matrix* covarianceOut) const;
554
570 static std::map<StateDataInterval, std::shared_ptr<Matrix>>
572 const std::map<StateDataInterval, std::vector<StateData>>& queryBuckets,
573 const std::unique_ptr<Marginals>& marginals);
574
590 const JointMarginal& blockMatrix, const KeyVector& keyVector,
591 size_t blockSize);
592};
593
594} // namespace gtsam
White-Noise-On-Acceleration (WNOA) motion prior factor between two states (pose and velocity at times...
A class for computing marginals in a NonlinearFactorGraph.
Introduces a lightweight struct for identifying states in continuous-time estimation and interpolatio...
Global functions in a separate testing namespace.
Definition chartTesting.h:28
FastVector< Key > KeyVector
Define collection type once and for all - also used in wrappers.
Definition Key.h:91
Matrix * OptionalMatrixType
This typedef will be used everywhere boost::optional<Matrix&> reference was used previously.
Definition NonlinearFactor.h:57
std::pair< std::optional< StateData >, std::optional< StateData > > StateDataInterval
Type alias for a pair of optional bordering states for an interpolated state.
Definition WnoaInterpolator.h:45
std::map< Key, Matrix > InterpCovarianceMap
Type alias for a map from variable keys to interpolated state covariances.
Definition WnoaInterpolator.h:92
std::vector< Matrix > * OptionalMatrixVecType
The OptionalMatrixVecType is a pointer to a vector of matrices.
Definition NonlinearFactor.h:63
A manifold defines a space in which there is a notion of a linear tangent space that can be centered ...
Definition Group.h:37
A class to store and access a joint marginal, returned from Gaussian and nonlinear covariance query A...
Definition JointMarginal.h:34
Definition NonlinearFactorGraph.h:57
A non-templated config holding any types of Manifold-group elements.
Definition Values.h:65
Simple container for a pose and its corresponding velocity.
Definition WnoaInterpolator.h:57
std::pair< PoseType, typename traits< PoseType >::TangentVector > asPair() const
Returns pose and velocity as a std::pair.
Definition WnoaInterpolator.h:62
Timestamped pose and velocity container.
Definition WnoaInterpolator.h:76
PoseVel interpolatePoseAndVelocity_(const TimestampedPoseVel &tPoseVel_k, const TimestampedPoseVel &tPoseVel_kp1, double t_tau, OptionalMatrixVecType H=nullptr, const std::shared_ptr< Matrix > &mainSolveMarginalMatrix=nullptr, Matrix *covarianceOut=nullptr, const std::shared_ptr< const LambdaPsiMats > &LambdaPsiPreComp=nullptr, const std::shared_ptr< const LocalStateVecs > &localStateVecsPreComp=nullptr, const std::shared_ptr< const StateJacobians > &stateJacobiansPreComp=nullptr) const
Internal implementation that performs interpolation between two bordering states.
Definition WnoaInterpolator.cpp:217
void formLocalStateAndJacobians_(const TimestampedPoseVel &tPoseVel_k, const TimestampedPoseVel &tPoseVel_kp1, const std::shared_ptr< const LocalStateVecs > &localStateVecsPreComp, const std::shared_ptr< const StateJacobians > &stateJacobiansPreComp, VectorN *xi_dot_k, VectorN *xi_kp1, VectorN *xi_dot_kp1, StateJacobians *jacs=nullptr) const
Step 1 of interpolatePoseAndVelocity: form local state vectors and optional local Jacobians.
Definition WnoaInterpolator.cpp:287
static std::map< StateDataInterval, std::shared_ptr< Matrix > > ComputeJointMarginals(const std::map< StateDataInterval, std::vector< StateData > > &queryBuckets, const std::unique_ptr< Marginals > &marginals)
Compute joint marginal covariances for requested state intervals.
Definition WnoaInterpolator.cpp:448
void computeCompleteJacobians_(const Matrix2N &Lambda, const Matrix2N &Psi, const VectorN &xidot_tau, const MatrixN &right_jac_tau, const MatrixN &dTtau_dTk, const MatrixN &dTtau_dxitau, const StateJacobians &jacs, OptionalMatrixVecType H) const
Step 4 of interpolatePoseAndVelocity: compose full Jacobians with chain rule.
Definition WnoaInterpolator.cpp:366
PoseVel extrapolatePoseAndVelocity(const PoseVelocity< PoseType > &poseVel, double t_diff, OptionalMatrixVecType H=nullptr, const std::shared_ptr< Matrix > &mainSolveMarginalMatrix=nullptr, Matrix *covarianceOut=nullptr) const
Extrapolate pose and velocity from a border state.
Definition WnoaInterpolator.cpp:182
void interpolateLocalState_(double t_k, double t_kp1, double t_tau, const VectorN &xi_dot_k, const VectorN &xi_kp1, const VectorN &xi_dot_kp1, const std::shared_ptr< const LambdaPsiMats > &LambdaPsiPreComp, Matrix2N *Lambda, Matrix2N *Psi, VectorN *xi_tau, VectorN *xidot_tau) const
Step 2 of interpolatePoseAndVelocity: interpolate local state using Lambda/Psi matrices.
Definition WnoaInterpolator.cpp:324
PoseVel interpolateBoundaryLeft(const PoseVelocity< PoseType > &poseVel_k, OptionalMatrixVecType H=nullptr, const std::shared_ptr< Matrix > &mainSolveMarginalMatrix=nullptr, Matrix *covarianceOut=nullptr) const
Interpolate pose and velocity at the left boundary.
Definition WnoaInterpolator.cpp:127
std::pair< Matrix, Matrix > getLambdaPsi(double t_k, double t_kp1, double t_tau) const
Compute interpolation matrices Lambda and Psi (WNOA-optimized).
Definition WnoaInterpolator.cpp:567
void computeInterpolationCovariance_(const TimestampedPoseVel &tPoseVel_k, const TimestampedPoseVel &tPoseVel_kp1, const PoseVel &poseVel_tau, double t_tau, const Matrix2N &Lambda, const Matrix2N &Psi, const std::shared_ptr< Matrix > &mainSolveMarginalMatrix, Matrix *covarianceOut) const
Step 5 of interpolatePoseAndVelocity: compute interpolated covariance when requested.
Definition WnoaInterpolator.cpp:430
std::pair< Matrix, Matrix > getLambdaPsiGeneral(double t_k, double t_kp1, double t_tau) const
Compute interpolation matrices Lambda and Psi for a general motion model.
Definition WnoaInterpolator.cpp:598
PoseVel interpolateBoundaryRight(const PoseVelocity< PoseType > &poseVel_kp1, OptionalMatrixVecType H=nullptr, const std::shared_ptr< Matrix > &mainSolveMarginalMatrix=nullptr, Matrix *covarianceOut=nullptr) const
Interpolate pose and velocity at the right boundary.
Definition WnoaInterpolator.cpp:158
PoseVel mapLocalStateToManifold_(const PoseType &T_k, const VectorN &xi_tau, const VectorN &xidot_tau, MatrixN *right_jac_tau, MatrixN *dTtau_dTk=nullptr, MatrixN *dTtau_dxitau=nullptr) const
Step 3 of interpolatePoseAndVelocity: map interpolated local state back to manifold.
Definition WnoaInterpolator.cpp:348
LocalStateVecs computeLocalStateVecs(const TimestampedPoseVel &pvk, const TimestampedPoseVel &pvkp1, StateJacobians *jacs=nullptr) const
Compute the local state vectors (xi, xi_dot) for a pair of bordering states.
Definition WnoaInterpolator.cpp:621
Matrix2N computeConditionalCov(const TimestampedPoseVel &pvk, const TimestampedPoseVel &pvkp1, const TimestampedPoseVel &pvtau, OptionalMatrixType Lambda=nullptr, OptionalMatrixType Psi=nullptr) const
Compute the conditional covariance of the interpolated state.
Definition WnoaInterpolator.cpp:670
static Matrix ConstructMatrixFromJointMarginal(const JointMarginal &blockMatrix, const KeyVector &keyVector, size_t blockSize)
Construct a full covariance matrix from a joint marginal block matrix.
Definition WnoaInterpolator.cpp:711
PoseVel interpolatePoseAndVelocity(const std::optional< TimestampedPoseVel > &Tvarpi_k, const std::optional< TimestampedPoseVel > &Tvarpi_kp1, double t_tau, OptionalMatrixVecType H=nullptr, const std::shared_ptr< Matrix > &mainSolveMarginalMatrix=nullptr, Matrix *covarianceOut=nullptr, const std::shared_ptr< const LambdaPsiMats > &LambdaPsiPreComp=nullptr, const std::shared_ptr< const LocalStateVecs > &localStateVecsPreComp=nullptr, const std::shared_ptr< const StateJacobians > &stateJacobiansPreComp=nullptr) const
Interpolate the pose and velocity at time t_tau.
Definition WnoaInterpolator.cpp:65
Values interpolatePosesAndVelocities(const NonlinearFactorGraph &mainSolveGraph, const Values &mainSolveSolution, const StateDataSet &mainSolveStates, const StateDataSet &interpolatedStates, std::shared_ptr< InterpCovarianceMap > covarianceMapOut=nullptr) const
Interpolate multiple poses and velocities given a solved factor graph.
Definition WnoaInterpolator.cpp:488
Definition WnoaInterpolator.h:138