23#include <gtsam/geometry/Unit3.h>
37template <
int K,
class Derived>
43inline std::string attitudeFactorName() {
44 if constexpr (std::is_same_v<VALUE, Rot3>) {
45 return "AttitudeFactorRot3";
46 }
else if constexpr (std::is_same_v<VALUE, Pose3>) {
47 return "AttitudeFactorPose3";
48 }
else if constexpr (std::is_same_v<VALUE, NavState>) {
49 return "AttitudeFactorNavState";
50 }
else if constexpr (std::is_same_v<VALUE, Gal3>) {
51 return "AttitudeFactorGal3";
52 }
else if constexpr (std::is_same_v<VALUE, Se23>) {
53 return "AttitudeFactorSe23";
54 }
else if constexpr (is_extended_pose3_v<VALUE>) {
55 constexpr int K = std::remove_reference_t<VALUE>::K;
56 const std::string valueName = (K == Eigen::Dynamic)
58 :
"ExtendedPose3" + std::to_string(K);
59 return "AttitudeFactor" + valueName;
61 return "AttitudeFactor";
94 Unit3 nRef_, bMeasured_;
110 : Base(model,
key), nRef_(nRef), bMeasured_(bMeasured) {}
117 Matrix23 D_nMeasured_R;
118 const Unit3 nMeasured = nRb.
rotate(bMeasured_, D_nMeasured_R);
119 Matrix22 D_e_nMeasured;
120 const Vector error = nRef_.
errorVector(nMeasured, {}, D_e_nMeasured);
121 *H = D_e_nMeasured * D_nMeasured_R;
128 const Unit3& nRef()
const {
return nRef_; }
129 const Unit3& bMeasured()
const {
return bMeasured_; }
131#ifdef GTSAM_ALLOW_DEPRECATED_SINCE_V43
132 [[deprecated(
"Use nRef() instead")]]
133 const Unit3& nZ()
const {
137 [[deprecated(
"Use bMeasured() instead")]]
138 const Unit3& bRef()
const {
144 gtsam::NonlinearFactor::shared_ptr
clone()
const override {
145 return std::static_pointer_cast<gtsam::NonlinearFactor>(
146 gtsam::NonlinearFactor::shared_ptr(
new This(*
this)));
151 const std::string& s =
"",
153 std::cout << (s.empty() ?
"" : s +
" ")
154 << detail::attitudeFactorName<VALUE>() <<
" on "
155 << keyFormatter(this->key()) <<
"\n";
156 nRef_.print(
" reference direction in nav frame: ");
157 bMeasured_.print(
" measured direction in body frame: ");
158 this->noiseModel_->print(
" noise model: ");
163 double tol = 1e-9)
const override {
164 const This* e =
dynamic_cast<const This*
>(&expected);
166 nRef_.equals(e->nRef_, tol) && bMeasured_.equals(e->bMeasured_, tol);
172 if constexpr (std::is_same_v<VALUE, Rot3>) {
176 Matrix H_rotation_value;
177 const Rot3 nRb = value.rotation(H_rotation_value);
178 Matrix23 H_error_rotation;
180 *H = H_error_rotation * H_rotation_value;
189#if GTSAM_ENABLE_BOOST_SERIALIZATION
191 friend class boost::serialization::access;
192 template <
class ARCHIVE>
193 void serialize(ARCHIVE& ar,
const unsigned int ) {
194 ar& boost::serialization::make_nvp(
195 "NoiseModelFactor1", boost::serialization::base_object<Base>(*
this));
196 ar& boost::serialization::make_nvp(
"nRef_", nRef_);
197 ar& boost::serialization::make_nvp(
"bMeasured_", bMeasured_);
202template <
class VALUE>
3D Galilean Group SGal(3) state (attitude, position, velocity, time)
Extended pose Lie group SE_k(3), with static or dynamic k.
3D Pose manifold SO(3) x R^3 and group SE(3)
Navigation state composing of attitude, position, and velocity.
Base class for noise model factors with N variables.
Global functions in a separate testing namespace.
Definition chartTesting.h:28
KeyFormatter DefaultKeyFormatter
Assign default key formatter.
Definition Key.cpp:30
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
std::function< std::string(Key)> KeyFormatter
Typedef for a function to format a key, i.e. to convert it to a string.
Definition Key.h:35
noiseModel::Base::shared_ptr SharedNoiseModel
Aliases.
Definition NoiseModel.h:846
std::uint64_t Key
Integer nonlinear key type.
Definition types.h:43
A manifold defines a space in which there is a notion of a linear tangent space that can be centered ...
Definition Group.h:37
OptionalJacobian is an Eigen::Ref like class that can take be constructed using either a fixed size o...
Definition OptionalJacobian.h:40
A helper that implements the traits interface for GTSAM types.
Definition Testable.h:152
Lie group SE_k(3): semidirect product of SO(3) with k copies of R^3.
Definition ExtendedPose3.h:52
Rot3 is a 3D rotation represented as a rotation matrix if the preprocessor symbol GTSAM_USE_QUATERNIO...
Definition Rot3.h:65
Point3 rotate(const Point3 &p, OptionalJacobian< 3, 3 > H1={}, OptionalJacobian< 3, 3 > H2={}) const
rotate point from rotated coordinate frame to world
Definition Rot3M.cpp:165
Represents a 3D point on a unit sphere.
Definition Unit3.h:44
Vector2 errorVector(const Unit3 &q, OptionalJacobian< 2, 2 > H_p={}, OptionalJacobian< 2, 2 > H_q={}) const
Signed, vector-valued error between two directions NOTE(hayk): This method has zero derivatives if th...
Definition Unit3.cpp:242
bool equals(const This &other, double tol=1e-9) const
check equality
Definition Factor.cpp:42
Definition AttitudeFactor.h:35
Unary factor that constrains the rotation component of a value.
Definition AttitudeFactor.h:83
Vector attitudeError(const Rot3 &nRb, OptionalJacobian< 2, 3 > H={}) const
vector of errors
Definition AttitudeFactor.h:115
AttitudeFactor()
default constructor - only use for serialization
Definition AttitudeFactor.h:98
AttitudeFactor(Key key, const Unit3 &nRef, const SharedNoiseModel &model, const Unit3 &bMeasured=Unit3(0, 0, 1))
Constructor.
Definition AttitudeFactor.h:108
gtsam::NonlinearFactor::shared_ptr clone() const override
Definition AttitudeFactor.h:144
Vector evaluateError(const VALUE &value, OptionalMatrixType H) const override
vector of errors
Definition AttitudeFactor.h:170
void print(const std::string &s="", const KeyFormatter &keyFormatter=DefaultKeyFormatter) const override
print
Definition AttitudeFactor.h:150
std::shared_ptr< This > shared_ptr
shorthand for a smart pointer to a factor
Definition AttitudeFactor.h:91
bool equals(const NonlinearFactor &expected, double tol=1e-9) const override
equals
Definition AttitudeFactor.h:162
virtual Vector evaluateError(const ValueTypes &... x, OptionalMatrixTypeT< ValueTypes >... H) const=0
Key key() const
Definition NoiseModelFactorN.h:307
Nonlinear factor base class.
Definition NonlinearFactor.h:70
double error(const Values &c) const override
Calculate the error of the factor.
Definition NonlinearFactor.cpp:146