gtsam
Loading...
Searching...
No Matches
LeggedEstimatorFactors.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
17
18#pragma once
19
20#include <gtsam/base/Matrix.h>
24
25namespace gtsam {
26
28inline int leggedFootBlockStart(size_t foot) {
29 return 9 + 3 * static_cast<int>(foot);
30}
31
47inline Vector3 extendedPoseContactPrediction(const ExtendedPose3d& state,
48 size_t footColumn,
49 OptionalMatrixType H = {}) {
50 Matrix36 prediction_H_pose;
51 const Pose3 pose(state.rotation(), state.x(0));
52 const Point3 foothold = state.x(footColumn);
53 const Vector3 prediction = pose.transformTo(foothold, prediction_H_pose);
54
55 if (H) {
56 H->setZero(3, static_cast<Eigen::Index>(state.dim()));
57 H->block(0, 0, 3, 6) = prediction_H_pose;
58 const int start = leggedFootBlockStart(footColumn - 2);
59 H->block(0, start, 3, 3) = I_3x3;
60 }
61
62 return prediction;
63}
64
66class ExtendedPoseContactFactor : public NoiseModelFactorN<ExtendedPose3d> {
68
69 public:
71
73 ExtendedPoseContactFactor(Key key, size_t footColumn,
74 const Point3& measurement,
75 const SharedNoiseModel& model)
76 : Base(model, key), footColumn_(footColumn), measurement_(measurement) {}
77
79 NonlinearFactor::shared_ptr clone() const override {
80 return std::static_pointer_cast<NonlinearFactor>(
81 NonlinearFactor::shared_ptr(new ExtendedPoseContactFactor(*this)));
82 }
83
85 Vector evaluateError(const ExtendedPose3d& state,
86 OptionalMatrixType H) const override {
87 const Vector3 prediction =
88 extendedPoseContactPrediction(state, footColumn_, H);
89
90 return prediction - measurement_;
91 }
92
93 private:
94 size_t footColumn_;
95 Point3 measurement_;
96};
97
99class ExtendedPoseHeightFactor : public NoiseModelFactorN<ExtendedPose3d> {
101
102 public:
104
106 ExtendedPoseHeightFactor(Key key, size_t footColumn, double terrainHeight,
107 const SharedNoiseModel& model)
108 : Base(model, key),
109 footColumn_(footColumn),
110 terrainHeight_(terrainHeight) {}
111
113 NonlinearFactor::shared_ptr clone() const override {
114 return std::static_pointer_cast<NonlinearFactor>(
115 NonlinearFactor::shared_ptr(new ExtendedPoseHeightFactor(*this)));
116 }
117
119 Vector evaluateError(const ExtendedPose3d& state,
120 OptionalMatrixType H) const override {
121 if (H) {
122 H->setZero(1, static_cast<Eigen::Index>(state.dim()));
123 const Matrix3 R = state.rotation().matrix();
124 const int start = leggedFootBlockStart(footColumn_ - 2);
125 H->block(0, start, 1, 3) = R.row(2);
126 }
127
128 return Vector1(state.x(footColumn_).z() - terrainHeight_);
129 }
130
131 private:
132 size_t footColumn_;
133 double terrainHeight_;
134};
135
138 : public NoiseModelFactorT<Vector3, NavState, Point3> {
140
141 public:
143
146 const Point3& measurement,
147 const SharedNoiseModel& model)
148 : Base(model, navKey, pointKey), measurement_(measurement) {}
149
151 NonlinearFactor::shared_ptr clone() const override {
152 return std::static_pointer_cast<NonlinearFactor>(
153 NonlinearFactor::shared_ptr(new NavStatePointContactFactor(*this)));
154 }
155
157 Vector3 evaluateError(const NavState& navState, const Point3& foothold,
159 OptionalMatrixType H2) const override {
160 Matrix36 prediction_H_pose;
161 Matrix3 prediction_H_foothold;
162 const Vector3 prediction = navState.pose().transformTo(
163 foothold, prediction_H_pose, prediction_H_foothold);
164
165 if (H1) {
166 H1->setZero(3, 9);
167 H1->block(0, 0, 3, 6) = prediction_H_pose;
168 }
169 if (H2) {
170 *H2 = prediction_H_foothold;
171 }
172
173 return prediction - measurement_;
174 }
175
176 private:
177 Point3 measurement_;
178};
179
182 : public NoiseModelFactorT<Vector3, Pose3, Point3> {
184
185 public:
187
189 Pose3PointContactFactor(Key poseKey, Key pointKey, const Point3& measurement,
190 const SharedNoiseModel& model)
191 : Base(model, poseKey, pointKey), measurement_(measurement) {}
192
194 NonlinearFactor::shared_ptr clone() const override {
195 return std::static_pointer_cast<NonlinearFactor>(
196 NonlinearFactor::shared_ptr(new Pose3PointContactFactor(*this)));
197 }
198
200 Vector3 evaluateError(const Pose3& pose, const Point3& foothold,
202 OptionalMatrixType H2) const override {
203 return pose.transformTo(foothold, H1, H2) - measurement_;
204 }
205
206 private:
207 Point3 measurement_;
208};
209
211class PointHeightFactor : public NoiseModelFactorN<Point3> {
212 using Base = NoiseModelFactorN<Point3>;
213
214 public:
216
218 PointHeightFactor(Key key, double terrainHeight,
219 const SharedNoiseModel& model)
220 : Base(model, key), terrainHeight_(terrainHeight) {}
221
223 NonlinearFactor::shared_ptr clone() const override {
224 return std::static_pointer_cast<NonlinearFactor>(
225 NonlinearFactor::shared_ptr(new PointHeightFactor(*this)));
226 }
227
229 Vector evaluateError(const Point3& foothold,
230 OptionalMatrixType H) const override {
231 if (H) {
232 H->resize(1, 3);
233 *H = Matrix13{{0.0, 0.0, 1.0}};
234 }
235 return Vector1(foothold.z() - terrainHeight_);
236 }
237
238 private:
239 double terrainHeight_;
240};
241
242} // namespace gtsam
typedef and functions to augment Eigen's MatrixXd
Macros for Matrix constants to avoid excessive template instantiation.
Base class for noise model factors with N variables.
Global functions in a separate testing namespace.
Definition chartTesting.h:28
int leggedFootBlockStart(size_t foot)
Return the tangent-space start index of a foot block.
Definition LeggedEstimatorFactors.h:28
Matrix * OptionalMatrixType
This typedef will be used everywhere boost::optional<Matrix&> reference was used previously.
Definition NonlinearFactor.h:57
NoiseModelFactorT< Vector, ValueTypes... > NoiseModelFactorN
Noise model factor with N value types and dynamic-sized error vector.
Definition NoiseModelFactorN.h:561
Vector3 Point3
As of GTSAM 4, in order to make GTSAM more lean, it is now possible to just typedef Point3 to Vector3...
Definition Point3.h:38
noiseModel::Base::shared_ptr SharedNoiseModel
Aliases.
Definition NoiseModel.h:846
Vector3 extendedPoseContactPrediction(const ExtendedPose3d &state, size_t footColumn, OptionalMatrixType H={})
Predict the IMU-frame contact vector for an ExtendedPose3 state.
Definition LeggedEstimatorFactors.h:47
std::uint64_t Key
Integer nonlinear key type.
Definition types.h:43
size_t dim() const
Definition ExtendedPose3.h:166
Point3 x(size_t i, ComponentJacobian H={}) const
i-th R^3 component, returned by value.
Definition ExtendedPose3-inl.h:89
const Rot3 & rotation(ComponentJacobian H={}) const
Rotation component.
Definition ExtendedPose3-inl.h:76
A 3D pose (R,t) : (Rot3,Point3).
Definition Pose3.h:42
Point3 transformTo(const Point3 &point, OptionalJacobian< 3, 6 > Hself={}, OptionalJacobian< 3, 3 > Hpoint={}) const
takes point in world coordinates and transforms it to Pose coordinates
Definition Pose3.cpp:204
Matrix3 matrix() const
return 3*3 rotation matrix
Definition Rot3M.cpp:261
Vector evaluateError(const ExtendedPose3d &state, OptionalMatrixType H) const override
Evaluate the contact residual and optional Jacobian.
Definition LeggedEstimatorFactors.h:85
NonlinearFactor::shared_ptr clone() const override
Return a deep copy.
Definition LeggedEstimatorFactors.h:79
ExtendedPoseContactFactor(Key key, size_t footColumn, const Point3 &measurement, const SharedNoiseModel &model)
Construct from a state key, foot column, and IMU-frame measurement.
Definition LeggedEstimatorFactors.h:73
Vector evaluateError(const ExtendedPose3d &state, OptionalMatrixType H) const override
Evaluate the height residual and optional Jacobian.
Definition LeggedEstimatorFactors.h:119
NonlinearFactor::shared_ptr clone() const override
Return a deep copy.
Definition LeggedEstimatorFactors.h:113
ExtendedPoseHeightFactor(Key key, size_t footColumn, double terrainHeight, const SharedNoiseModel &model)
Construct from a state key, foot column, and terrain height.
Definition LeggedEstimatorFactors.h:106
NonlinearFactor::shared_ptr clone() const override
Return a deep copy.
Definition LeggedEstimatorFactors.h:151
NavStatePointContactFactor(Key navKey, Key pointKey, const Point3 &measurement, const SharedNoiseModel &model)
Construct from a NavState key, foothold key, and IMU-frame measurement.
Definition LeggedEstimatorFactors.h:145
Vector3 evaluateError(const NavState &navState, const Point3 &foothold, OptionalMatrixType H1, OptionalMatrixType H2) const override
Evaluate the contact residual and optional Jacobians.
Definition LeggedEstimatorFactors.h:157
NonlinearFactor::shared_ptr clone() const override
Return a deep copy.
Definition LeggedEstimatorFactors.h:194
Pose3PointContactFactor(Key poseKey, Key pointKey, const Point3 &measurement, const SharedNoiseModel &model)
Construct from a Pose3 key, foothold key, and IMU-frame measurement.
Definition LeggedEstimatorFactors.h:189
Vector3 evaluateError(const Pose3 &pose, const Point3 &foothold, OptionalMatrixType H1, OptionalMatrixType H2) const override
Evaluate the contact residual and optional Jacobians.
Definition LeggedEstimatorFactors.h:200
Vector evaluateError(const Point3 &foothold, OptionalMatrixType H) const override
Evaluate the height residual and optional Jacobian.
Definition LeggedEstimatorFactors.h:229
NonlinearFactor::shared_ptr clone() const override
Return a deep copy.
Definition LeggedEstimatorFactors.h:223
PointHeightFactor(Key key, double terrainHeight, const SharedNoiseModel &model)
Construct from a foothold key and terrain height.
Definition LeggedEstimatorFactors.h:218
Navigation state: Pose (rotation, translation) + velocity Following Barrau20icra, this class belongs ...
Definition NavState.h:45
NoiseModelFactorT()
Definition NoiseModelFactorN.h:257
virtual Vector evaluateError(const ValueTypes &... x, OptionalMatrixTypeT< ValueTypes >... H) const=0
Key key() const
Definition NoiseModelFactorN.h:307