@@ -150,7 +150,7 @@ void Trajectory::InitFromChunksList(const std::list<Chunk>&chunkslist0) {
150
150
chunkcumulateddurationslist.resize (0 );
151
151
std::list<Chunk>::iterator itchunk = chunkslist.begin ();
152
152
while (itchunk != chunkslist.end ()) {
153
- assert (degree == itchunk->degree );
153
+ // assert(degree == itchunk->degree);
154
154
dReal chunkduration = itchunk->duration ;
155
155
if (chunkduration > TINY) {
156
156
chunkdurationslist.push_back (chunkduration);
@@ -260,50 +260,81 @@ void Trajectory::Evaldd(dReal s, std::vector<dReal>&qdd) const {
260
260
261
261
void Trajectory::ComputeChunk (dReal t0, dReal tnext, dReal s, dReal sd, dReal
262
262
sdd, const Chunk& currentchunk, Chunk& newchunk) {
263
- assert (currentchunk.degree <= 3 );
264
- dReal a0, a1, a2, b0, b1, b2, b3, b4, c0, c1, c2, c3, c4, c5, c6, u0, u1, u2, u3;
265
- std::vector<dReal> coefficientsvector;
263
+ assert (currentchunk.degree <= 5 );
264
+ std::vector<dReal> a, b, c, d, e, coefficientsvector;
266
265
std::vector<Polynomial> polynomialsvector;
267
- // current chunk : u0 + u1*s + u2*s^2
266
+ std::vector<std::vector<dReal> > coeffsvects;
267
+ // current chunk : u0 + u1*s + u2*s^2 + u3*s^3 + u4*s^4 + u5*s^5
268
268
// profile : s + sd*t + 0.5*sdd*t^2
269
- // new chunk : v0 + v1*t + v2*t^2 + v3*t^3 + v4*t^4 + v5*t^5 + v6*t^6;
270
- a0 = s + sd*t0 + 0.5 *sdd*t0*t0;
271
- a1 = sd + sdd*t0;
272
- a2 = 0.5 *sdd;
273
- b0 = a0*a0;
274
- b1 = 2 *a0*a1;
275
- b2 = 2 *a0*a2+a1*a1;
276
- b3 = 2 *a1*a2;
277
- b4 = a2*a2;
278
- c0 = b0*a0;
279
- c1 = b1*a0 + b0*a1;
280
- c2 = b2*a0 + b1*a1 + b0*a2;
281
- c3 = b3*a0 + b2*a1 + b1*a2;
282
- c4 = b4*a0 + b3*a1 + b2*a2;
283
- c5 = b4*a1 + b3*a2;
284
- c6 = b4*a2;
285
- for (int i=0 ; i<currentchunk.dimension ; i++) {
286
- u0 = currentchunk.polynomialsvector [i].coefficientsvector [0 ];
287
- u1 = 0 ;
288
- if (currentchunk.degree >= 1 )
289
- u1 = currentchunk.polynomialsvector [i].coefficientsvector [1 ];
290
- u2 = 0 ;
291
- if (currentchunk.degree >= 2 )
292
- u2 = currentchunk.polynomialsvector [i].coefficientsvector [2 ];
293
- u3 = 0 ;
294
- if (currentchunk.degree >= 3 )
295
- u3 = currentchunk.polynomialsvector [i].coefficientsvector [3 ];
296
- coefficientsvector.resize (0 );
297
- coefficientsvector.push_back (u3*c0 + u2*b0 + u1*a0 + u0); // v0
298
- coefficientsvector.push_back (u3*c1 + u2*b1 + u1*a1); // v1
299
- coefficientsvector.push_back (u3*c2 + u2*b2 + u1*a2); // v2
300
- coefficientsvector.push_back (u3*c3 + u2*b3); // v3
301
- coefficientsvector.push_back (u3*c4 + u2*b4); // v4
302
- coefficientsvector.push_back (u3*c5); // v5
303
- coefficientsvector.push_back (u3*c6); // v6
304
- polynomialsvector.push_back (Polynomial (coefficientsvector));
269
+ // new chunk : v0 + v1*t + v2*t^2 + v3*t^3 + v4*t^4 + v5*t^5 + v6*t^6 + v7*t^ + v8*t^8 + v9*t^9 + v10*t^10;
270
+
271
+ if (currentchunk.degree >= 1 ) {
272
+ a.resize (0 );
273
+ a.push_back (s + sd*t0 + 0.5 *sdd*t0*t0);
274
+ a.push_back (sd + sdd*t0);
275
+ a.push_back (0.5 *sdd);
276
+ coeffsvects.push_back (a);
305
277
}
306
- newchunk = Chunk (tnext-t0, polynomialsvector);
278
+ if (currentchunk.degree >= 2 ) {
279
+ b.resize (0 );
280
+ b.push_back (a[0 ]*a[0 ]);
281
+ b.push_back (2 *a[0 ]*a[1 ]);
282
+ b.push_back (2 *a[0 ]*a[2 ] + a[1 ]*a[1 ]);
283
+ b.push_back (2 *a[1 ]*a[2 ]);
284
+ b.push_back (a[2 ]*a[2 ]);
285
+ coeffsvects.push_back (b);
286
+ }
287
+ if (currentchunk.degree >= 3 ) {
288
+ c.push_back (b[0 ]*a[0 ]);
289
+ c.push_back (b[1 ]*a[0 ] + b[0 ]*a[1 ]);
290
+ c.push_back (b[2 ]*a[0 ] + b[1 ]*a[1 ] + b[0 ]*a[2 ]);
291
+ c.push_back (b[3 ]*a[0 ] + b[2 ]*a[1 ] + b[1 ]*a[2 ]);
292
+ c.push_back (b[4 ]*a[0 ] + b[3 ]*a[1 ] + b[2 ]*a[2 ]);
293
+ c.push_back (b[4 ]*a[1 ] + b[3 ]*a[2 ]);
294
+ c.push_back (b[4 ]*a[2 ]);
295
+ coeffsvects.push_back (c);
296
+ }
297
+ if (currentchunk.degree >= 4 ) {
298
+ d.push_back (b[0 ]*b[0 ]);
299
+ d.push_back (2 *b[0 ]*b[1 ]);
300
+ d.push_back (2 *b[0 ]*b[2 ] + b[1 ]*b[1 ]);
301
+ d.push_back (2 *(b[0 ]*b[3 ] + b[1 ]*b[2 ]));
302
+ d.push_back (2 *(b[0 ]*b[4 ] + b[1 ]*b[3 ]) + b[2 ]*b[2 ]);
303
+ d.push_back (2 *(b[1 ]*b[4 ] + b[2 ]*b[3 ]));
304
+ d.push_back (2 *b[2 ]*b[4 ] + b[3 ]*b[3 ]);
305
+ d.push_back (2 *b[3 ]*b[4 ]);
306
+ d.push_back (b[4 ]*b[4 ]);
307
+ coeffsvects.push_back (d);
308
+ }
309
+ if (currentchunk.degree >= 5 ) {
310
+ e.push_back (a[0 ]*d[0 ]);
311
+ e.push_back (d[1 ]*a[0 ] + d[0 ]*a[1 ]);
312
+ e.push_back (d[2 ]*a[0 ] + d[1 ]*a[1 ] + d[0 ]*a[2 ]);
313
+ e.push_back (d[3 ]*a[0 ] + d[2 ]*a[1 ] + d[1 ]*a[2 ]);
314
+ e.push_back (d[4 ]*a[0 ] + d[3 ]*a[1 ] + d[2 ]*a[2 ]);
315
+ e.push_back (d[5 ]*a[0 ] + d[4 ]*a[1 ] + d[3 ]*a[2 ]);
316
+ e.push_back (d[6 ]*a[0 ] + d[5 ]*a[1 ] + d[4 ]*a[2 ]);
317
+ e.push_back (d[7 ]*a[0 ] + d[6 ]*a[1 ] + d[5 ]*a[2 ]);
318
+ e.push_back (d[8 ]*a[0 ] + d[7 ]*a[1 ] + d[6 ]*a[2 ]);
319
+ e.push_back (d[8 ]*a[1 ] + d[7 ]*a[2 ]);
320
+ e.push_back (d[8 ]*a[2 ]);
321
+ coeffsvects.push_back (e);
322
+ }
323
+
324
+ for (int i = 0 ; i < currentchunk.dimension ; i++) {
325
+ coefficientsvector.resize (0 );
326
+ coefficientsvector.push_back (currentchunk.polynomialsvector [i].coefficientsvector [0 ]);
327
+ for (int k = 1 ; k <= currentchunk.degree ; k++){
328
+ coefficientsvector.resize (2 *k + 1 , 0 );
329
+ dReal u = currentchunk.polynomialsvector [i].coefficientsvector [k];
330
+ int l = 2 *k + 1 ;
331
+ for (int j = 0 ; j < l; j++) {
332
+ coefficientsvector[j] += u*coeffsvects[k - 1 ][j];
333
+ }
334
+ }
335
+ polynomialsvector.push_back (Polynomial (coefficientsvector));
336
+ }
337
+ newchunk = Chunk (tnext - t0, polynomialsvector);
307
338
}
308
339
309
340
@@ -400,6 +431,10 @@ int Trajectory::Reparameterize(Constraints& constraints, Trajectory& restrajecto
400
431
sdcur = sdnext2;
401
432
}
402
433
434
+ if (newchunkslist.size () < 1 ) {
435
+ return -1 ;
436
+ }
437
+
403
438
restrajectory = Trajectory (newchunkslist);
404
439
return 1 ;
405
440
}
0 commit comments