Skip to content

Commit e5fb8be

Browse files
Smooth path even if goal pose is so much near to the robot
Signed-off-by: CihatAltiparmak <cihataltiparmak1@gmail.com>
1 parent 9cd0f9f commit e5fb8be

File tree

2 files changed

+24
-26
lines changed

2 files changed

+24
-26
lines changed

nav2_smoother/include/nav2_smoother/smoother_utils.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,10 @@ inline void updateApproximatePathOrientations(
9999
reversing_segment = false;
100100

101101
// Find if this path segment is in reverse
102-
dx = path.poses[2].pose.position.x - path.poses[1].pose.position.x;
103-
dy = path.poses[2].pose.position.y - path.poses[1].pose.position.y;
102+
dx = path.poses[1].pose.position.x - path.poses[0].pose.position.x;
103+
dy = path.poses[1].pose.position.y - path.poses[0].pose.position.y;
104104
theta = atan2(dy, dx);
105-
pt_yaw = tf2::getYaw(path.poses[1].pose.orientation);
105+
pt_yaw = tf2::getYaw(path.poses[0].pose.orientation);
106106
if (fabs(angles::shortest_angular_distance(pt_yaw, theta)) > M_PI_2) {
107107
reversing_segment = true;
108108
}

nav2_smoother/src/simple_smoother.cpp

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -81,29 +81,27 @@ bool SimpleSmoother::smooth(
8181
std::lock_guard<nav2_costmap_2d::Costmap2D::mutex_t> lock(*(costmap->getMutex()));
8282

8383
for (unsigned int i = 0; i != path_segments.size(); i++) {
84-
if (path_segments[i].end - path_segments[i].start > 9) {
85-
// Populate path segment
86-
curr_path_segment.poses.clear();
87-
std::copy(
88-
path.poses.begin() + path_segments[i].start,
89-
path.poses.begin() + path_segments[i].end + 1,
90-
std::back_inserter(curr_path_segment.poses));
91-
92-
// Make sure we're still able to smooth with time remaining
93-
steady_clock::time_point now = steady_clock::now();
94-
time_remaining = max_time.seconds() - duration_cast<duration<double>>(now - start).count();
95-
refinement_ctr_ = 0;
96-
97-
// Attempt to smooth the segment
98-
// May throw SmootherTimedOut
99-
smoothImpl(curr_path_segment, reversing_segment, costmap.get(), time_remaining);
100-
101-
// Assemble the path changes to the main path
102-
std::copy(
103-
curr_path_segment.poses.begin(),
104-
curr_path_segment.poses.end(),
105-
path.poses.begin() + path_segments[i].start);
106-
}
84+
// Populate path segment
85+
curr_path_segment.poses.clear();
86+
std::copy(
87+
path.poses.begin() + path_segments[i].start,
88+
path.poses.begin() + path_segments[i].end + 1,
89+
std::back_inserter(curr_path_segment.poses));
90+
91+
// Make sure we're still able to smooth with time remaining
92+
steady_clock::time_point now = steady_clock::now();
93+
time_remaining = max_time.seconds() - duration_cast<duration<double>>(now - start).count();
94+
refinement_ctr_ = 0;
95+
96+
// Attempt to smooth the segment
97+
// May throw SmootherTimedOut
98+
smoothImpl(curr_path_segment, reversing_segment, costmap.get(), time_remaining);
99+
100+
// Assemble the path changes to the main path
101+
std::copy(
102+
curr_path_segment.poses.begin(),
103+
curr_path_segment.poses.end(),
104+
path.poses.begin() + path_segments[i].start);
107105
}
108106

109107
return true;

0 commit comments

Comments
 (0)