2019-04-09 20:05:24 -04:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Author: Mathieu Labbe
|
|
|
|
|
* This file is a copy of GPSPose2Factor.h of gtsam examples for Pose3
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* A simple 3D 'GPS' like factor
|
|
|
|
|
* The factor contains a X-Y-Z position measurement (mx, my, mz) for a Pose, but no rotation information
|
|
|
|
|
* The error vector will be [x-mx, y-my, z-mz]'
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include <gtsam/nonlinear/NonlinearFactor.h>
|
|
|
|
|
#include <gtsam/base/Matrix.h>
|
|
|
|
|
#include <gtsam/base/Vector.h>
|
|
|
|
|
#include <gtsam/geometry/Pose3.h>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace rtabmap {
|
|
|
|
|
|
2022-04-28 09:18:30 -04:00
|
|
|
template<class VALUE>
|
|
|
|
|
class XYZFactor: public gtsam::NoiseModelFactor1<VALUE> {
|
2019-04-09 20:05:24 -04:00
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
// measurement information
|
|
|
|
|
double mx_, my_, mz_;
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Constructor
|
|
|
|
|
* @param poseKey associated pose variable key
|
|
|
|
|
* @param model noise model for GPS sensor, in X-Y
|
|
|
|
|
* @param m Point2 measurement
|
|
|
|
|
*/
|
2022-04-28 09:18:30 -04:00
|
|
|
XYZFactor(gtsam::Key poseKey, const gtsam::Point3 m, gtsam::SharedNoiseModel model) :
|
|
|
|
|
gtsam::NoiseModelFactor1<VALUE>(model, poseKey), mx_(m.x()), my_(m.y()), mz_(m.z()) {}
|
2019-04-09 20:05:24 -04:00
|
|
|
|
|
|
|
|
// error function
|
|
|
|
|
// @param p the pose in Pose
|
|
|
|
|
// @param H the optional Jacobian matrix, which use boost optional and has default null pointer
|
2023-05-14 13:14:53 -07:00
|
|
|
gtsam::Vector evaluateError(const gtsam::Pose3& p,
|
2023-08-07 22:33:23 +08:00
|
|
|
#if GTSAM_VERSION_NUMERIC >= 40300
|
2026-04-27 06:33:05 +08:00
|
|
|
gtsam::OptionalMatrixType H = OptionalNone) const {
|
2023-05-14 13:14:53 -07:00
|
|
|
#else
|
|
|
|
|
boost::optional<gtsam::Matrix&> H = boost::none) const {
|
|
|
|
|
#endif
|
2019-04-09 20:05:24 -04:00
|
|
|
if(H)
|
|
|
|
|
{
|
|
|
|
|
p.translation(H);
|
|
|
|
|
}
|
|
|
|
|
return (gtsam::Vector3() << p.x() - mx_, p.y() - my_, p.z() - mz_).finished();
|
|
|
|
|
}
|
2023-05-14 13:14:53 -07:00
|
|
|
gtsam::Vector evaluateError(const gtsam::Point3& p,
|
2023-08-07 22:33:23 +08:00
|
|
|
#if GTSAM_VERSION_NUMERIC >= 40300
|
2026-04-27 06:33:05 +08:00
|
|
|
gtsam::OptionalMatrixType H = OptionalNone) const {
|
2023-05-14 13:14:53 -07:00
|
|
|
#else
|
|
|
|
|
boost::optional<gtsam::Matrix&> H = boost::none) const {
|
|
|
|
|
#endif
|
2026-08-06 13:32:20 -07:00
|
|
|
if(H)
|
|
|
|
|
{
|
|
|
|
|
*H = gtsam::Matrix::Identity(3, 3);
|
|
|
|
|
}
|
2022-04-28 09:18:30 -04:00
|
|
|
return (gtsam::Vector3() << p.x() - mx_, p.y() - my_, p.z() - mz_).finished();
|
|
|
|
|
}
|
2019-04-09 20:05:24 -04:00
|
|
|
};
|
|
|
|
|
|
2026-04-27 06:33:05 +08:00
|
|
|
} // namespace rtabmap
|
2019-04-09 20:05:24 -04:00
|
|
|
|