Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added costmap in goal_checker plugins #2965

Merged
merged 4 commits into from
May 27, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ class SimpleGoalChecker : public nav2_core::GoalChecker
// Standard GoalChecker Interface
void initialize(
const rclcpp_lifecycle::LifecycleNode::WeakPtr & parent,
const std::string & plugin_name) override;
const std::string & plugin_name,
const std::shared_ptr<nav2_costmap_2d::Costmap2DROS> & costmap_ros) override;
void reset() override;
bool isGoalReached(
const geometry_msgs::msg::Pose & query_pose, const geometry_msgs::msg::Pose & goal_pose,
Expand All @@ -79,6 +80,8 @@ class SimpleGoalChecker : public nav2_core::GoalChecker
rclcpp::node_interfaces::OnSetParametersCallbackHandle::SharedPtr dyn_params_handler_;
std::string plugin_name_;

std::shared_ptr<nav2_costmap_2d::Costmap2DROS> costmap_ros_;
SteveMacenski marked this conversation as resolved.
Show resolved Hide resolved

/**
* @brief Callback executed when a paramter change is detected
* @param parameters list of changed parameters
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ class StoppedGoalChecker : public SimpleGoalChecker
// Standard GoalChecker Interface
void initialize(
const rclcpp_lifecycle::LifecycleNode::WeakPtr & parent,
const std::string & plugin_name) override;
const std::string & plugin_name,
const std::shared_ptr<nav2_costmap_2d::Costmap2DROS> & costmap_ros) override;
bool isGoalReached(
const geometry_msgs::msg::Pose & query_pose, const geometry_msgs::msg::Pose & goal_pose,
const geometry_msgs::msg::Twist & velocity) override;
Expand All @@ -71,6 +72,8 @@ class StoppedGoalChecker : public SimpleGoalChecker
rclcpp::node_interfaces::OnSetParametersCallbackHandle::SharedPtr dyn_params_handler_;
std::string plugin_name_;

std::shared_ptr<nav2_costmap_2d::Costmap2DROS> costmap_ros_;
SteveMacenski marked this conversation as resolved.
Show resolved Hide resolved

/**
* @brief Callback executed when a paramter change is detected
* @param parameters list of changed parameters
Expand Down
5 changes: 4 additions & 1 deletion nav2_controller/plugins/simple_goal_checker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,14 @@ SimpleGoalChecker::SimpleGoalChecker()

void SimpleGoalChecker::initialize(
const rclcpp_lifecycle::LifecycleNode::WeakPtr & parent,
const std::string & plugin_name)
const std::string & plugin_name,
const std::shared_ptr<nav2_costmap_2d::Costmap2DROS> & costmap_ros)
{
plugin_name_ = plugin_name;
auto node = parent.lock();

costmap_ros_ = costmap_ros;

nav2_util::declare_parameter_if_not_declared(
node,
plugin_name + ".xy_goal_tolerance", rclcpp::ParameterValue(0.25));
Expand Down
7 changes: 5 additions & 2 deletions nav2_controller/plugins/stopped_goal_checker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,16 @@ StoppedGoalChecker::StoppedGoalChecker()

void StoppedGoalChecker::initialize(
const rclcpp_lifecycle::LifecycleNode::WeakPtr & parent,
const std::string & plugin_name)
const std::string & plugin_name,
const std::shared_ptr<nav2_costmap_2d::Costmap2DROS> & costmap_ros)
{
plugin_name_ = plugin_name;
SimpleGoalChecker::initialize(parent, plugin_name);
SimpleGoalChecker::initialize(parent, plugin_name, costmap_ros);

auto node = parent.lock();

costmap_ros_ = costmap_ros;

nav2_util::declare_parameter_if_not_declared(
node,
plugin_name + ".rot_stopped_velocity", rclcpp::ParameterValue(0.25));
Expand Down
12 changes: 8 additions & 4 deletions nav2_controller/plugins/test/goal_checker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,10 @@ TEST(VelocityIterator, two_checks)

SimpleGoalChecker gc;
StoppedGoalChecker sgc;
gc.initialize(x, "nav2_controller");
sgc.initialize(x, "nav2_controller");
auto costmap = std::make_shared<nav2_costmap_2d::Costmap2DROS>("test_costmap");

gc.initialize(x, "nav2_controller", costmap);
sgc.initialize(x, "nav2_controller", costmap);
sameResult(gc, sgc, 0, 0, 0, 0, 0, 0, 0, 0, 0, true);
sameResult(gc, sgc, 0, 0, 0, 1, 0, 0, 0, 0, 0, false);
sameResult(gc, sgc, 0, 0, 0, 0, 1, 0, 0, 0, 0, false);
Expand All @@ -170,8 +172,10 @@ TEST(StoppedGoalChecker, get_tol_and_dynamic_params)

SimpleGoalChecker gc;
StoppedGoalChecker sgc;
sgc.initialize(x, "test");
gc.initialize(x, "test2");
auto costmap = std::make_shared<nav2_costmap_2d::Costmap2DROS>("test_costmap");

sgc.initialize(x, "test", costmap);
gc.initialize(x, "test2", costmap);
geometry_msgs::msg::Pose pose_tol;
geometry_msgs::msg::Twist vel_tol;

Expand Down
2 changes: 1 addition & 1 deletion nav2_controller/src/controller_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ ControllerServer::on_configure(const rclcpp_lifecycle::State & state)
RCLCPP_INFO(
get_logger(), "Created goal checker : %s of type %s",
goal_checker_ids_[i].c_str(), goal_checker_types_[i].c_str());
goal_checker->initialize(node, goal_checker_ids_[i]);
goal_checker->initialize(node, goal_checker_ids_[i], costmap_ros_);
goal_checkers_.insert({goal_checker_ids_[i], goal_checker});
} catch (const pluginlib::PluginlibException & ex) {
RCLCPP_FATAL(
Expand Down
7 changes: 6 additions & 1 deletion nav2_core/include/nav2_core/goal_checker.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@
#include "geometry_msgs/msg/pose.hpp"
#include "geometry_msgs/msg/twist.hpp"

#include "nav2_costmap_2d/costmap_2d_ros.hpp"


namespace nav2_core
{

Expand All @@ -68,7 +71,9 @@ class GoalChecker
*/
virtual void initialize(
const rclcpp_lifecycle::LifecycleNode::WeakPtr & parent,
const std::string & plugin_name) = 0;
const std::string & plugin_name,
const std::shared_ptr<nav2_costmap_2d::Costmap2DROS> &) = 0;
SteveMacenski marked this conversation as resolved.
Show resolved Hide resolved

virtual void reset() = 0;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ TEST(RotationShimControllerTest, computeVelocityTests)
pose.header.frame_id = "base_link";
geometry_msgs::msg::Twist velocity;
nav2_controller::SimpleGoalChecker checker;
checker.initialize(node, "checker");
checker.initialize(node, "checker", costmap);

// send without setting a path - should go to RPP immediately
// then it should throw an exception because the path is empty and invalid
Expand Down