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
#define MC_TRAJECTORY_DLLAPI
Definition: api.h:50
Definition: BSpline.h:15
Definition: StateBuilder.h:28
Represents an Exact Cubic spline : a curve that passes exactly through waypoints in position,...
Definition: ExactCubic.h:23
void waypoint(size_t idx, const double t)
Updates the time at which an existing waypoint should be reached.
ExactCubic(double duration, const point_t &start, const point_t &target, const std::vector< waypoint_t > &waypoints={}, const point_t &init_vel={}, const point_t &init_acc={}, const point_t &end_vel={}, const point_t &end_acc={})
void update() override
Triggers recreation of the curve. Will only occur if the curve parameters were modified (waypoints,...
ndcurves::exact_cubic< double, double, false, point_t > exact_cubic_t
Definition: ExactCubic.h:27
const point_t & init_vel() const
Gets the curve's initial velocity.
const point_t & end_acc() const
Gets the curve's final acceleration.
const point_t & end_vel() const
Gets the curve's final velocity.
std::vector< Eigen::Vector3d > splev(double t, unsigned int der=0)
Computes the position along the curve at time t, and its derivatives up to the nth order (typically v...
double waypointTime(size_t idx) const
Gets the time at which a waypoint should be reached.
std::pair< double, point_t > waypoint_t
Definition: ExactCubic.h:26
Eigen::Vector3d point_t
Definition: ExactCubic.h:25
ndcurves::curve_constraints< point_t > spline_constraints_t
Definition: ExactCubic.h:28
const waypoint_t & waypoint(size_t idx) const
Gets position of a waypoint.
std::vector< Eigen::Vector3d > sampleTrajectory()
Sample positions along the trajectory (for visualization purposes)
void addToGUI(mc_rtc::gui::StateBuilder &gui, const std::vector< std::string > &category)
Add GUI elements to control the curve's waypoints and targets.
void waypoint(size_t idx, const point_t &waypoint)
Updates the position of an existing waypoint.
void constraints(const point_t &init_vel, const point_t &init_acc, const point_t &end_vel, const point_t &end_acc)
Defines the initial/final velocity and acceleration constraints for the curve.
const point_t & init_acc() const
Gets the curve's initial acceleration.
Definition: Spline.h:15