Skip to content

Commit 638ab6c

Browse files
committed
add path argument to goal checker interface
Signed-off-by: Jonas Otto <[email protected]>
1 parent 4dd1be9 commit 638ab6c

File tree

8 files changed

+34
-25
lines changed

8 files changed

+34
-25
lines changed

nav2_controller/include/nav2_controller/plugins/simple_goal_checker.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ class SimpleGoalChecker : public nav2_core::GoalChecker
6666
void reset() override;
6767
bool isGoalReached(
6868
const geometry_msgs::msg::Pose & query_pose, const geometry_msgs::msg::Pose & goal_pose,
69-
const geometry_msgs::msg::Twist & velocity) override;
69+
const geometry_msgs::msg::Twist & velocity, const nav_msgs::msg::Path & current_path) override;
7070
bool getTolerances(
7171
geometry_msgs::msg::Pose & pose_tolerance,
7272
geometry_msgs::msg::Twist & vel_tolerance) override;

nav2_controller/include/nav2_controller/plugins/stopped_goal_checker.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ class StoppedGoalChecker : public SimpleGoalChecker
6161
const std::shared_ptr<nav2_costmap_2d::Costmap2DROS> costmap_ros) override;
6262
bool isGoalReached(
6363
const geometry_msgs::msg::Pose & query_pose, const geometry_msgs::msg::Pose & goal_pose,
64-
const geometry_msgs::msg::Twist & velocity) override;
64+
const geometry_msgs::msg::Twist & velocity, const nav_msgs::msg::Path & current_path) override;
6565
bool getTolerances(
6666
geometry_msgs::msg::Pose & pose_tolerance,
6767
geometry_msgs::msg::Twist & vel_tolerance) override;

nav2_controller/plugins/simple_goal_checker.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ void SimpleGoalChecker::reset()
9797

9898
bool SimpleGoalChecker::isGoalReached(
9999
const geometry_msgs::msg::Pose & query_pose, const geometry_msgs::msg::Pose & goal_pose,
100-
const geometry_msgs::msg::Twist &)
100+
const geometry_msgs::msg::Twist &, const nav_msgs::msg::Path &)
101101
{
102102
if (check_xy_) {
103103
double dx = query_pose.position.x - goal_pose.position.x,

nav2_controller/plugins/stopped_goal_checker.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,9 @@ void StoppedGoalChecker::initialize(
8282

8383
bool StoppedGoalChecker::isGoalReached(
8484
const geometry_msgs::msg::Pose & query_pose, const geometry_msgs::msg::Pose & goal_pose,
85-
const geometry_msgs::msg::Twist & velocity)
85+
const geometry_msgs::msg::Twist & velocity, const nav_msgs::msg::Path & current_path)
8686
{
87-
bool ret = SimpleGoalChecker::isGoalReached(query_pose, goal_pose, velocity);
87+
bool ret = SimpleGoalChecker::isGoalReached(query_pose, goal_pose, velocity, current_path);
8888
if (!ret) {
8989
return ret;
9090
}

nav2_controller/plugins/test/goal_checker.cpp

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
#include "nav2_controller/plugins/simple_goal_checker.hpp"
4040
#include "nav2_controller/plugins/stopped_goal_checker.hpp"
4141
#include "nav_2d_utils/conversions.hpp"
42+
#include "nav_msgs/msg/path.hpp"
4243
#include "nav2_util/lifecycle_node.hpp"
4344

4445
using nav2_controller::SimpleGoalChecker;
@@ -49,6 +50,7 @@ void checkMacro(
4950
double x0, double y0, double theta0,
5051
double x1, double y1, double theta1,
5152
double xv, double yv, double thetav,
53+
const nav_msgs::msg::Path & path,
5254
bool expected_result)
5355
{
5456
gc.reset();
@@ -67,12 +69,12 @@ void checkMacro(
6769
EXPECT_TRUE(
6870
gc.isGoalReached(
6971
nav_2d_utils::pose2DToPose(pose0),
70-
nav_2d_utils::pose2DToPose(pose1), nav_2d_utils::twist2Dto3D(v)));
72+
nav_2d_utils::pose2DToPose(pose1), nav_2d_utils::twist2Dto3D(v), path));
7173
} else {
7274
EXPECT_FALSE(
7375
gc.isGoalReached(
7476
nav_2d_utils::pose2DToPose(pose0),
75-
nav_2d_utils::pose2DToPose(pose1), nav_2d_utils::twist2Dto3D(v)));
77+
nav_2d_utils::pose2DToPose(pose1), nav_2d_utils::twist2Dto3D(v), path));
7678
}
7779
}
7880

@@ -81,20 +83,22 @@ void sameResult(
8183
double x0, double y0, double theta0,
8284
double x1, double y1, double theta1,
8385
double xv, double yv, double thetav,
86+
const nav_msgs::msg::Path & path,
8487
bool expected_result)
8588
{
86-
checkMacro(gc0, x0, y0, theta0, x1, y1, theta1, xv, yv, thetav, expected_result);
87-
checkMacro(gc1, x0, y0, theta0, x1, y1, theta1, xv, yv, thetav, expected_result);
89+
checkMacro(gc0, x0, y0, theta0, x1, y1, theta1, xv, yv, thetav, path, expected_result);
90+
checkMacro(gc1, x0, y0, theta0, x1, y1, theta1, xv, yv, thetav, path, expected_result);
8891
}
8992

