40 #ifndef ROBOT_CONTROLLERS_TRAJECTORY_SPLINE_SAMPLER_H_ 41 #define ROBOT_CONTROLLERS_TRAJECTORY_SPLINE_SAMPLER_H_ 65 for (
int i=1; i<=n; i++)
67 powers[i] = powers[i-1]*x;
83 double p1,
double v1,
double a1,
103 s.
coef[3] = (-20.0*p0 + 20.0*p1 - 3.0*a0*T[2] + a1*T[2] -
104 12.0*v0*T[1] - 8.0*v1*T[1]) / (2.0*T[3]);
105 s.
coef[4] = (30.0*p0 - 30.0*p1 + 3.0*a0*T[2] - 2.0*a1*T[2] +
106 16.0*v0*T[1] + 14.0*v1*T[1]) / (2.0*T[4]);
107 s.
coef[5] = (-12.0*p0 + 12.0*p1 - a0*T[2] + a1*T[2] -
108 6.0*v0*T[1] - 6.0*v1*T[1]) / (2.0*T[5]);
116 double& position,
double& velocity,
double& acceleration)
121 position = T[0]*s.
coef[0] +
128 velocity = T[0]*s.
coef[1] +
134 acceleration = 2.0*T[0]*s.
coef[2] +
136 12.0*T[2]*s.
coef[4] +
165 s.
coef[2] = (3.0 * p1 - 3.0 * p0 - 2.0 *v0*T[1] - v1*T[1]) / T[2];
166 s.
coef[3] = (-2.0 * p1 + 2.0 * p0 + v0*T[1] + v1*T[1]) / T[3];
178 position = T[0]*s.
coef[0] +
183 velocity = T[0]*s.
coef[1] +
216 trajectory_(trajectory)
219 if (trajectory.
size() == 0)
225 size_t num_joints = trajectory.
points[0].q.size();
228 if (trajectory.
size() == 1)
231 segments_[0].start_time = segments_[0].end_time = trajectory.
points[0].time;
234 segments_[0].splines.resize(num_joints);
235 for (
size_t j = 0; j < num_joints; ++j)
238 trajectory.
points[0].q[j],
240 segments_[0].splines[j]);
242 segments_[0].type =
LINEAR;
243 result.q.resize(num_joints);
248 segments_.resize(trajectory.
size()-1);
251 for (
size_t p = 0; p < segments_.size(); ++p)
254 segments_[p].start_time = trajectory.
points[p].time;
255 segments_[p].end_time = trajectory.
points[p+1].time;
258 segments_[p].splines.resize(num_joints);
259 if (trajectory.
points[p].qdd.size() == trajectory.
points[p].q.size())
261 result.q.resize(num_joints);
262 result.qd.resize(num_joints);
263 result.qdd.resize(num_joints);
266 for (
size_t j = 0; j < num_joints; ++j)
269 trajectory.
points[p].qd[j],
270 trajectory.
points[p].qdd[j],
271 trajectory.
points[p+1].q[j],
272 trajectory.
points[p+1].qd[j],
273 trajectory.
points[p+1].qdd[j],
274 segments_[p].end_time - segments_[p].start_time,
275 segments_[p].splines[j]);
279 else if (trajectory.
points[p].qd.size() == trajectory.
points[p].q.size())
281 result.q.resize(num_joints);
282 result.qd.resize(num_joints);
285 for (
size_t j = 0; j < num_joints; ++j)
288 trajectory.
points[p].qd[j],
289 trajectory.
points[p+1].q[j],
290 trajectory.
points[p+1].qd[j],
291 segments_[p].end_time - segments_[p].start_time,
292 segments_[p].splines[j]);
294 segments_[p].type =
CUBIC;
298 result.q.resize(num_joints);
301 for (
size_t j = 0; j < num_joints; ++j)
304 trajectory.
points[p+1].q[j],
305 segments_[p].end_time - segments_[p].start_time,
306 segments_[p].splines[j]);
308 segments_[p].type =
LINEAR;
319 while ((seg_ + 1 <
int(segments_.size())) &&
320 (segments_[seg_ + 1].start_time < time))
330 if (time > end_time())
334 for (
size_t i = 0; i < segments_[seg_].splines.size(); ++i)
360 return segments_[segments_.size()-1].end_time;
378 #endif // ROBOT_CONTROLLERS_TRAJECTORY_SPLINE_SAMPLER_H_ Basis for a Trajectory Point.
static void LinearSpline(double p0, double p1, double t, Spline &s)
static void sampleCubicSpline(Spline s, double t, double &position, double &velocity)
Sample from the spline at time t.
Sampler that uses splines.
std::vector< TrajectoryPoint > points
std::vector< Spline > splines
spline type (to choose interpolation)
std::vector< Segment > segments_
virtual double end_time()
Get the end time of our trajectory.
virtual Trajectory getTrajectory()
Get the trajectory that we are sampling from.
static void QuinticSpline(double p0, double v0, double a0, double p1, double v1, double a1, double t, Spline &s)
Create a quintic spline with between (p0,v0,a0) and (p1,v1,a1)
static void CubicSpline(double p0, double v0, double p1, double v1, double t, Spline &s)
Constructor for a cubic spline with between (p0,v0) and (p1,v1)
static void sampleQuinticSpline(Spline &s, double t, double &position, double &velocity, double &acceleration)
Sample from the spline at time t.
SplineTrajectorySampler(const Trajectory &trajectory)
Construct a trajectory sampler.
static void generatePowers(int n, double x, double *powers)
Helper function for splines.
virtual TrajectoryPoint sample(double time)
Sample from this trajectory.
static void sampleLinearSpline(Spline &s, double t, double &position)
Base class for samplers of trajectories.