@@ -333,6 +333,24 @@ bool TerrainOmplRrt::getSolutionPath(std::vector<Eigen::Vector3d>& path) {
333
333
// return segment_curvature;
334
334
// }
335
335
336
+ PathSegment TerrainOmplRrt::extractPathSegment (ompl::base::State* from, ompl::base::State* to,
337
+ ompl::base::OwenStateSpace::PathType& path, double t_start, double t_end,
338
+ double dt) const {
339
+ ompl::base::State* state = problem_setup_->getStateSpace ()->allocState ();
340
+ PathSegment trajectory;
341
+ for (double t = t_start; t <= t_end; t += dt) {
342
+ // Append to trajectory
343
+ problem_setup_->getStateSpace ()->as <ompl::base::OwenStateSpace>()->interpolate (from, to, t, path, state);
344
+ State segment_state;
345
+ segment_state.position = dubinsairplanePosition (state);
346
+ double yaw = dubinsairplaneYaw (state);
347
+ Eigen::Vector3d velocity = Eigen::Vector3d (std::cos (yaw), std::sin (yaw), 0.0 );
348
+ segment_state.velocity = velocity;
349
+ trajectory.states .emplace_back (segment_state);
350
+ }
351
+ return trajectory;
352
+ }
353
+
336
354
void TerrainOmplRrt::solutionPathToPath (ompl::geometric::PathGeometric path, Path& trajectory_segments,
337
355
double resolution) const {
338
356
trajectory_segments.segments .clear ();
@@ -341,72 +359,64 @@ void TerrainOmplRrt::solutionPathToPath(ompl::geometric::PathGeometric path, Pat
341
359
for (size_t idx = 0 ; idx < state_vector.size () - 1 ; idx++) {
342
360
auto from = state_vector[idx]; // Start of the segment
343
361
auto to = state_vector[idx + 1 ]; // End of the segment
344
- auto path = problem_setup_->getStateSpace ()->as <ompl::base::OwenStateSpace>()->getPath (from, to);
345
- // ompl::base::OwenStateSpace::SegmentStarts segmentStarts;
346
- // problem_setup_->getStateSpace()->as<ompl::base::OwenStateSpace>()->calculateSegments(
347
- // from, to, dubins_path, segmentStarts);
348
-
349
- ompl::base::State* segment_start_state = problem_setup_->getStateSpace ()->allocState ();
350
- ompl::base::State* segment_end_state = problem_setup_->getStateSpace ()->allocState ();
351
-
352
- // const double total_length = dubins_path.length_2D();
353
- // const double dt = resolution / dubins_path.length_2D();
354
- double progress{0.0 };
355
- // for (size_t start_idx = 0; start_idx < segmentStarts.segmentStarts.size(); start_idx++) {
356
- // if (dubins_path.getSegmentLength(start_idx) > 0.0) {
357
- // double segment_progress = dubins_path.getSegmentLength(start_idx) / total_length;
358
- // // Read segment start and end statess
359
- // segmentStart2omplState(segmentStarts.segmentStarts[start_idx], segment_start_state);
360
- // if ((start_idx + 1) > (segmentStarts.segmentStarts.size() - 1)) {
361
- // segment_end_state = to;
362
- // } else if ((start_idx + 1) > (segmentStarts.segmentStarts.size() - 2) &&
363
- // dubins_path.getSegmentLength(start_idx + 1) == 0.0) {
364
- // segment_end_state = to;
365
- // } else {
366
- // segmentStart2omplState(segmentStarts.segmentStarts[start_idx + 1], segment_end_state);
367
- // }
368
-
369
- // // Append to trajectory
370
- // PathSegment trajectory;
371
- // trajectory.curvature = getSegmentCurvature(problem_setup_, dubins_path, start_idx);
372
- // ompl::base::State* state = problem_setup_->getStateSpace()->allocState();
373
- // trajectory.flightpath_angle = dubins_path.getGamma();
374
- // double yaw;
375
- // double track_progress{0.0};
376
- // for (double t = progress; t <= progress + segment_progress; t = t + dt) {
377
- // State segment_state;
378
- // problem_setup_->getStateSpace()->as<ompl::base::OwenStateSpace>()->interpolate(
379
- // dubins_path, segmentStarts, t, state);
380
- // Eigen::Vector3d position = dubinsairplanePosition(state);
381
- // yaw = dubinsairplaneYaw(state);
382
- // Eigen::Vector3d velocity = Eigen::Vector3d(std::cos(yaw), std::sin(yaw), 0.0);
383
- // segment_state.position = position;
384
- // segment_state.velocity = velocity;
385
- // segment_state.attitude = Eigen::Vector4d(std::cos(yaw / 2.0), 0.0, 0.0, std::sin(yaw / 2.0));
386
- // trajectory.states.emplace_back(segment_state);
387
- // track_progress = t;
388
- // }
389
- // // Append end state
390
- // if (((start_idx + 1) > (segmentStarts.segmentStarts.size() - 1)) ||
391
- // ((start_idx + 1) > (segmentStarts.segmentStarts.size() - 2) &&
392
- // dubins_path.getSegmentLength(start_idx + 1) == 0.0)) {
393
- // // Append segment with last state
394
- // State end_state;
395
- // Eigen::Vector3d end_position = dubinsairplanePosition(segment_end_state);
396
- // double end_yaw = dubinsairplaneYaw(segment_end_state);
397
- // Eigen::Vector3d end_velocity = Eigen::Vector3d(std::cos(end_yaw), std::sin(end_yaw), 0.0);
398
- // end_state.position = end_position;
399
- // end_state.velocity = end_velocity;
400
- // end_state.attitude = Eigen::Vector4d(std::cos(end_yaw / 2.0), 0.0, 0.0, std::sin(end_yaw / 2.0));
401
- // trajectory.states.emplace_back(end_state);
402
- // }
403
- // progress = track_progress;
404
- // // Do not append trajectory if the segment is too short
405
- // if (trajectory.states.size() > 1) {
406
- // trajectory_segments.segments.push_back(trajectory);
407
- // }
408
- // }
409
- // }
362
+ auto dubins_path = problem_setup_->getStateSpace ()->as <ompl::base::OwenStateSpace>()->getPath (from, to);
363
+
364
+ if (dubins_path->phi_ == 0 .) {
365
+ if (dubins_path->numTurns_ == 0 ) {
366
+ // Low path case
367
+ double t_start{0.0 };
368
+ double t_end{0.0 };
369
+ double length = dubins_path->path_ .length ();
370
+ for (int idx = 0 ; idx < 3 ; idx++) {
371
+ t_end = idx == 2 ? 1.0 : dubins_path->path_ .length_ [idx] / length + t_start;
372
+ auto trajectory = extractPathSegment (from, to, *dubins_path, t_start, t_end);
373
+ if (trajectory.states .size () > 1 ) {
374
+ trajectory_segments.segments .push_back (trajectory);
375
+ }
376
+ t_start = t_end;
377
+ }
378
+ } else {
379
+ // high altitude path
380
+
381
+ // Parse Trochoidal periodic paths
382
+ double lengthPeriodicPath = 2.0 * M_PI * dubins_path->turnRadius_ ;
383
+ auto lengthPath = dubins_path->path_ .length ();
384
+ auto lengthTotal = lengthPath + lengthPeriodicPath * dubins_path->numTurns_ ;
385
+ double t_start, t_end;
386
+ for (int k = 0 ; k < dubins_path->numTurns_ ; k++) {
387
+ // / TODO: Further divide this into segments
388
+ t_start = lengthPeriodicPath * k / lengthTotal;
389
+ t_end = lengthPeriodicPath * (k + 1 ) / lengthTotal;
390
+ auto trajectory = extractPathSegment (from, to, *dubins_path, t_start, t_end);
391
+ if (trajectory.states .size () > 1 ) {
392
+ trajectory_segments.segments .push_back (trajectory);
393
+ }
394
+ }
395
+ // Path
396
+ t_start = lengthPeriodicPath * dubins_path->numTurns_ / lengthTotal;
397
+ auto trajectory = extractPathSegment (from, to, *dubins_path, t_start, 1.0 );
398
+ if (trajectory.states .size () > 1 ) {
399
+ trajectory_segments.segments .push_back (trajectory);
400
+ }
401
+ }
402
+ } else {
403
+ // medium altitude path
404
+ auto lengthTurn = std::abs (dubins_path->phi_ );
405
+ auto lengthPath = dubins_path->path_ .length ();
406
+ auto lengthTotal = lengthTurn + lengthPath;
407
+ {
408
+ auto trajectory = extractPathSegment (from, to, *dubins_path, 0.0 , lengthTurn / lengthTotal);
409
+ if (trajectory.states .size () > 1 ) {
410
+ trajectory_segments.segments .push_back (trajectory);
411
+ }
412
+ }
413
+ {
414
+ auto trajectory = extractPathSegment (from, to, *dubins_path, lengthTurn / lengthTotal, 1.0 );
415
+ if (trajectory.states .size () > 1 ) {
416
+ trajectory_segments.segments .push_back (trajectory);
417
+ }
418
+ }
419
+ }
410
420
}
411
421
}
412
422
0 commit comments