DynamicsPriors.h 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /**
  2. * @file DynamicsPriors.h
  3. *
  4. * @brief Priors to be used with dynamic systems (Specifically PoseRTV)
  5. *
  6. * @date Nov 22, 2011
  7. * @author Alex Cunningham
  8. */
  9. #pragma once
  10. #include <gtsam_unstable/dynamics/PoseRTV.h>
  11. #include <gtsam_unstable/slam/PartialPriorFactor.h>
  12. namespace gtsam {
  13. // Indices of relevant variables in the PoseRTV tangent vector:
  14. // [ rx ry rz tx ty tz vx vy vz ]
  15. static const size_t kRollIndex = 0;
  16. static const size_t kPitchIndex = 1;
  17. static const size_t kHeightIndex = 5;
  18. static const size_t kVelocityZIndex = 8;
  19. static const std::vector<size_t> kVelocityIndices = { 6, 7, 8 };
  20. /**
  21. * Forces the value of the height (z) in a PoseRTV to a specific value.
  22. * Dim: 1
  23. */
  24. struct DHeightPrior : public gtsam::PartialPriorFactor<PoseRTV> {
  25. typedef gtsam::PartialPriorFactor<PoseRTV> Base;
  26. DHeightPrior(Key key, double height, const gtsam::SharedNoiseModel& model)
  27. : Base(key, kHeightIndex, height, model) {}
  28. };
  29. /**
  30. * Forces the roll to a particular value - useful for flying robots
  31. * Implied value is zero
  32. * Dim: 1
  33. */
  34. struct DRollPrior : public gtsam::PartialPriorFactor<PoseRTV> {
  35. typedef gtsam::PartialPriorFactor<PoseRTV> Base;
  36. /** allows for explicit roll parameterization - uses canonical coordinate */
  37. DRollPrior(Key key, double wx, const gtsam::SharedNoiseModel& model)
  38. : Base(key, kRollIndex, wx, model) { }
  39. /** Forces roll to zero */
  40. DRollPrior(Key key, const gtsam::SharedNoiseModel& model)
  41. : Base(key, kRollIndex, 0.0, model) { }
  42. };
  43. /**
  44. * Constrains the full velocity of a state to a particular value
  45. * Useful for enforcing a stationary state
  46. * Dim: 3
  47. */
  48. struct VelocityPrior : public gtsam::PartialPriorFactor<PoseRTV> {
  49. typedef gtsam::PartialPriorFactor<PoseRTV> Base;
  50. VelocityPrior(Key key, const gtsam::Vector& vel, const gtsam::SharedNoiseModel& model)
  51. : Base(key, kVelocityIndices, vel, model) {}
  52. };
  53. /**
  54. * Ground constraint: forces the robot to be upright (no roll, pitch), a fixed height, and no
  55. * velocity in z direction
  56. * Dim: 4
  57. */
  58. struct DGroundConstraint : public gtsam::PartialPriorFactor<PoseRTV> {
  59. typedef gtsam::PartialPriorFactor<PoseRTV> Base;
  60. /**
  61. * Primary constructor allows for variable height of the "floor"
  62. */
  63. DGroundConstraint(Key key, double height, const gtsam::SharedNoiseModel& model)
  64. : Base(key, { kHeightIndex, kVelocityZIndex, kRollIndex, kPitchIndex },
  65. Vector::Unit(4, 0)*height, model) {}
  66. /**
  67. * Fully specify vector - use only for debugging
  68. */
  69. DGroundConstraint(Key key, const Vector& constraint, const gtsam::SharedNoiseModel& model)
  70. : Base(key, { kHeightIndex, kVelocityZIndex, kRollIndex, kPitchIndex }, constraint, model) {
  71. assert(constraint.size() == 4);
  72. }
  73. };
  74. } // \namespace gtsam