diff --git a/include/teb_local_planner/timed_elastic_band.h b/include/teb_local_planner/timed_elastic_band.h index 12c7d275..7487a664 100644 --- a/include/teb_local_planner/timed_elastic_band.h +++ b/include/teb_local_planner/timed_elastic_band.h @@ -642,6 +642,8 @@ class TimedElasticBand //@} protected: + int findNearestStartState(const PoseSE2& new_start, int min_samples, std::function distance); + PoseSequence pose_vec_; //!< Internal container storing the sequence of optimzable pose vertices TimeDiffSequence timediff_vec_; //!< Internal container storing the sequence of optimzable timediff vertices diff --git a/src/timed_elastic_band.cpp b/src/timed_elastic_band.cpp index b16a3f62..551047d5 100644 --- a/src/timed_elastic_band.cpp +++ b/src/timed_elastic_band.cpp @@ -538,6 +538,27 @@ int TimedElasticBand::findClosestTrajectoryPose(const Obstacle& obstacle, double return findClosestTrajectoryPose(obstacle.getCentroid(), distance); } +int TimedElasticBand::findNearestStartState(const PoseSE2& new_start, int min_samples, std::function distance) +{ + if (sizePoses() == 0) { + return -1; + } + double dist_cache = distance(new_start, Pose(0)); + const int lookahead = sizePoses() - min_samples; + + int nearest_idx = 0; + for (int i = 1; i <= lookahead; ++i) + { + double dist = distance(new_start, Pose(i));; + if (dist new_start, boost::optional new_goal, int min_samples) { @@ -548,20 +569,16 @@ void TimedElasticBand::updateAndPruneTEB(boost::optional new_sta { // find nearest state (using l2-norm) in order to prune the trajectory // (remove already passed states) - double dist_cache = (new_start->position()- Pose(0).position()).norm(); - double dist; - int lookahead = std::min( sizePoses()-min_samples, 10); // satisfy min_samples, otherwise max 10 samples - - int nearest_idx = 0; - for (int i = 1; i<=lookahead; ++i) + int nearest_idx = findNearestStartState(new_start.get(), min_samples, [](const PoseSE2& a, const PoseSE2& b) { - dist = (new_start->position()- Pose(i).position()).norm(); - if (dist