9093
void trueFalse(
9194
nav2_core::GoalChecker & gc0, nav2_core::GoalChecker & gc1,
9295
double x0, double y0, double theta0,
9396
double x1, double y1, double theta1,
94-
double xv, double yv, double thetav)
97+
double xv, double yv, double thetav,
98+
const nav_msgs::msg::Path & path)
9599
{
96-
checkMacro(gc0, x0, y0, theta0, x1, y1, theta1, xv, yv, thetav, true);
97-
checkMacro(gc1, x0, y0, theta0, x1, y1, theta1, xv, yv, thetav, false);
100+
checkMacro(gc0, x0, y0, theta0, x1, y1, theta1, xv, yv, thetav, path, true);
101+
checkMacro(gc1, x0, y0, theta0, x1, y1, theta1, xv, yv, thetav, path, false);
98102
}
99103
class TestLifecycleNode : public nav2_util::LifecycleNode
100104
{
@@ -162,18 +166,19 @@ TEST(VelocityIterator, two_checks)
162166
SimpleGoalChecker gc;
163167
StoppedGoalChecker sgc;
164168
auto costmap = std::make_shared<nav2_costmap_2d::Costmap2DROS>("test_costmap");
169+
nav_msgs::msg::Path path;
165170

166171
gc.initialize(x, "nav2_controller", costmap);
167172
sgc.initialize(x, "nav2_controller", costmap);
168-
sameResult(gc, sgc, 0, 0, 0, 0, 0, 0, 0, 0, 0, true);
169-
sameResult(gc, sgc, 0, 0, 0, 1, 0, 0, 0, 0, 0, false);
170-
sameResult(gc, sgc, 0, 0, 0, 0, 1, 0, 0, 0, 0, false);
171-
sameResult(gc, sgc, 0, 0, 0, 0, 0, 1, 0, 0, 0, false);
172-
sameResult(gc, sgc, 0, 0, 3.14, 0, 0, -3.14, 0, 0, 0, true);
173-
trueFalse(gc, sgc, 0, 0, 3.14, 0, 0, -3.14, 1, 0, 0);
174-
trueFalse(gc, sgc, 0, 0, 0, 0, 0, 0, 1, 0, 0);
175-
trueFalse(gc, sgc, 0, 0, 0, 0, 0, 0, 0, 1, 0);
176-
trueFalse(gc, sgc, 0, 0, 0, 0, 0, 0, 0, 0, 1);
173+
sameResult(gc, sgc, 0, 0, 0, 0, 0, 0, 0, 0, 0, path, true);
174+
sameResult(gc, sgc, 0, 0, 0, 1, 0, 0, 0, 0, 0, path, false);
175+
sameResult(gc, sgc, 0, 0, 0, 0, 1, 0, 0, 0, 0, path, false);
176+
sameResult(gc, sgc, 0, 0, 0, 0, 0, 1, 0, 0, 0, path, false);
177+
sameResult(gc, sgc, 0, 0, 3.14, 0, 0, -3.14, 0, 0, 0, path, true);
178+
trueFalse(gc, sgc, 0, 0, 3.14, 0, 0, -3.14, 1, 0, 0, path);
179+
trueFalse(gc, sgc, 0, 0, 0, 0, 0, 0, 1, 0, 0, path);
180+
trueFalse(gc, sgc, 0, 0, 0, 0, 0, 0, 0, 1, 0, path);
181+
trueFalse(gc, sgc, 0, 0, 0, 0, 0, 0, 0, 0, 1, path);
177182
}
178183

179184
TEST(StoppedGoalChecker, get_tol_and_dynamic_params)

nav2_controller/src/controller_server.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -749,7 +749,7 @@ bool ControllerServer::isGoalReached()
749749

750750
return goal_checkers_[current_goal_checker_]->isGoalReached(
751751
pose.pose, transformed_end_pose.pose,
752-
velocity);
752+
velocity, current_path_);
753753
}
754754

755755
bool ControllerServer::getRobotPose(geometry_msgs::msg::PoseStamped & pose)

nav2_core/include/nav2_core/goal_checker.hpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
#include "rclcpp_lifecycle/lifecycle_node.hpp"
4343
#include "geometry_msgs/msg/pose.hpp"
4444
#include "geometry_msgs/msg/twist.hpp"
45+
#include "nav_msgs/msg/path.hpp"
4546

4647
#include "nav2_costmap_2d/costmap_2d_ros.hpp"
4748

@@ -84,8 +85,10 @@ class GoalChecker
8485
* @return True if goal is reached
8586
*/
8687
virtual bool isGoalReached(
87-
const geometry_msgs::msg::Pose & query_pose, const geometry_msgs::msg::Pose & goal_pose,
88-
const geometry_msgs::msg::Twist & velocity) = 0;
88+
const geometry_msgs::msg::Pose & query_pose,
89+
const geometry_msgs::msg::Pose & goal_pose,
90+
const geometry_msgs::msg::Twist & velocity,
91+
const nav_msgs::msg::Path & current_path) = 0;
8992

9093
/**
9194
* @brief Get the maximum possible tolerances used for goal checking in the major types.

nav2_mppi_controller/test/utils_test.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ class TestGoalChecker : public nav2_core::GoalChecker
5353
virtual bool isGoalReached(
5454
const geometry_msgs::msg::Pose & /*query_pose*/,
5555
const geometry_msgs::msg::Pose & /*goal_pose*/,
56-
const geometry_msgs::msg::Twist & /*velocity*/) {return false;}
56+
const geometry_msgs::msg::Twist & /*velocity*/,
57+
const nav_msgs::msg::Path & /*current_path*/) {return false;}
5758

5859
virtual bool getTolerances(
5960
geometry_msgs::msg::Pose & pose_tolerance,

0 commit comments

Comments
 (0)