19 #include "std_msgs/msg/string.hpp"
21 #include "nav2_behavior_tree/plugins/action/goal_checker_selector_node.hpp"
23 #include "rclcpp/rclcpp.hpp"
25 namespace nav2_behavior_tree
28 using std::placeholders::_1;
31 const std::string & name,
32 const BT::NodeConfiguration & conf)
33 : BT::SyncActionNode(name, conf)
38 void GoalCheckerSelector::initialize()
40 createROSInterfaces();
43 void GoalCheckerSelector::createROSInterfaces()
45 std::string topic_new;
46 getInput(
"topic_name", topic_new);
47 if (topic_new != topic_name_ || !goal_checker_selector_sub_) {
48 topic_name_ = topic_new;
49 node_ = config().blackboard->get<rclcpp::Node::SharedPtr>(
"node");
51 rclcpp::QoS qos(rclcpp::KeepLast(1));
52 qos.transient_local().reliable();
54 goal_checker_selector_sub_ = node_->create_subscription<std_msgs::msg::String>(
55 topic_name_, qos, std::bind(&GoalCheckerSelector::callbackGoalCheckerSelect,
this, _1));
59 BT::NodeStatus GoalCheckerSelector::tick()
61 if (!BT::isStatusActive(status())) {
65 rclcpp::spin_some(node_);
72 if (last_selected_goal_checker_.empty()) {
73 std::string default_goal_checker;
74 getInput(
"default_goal_checker", default_goal_checker);
75 if (default_goal_checker.empty()) {
76 return BT::NodeStatus::FAILURE;
78 last_selected_goal_checker_ = default_goal_checker;
82 setOutput(
"selected_goal_checker", last_selected_goal_checker_);
84 return BT::NodeStatus::SUCCESS;
88 GoalCheckerSelector::callbackGoalCheckerSelect(
const std_msgs::msg::String::SharedPtr msg)
90 last_selected_goal_checker_ = msg->data;
95 #include "behaviortree_cpp/bt_factory.h"
96 BT_REGISTER_NODES(factory)
The GoalCheckerSelector behavior is used to switch the goal checker of the controller server....
GoalCheckerSelector(const std::string &xml_tag_name, const BT::NodeConfiguration &conf)
A constructor for nav2_behavior_tree::GoalCheckerSelector.