19 #ifndef _CLASS_EXACTCUBIC 20 #define _CLASS_EXACTCUBIC 38 typename Point = Eigen::Matrix<Numeric, Eigen::Dynamic, 1>,
39 typename T_Point = std::vector<Point, Eigen::aligned_allocator<Point> >,
40 typename SplineBase = polynomial<Time, Numeric, Safe, Point, T_Point> >
45 typedef Eigen::Matrix<Numeric, Eigen::Dynamic, Eigen::Dynamic>
MatrixX;
46 typedef Eigen::Matrix<Numeric, 3, 3>
Matrix3;
74 template <
typename In>
76 t_spline_t subSplines = computeWayPoints<In>(wayPointsBegin, wayPointsEnd);
77 for (
cit_spline_t it = subSplines.begin(); it != subSplines.end(); ++it) {
88 template <
typename In>
93 computeWayPoints<In>(wayPointsBegin, wayPointsEnd, constraints);
94 for (
cit_spline_t it = subSplines.begin(); it != subSplines.end(); ++it) {
102 for (
cit_spline_t it = subSplines.begin(); it != subSplines.end(); ++it) {
119 boost::shared_ptr<spline_t> s_ptr =
124 throw std::runtime_error(
125 "Parent piecewise curve do not contain only curves created from " 126 "exact_cubic class methods");
138 return polynomial_t(coeffs.begin(), coeffs.end(), t_min, t_max);
151 return polynomial_t(coeffs.begin(), coeffs.end(), t_min, t_max);
161 template <
typename In>
162 t_spline_t computeWayPoints(In wayPointsBegin, In wayPointsEnd)
const {
163 const std::size_t
dim = wayPointsBegin->second.size();
164 const std::size_t size = std::distance(wayPointsBegin, wayPointsEnd);
165 if (Safe && size < 1) {
166 throw std::length_error(
167 "size of waypoints must be superior to 0");
170 subSplines.reserve(size);
172 MatrixX h1 = MatrixX::Zero(size, size);
173 MatrixX h2 = MatrixX::Zero(size, size);
174 MatrixX h3 = MatrixX::Zero(size, size);
175 MatrixX h4 = MatrixX::Zero(size, size);
176 MatrixX h5 = MatrixX::Zero(size, size);
177 MatrixX h6 = MatrixX::Zero(size, size);
183 In it(wayPointsBegin), next(wayPointsBegin);
186 for (std::size_t i(0); next != wayPointsEnd; ++next, ++it, ++i) {
187 num_t const dTi((*next).first - (*it).first);
188 num_t const dTi_sqr(dTi * dTi);
189 num_t const dTi_cube(dTi_sqr * dTi);
191 h3(i, i) = -3 / dTi_sqr;
192 h3(i, i + 1) = 3 / dTi_sqr;
194 h4(i, i + 1) = -1 / dTi;
195 h5(i, i) = 2 / dTi_cube;
196 h5(i, i + 1) = -2 / dTi_cube;
197 h6(i, i) = 1 / dTi_sqr;
198 h6(i, i + 1) = 1 / dTi_sqr;
202 num_t const dTi_1((*it2).first - (*next).first);
203 num_t const dTi_1sqr(dTi_1 * dTi_1);
206 h1(i + 1, i) = 2 / dTi;
207 h1(i + 1, i + 1) = 4 / dTi + 4 / dTi_1;
208 h1(i + 1, i + 2) = 2 / dTi_1;
209 h2(i + 1, i) = -6 / dTi_sqr;
210 h2(i + 1, i + 1) = (6 / dTi_1sqr) - (6 / dTi_sqr);
211 h2(i + 1, i + 2) = 6 / dTi_1sqr;
213 x.row(i) = (*it).second.transpose();
216 x.row(size - 1) = (*it).second.transpose();
224 it = wayPointsBegin, next = wayPointsBegin;
226 for (
int i = 0; next != wayPointsEnd; ++i, ++it, ++next) {
227 subSplines.push_back(create_cubic(a.row(i), b.row(i), c.row(i), d.row(i),
228 (*it).first, (*next).first));
233 template <
typename In>
234 t_spline_t computeWayPoints(In wayPointsBegin, In wayPointsEnd,
236 std::size_t
const size(std::distance(wayPointsBegin, wayPointsEnd));
237 if (Safe && size < 1) {
238 throw std::length_error(
239 "number of waypoints should be superior to one");
242 subSplines.reserve(size - 1);
244 In it(wayPointsBegin), next(wayPointsBegin), end(wayPointsEnd - 1);
246 for (std::size_t i(0); next != end; ++next, ++it, ++i) {
247 compute_one_spline<In>(it, next, cons, subSplines);
249 compute_end_spline<In>(it, next, cons, subSplines);
253 template <
typename In>
254 void compute_one_spline(In wayPointsBegin, In wayPointsNext,
257 const point_t &a0 = wayPointsBegin->second, a1 = wayPointsNext->second;
258 const point_t &b0 = constraints.init_vel, c0 = constraints.init_acc / 2.;
259 const num_t &init_t = wayPointsBegin->first, end_t = wayPointsNext->first;
260 const num_t dt = end_t - init_t, dt_2 = dt * dt, dt_3 = dt_2 * dt;
261 const point_t d0 = (a1 - a0 - b0 * dt - c0 * dt_2) / dt_3;
262 subSplines.push_back(create_cubic(a0, b0, c0, d0, init_t, end_t));
263 constraints.init_vel = subSplines.back().derivate(end_t, 1);
264 constraints.init_acc = subSplines.back().derivate(end_t, 2);
267 template <
typename In>
268 void compute_end_spline(In wayPointsBegin, In wayPointsNext,
271 const std::size_t
dim = wayPointsBegin->second.size();
272 const point_t &a0 = wayPointsBegin->second, a1 = wayPointsNext->second;
273 const point_t &b0 = constraints.init_vel, b1 = constraints.end_vel,
274 c0 = constraints.init_acc / 2., c1 = constraints.end_acc;
275 const num_t &init_t = wayPointsBegin->first, end_t = wayPointsNext->first;
276 const num_t dt = end_t - init_t, dt_2 = dt * dt, dt_3 = dt_2 * dt,
277 dt_4 = dt_3 * dt, dt_5 = dt_4 * dt;
279 const point_t alpha_0 = a1 - a0 - b0 * dt - c0 * dt_2;
280 const point_t alpha_1 = b1 - b0 - 2 * c0 * dt;
281 const point_t alpha_2 = c1 - 2 * c0;
282 const num_t x_d_0 = dt_3, x_d_1 = 3 * dt_2, x_d_2 = 6 * dt;
283 const num_t x_e_0 = dt_4, x_e_1 = 4 * dt_3, x_e_2 = 12 * dt_2;
284 const num_t x_f_0 = dt_5, x_f_1 = 5 * dt_4, x_f_2 = 20 * dt_3;
287 rhs.row(0) = alpha_0;
288 rhs.row(1) = alpha_1;
289 rhs.row(2) = alpha_2;
290 Matrix3 eq = Matrix3::Zero(3, 3);
300 rhs = eq.inverse().eval() * rhs;
304 subSplines.push_back(create_quintic(a0, b0, c0, d, e, f, init_t, end_t));
309 friend class boost::serialization::access;
310 template <
class Archive>
311 void serialize(Archive& ar,
const unsigned int version) {
320 DEFINE_CLASS_TEMPLATE_VERSION(
322 typename T_Point,
typename SplineBase),
325 #endif //_CLASS_EXACTCUBIC virtual ~exact_cubic()
Destructor.
Definition: exact_cubic.h:114
T_Point t_point_t
Definition: exact_cubic.h:44
Definition: bernstein.h:20
exact_cubic(const exact_cubic &other)
Copy Constructor.
Definition: exact_cubic.h:111
t_spline_t::const_iterator cit_spline_t
Definition: exact_cubic.h:52
Definition: exact_cubic.h:41
void PseudoInverse(_Matrix_Type_ &pinvmat)
An inverse kinematics architecture enforcing an arbitrary number of strict priority levels (Reference...
Definition: MathDefs.h:26
std::vector< spline_t > t_spline_t
Definition: exact_cubic.h:50
virtual std::size_t dim() const
Get dimension of curve.
Definition: piecewise_curve.h:641
std::size_t getNumberCurves()
Definition: piecewise_curve.h:654
exact_cubic(In wayPointsBegin, In wayPointsEnd, const spline_constraints &constraints)
Constructor.
Definition: exact_cubic.h:89
Eigen::Matrix< Numeric, Eigen::Dynamic, Eigen::Dynamic > MatrixX
Definition: exact_cubic.h:45
const Eigen::Ref< const point_t > point_ref_t
Definition: exact_cubic.h:43
Definition of a cubic spline.
SplineBase spline_t
Definition: exact_cubic.h:49
exact_cubic(const t_spline_t &subSplines)
Constructor.
Definition: exact_cubic.h:101
interface for a Curve of arbitrary dimension.
exact_cubic(const t_curve_ptr_t &subSplines)
Definition: exact_cubic.h:107
Eigen::Matrix< Numeric, 3, 3 > Matrix3
Definition: exact_cubic.h:46
t_curve_ptr_t curves_
Definition: piecewise_curve.h:659
T_Point t_point_t
Definition: polynomial.h:37
curve_abc< Time, Numeric, Safe, point_t > curve_abc_t
Definition: exact_cubic.h:57
Numeric num_t
Definition: exact_cubic.h:48
std::vector< Point, Eigen::aligned_allocator< Point > > T_Point
Definition: effector_spline.h:29
piecewise_curve< Time, Numeric, Safe, point_t > piecewise_curve_t
Definition: exact_cubic.h:58
curve_constraints< Point > spline_constraints
Definition: exact_cubic.h:53
Represents a polynomial of an arbitrary order defined on the interval . It follows the equation : ...
Definition: fwd.h:42
piecewise_curve_t::t_curve_ptr_t t_curve_ptr_t
Definition: exact_cubic.h:60
double Time
Definition: effector_spline.h:27
void serialize(Archive &ar, const unsigned int version)
Definition: exact_cubic.h:311
exact_cubic(In wayPointsBegin, In wayPointsEnd)
Constructor.
Definition: exact_cubic.h:75
Eigen::Matrix< Numeric, Eigen::Dynamic, 1 > Point
Definition: effector_spline.h:28
spline_t getSplineAt(std::size_t index)
Definition: exact_cubic.h:118
std::size_t getNumberSplines()
Definition: exact_cubic.h:116
struct to define constraints on start / end velocities and acceleration on a curve ...
Point point_t
Definition: exact_cubic.h:42
t_spline_t::iterator it_spline_t
Definition: exact_cubic.h:51
double Numeric
Definition: effector_spline.h:26
class allowing to create a piecewise curve.
polynomial< Time, Numeric, Safe, point_t > polynomial_t
Definition: exact_cubic.h:59
void add_curve(const Curve &curve)
Definition: piecewise_curve.h:176
Definition: curve_constraint.h:20
std::vector< curve_ptr_t > t_curve_ptr_t
Definition: piecewise_curve.h:50
exact_cubic()
Empty constructor. Add at least one curve to call other class functions.
Definition: exact_cubic.h:67
Time time_t
Definition: exact_cubic.h:47
Represents a curve of dimension Dim. If value of parameter Safe is false, no verification is made on ...
Definition: curve_abc.h:37
exact_cubic< Time, Numeric, Safe, point_t, T_Point, SplineBase > exact_cubic_t
Definition: exact_cubic.h:56