GPSFactor.cpp
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 
19 #include "GPSFactor.h"
20 
21 using namespace std;
22 
23 namespace gtsam {
24 
25 //***************************************************************************
26 void GPSFactor::print(const string& s, const KeyFormatter& keyFormatter) const {
27  cout << (s.empty() ? "" : s + " ") << "GPSFactor on " << keyFormatter(key())
28  << "\n";
29  cout << " GPS measurement: " << nT_ << "\n";
30  noiseModel_->print(" noise model: ");
31 }
32 
33 //***************************************************************************
34 bool GPSFactor::equals(const NonlinearFactor& expected, double tol) const {
35  const This* e = dynamic_cast<const This*>(&expected);
36  return e != nullptr && Base::equals(*e, tol) && traits<Point3>::Equals(nT_, e->nT_, tol);
37 }
38 
39 //***************************************************************************
40 Vector GPSFactor::evaluateError(const Pose3& p,
41  OptionalMatrixType H) const {
42  return p.translation(H) -nT_;
43 }
44 
45 //***************************************************************************
46 pair<Pose3, Vector3> GPSFactor::EstimateState(double t1, const Point3& NED1,
47  double t2, const Point3& NED2, double timestamp) {
48  // Estimate initial velocity as difference in NED frame
49  double dt = t2 - t1;
50  Point3 nV = (NED2 - NED1) / dt;
51 
52  // Estimate initial position as linear interpolation
53  Point3 nT = NED1 + nV * (timestamp - t1);
54 
55  // Estimate Rotation
56  double yaw = atan2(nV.y(), nV.x());
57  Rot3 nRy = Rot3::Yaw(yaw); // yaw frame
58  Point3 yV = nRy.inverse() * nV; // velocity in yaw frame
59  double pitch = -atan2(yV.z(), yV.x()), roll = 0;
60  Rot3 nRb = Rot3::Ypr(yaw, pitch, roll);
61 
62  // Construct initial pose
63  Pose3 nTb(nRb, nT); // nTb
64 
65  return make_pair(nTb, nV);
66 }
67 
68 //***************************************************************************
69 void GPSFactorArm::print(const string& s, const KeyFormatter& keyFormatter) const {
70  cout << s << "GPSFactorArm on " << keyFormatter(key()) << "\n";
71  cout << " GPS measurement: " << nT_.transpose() << "\n";
72  cout << " Lever arm: " << bL_.transpose() << "\n";
73  noiseModel_->print(" noise model: ");
74 }
75 
76 //***************************************************************************
77 bool GPSFactorArm::equals(const NonlinearFactor& expected, double tol) const {
78  const This* e = dynamic_cast<const This*>(&expected);
79  return e != nullptr && Base::equals(*e, tol) &&
80  traits<Point3>::Equals(nT_, e->nT_, tol) &&
81  traits<Point3>::Equals(bL_, e->bL_, tol);
82 }
83 
84 //***************************************************************************
85 Vector GPSFactorArm::evaluateError(const Pose3& p,
86  OptionalMatrixType H) const {
87  const Matrix3 nRb = p.rotation().matrix();
88  if (H) {
89  H->resize(3, 6);
90 
91  H->block<3, 3>(0, 0) = -nRb * skewSymmetric(bL_);
92  H->block<3, 3>(0, 3) = nRb;
93  }
94 
95  return p.translation() + nRb * bL_ - nT_;
96 }
97 
98 //***************************************************************************
99 void GPSFactorArmCalib::print(const string& s, const KeyFormatter& keyFormatter) const {
100  cout << s << "GPSFactorArmCalib on " << keyFormatter(key()) << "\n";
101  cout << " GPS measurement: " << nT_.transpose() << "\n";
102  noiseModel_->print(" noise model: ");
103 }
104 
105 //***************************************************************************
106 bool GPSFactorArmCalib::equals(const NonlinearFactor& expected, double tol) const {
107  const This* e = dynamic_cast<const This*>(&expected);
108  return e != nullptr && Base::equals(*e, tol) &&
109  traits<Point3>::Equals(nT_, e->nT_, tol);
110 }
111 
112 //***************************************************************************
113 Vector GPSFactorArmCalib::evaluateError(const Pose3& p, const Point3& bL,
114  OptionalMatrixType H1, OptionalMatrixType H2) const {
115  const Matrix3 nRb = p.rotation().matrix();
116  if (H1) {
117  H1->resize(3, 6);
118 
119  H1->block<3, 3>(0, 0) = -nRb * skewSymmetric(bL);
120  H1->block<3, 3>(0, 3) = nRb;
121  }
122  if (H2){
123  H2->resize(3, 3);
124  *H2 = nRb;
125  }
126 
127  return p.translation() + nRb * bL - nT_;
128 }
129 
130 //***************************************************************************
131 void GPSFactor2::print(const string& s, const KeyFormatter& keyFormatter) const {
132  cout << s << "GPSFactor2 on " << keyFormatter(key()) << "\n";
133  cout << " GPS measurement: " << nT_.transpose() << endl;
134  noiseModel_->print(" noise model: ");
135 }
136 
137 //***************************************************************************
138 bool GPSFactor2::equals(const NonlinearFactor& expected, double tol) const {
139  const This* e = dynamic_cast<const This*>(&expected);
140  return e != nullptr && Base::equals(*e, tol) &&
141  traits<Point3>::Equals(nT_, e->nT_, tol);
142 }
143 
144 //***************************************************************************
145 Vector GPSFactor2::evaluateError(const NavState& p,
146  OptionalMatrixType H) const {
147  return p.position(H) -nT_;
148 }
149 
150 //***************************************************************************
151 void GPSFactor2Arm::print(const string& s, const KeyFormatter& keyFormatter) const {
152  cout << s << "GPSFactor2Arm on " << keyFormatter(key()) << "\n";
153  cout << " GPS measurement: " << nT_.transpose() << "\n";
154  cout << " Lever arm: " << bL_.transpose() << "\n";
155  noiseModel_->print(" noise model: ");
156 }
157 
158 //***************************************************************************
159 bool GPSFactor2Arm::equals(const NonlinearFactor& expected, double tol) const {
160  const This* e = dynamic_cast<const This*>(&expected);
161  return e != nullptr && Base::equals(*e, tol) &&
162  traits<Point3>::Equals(nT_, e->nT_, tol) &&
163  traits<Point3>::Equals(bL_, e->bL_, tol);
164 }
165 
166 //***************************************************************************
167 Vector GPSFactor2Arm::evaluateError(const NavState& p,
168  OptionalMatrixType H) const {
169  const Matrix3 nRb = p.attitude().matrix();
170  if (H) {
171  H->resize(3, 9);
172 
173  H->block<3, 3>(0, 0) = -nRb * skewSymmetric(bL_);
174  H->block<3, 3>(0, 3) = nRb;
175  H->block<3, 3>(0, 6).setZero();
176  }
177 
178  return p.position() + nRb * bL_ - nT_;
179 }
180 
181 //***************************************************************************
182 void GPSFactor2ArmCalib::print(const string& s, const KeyFormatter& keyFormatter) const {
183  cout << s << "GPSFactor2ArmCalib on " << keyFormatter(key()) << "\n";
184  cout << " GPS measurement: " << nT_.transpose() << "\n";
185  noiseModel_->print(" noise model: ");
186 }
187 
188 //***************************************************************************
189 bool GPSFactor2ArmCalib::equals(const NonlinearFactor& expected, double tol) const {
190  const This* e = dynamic_cast<const This*>(&expected);
191  return e != nullptr && Base::equals(*e, tol) &&
192  traits<Point3>::Equals(nT_, e->nT_, tol);
193 }
194 
195 //***************************************************************************
196 Vector GPSFactor2ArmCalib::evaluateError(const NavState& p, const Point3& bL,
197  OptionalMatrixType H1, OptionalMatrixType H2) const {
198  const Matrix3 nRb = p.attitude().matrix();
199  if (H1) {
200  H1->resize(3, 9);
201 
202  H1->block<3, 3>(0, 0) = -nRb * skewSymmetric(bL);
203  H1->block<3, 3>(0, 3) = nRb;
204  H1->block<3, 3>(0, 6).setZero();
205  }
206  if (H2){
207  H2->resize(3, 3);
208  *H2 = nRb;
209  }
210 
211  return p.position() + nRb * bL - nT_;
212 }
213 
214 }
H
set noclip points set clip one set noclip two set bar set border lt lw set xdata set ydata set zdata set x2data set y2data set boxwidth set dummy y set format x g set format y g set format x2 g set format y2 g set format z g set angles radians set nogrid set key title set key left top Right noreverse box linetype linewidth samplen spacing width set nolabel set noarrow set nologscale set logscale x set set pointsize set encoding default set nopolar set noparametric set set set set surface set nocontour set clabel set mapping cartesian set nohidden3d set cntrparam order set cntrparam linear set cntrparam levels auto set cntrparam points set size set set xzeroaxis lt lw set x2zeroaxis lt lw set yzeroaxis lt lw set y2zeroaxis lt lw set tics in set ticslevel set tics set mxtics default set mytics default set mx2tics default set my2tics default set xtics border mirror norotate autofreq set ytics border mirror norotate autofreq set ztics border nomirror norotate autofreq set nox2tics set noy2tics set timestamp bottom norotate set rrange[*:*] noreverse nowriteback set trange[*:*] noreverse nowriteback set urange[*:*] noreverse nowriteback set vrange[*:*] noreverse nowriteback set xlabel matrix size set x2label set timefmt d m y n H
Definition: gnuplot_common_settings.hh:74
Eigen::internal::print
EIGEN_STRONG_INLINE Packet4f print(const Packet4f &a)
Definition: NEON/PacketMath.h:3115
s
RealScalar s
Definition: level1_cplx_impl.h:126
e
Array< double, 1, 3 > e(1./3., 0.5, 2.)
dt
const double dt
Definition: testVelocityConstraint.cpp:15
gtsam::NavState
Definition: NavState.h:38
gtsam::Factor
Definition: Factor.h:70
initial::nRb
const Rot3 nRb
Definition: testScenarioRunner.cpp:149
gtsam::Vector
Eigen::VectorXd Vector
Definition: Vector.h:39
gtsam::skewSymmetric
Matrix3 skewSymmetric(double wx, double wy, double wz)
Definition: base/Matrix.h:381
gtsam::Rot3
Rot3 is a 3D rotation represented as a rotation matrix if the preprocessor symbol GTSAM_USE_QUATERNIO...
Definition: Rot3.h:58
gtsam::KeyFormatter
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
gtsam::Pose3
Definition: Pose3.h:37
cholesky::expected
Matrix expected
Definition: testMatrix.cpp:916
gtsam::Rot3::inverse
Rot3 inverse() const
inverse of a rotation
Definition: Rot3.h:312
atan2
AnnoyingScalar atan2(const AnnoyingScalar &y, const AnnoyingScalar &x)
Definition: AnnoyingScalar.h:110
key
const gtsam::Symbol key('X', 0)
gtsam
traits
Definition: SFMdata.h:40
gtsam::traits
Definition: Group.h:36
std
Definition: BFloat16.h:88
gtsam::NonlinearFactor
Definition: NonlinearFactor.h:69
p
float * p
Definition: Tutorial_Map_using.cpp:9
gtsam::tol
const G double tol
Definition: Group.h:79
gtsam::Point3
Vector3 Point3
Definition: Point3.h:38
gtsam::OptionalMatrixType
Matrix * OptionalMatrixType
Definition: NonlinearFactor.h:56
setZero
v setZero(3)
GPSFactor.h
Header file for GPS factor.


gtsam
Author(s):
autogenerated on Wed Mar 19 2025 03:01:45