VelocityConstraint3.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /**
  2. * @file VelocityConstraint3.h
  3. * @brief A simple 3-way factor constraining double poses and velocity
  4. * @author Duy-Nguyen Ta
  5. */
  6. #pragma once
  7. #include <gtsam/nonlinear/NonlinearFactor.h>
  8. namespace gtsam {
  9. class VelocityConstraint3 : public NoiseModelFactor3<double, double, double> {
  10. public:
  11. protected:
  12. typedef NoiseModelFactor3<double, double, double> Base;
  13. /** default constructor to allow for serialization */
  14. VelocityConstraint3() {}
  15. double dt_;
  16. public:
  17. typedef boost::shared_ptr<VelocityConstraint3 > shared_ptr;
  18. ///TODO: comment
  19. VelocityConstraint3(Key key1, Key key2, Key velKey, double dt, double mu = 1000.0)
  20. : Base(noiseModel::Constrained::All(1, std::abs(mu)), key1, key2, velKey), dt_(dt) {}
  21. ~VelocityConstraint3() override {}
  22. /// @return a deep copy of this factor
  23. gtsam::NonlinearFactor::shared_ptr clone() const override {
  24. return boost::static_pointer_cast<gtsam::NonlinearFactor>(
  25. gtsam::NonlinearFactor::shared_ptr(new VelocityConstraint3(*this))); }
  26. /** x1 + v*dt - x2 = 0, with optional derivatives */
  27. Vector evaluateError(const double& x1, const double& x2, const double& v,
  28. boost::optional<Matrix&> H1 = boost::none,
  29. boost::optional<Matrix&> H2 = boost::none,
  30. boost::optional<Matrix&> H3 = boost::none) const override {
  31. const size_t p = 1;
  32. if (H1) *H1 = Matrix::Identity(p,p);
  33. if (H2) *H2 = -Matrix::Identity(p,p);
  34. if (H3) *H3 = Matrix::Identity(p,p)*dt_;
  35. return (Vector(1) << x1+v*dt_-x2).finished();
  36. }
  37. private:
  38. /** Serialization function */
  39. friend class boost::serialization::access;
  40. template<class ARCHIVE>
  41. void serialize(ARCHIVE & ar, const unsigned int /*version*/) {
  42. ar & boost::serialization::make_nvp("NoiseModelFactor3",
  43. boost::serialization::base_object<Base>(*this));
  44. }
  45. }; // \VelocityConstraint3
  46. }