Skip to content

Commit 6e1c85e

Browse files
authored
fix simple smoother failing during final approach (#4817)
* new test case for end of path approach Signed-off-by: rayferric <63957587+rayferric@users.noreply.github.com> * modify tests to match the more permissive smoother policy Signed-off-by: rayferric <63957587+rayferric@users.noreply.github.com> * implement steve's suggestions Signed-off-by: rayferric <63957587+rayferric@users.noreply.github.com> --------- Signed-off-by: rayferric <63957587+rayferric@users.noreply.github.com>
1 parent 59f1f70 commit 6e1c85e

File tree

3 files changed

+25
-27
lines changed

3 files changed

+25
-27
lines changed

nav2_smoother/include/nav2_smoother/simple_smoother.hpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,8 @@ class SimpleSmoother : public nav2_core::Smoother
9292
* @param reversing_segment Return if this is a reversing segment
9393
* @param costmap Pointer to minimal costmap
9494
* @param max_time Maximum time to compute, stop early if over limit
95-
* @return If smoothing was successful
9695
*/
97-
bool smoothImpl(
96+
void smoothImpl(
9897
nav_msgs::msg::Path & path,
9998
bool & reversing_segment,
10099
const nav2_costmap_2d::Costmap2D * costmap,

nav2_smoother/src/simple_smoother.cpp

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,7 @@ bool SimpleSmoother::smooth(
6565
steady_clock::time_point start = steady_clock::now();
6666
double time_remaining = max_time.seconds();
6767

68-
bool success = true, reversing_segment;
69-
unsigned int segments_smoothed = 0;
68+
bool reversing_segment;
7069
nav_msgs::msg::Path curr_path_segment;
7170
curr_path_segment.header = path.header;
7271

@@ -88,15 +87,9 @@ bool SimpleSmoother::smooth(
8887
time_remaining = max_time.seconds() - duration_cast<duration<double>>(now - start).count();
8988
refinement_ctr_ = 0;
9089

91-
bool segment_was_smoothed = smoothImpl(
92-
curr_path_segment, reversing_segment, costmap.get(), time_remaining);
93-
94-
if (segment_was_smoothed) {
95-
segments_smoothed++;
96-
}
97-
98-
// Smooth path segment naively
99-
success = success && segment_was_smoothed;
90+
// Attempt to smooth the segment
91+
// May throw SmootherTimedOut
92+
smoothImpl(curr_path_segment, reversing_segment, costmap.get(), time_remaining);
10093

10194
// Assemble the path changes to the main path
10295
std::copy(
@@ -106,14 +99,10 @@ bool SimpleSmoother::smooth(
10699
}
107100
}
108101

109-
if (segments_smoothed == 0) {
110-
throw nav2_core::FailedToSmoothPath("No segments were smoothed");
111-
}
112-
113-
return success;
102+
return true;
114103
}
115104

116-
bool SimpleSmoother::smoothImpl(
105+
void SimpleSmoother::smoothImpl(
117106
nav_msgs::msg::Path & path,
118107
bool & reversing_segment,
119108
const nav2_costmap_2d::Costmap2D * costmap,
@@ -142,7 +131,7 @@ bool SimpleSmoother::smoothImpl(
142131
"Number of iterations has exceeded limit of %i.", max_its_);
143132
path = last_path;
144133
updateApproximatePathOrientations(path, reversing_segment);
145-
return false;
134+
return;
146135
}
147136

148137
// Make sure still have time left to process
@@ -188,7 +177,7 @@ bool SimpleSmoother::smoothImpl(
188177
"Returning the last path before the infeasibility was introduced.");
189178
path = last_path;
190179
updateApproximatePathOrientations(path, reversing_segment);
191-
return false;
180+
return;
192181
}
193182
}
194183

@@ -204,7 +193,6 @@ bool SimpleSmoother::smoothImpl(
204193

205194
updateApproximatePathOrientations(new_path, reversing_segment);
206195
path = new_path;
207-
return true;
208196
}
209197

210198
double SimpleSmoother::getFieldByDim(

nav2_smoother/test/test_simple_smoother.cpp

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ TEST(SmootherTest, test_simple_smoother)
180180
EXPECT_NEAR(straight_regular_path.poses[5].pose.position.x, 0.607, 0.01);
181181
EXPECT_NEAR(straight_regular_path.poses[5].pose.position.y, 0.387, 0.01);
182182

183-
// Test that collisions are rejected
183+
// Test that collisions are disregarded
184184
nav_msgs::msg::Path collision_path;
185185
collision_path.poses.resize(11);
186186
collision_path.poses[0].pose.position.x = 0.0;
@@ -205,7 +205,7 @@ TEST(SmootherTest, test_simple_smoother)
205205
collision_path.poses[9].pose.position.y = 1.4;
206206
collision_path.poses[10].pose.position.x = 1.5;
207207
collision_path.poses[10].pose.position.y = 1.5;
208-
EXPECT_THROW(smoother->smooth(collision_path, max_time), nav2_core::FailedToSmoothPath);
208+
EXPECT_TRUE(smoother->smooth(collision_path, max_time));
209209

210210
// test cusp / reversing segments
211211
nav_msgs::msg::Path reversing_path;
@@ -232,7 +232,7 @@ TEST(SmootherTest, test_simple_smoother)
232232
reversing_path.poses[9].pose.position.y = 0.1;
233233
reversing_path.poses[10].pose.position.x = 0.5;
234234
reversing_path.poses[10].pose.position.y = 0.0;
235-
EXPECT_THROW(smoother->smooth(reversing_path, max_time), nav2_core::FailedToSmoothPath);
235+
EXPECT_TRUE(smoother->smooth(reversing_path, max_time));
236236

237237
// test rotate in place
238238
tf2::Quaternion quat1, quat2;
@@ -244,7 +244,18 @@ TEST(SmootherTest, test_simple_smoother)
244244
straight_irregular_path.poses[6].pose.position.x = 0.5;
245245
straight_irregular_path.poses[6].pose.position.y = 0.5;
246246
straight_irregular_path.poses[6].pose.orientation = tf2::toMsg(quat2);
247-
EXPECT_THROW(smoother->smooth(straight_irregular_path, max_time), nav2_core::FailedToSmoothPath);
247+
EXPECT_TRUE(smoother->smooth(straight_irregular_path, max_time));
248+
249+
// test approach
250+
nav_msgs::msg::Path approach_path;
251+
approach_path.poses.resize(3);
252+
approach_path.poses[0].pose.position.x = 0.5;
253+
approach_path.poses[0].pose.position.y = 0.0;
254+
approach_path.poses[1].pose.position.x = 0.5;
255+
approach_path.poses[1].pose.position.y = 0.1;
256+
approach_path.poses[2].pose.position.x = 0.5;
257+
approach_path.poses[2].pose.position.y = 0.2;
258+
EXPECT_TRUE(smoother->smooth(approach_path, max_time));
248259

249260
// test max iterations
250261
smoother->setMaxItsToInvalid();
@@ -272,5 +283,5 @@ TEST(SmootherTest, test_simple_smoother)
272283
max_its_path.poses[9].pose.position.y = 0.9;
273284
max_its_path.poses[10].pose.position.x = 0.5;
274285
max_its_path.poses[10].pose.position.y = 1.0;
275-
EXPECT_THROW(smoother->smooth(max_its_path, max_time), nav2_core::FailedToSmoothPath);
286+
EXPECT_TRUE(smoother->smooth(max_its_path, max_time));
276287
}

0 commit comments

Comments
 (0)