Calico
A visual-inertial calibration library designed for rapid problem construction and debugging.
trajectory.h
1 #ifndef CALICO_TRAJECTORY_H_
2 #define CALICO_TRAJECTORY_H_
3 
4 #include "absl/container/flat_hash_map.h"
5 #include "absl/status/status.h"
6 #include "calico/bspline.h"
7 #include "calico/typedefs.h"
8 #include "ceres/problem.h"
9 #include "ceres/rotation.h"
10 
11 
12 namespace calico {
13 
15  int spline_index;
16  double knot0;
17  double knot1;
18  double stamp;
19  int num_control_points;
20  Eigen::MatrixXd basis_matrix;
21 };
22 
25 class Trajectory {
26  public:
28  static constexpr int kDefaultSplineOrder = 6;
29 
31  static constexpr double kDefaultKnotFrequency = 10;
32 
56  absl::Status FitSpline(
57  const absl::flat_hash_map<double, Pose3d>& poses_world_sensorrig,
58  double knot_frequency = kDefaultKnotFrequency,
59  int spline_order = kDefaultSplineOrder);
60 
64  int AddParametersToProblem(ceres::Problem& problem);
65 
66  void EnablePositionEstimation(bool enable);
67  void EnableRotationEstimation(bool enable);
68 
70  const BSpline<3>& rotation_spline() const { return spline_rotation_world_from_body_; }
71  BSpline<3>& rotation_spline() { return spline_rotation_world_from_body_; }
72 
74  const BSpline<3>& position_spline() const { return spline_position_world_to_body_; }
75  BSpline<3>& position_spline() { return spline_position_world_to_body_; }
76 
84  absl::StatusOr<std::vector<Pose3d>>
85  Interpolate(const std::vector<double>& interp_times) const;
86 
100  template <typename T>
101  static Pose3<T> VectorToPose3(const Eigen::Vector<T, 6>& vector) {
102  const Eigen::Vector3<T> phi = vector.head(3);
103  const Eigen::Vector3<T> pos = vector.tail(3);
104  Eigen::Vector4<T> q;
105  ceres::AngleAxisToQuaternion(phi.data(), q.data());
106  const Eigen::Quaternion<T> rot(q(0), q(1), q(2), q(3));
107  return Pose3<T>(rot, pos);
108  }
109 
111  const absl::flat_hash_map<double, Pose3d>& trajectory() const;
112  absl::flat_hash_map<double, Pose3d>& trajectory();
113 
116 
119 
120  private:
121  absl::flat_hash_map<double, Pose3d> pose_id_to_pose_world_body_;
122  BSpline<3> spline_rotation_world_from_body_;
123  BSpline<3> spline_position_world_to_body_;
124  bool position_enabled_;
125  bool rotation_enabled_;
126 
127  // Convenience function for unwrapping discrete axis-angle vectors in order to
128  // get a more continuous signal.
129  void UnwrapPhaseLogMap(std::vector<Eigen::Vector3d>& phi);
130 
131 };
132 
133 } // namespace calico
134 
135 #endif //CALICO_TRAJECTORY_H_
Definition: typedefs.h:38
Definition: trajectory.h:25
const absl::flat_hash_map< double, Pose3d > & trajectory() const
Setter/getter for the internal map between timestamp and pose.
Definition: trajectory.cpp:70
static constexpr int kDefaultSplineOrder
Default spline order of 6.
Definition: trajectory.h:28
static Pose3< T > VectorToPose3(const Eigen::Vector< T, 6 > &vector)
Definition: trajectory.h:101
absl::Status FitSpline(const absl::flat_hash_map< double, Pose3d > &poses_world_sensorrig, double knot_frequency=kDefaultKnotFrequency, int spline_order=kDefaultSplineOrder)
Definition: trajectory.cpp:14
const BSpline< 3 > & rotation_spline() const
Accessors for the rotation spline.
Definition: trajectory.h:70
int AddParametersToProblem(ceres::Problem &problem)
Definition: trajectory.cpp:53
TrajectoryEvaluationParams GetEvaluationParamsPosition(double stamp) const
Get the parameters needed to evaluate the position spline for a given timestamp.
Definition: trajectory.cpp:78
static constexpr double kDefaultKnotFrequency
Default knot frequency at 10Hz.
Definition: trajectory.h:31
TrajectoryEvaluationParams GetEvaluationParamsRotation(double stamp) const
Get the parameters needed to evaluate the rotation spline for a given timestamp.
Definition: trajectory.cpp:96
absl::StatusOr< std::vector< Pose3d > > Interpolate(const std::vector< double > &interp_times) const
Definition: trajectory.cpp:129
const BSpline< 3 > & position_spline() const
Accesors for the position spline.
Definition: trajectory.h:74
Primary calico namespace.
Definition: __init__.py:1
Definition: trajectory.h:14