Skip to content

Commit

Permalink
migrate lerp function from dwa_planner to wheel_stuck_utils
Browse files Browse the repository at this point in the history
Signed-off-by: Autumn60 <[email protected]>
  • Loading branch information
Autumn60 committed Jul 13, 2024
1 parent 38c937a commit 69ecf09
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#ifndef WHEEL_STUCK_UTILS__MATH__MATH_HPP_
#define WHEEL_STUCK_UTILS__MATH__MATH_HPP_

#include <algorithm>

namespace wheel_stuck_utils::math
{
inline double lerp(const double a, const double b, double t)
{
t = std::max(0.0, std::min(1.0, t));
return a + t * (b - a);
}
} // namespace wheel_stuck_utils::math

#endif // WHEEL_STUCK_UTILS__MATH__MATH_HPP_
7 changes: 0 additions & 7 deletions src/planning/dwa_planner/include/dwa_planner/dwa_planner.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#include <nav_msgs/msg/occupancy_grid.hpp>
#include <nav_msgs/msg/odometry.hpp>

#include <algorithm>
#include <vector>

namespace dwa_planner
Expand Down Expand Up @@ -75,12 +74,6 @@ class DWAPlanner : public rclcpp::Node
double calculate_stage_cost(const State & state);
double calculate_terminal_cost(const State & state);

inline static double lerp(const double a, const double b, double t)
{
t = std::max(0.0, std::min(1.0, t));
return a + t * (b - a);
}

OccupancyGridSubscription::SharedPtr map_sub_;
OdometrySubscription::SharedPtr odom_sub_;
PoseStampedSubscription::SharedPtr goal_sub_;
Expand Down
7 changes: 5 additions & 2 deletions src/planning/dwa_planner/src/dwa_planner.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "dwa_planner/dwa_planner.hpp"

#include <wheel_stuck_utils/math/math.hpp>

#include <limits>

namespace dwa_planner
Expand Down Expand Up @@ -183,9 +185,10 @@ DWAPlanner::Trajectory DWAPlanner::planning()
Trajectory best_trajectory;

for (int v = 0; v < velocity_resolution_; v++) {
double velocity = lerp(window.min_velocity, window.max_velocity, v * velocity_resolution_inv_);
double velocity = wheel_stuck_utils::math::lerp(
window.min_velocity, window.max_velocity, v * velocity_resolution_inv_);
for (int a = 0; a < angular_velocity_resolution_; a++) {
double angular_velocity = lerp(
double angular_velocity = wheel_stuck_utils::math::lerp(
window.min_angular_velocity, window.max_angular_velocity,
a * angular_velocity_resolution_inv_);

Expand Down

0 comments on commit 69ecf09

Please sign in to comment.