2014-07-31 02:43:24 +08:00
|
|
|
/* ----------------------------------------------------------------------------
|
|
|
|
|
2019-02-11 22:39:48 +08:00
|
|
|
* GTSAM Copyright 2010, Georgia Tech Research Corporation,
|
2014-07-31 02:43:24 +08:00
|
|
|
* Atlanta, Georgia 30332-0415
|
|
|
|
* All Rights Reserved
|
|
|
|
* Authors: Frank Dellaert, et al. (see THANKS for the full author list)
|
|
|
|
|
|
|
|
* See LICENSE for the license information
|
|
|
|
|
|
|
|
* -------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
/**
|
2014-09-11 03:30:06 +08:00
|
|
|
* @file BiasedGPSFactor.h
|
2014-07-31 02:43:24 +08:00
|
|
|
* @author Luca Carlone
|
|
|
|
**/
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <ostream>
|
|
|
|
|
|
|
|
#include <gtsam/geometry/Pose3.h>
|
|
|
|
#include <gtsam/nonlinear/NonlinearFactor.h>
|
|
|
|
|
|
|
|
namespace gtsam {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A class to model GPS measurements, including a bias term which models
|
|
|
|
* common-mode errors and that can be partially corrected if other sensors are used
|
2022-07-27 04:44:30 +08:00
|
|
|
* @ingroup slam
|
2014-07-31 02:43:24 +08:00
|
|
|
*/
|
2022-12-23 06:25:48 +08:00
|
|
|
class BiasedGPSFactor: public NoiseModelFactorN<Pose3, Point3> {
|
2014-07-31 02:43:24 +08:00
|
|
|
|
|
|
|
private:
|
|
|
|
|
2014-09-11 03:30:06 +08:00
|
|
|
typedef BiasedGPSFactor This;
|
2022-12-23 06:25:48 +08:00
|
|
|
typedef NoiseModelFactorN<Pose3, Point3> Base;
|
2014-07-31 02:43:24 +08:00
|
|
|
|
|
|
|
Point3 measured_; /** The measurement */
|
|
|
|
|
|
|
|
public:
|
2023-01-11 05:07:58 +08:00
|
|
|
// Provide access to the Matrix& version of evaluateError:
|
|
|
|
using Base::evaluateError;
|
2014-07-31 02:43:24 +08:00
|
|
|
|
|
|
|
// shorthand for a smart pointer to a factor
|
2014-10-25 01:06:45 +08:00
|
|
|
typedef boost::shared_ptr<BiasedGPSFactor> shared_ptr;
|
2014-07-31 02:43:24 +08:00
|
|
|
|
|
|
|
/** default constructor - only use for serialization */
|
2014-09-11 03:30:06 +08:00
|
|
|
BiasedGPSFactor() {}
|
2014-07-31 02:43:24 +08:00
|
|
|
|
|
|
|
/** Constructor */
|
2014-09-11 03:30:06 +08:00
|
|
|
BiasedGPSFactor(Key posekey, Key biaskey, const Point3 measured,
|
2014-07-31 02:43:24 +08:00
|
|
|
const SharedNoiseModel& model) :
|
|
|
|
Base(model, posekey, biaskey), measured_(measured) {
|
|
|
|
}
|
|
|
|
|
2021-01-29 12:02:13 +08:00
|
|
|
~BiasedGPSFactor() override {}
|
2014-07-31 02:43:24 +08:00
|
|
|
|
|
|
|
/** implement functions needed for Testable */
|
|
|
|
|
|
|
|
/** print */
|
2020-07-26 15:57:54 +08:00
|
|
|
void print(const std::string& s, const KeyFormatter& keyFormatter = DefaultKeyFormatter) const override {
|
2014-09-11 03:30:06 +08:00
|
|
|
std::cout << s << "BiasedGPSFactor("
|
2022-12-23 06:25:48 +08:00
|
|
|
<< keyFormatter(this->key<1>()) << ","
|
|
|
|
<< keyFormatter(this->key<2>()) << ")\n"
|
2016-02-12 16:06:07 +08:00
|
|
|
<< " measured: " << measured_.transpose() << std::endl;
|
2014-07-31 02:43:24 +08:00
|
|
|
this->noiseModel_->print(" noise model: ");
|
|
|
|
}
|
|
|
|
|
|
|
|
/** equals */
|
2020-07-26 15:57:54 +08:00
|
|
|
bool equals(const NonlinearFactor& expected, double tol=1e-9) const override {
|
2014-07-31 02:43:24 +08:00
|
|
|
const This *e = dynamic_cast<const This*> (&expected);
|
2020-04-07 05:31:05 +08:00
|
|
|
return e != nullptr && Base::equals(*e, tol) && traits<Point3>::Equals(this->measured_, e->measured_, tol);
|
2014-07-31 02:43:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/** implement functions needed to derive from Factor */
|
|
|
|
|
|
|
|
/** vector of errors */
|
|
|
|
Vector evaluateError(const Pose3& pose, const Point3& bias,
|
2023-01-10 06:52:56 +08:00
|
|
|
OptionalMatrixType H1, OptionalMatrixType H2) const override {
|
2014-07-31 02:43:24 +08:00
|
|
|
|
|
|
|
if (H1 || H2){
|
|
|
|
H1->resize(3,6); // jacobian wrt pose
|
2023-01-08 15:59:39 +08:00
|
|
|
(*H1) << Z_3x3, pose.rotation().matrix();
|
2014-07-31 02:43:24 +08:00
|
|
|
H2->resize(3,3); // jacobian wrt bias
|
2023-01-08 15:59:39 +08:00
|
|
|
(*H2) << I_3x3;
|
2014-07-31 02:43:24 +08:00
|
|
|
}
|
2016-02-12 16:06:07 +08:00
|
|
|
return pose.translation() + bias - measured_;
|
2014-07-31 02:43:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/** return the measured */
|
|
|
|
const Point3 measured() const {
|
|
|
|
return measured_;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
/** Serialization function */
|
|
|
|
friend class boost::serialization::access;
|
|
|
|
template<class ARCHIVE>
|
2015-03-06 23:12:09 +08:00
|
|
|
void serialize(ARCHIVE & ar, const unsigned int /*version*/) {
|
2022-12-23 06:25:48 +08:00
|
|
|
// NoiseModelFactor2 instead of NoiseModelFactorN for backward compatibility
|
2014-07-31 02:43:24 +08:00
|
|
|
ar & boost::serialization::make_nvp("NoiseModelFactor2",
|
|
|
|
boost::serialization::base_object<Base>(*this));
|
|
|
|
ar & BOOST_SERIALIZATION_NVP(measured_);
|
|
|
|
}
|
2014-09-11 03:30:06 +08:00
|
|
|
}; // \class BiasedGPSFactor
|
2014-07-31 02:43:24 +08:00
|
|
|
|
|
|
|
} /// namespace gtsam
|