Skip to content

Commit 9389c65

Browse files
Apply suggestions
Signed-off-by: CihatAltiparmak <cihataltiparmak1@gmail.com>
1 parent e5fb8be commit 9389c65

File tree

3 files changed

+31
-26
lines changed

3 files changed

+31
-26
lines changed

nav2_bt_navigator/behavior_trees/navigate_to_pose_w_replanning_and_recovery.xml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,18 @@
1212
<PlannerSelector selected_planner="{selected_planner}" default_planner="GridBased" topic_name="planner_selector"/>
1313
<RateController hz="1.0">
1414
<RecoveryNode number_of_retries="1" name="ComputePathToPose">
15-
<ComputePathToPose goal="{goal}" path="{path}" planner_id="{selected_planner}" error_code_id="{compute_path_error_code}" error_msg="{compute_path_error_msg}"/>
15+
<Sequence>
16+
<ComputePathToPose goal="{goal}" path="{path}" planner_id="{selected_planner}" error_code_id="{compute_path_error_code}" error_msg="{compute_path_error_msg}"/>
17+
<SmoothPath unsmoothed_path="{path}" smoothed_path="{smoothed_path}" smoother_id="simple_smoother" error_code_id="{smoother_error_code}" error_msg="{smoother_error_msg}"/>
18+
</Sequence>
1619
<Sequence>
1720
<WouldAPlannerRecoveryHelp error_code="{compute_path_error_code}"/>
1821
<ClearEntireCostmap name="ClearGlobalCostmap-Context" service_name="global_costmap/clear_entirely_global_costmap"/>
1922
</Sequence>
2023
</RecoveryNode>
2124
</RateController>
2225
<RecoveryNode number_of_retries="1" name="FollowPath">
23-
<FollowPath path="{path}" controller_id="{selected_controller}" error_code_id="{follow_path_error_code}" error_msg="{follow_path_error_msg}"/>
26+
<FollowPath path="{smoothed_path}" controller_id="{selected_controller}" error_code_id="{follow_path_error_code}" error_msg="{follow_path_error_msg}"/>
2427
<Sequence>
2528
<WouldAControllerRecoveryHelp error_code="{follow_path_error_code}"/>
2629
<ClearEntireCostmap name="ClearLocalCostmap-Context" service_name="local_costmap/clear_entirely_local_costmap"/>

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[1].pose.position.x - path.poses[0].pose.position.x;
103-
dy = path.poses[1].pose.position.y - path.poses[0].pose.position.y;
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;
104104
theta = atan2(dy, dx);
105-
pt_yaw = tf2::getYaw(path.poses[0].pose.orientation);
105+
pt_yaw = tf2::getYaw(path.poses[1].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: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -81,27 +81,29 @@ 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-
// 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);
84+
if (path_segments[i].end - path_segments[i].start > 3) {
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+
}
105107
}
106108

107109
return true;

0 commit comments

Comments
 (0)