Skip to content

Commit

Permalink
Added costmap in goal_checker plugins (#2965)
Browse files Browse the repository at this point in the history
* Added costmap in the goal checker

* Added costmap in goal_checker

* Adressed comments in PR

* Fixed linting error
  • Loading branch information
hardesh authored May 27, 2022
1 parent 35561ba commit 32d1004
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 12 deletions.
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 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 Down
3 changes: 2 additions & 1 deletion nav2_controller/plugins/simple_goal_checker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ 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();
Expand Down
5 changes: 3 additions & 2 deletions nav2_controller/plugins/stopped_goal_checker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,11 @@ 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();

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> costmap_ros) = 0;

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

0 comments on commit 32d1004

Please sign in to comment.