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
4546using nav2_controller::SimpleGoalChecker;
4647using nav2_controller::StoppedGoalChecker;
48+ using nav2_controller::PositionGoalChecker;
4749
4850void 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+
160172TEST (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
244276TEST (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
356409int main (int argc, char ** argv)
0 commit comments