Skip to content

Commit

Permalink
path align improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
SteveMacenski committed Mar 12, 2024
1 parent 81f5480 commit ddef1e8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
20 changes: 12 additions & 8 deletions nav2_mppi_controller/include/nav2_mppi_controller/tools/utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -697,17 +697,21 @@ inline unsigned int removePosesAfterFirstInversion(nav_msgs::msg::Path & path)
* @brief Compare to trajectory points to find closest path point along integrated distances
* @param vec Vect to check
* @return dist Distance to look for
* @return init Starting index to indec from
*/
inline size_t findClosestPathPt(const std::vector<float> & vec, float dist, size_t init = 0)
inline size_t findClosestPathPt(
const std::vector<float> & vec, const float dist, const size_t init)
{
auto iter = std::lower_bound(vec.begin() + init, vec.end(), dist);
if (iter == vec.begin() + init) {
return 0;
}
if (dist - *(iter - 1) < *iter - dist) {
return iter - 1 - vec.begin();
for (size_t i = init; i != vec.size(); i++) {
if (vec[i] > dist) {
if (i > 0 && dist - vec[i - 1] < vec[i] - dist) {
return i - 1;
} else {
return i;
}
}
}
return iter - vec.begin();
return vec.size() - 1;
}

} // namespace mppi::utils
Expand Down
2 changes: 1 addition & 1 deletion nav2_mppi_controller/src/critics/path_align_critic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ void PathAlignCritic::score(CriticData & data)
dy = P_y(path_pt) - Ty;
num_samples += 1.0f;
if (use_path_orientations_) {
dyaw = angles::shortest_angular_distance(P_yaw(path_pt), data.trajectories.yaws(t, p));
dyaw = angles::shortest_angular_distance(P_yaw(path_pt), T_yaw(t, p));
summed_path_dist += sqrtf(dx * dx + dy * dy + dyaw * dyaw);
} else {
summed_path_dist += sqrtf(dx * dx + dy * dy);
Expand Down

0 comments on commit ddef1e8

Please sign in to comment.