effector_spline.h
Go to the documentation of this file.
1 
19 #ifndef _CLASS_EFFECTORSPLINE
20 #define _CLASS_EFFECTORSPLINE
21 
22 #include "ndcurves/exact_cubic.h"
23 
24 namespace ndcurves {
25 namespace helpers {
26 typedef double Numeric;
27 typedef double Time;
28 typedef Eigen::Matrix<Numeric, Eigen::Dynamic, 1> Point;
29 typedef std::vector<Point, Eigen::aligned_allocator<Point> > T_Point;
30 typedef std::pair<double, Point> Waypoint;
31 typedef std::vector<Waypoint> T_Waypoint;
36 
38 Waypoint compute_offset(const Waypoint& source, const Point& normal, const Numeric offset, const Time time_offset) {
39  Numeric norm = normal.norm();
40  if (norm < 0.) {
41  throw std::runtime_error("Norm of normal is less than 0!");
42  }
43  return std::make_pair(source.first + time_offset, (source.second + normal / norm * offset));
44 }
45 
48 spline_t make_end_spline(const Point& normal, const Point& from, const Numeric offset, const Time init_time,
49  const Time time_offset) {
50  Numeric norm = normal.norm();
51  if (norm < 0.) {
52  throw std::runtime_error("Norm of normal is less than 0!");
53  }
54  Point n = normal / norm;
55  Point d = offset / (time_offset * time_offset * time_offset) * -n;
56  Point c = -3 * d * time_offset;
57  Point b = -c * time_offset;
58  T_Point points;
59  points.push_back(from);
60  points.push_back(b);
61  points.push_back(c);
62  points.push_back(d);
63  return spline_t(points.begin(), points.end(), init_time, init_time + time_offset);
64 }
65 
67 spline_constraints_t compute_required_offset_velocity_acceleration(const spline_t& end_spline,
68  const Time /*time_offset*/) {
69  spline_constraints_t constraints(end_spline.dim());
70  constraints.end_acc = end_spline.derivate(end_spline.min(), 2);
71  constraints.end_vel = end_spline.derivate(end_spline.min(), 1);
72  return constraints;
73 }
74 
90 template <typename In>
91 exact_cubic_t* effector_spline(In wayPointsBegin, In wayPointsEnd, const Point& lift_normal = Eigen::Vector3d::UnitZ(),
92  const Point& land_normal = Eigen::Vector3d::UnitZ(), const Numeric lift_offset = 0.02,
93  const Numeric land_offset = 0.02, const Time lift_offset_duration = 0.02,
94  const Time land_offset_duration = 0.02) {
95  T_Waypoint waypoints;
96  const Waypoint &inPoint = *wayPointsBegin, endPoint = *(wayPointsEnd - 1);
97  waypoints.push_back(inPoint);
98  // adding initial offset
99  waypoints.push_back(compute_offset(inPoint, lift_normal, lift_offset, lift_offset_duration));
100  // inserting all waypoints but last
101  waypoints.insert(waypoints.end(), wayPointsBegin + 1, wayPointsEnd - 1);
102  // inserting waypoint to start landing
103  const Waypoint& landWaypoint = compute_offset(endPoint, land_normal, land_offset, -land_offset_duration);
104  waypoints.push_back(landWaypoint);
105  // specifying end velocity constraint such that landing will be in straight line
106  spline_t end_spline =
107  make_end_spline(land_normal, landWaypoint.second, land_offset, landWaypoint.first, land_offset_duration);
108  spline_constraints_t constraints = compute_required_offset_velocity_acceleration(end_spline, land_offset_duration);
109  exact_cubic_t splines(waypoints.begin(), waypoints.end(), constraints);
110  splines.add_curve(end_spline);
111  return new exact_cubic_t(splines);
112 }
113 } // namespace helpers
114 } // namespace ndcurves
115 #endif //_CLASS_EFFECTORSPLINE
Definition: bernstein.h:20
class allowing to create an Exact cubic spline.
exact_cubic_t::spline_constraints spline_constraints_t
Definition: effector_spline.h:33
Definition: exact_cubic.h:41
std::vector< spline_t > t_spline_t
Definition: exact_cubic.h:50
SplineBase spline_t
Definition: exact_cubic.h:49
std::vector< Waypoint > T_Waypoint
Definition: effector_spline.h:31
spline_t make_end_spline(const Point &normal, const Point &from, const Numeric offset, const Time init_time, const Time time_offset)
Compute spline from land way point to end point. Constraints are null velocity and acceleration...
Definition: effector_spline.h:48
std::vector< Point, Eigen::aligned_allocator< Point > > T_Point
Definition: effector_spline.h:29
exact_cubic_t::spline_t spline_t
Definition: effector_spline.h:35
double Time
Definition: effector_spline.h:27
exact_cubic_t::t_spline_t t_spline_t
Definition: effector_spline.h:34
spline_constraints_t compute_required_offset_velocity_acceleration(const spline_t &end_spline, const Time)
Compute end velocity : along landing normal and respecting time.
Definition: effector_spline.h:67
point_t end_acc
Definition: curve_constraint.h:66
exact_cubic< Time, Numeric, true, Point, T_Point > exact_cubic_t
Definition: effector_spline.h:32
std::pair< double, Point > Waypoint
Definition: effector_spline.h:30
Eigen::Matrix< Numeric, Eigen::Dynamic, 1 > Point
Definition: effector_spline.h:28
double Numeric
Definition: effector_spline.h:26
Waypoint compute_offset(const Waypoint &source, const Point &normal, const Numeric offset, const Time time_offset)
Compute time such that the equation from source to offsetpoint is necessarily a line.
Definition: effector_spline.h:38
exact_cubic_t * effector_spline(In wayPointsBegin, In wayPointsEnd, const Point &lift_normal=Eigen::Vector3d::UnitZ(), const Point &land_normal=Eigen::Vector3d::UnitZ(), const Numeric lift_offset=0.02, const Numeric land_offset=0.02, const Time lift_offset_duration=0.02, const Time land_offset_duration=0.02)
Helper method to create a spline typically used to guide the 3d trajectory of a robot end effector...
Definition: effector_spline.h:91
Definition: curve_constraint.h:22