gtsam/gtsam/navigation/BarometricFactor.h

115 lines
3.7 KiB
C
Raw Normal View History

2021-12-17 09:58:21 +08:00
/* ----------------------------------------------------------------------------
* GTSAM Copyright 2010, Georgia Tech Research Corporation,
* 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
* -------------------------------------------------------------------------- */
/**
* @file BarometricFactor.h
* @author Peter Milani
* @brief Header file for Barometric factor
* @date December 16, 2021
**/
#pragma once
#include <gtsam/geometry/Pose3.h>
2021-12-20 05:24:52 +08:00
#include <gtsam/navigation/NavState.h>
#include <gtsam/nonlinear/NonlinearFactor.h>
2021-12-17 09:58:21 +08:00
namespace gtsam {
/**
* Prior on height in a cartesian frame.
* Receive barometric pressure in kilopascals
* Model with a slowly moving bias to capture differences
* between the height and the standard atmosphere
* https://www.grc.nasa.gov/www/k-12/airplane/atmosmet.html
2022-07-27 04:25:41 +08:00
* @ingroup navigation
2021-12-17 09:58:21 +08:00
*/
class GTSAM_EXPORT BarometricFactor : public NoiseModelFactorN<Pose3, double> {
2021-12-20 05:24:52 +08:00
private:
typedef NoiseModelFactorN<Pose3, double> Base;
2021-12-20 05:24:52 +08:00
double nT_; ///< Height Measurement based on a standard atmosphere
public:
2023-01-12 03:14:26 +08:00
2023-01-11 08:15:06 +08:00
// Provide access to the Matrix& version of evaluateError:
using Base::evaluateError;
2021-12-20 05:24:52 +08:00
/// shorthand for a smart pointer to a factor
typedef std::shared_ptr<BarometricFactor> shared_ptr;
2021-12-20 05:24:52 +08:00
/// Typedef to this class
typedef BarometricFactor This;
/** default constructor - only use for serialization */
BarometricFactor() : nT_(0) {}
~BarometricFactor() override {}
/**
* @brief Constructor from a measurement of pressure in KPa.
* @param key of the Pose3 variable that will be constrained
* @param key of the barometric bias that will be constrained
* @param baroIn measurement in KPa
* @param model Gaussian noise model 1 dimension
*/
BarometricFactor(Key key, Key baroKey, const double& baroIn,
const SharedNoiseModel& model)
: Base(model, key, baroKey), nT_(heightOut(baroIn)) {}
/// @return a deep copy of this factor
gtsam::NonlinearFactor::shared_ptr clone() const override {
2023-01-18 06:39:55 +08:00
return std::static_pointer_cast<gtsam::NonlinearFactor>(
2021-12-20 05:24:52 +08:00
gtsam::NonlinearFactor::shared_ptr(new This(*this)));
}
/// print
void print(
const std::string& s = "",
const KeyFormatter& keyFormatter = DefaultKeyFormatter) const override;
/// equals
bool equals(const NonlinearFactor& expected,
double tol = 1e-9) const override;
/// vector of errors
Vector evaluateError(const Pose3& p, const double& b,
OptionalMatrixType H, OptionalMatrixType H2) const override;
2021-12-20 05:24:52 +08:00
inline const double& measurementIn() const { return nT_; }
inline double heightOut(double n) const {
// From https://www.grc.nasa.gov/www/k-12/airplane/atmosmet.html
return (std::pow(n / 101.29, 1. / 5.256) * 288.08 - 273.1 - 15.04) /
-0.00649;
};
inline double baroOut(const double& meters) {
double temp = 15.04 - 0.00649 * meters;
return 101.29 * std::pow(((temp + 273.1) / 288.08), 5.256);
};
private:
/// Serialization function
2023-01-19 03:36:21 +08:00
#ifdef GTSAM_ENABLE_BOOST_SERIALIZATION ///
2021-12-20 05:24:52 +08:00
friend class boost::serialization::access;
template <class ARCHIVE>
void serialize(ARCHIVE& ar, const unsigned int /*version*/) {
// NoiseModelFactor1 instead of NoiseModelFactorN for backward compatibility
2021-12-20 05:24:52 +08:00
ar& boost::serialization::make_nvp(
"NoiseModelFactor1",
2021-12-17 09:58:21 +08:00
boost::serialization::base_object<Base>(*this));
2021-12-20 05:24:52 +08:00
ar& BOOST_SERIALIZATION_NVP(nT_);
}
2023-01-19 03:36:21 +08:00
#endif
2021-12-17 09:58:21 +08:00
};
2021-12-20 05:24:52 +08:00
} // namespace gtsam