Skip to content

Commit a8f5ad7

Browse files
committed
Increase code coverage
Signed-off-by: mini-1235 <[email protected]>
1 parent 4b7deb2 commit a8f5ad7

File tree

4 files changed

+324
-2
lines changed

4 files changed

+324
-2
lines changed

nav2_controller/include/nav2_controller/plugins/simple_path_handler.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ class SimplePathHandler : public nav2_core::PathHandler
4949
const geometry_msgs::msg::PoseStamped & pose) override;
5050
geometry_msgs::msg::PoseStamped getTransformedGoal(
5151
const builtin_interfaces::msg::Time & stamp) override;
52+
nav_msgs::msg::Path getPlan() {return global_plan_;}
5253

5354
protected:
5455
/**

nav2_controller/plugins/test/CMakeLists.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,7 @@ ament_add_gtest(pctest progress_checker.cpp)
22
target_link_libraries(pctest simple_progress_checker pose_progress_checker)
33

44
ament_add_gtest(gctest goal_checker.cpp)
5-
target_link_libraries(gctest simple_goal_checker stopped_goal_checker)
5+
target_link_libraries(gctest simple_goal_checker stopped_goal_checker position_goal_checker)
6+
7+
ament_add_gtest(phtest path_handler.cpp)
8+
target_link_libraries(phtest simple_path_handler)

nav2_controller/plugins/test/goal_checker.cpp

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,14 @@
3838
#include "gtest/gtest.h"
3939
#include "nav2_controller/plugins/simple_goal_checker.hpp"
4040
#include "nav2_controller/plugins/stopped_goal_checker.hpp"
41+
#include "nav2_controller/plugins/position_goal_checker.hpp"
4142
#include "nav2_util/geometry_utils.hpp"
4243
#include "nav2_ros_common/lifecycle_node.hpp"
4344
#include "nav_msgs/msg/path.hpp"
4445

4546
using nav2_controller::SimpleGoalChecker;
4647
using nav2_controller::StoppedGoalChecker;
48+
using nav2_controller::PositionGoalChecker;
4749

4850
void checkMacro(
4951
nav2_core::GoalChecker & gc,
@@ -157,6 +159,16 @@ TEST(VelocityIterator, stopped_goal_checker_reset)
157159
EXPECT_TRUE(true);
158160
}
159161

162+
TEST(VelocityIterator, position_goal_checker_reset)
163+
{
164+
auto x = std::make_shared<TestLifecycleNode>("position_goal_checker");
165+
166+
nav2_core::GoalChecker * pgc = new PositionGoalChecker;
167+
pgc->reset();
168+
delete pgc;
169+
EXPECT_TRUE(true);
170+
}
171+
160172
TEST(VelocityIterator, two_checks)
161173
{
162174
auto x = std::make_shared<TestLifecycleNode>("goal_checker");
@@ -184,10 +196,12 @@ TEST(StoppedGoalChecker, get_tol_and_dynamic_params)
184196

185197
SimpleGoalChecker gc;
186198
StoppedGoalChecker sgc;
199+
PositionGoalChecker pgc;
187200
auto costmap = std::make_shared<nav2_costmap_2d::Costmap2DROS>("test_costmap");
188201

189202
sgc.initialize(x, "test", costmap);
190203
gc.initialize(x, "test2", costmap);
204+
pgc.initialize(x, "test3", costmap);
191205
geometry_msgs::msg::Pose pose_tol;
192206
geometry_msgs::msg::Twist vel_tol;
193207

@@ -239,6 +253,24 @@ TEST(StoppedGoalChecker, get_tol_and_dynamic_params)
239253
EXPECT_TRUE(gc.getTolerances(pose_tol, vel_tol));
240254
EXPECT_EQ(pose_tol.position.x, 200.0);
241255
EXPECT_EQ(pose_tol.position.y, 200.0);
256+
257+
// Test position goal checker's dynamic parameters
258+
results = rec_param->set_parameters_atomically(
259+
{rclcpp::Parameter("test3.xy_goal_tolerance", 200.0),
260+
rclcpp::Parameter("test3.path_length_tolerance", 200.0),
261+
rclcpp::Parameter("test3.stateful", true)});
262+
263+
rclcpp::spin_until_future_complete(
264+
x->get_node_base_interface(),
265+
results);
266+
267+
EXPECT_EQ(x->get_parameter("test3.xy_goal_tolerance").as_double(), 200.0);
268+
EXPECT_EQ(x->get_parameter("test3.path_length_tolerance").as_double(), 200.0);
269+
EXPECT_EQ(x->get_parameter("test3.stateful").as_bool(), true);
270+
271+
EXPECT_TRUE(pgc.getTolerances(pose_tol, vel_tol));
272+
EXPECT_EQ(pose_tol.position.x, 200.0);
273+
EXPECT_EQ(pose_tol.position.y, 200.0);
242274
}
243275

244276
TEST(StoppedGoalChecker, is_reached)
@@ -247,10 +279,12 @@ TEST(StoppedGoalChecker, is_reached)
247279

248280
SimpleGoalChecker gc;
249281
StoppedGoalChecker sgc;
282+
PositionGoalChecker pgc;
250283
auto costmap = std::make_shared<nav2_costmap_2d::Costmap2DROS>("test_costmap");
251284

252285
sgc.initialize(x, "test", costmap);
253286
gc.initialize(x, "test2", costmap);
287+
pgc.initialize(x, "test3", costmap);
254288
geometry_msgs::msg::Pose goal_pose;
255289
geometry_msgs::msg::Twist velocity;
256290
geometry_msgs::msg::Pose current_pose;
@@ -261,23 +295,28 @@ TEST(StoppedGoalChecker, is_reached)
261295
nav_msgs::msg::Path transformed_global_plan_;
262296
EXPECT_TRUE(sgc.isGoalReached(current_pose, goal_pose, velocity, transformed_global_plan_));
263297
EXPECT_TRUE(gc.isGoalReached(current_pose, goal_pose, velocity, transformed_global_plan_));
298+
EXPECT_TRUE(pgc.isGoalReached(current_pose, goal_pose, velocity, transformed_global_plan_));
264299
sgc.reset();
265300
gc.reset();
301+
pgc.reset();
266302

267303
// Current linear x speed exceeds tolerance
268304
velocity.linear.x = 0.25 + std::numeric_limits<double>::epsilon();
269305
EXPECT_FALSE(sgc.isGoalReached(current_pose, goal_pose, velocity, transformed_global_plan_));
270306
EXPECT_TRUE(gc.isGoalReached(current_pose, goal_pose, velocity, transformed_global_plan_));
307+
EXPECT_TRUE(pgc.isGoalReached(current_pose, goal_pose, velocity, transformed_global_plan_));
271308
sgc.reset();
272309
gc.reset();
310+
pgc.reset();
273311

274312
// Current linear x position is further than tolerance away from goal
275313
current_pose.position.x = 0.25 + std::numeric_limits<double>::epsilon();
276314
velocity.linear.x = 0.25;
277315
EXPECT_FALSE(sgc.isGoalReached(current_pose, goal_pose, velocity, transformed_global_plan_));
278316
EXPECT_FALSE(gc.isGoalReached(current_pose, goal_pose, velocity, transformed_global_plan_));
317+
EXPECT_FALSE(pgc.isGoalReached(current_pose, goal_pose, velocity, transformed_global_plan_));
279318
sgc.reset();
280-
gc.reset();
319+
pgc.reset();
281320
current_pose.position.x = 0.0;
282321
velocity.linear.x = 0.0;
283322

@@ -288,16 +327,20 @@ TEST(StoppedGoalChecker, is_reached)
288327
velocity.linear.y = 0.25 / std::sqrt(2);
289328
EXPECT_TRUE(sgc.isGoalReached(current_pose, goal_pose, velocity, transformed_global_plan_));
290329
EXPECT_TRUE(gc.isGoalReached(current_pose, goal_pose, velocity, transformed_global_plan_));
330+
EXPECT_TRUE(pgc.isGoalReached(current_pose, goal_pose, velocity, transformed_global_plan_));
291331
sgc.reset();
292332
gc.reset();
333+
pgc.reset();
293334

294335
// Current linear speed exceeds tolerance
295336
velocity.linear.x = 0.25 / std::sqrt(2) + std::numeric_limits<double>::epsilon();
296337
velocity.linear.y = 0.25 / std::sqrt(2) + std::numeric_limits<double>::epsilon();
297338
EXPECT_FALSE(sgc.isGoalReached(current_pose, goal_pose, velocity, transformed_global_plan_));
298339
EXPECT_TRUE(gc.isGoalReached(current_pose, goal_pose, velocity, transformed_global_plan_));
340+
EXPECT_TRUE(pgc.isGoalReached(current_pose, goal_pose, velocity, transformed_global_plan_));
299341
sgc.reset();
300342
gc.reset();
343+
pgc.reset();
301344

302345
// Current linear position is further than tolerance away from goal
303346
current_pose.position.x = 0.25 / std::sqrt(2) + std::numeric_limits<double>::epsilon();
@@ -306,8 +349,10 @@ TEST(StoppedGoalChecker, is_reached)
306349
velocity.linear.y = 0.25 / std::sqrt(2);
307350
EXPECT_FALSE(sgc.isGoalReached(current_pose, goal_pose, velocity, transformed_global_plan_));
308351
EXPECT_FALSE(gc.isGoalReached(current_pose, goal_pose, velocity, transformed_global_plan_));
352+
EXPECT_FALSE(pgc.isGoalReached(current_pose, goal_pose, velocity, transformed_global_plan_));
309353
sgc.reset();
310354
gc.reset();
355+
pgc.reset();
311356

312357
current_pose.position.x = 0.0;
313358
velocity.linear.x = 0.0;
@@ -317,23 +362,29 @@ TEST(StoppedGoalChecker, is_reached)
317362
velocity.angular.z = 0.25;
318363
EXPECT_TRUE(sgc.isGoalReached(current_pose, goal_pose, velocity, transformed_global_plan_));
319364
EXPECT_TRUE(gc.isGoalReached(current_pose, goal_pose, velocity, transformed_global_plan_));
365+
EXPECT_TRUE(pgc.isGoalReached(current_pose, goal_pose, velocity, transformed_global_plan_));
320366
sgc.reset();
321367
gc.reset();
368+
pgc.reset();
322369

323370
// Current angular speed exceeds tolerance
324371
velocity.angular.z = 0.25 + std::numeric_limits<double>::epsilon();
325372
EXPECT_FALSE(sgc.isGoalReached(current_pose, goal_pose, velocity, transformed_global_plan_));
326373
EXPECT_TRUE(gc.isGoalReached(current_pose, goal_pose, velocity, transformed_global_plan_));
374+
EXPECT_TRUE(pgc.isGoalReached(current_pose, goal_pose, velocity, transformed_global_plan_));
327375
sgc.reset();
328376
gc.reset();
377+
pgc.reset();
329378

330379
// Current angular position is further than tolerance away from goal
331380
current_pose.orientation = nav2_util::geometry_utils::orientationAroundZAxis(0.25 + 1e-15);
332381
velocity.angular.z = 0.25;
333382
EXPECT_FALSE(sgc.isGoalReached(current_pose, goal_pose, velocity, transformed_global_plan_));
334383
EXPECT_FALSE(gc.isGoalReached(current_pose, goal_pose, velocity, transformed_global_plan_));
384+
EXPECT_TRUE(pgc.isGoalReached(current_pose, goal_pose, velocity, transformed_global_plan_));
335385
sgc.reset();
336386
gc.reset();
387+
pgc.reset();
337388

338389
// Looping path, xy yaw tolerance reached but path longer than path_length_tolerance
339390
current_pose.orientation = nav2_util::geometry_utils::orientationAroundZAxis(0.25);
@@ -351,6 +402,8 @@ TEST(StoppedGoalChecker, is_reached)
351402
transformed_global_plan_));
352403
EXPECT_FALSE(gc.isGoalReached(first_pose.pose, last_pose.pose, velocity,
353404
transformed_global_plan_));
405+
EXPECT_FALSE(pgc.isGoalReached(first_pose.pose, last_pose.pose, velocity,
406+
transformed_global_plan_));
354407
}
355408

356409
int main(int argc, char ** argv)

0 commit comments

Comments
 (0)