ExactCubic.h
Go to the documentation of this file.
1 /*
2  * Copyright 2015-2019 CNRS-UM LIRMM, CNRS-AIST JRL
3  */
4 
5 #pragma once
6 
8 #include <mc_trajectory/Spline.h>
9 #include <mc_trajectory/api.h>
10 
11 #include <memory>
12 #include <ndcurves/exact_cubic.h>
13 #include <vector>
14 
15 namespace mc_trajectory
16 {
17 
22 struct MC_TRAJECTORY_DLLAPI ExactCubic : public Spline<Eigen::Vector3d, std::vector<std::pair<double, Eigen::Vector3d>>>
23 {
24 public:
25  using point_t = Eigen::Vector3d;
26  using waypoint_t = std::pair<double, point_t>;
27  using exact_cubic_t = ndcurves::exact_cubic<double, double, false, point_t>;
28  using spline_constraints_t = ndcurves::curve_constraints<point_t>;
29 
30 public:
31  /* \brief Construct a curve passing through the specified optional waypoints
32  * with optional initial/final constraints.
33  * There should be at least two waypoints (initial and final position).
34  *
35  * \param duration Duration of the curve
36  * \param start Starting position at time t=0
37  * \param target Target position at time t=duration
38  * \param init_vel Initial velocity
39  * \param init_acc Initial acceleration
40  * \param end_vel Final velocity
41  * \param end_acc Final acceleration
42  */
43  ExactCubic(double duration,
44  const point_t & start,
45  const point_t & target,
46  const std::vector<waypoint_t> & waypoints = {},
47  const point_t & init_vel = {},
48  const point_t & init_acc = {},
49  const point_t & end_vel = {},
50  const point_t & end_acc = {});
51 
56  void update() override;
57 
63  void waypoint(size_t idx, const point_t & waypoint);
64 
70  void waypoint(size_t idx, const double t);
71 
78  const waypoint_t & waypoint(size_t idx) const;
85  double waypointTime(size_t idx) const;
86 
95  void constraints(const point_t & init_vel,
96  const point_t & init_acc,
97  const point_t & end_vel,
98  const point_t & end_acc);
99 
104  const point_t & init_vel() const;
109  const point_t & init_acc() const;
114  const point_t & end_vel() const;
119  const point_t & end_acc() const;
120 
129  std::vector<Eigen::Vector3d> splev(double t, unsigned int der = 0);
130 
135  std::vector<Eigen::Vector3d> sampleTrajectory();
136 
142  void addToGUI(mc_rtc::gui::StateBuilder & gui, const std::vector<std::string> & category);
143 
144 private:
145  spline_constraints_t constraints_;
146  std::unique_ptr<exact_cubic_t> spline_ = nullptr;
147 };
148 
149 } // namespace mc_trajectory
mc_trajectory::ExactCubic::exact_cubic_t
ndcurves::exact_cubic< double, double, false, point_t > exact_cubic_t
Definition: ExactCubic.h:27
mc_trajectory::ExactCubic
Represents an Exact Cubic spline : a curve that passes exactly through waypoints in position,...
Definition: ExactCubic.h:22
mc_trajectory::ExactCubic::spline_constraints_t
ndcurves::curve_constraints< point_t > spline_constraints_t
Definition: ExactCubic.h:28
mc_trajectory::ExactCubic::waypoint_t
std::pair< double, point_t > waypoint_t
Definition: ExactCubic.h:26
StateBuilder.h
mc_trajectory
Definition: BSpline.h:14
mc_rtc::gui::StateBuilder
Definition: StateBuilder.h:27
api.h
mc_trajectory::ExactCubic::point_t
Eigen::Vector3d point_t
Definition: ExactCubic.h:25
mc_trajectory::Spline
Definition: Spline.h:14
MC_TRAJECTORY_DLLAPI
#define MC_TRAJECTORY_DLLAPI
Definition: api.h:50
Spline.h