Klamp't  0.8.1
Conversions.h
1 #include <KrisLibrary/spline/PiecewisePolynomial.h>
2 #include "ParabolicRamp.h"
3 #include "DynamicPath.h"
4 
5 inline Spline::PiecewisePolynomial Cast(const ParabolicRamp::ParabolicRamp1D& ramp)
6 {
7  Spline::PiecewisePolynomial res;
8  res.segments.resize(3);
9  res.timeShift.resize(3);
10  res.times.resize(4);
11  res.times[0] = 0;
12  res.times[1] = ramp.tswitch1;
13  res.times[2] = ramp.tswitch2;
14  res.times[3] = ramp.ttotal;
15  res.segments[0].Resize(3);
16  res.segments[0].coef[0] = ramp.x0;
17  res.segments[0].coef[1] = ramp.dx0;
18  res.segments[0].coef[2] = 0.5*ramp.a1;
19  res.timeShift[0] = 0;
20  res.segments[1].Resize(2);
21  res.segments[1].coef[0] = ramp.Evaluate(ramp.tswitch1);
22  res.segments[1].coef[1] = ramp.Derivative(ramp.tswitch1);
23  res.timeShift[1] = ramp.tswitch1;
24  res.segments[2].Resize(3);
25  res.segments[2].coef[0] = ramp.x1;
26  res.segments[2].coef[1] = ramp.dx1;
27  res.segments[2].coef[2] = 0.5*ramp.a2;
28  res.timeShift[2] = ramp.ttotal;
29 
30  if(ramp.ttotal == ramp.tswitch2) {
31  res.times.erase(--res.times.end());
32  res.segments.erase(--res.segments.end());
33  res.timeShift.erase(--res.timeShift.end());
34  }
35  if(ramp.tswitch1 == ramp.tswitch2) {
36  res.times.erase(++res.times.begin());
37  res.segments.erase(++res.segments.begin());
38  res.timeShift.erase(++res.timeShift.begin());
39  }
40  if(ramp.tswitch1 == 0 && res.segments.size()>1) {
41  res.times.erase(res.times.begin());
42  res.segments.erase(res.segments.begin());
43  res.timeShift.erase(res.timeShift.begin());
44  }
45  return res;
46 }
47 
48 inline Spline::PiecewisePolynomialND Cast(const ParabolicRamp::ParabolicRampND& ramp)
49 {
50  Spline::PiecewisePolynomialND res;
51  res.elements.resize(ramp.ramps.size());
52  for(size_t i=0;i<ramp.ramps.size();i++)
53  res.elements[i] = Cast(ramp.ramps[i]);
54  return res;
55 }
56 
57 //concatenates the ramps
58 inline Spline::PiecewisePolynomial Cast(const std::vector<ParabolicRamp::ParabolicRamp1D>& ramps)
59 {
60  assert(!ramps.empty());
61  if(ramps.size()==1) return Cast(ramps[0]);
62  Spline::PiecewisePolynomial p = Cast(ramps[0]);
63  for(size_t i=1;i<ramps.size();i++)
64  p.Concat(Cast(ramps[i]),true);
65  return p;
66 }
67 
68 inline Spline::PiecewisePolynomialND Cast(const std::vector<std::vector<ParabolicRamp::ParabolicRamp1D> >& ramps)
69 {
70  Spline::PiecewisePolynomialND res;
71  res.elements.resize(ramps.size());
72  for(size_t i=0;i<ramps.size();i++)
73  res.elements[i] = Cast(ramps[i]);
74  return res;
75 }
76 
77 inline Spline::PiecewisePolynomialND Cast(const ParabolicRamp::DynamicPath& path)
78 {
79  Spline::PiecewisePolynomialND res;
80  for(size_t i=0;i<path.ramps.size();i++) {
81  if(i==0) res = Cast(path.ramps[i]);
82  else res.Concat(Cast(path.ramps[i]),true);
83  }
84  return res;
85 }
Solves for optimal trajectores for a velocity-bounded ND system.
Definition: ParabolicRamp.h:110
std::vector< ParabolicRampND > ramps
The path is stored as a series of ramps.
Definition: DynamicPath.h:160
Real Derivative(Real t) const
Evaluates the derivative of the trajectory.
A bounded-velocity, bounded-acceleration trajectory consisting of parabolic ramps.
Definition: DynamicPath.h:114
Real Evaluate(Real t) const
Evaluates the trajectory.
Real x0
Input.
Definition: ParabolicRamp.h:97
Stores optimal trajectores for an acceleration and velocity-bounded 1D system.
Definition: ParabolicRamp.h:54
Real tswitch1
Calculated upon SolveX.
Definition: ParabolicRamp.h:101
Functions for optimal acceleration-bounded trajectories.