20 #include "std_msgs/msg/string.hpp"
22 #include "nav2_behavior_tree/plugins/action/smoother_selector_node.hpp"
24 #include "rclcpp/rclcpp.hpp"
26 namespace nav2_behavior_tree
29 using std::placeholders::_1;
32 const std::string & name,
33 const BT::NodeConfiguration & conf)
34 : BT::SyncActionNode(name, conf)
38 config().blackboard->template get<std::chrono::milliseconds>(
"bt_loop_duration");
41 void SmootherSelector::initialize()
43 createROSInterfaces();
46 void SmootherSelector::createROSInterfaces()
48 std::string topic_new;
49 getInput(
"topic_name", topic_new);
50 if (topic_new != topic_name_ || !smoother_selector_sub_) {
51 topic_name_ = topic_new;
52 node_ = config().blackboard->get<nav2::LifecycleNode::SharedPtr>(
"node");
53 callback_group_ = node_->create_callback_group(
54 rclcpp::CallbackGroupType::MutuallyExclusive,
56 callback_group_executor_.add_callback_group(callback_group_, node_->get_node_base_interface());
58 smoother_selector_sub_ = node_->create_subscription<std_msgs::msg::String>(
60 std::bind(&SmootherSelector::callbackSmootherSelect,
this, _1),
66 BT::NodeStatus SmootherSelector::tick()
68 if (!BT::isStatusActive(status())) {
72 callback_group_executor_.spin_all(bt_loop_duration_);
79 if (last_selected_smoother_.empty()) {
80 std::string default_smoother;
81 getInput(
"default_smoother", default_smoother);
82 if (default_smoother.empty()) {
83 return BT::NodeStatus::FAILURE;
85 last_selected_smoother_ = default_smoother;
89 setOutput(
"selected_smoother", last_selected_smoother_);
91 return BT::NodeStatus::SUCCESS;
95 SmootherSelector::callbackSmootherSelect(
const std_msgs::msg::String::SharedPtr msg)
97 last_selected_smoother_ = msg->data;
102 #include "behaviortree_cpp/bt_factory.h"
103 BT_REGISTER_NODES(factory)
A QoS profile for latched, reliable topics with a history of 10 messages.
The SmootherSelector behavior is used to switch the smoother that will be used by the smoother server...
SmootherSelector(const std::string &xml_tag_name, const BT::NodeConfiguration &conf)
A constructor for nav2_behavior_tree::SmootherSelector.