sam/BearingRangeFactor.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 
20 #pragma once
21 
24 
25 namespace gtsam {
26 
31 template <typename A1, typename A2,
32  typename B = typename Bearing<A1, A2>::result_type,
33  typename R = typename Range<A1, A2>::result_type>
35  : public ExpressionFactorN<BearingRange<A1, A2>, A1, A2> {
36  private:
40 
41  public:
42  typedef std::shared_ptr<This> shared_ptr;
43 
46 
48  BearingRangeFactor(Key key1, Key key2, const T &bearingRange,
49  const SharedNoiseModel &model)
50  : Base({{key1, key2}}, model, T(bearingRange)) {
51  this->initialize(expression({{key1, key2}}));
52  }
53 
55  BearingRangeFactor(Key key1, Key key2, const B &measuredBearing,
56  const R &measuredRange, const SharedNoiseModel &model)
57  : Base({{key1, key2}}, model, T(measuredBearing, measuredRange)) {
58  this->initialize(expression({{key1, key2}}));
59  }
60 
61  ~BearingRangeFactor() override {}
62 
65  return std::static_pointer_cast<gtsam::NonlinearFactor>(
67  }
68 
69  // Return measurement expression
70  Expression<T> expression(const typename Base::ArrayNKeys& keys) const override {
71  return Expression<T>(T::Measure, Expression<A1>(keys[0]),
72  Expression<A2>(keys[1]));
73  }
74 
75  Vector evaluateError(const A1& a1, const A2& a2,
77  std::vector<Matrix> Hs(2);
78  const auto &keys = Factor::keys();
79  const Vector error = this->unwhitenedError(
80  {{keys[0], genericValue(a1)}, {keys[1], genericValue(a2)}}, Hs);
81  if (H1) *H1 = Hs[0];
82  if (H2) *H2 = Hs[1];
83  return error;
84  }
85 
87  void print(const std::string& s = "",
88  const KeyFormatter& kf = DefaultKeyFormatter) const override {
89  std::cout << s << "BearingRangeFactor" << std::endl;
90  Base::print(s, kf);
91  }
92 
93 
94  private:
95 #ifdef GTSAM_ENABLE_BOOST_SERIALIZATION
96  friend class boost::serialization::access;
97  template <class ARCHIVE>
98  void serialize(ARCHIVE& ar, const unsigned int /*version*/) {
99  ar& boost::serialization::make_nvp(
100  "Base", boost::serialization::base_object<Base>(*this));
101  }
102 #endif
103 }; // BearingRangeFactor
104 
106 template <typename A1, typename A2, typename B, typename R>
107 struct traits<BearingRangeFactor<A1, A2, B, R> >
108  : public Testable<BearingRangeFactor<A1, A2, B, R> > {};
109 
110 } // namespace gtsam
Point2 a1
Definition: testPose2.cpp:769
static Matrix A1
BearingRangeFactor< A1, A2 > This
std::array< Key, NARY_EXPRESSION_SIZE > ArrayNKeys
std::string serialize(const T &input)
serializes to a string
void print(const std::string &s="", const KeyFormatter &keyFormatter=DefaultKeyFormatter) const override
print relies on Testable traits being defined for T
Expression< BearingRange< A1, A2 > > expression() const override
Return an expression that predicts the measurement given Values.
BearingRangeFactor(Key key1, Key key2, const B &measuredBearing, const R &measuredRange, const SharedNoiseModel &model)
Construct from separate bearing and range.
noiseModel::Diagonal::shared_ptr model
Rot2 R(Rot2::fromAngle(0.1))
Vector evaluateError(const A1 &a1, const A2 &a2, OptionalMatrixType H1=OptionalNone, OptionalMatrixType H2=OptionalNone) const
void initialize(const Expression< BearingRange< A1, A2 > > &expression)
Initialize with constructor arguments.
static BearingRange Measure(const A1 &a1, const A2 &a2, OptionalJacobian< dimension, traits< A1 >::dimension > H1={}, OptionalJacobian< dimension, traits< A2 >::dimension > H2={})
Prediction function that stacks measurements.
Definition: BearingRange.h:79
std::shared_ptr< This > shared_ptr
static const KeyFormatter DefaultKeyFormatter
Definition: Key.h:43
gtsam::NonlinearFactor::shared_ptr clone() const override
#define OptionalNone
void print(const std::string &s="", const KeyFormatter &kf=DefaultKeyFormatter) const override
print
Matrix * OptionalMatrixType
Eigen::VectorXd Vector
Definition: Vector.h:38
const Symbol key1('v', 1)
ExpressionFactorN< T, A1, A2 > Base
Vector unwhitenedError(const Values &x, OptionalMatrixVecType H=nullptr) const override
RealScalar s
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
pair< size_t, size_t > Range
Definition: testBTree.cpp:27
traits
Definition: chartTesting.h:28
Point2 a2
Definition: testPose2.cpp:770
GenericValue< T > genericValue(const T &v)
Definition: GenericValue.h:211
double error(const Values &c) const override
Bearing-Range product.
std::shared_ptr< This > shared_ptr
BearingRangeFactor()
Default constructor.
const KeyVector & keys() const
Access the factor&#39;s involved variable keys.
Definition: Factor.h:142
BearingRangeFactor(Key key1, Key key2, const T &bearingRange, const SharedNoiseModel &model)
Construct from BearingRange instance.
std::uint64_t Key
Integer nonlinear key type.
Definition: types.h:102
noiseModel::Base::shared_ptr SharedNoiseModel
Definition: NoiseModel.h:741
const Symbol key2('v', 2)
Expression< T > expression(const typename Base::ArrayNKeys &keys) const override


gtsam
Author(s):
autogenerated on Tue Jul 4 2023 02:33:57