18#include "auto_apms_behavior_tree_core/node.hpp"
19#include "auto_apms_util/container.hpp"
20#include "rcl_interfaces/srv/list_parameters.hpp"
22#define INPUT_KEY_PARAM_NAME "parameter"
23#define INPUT_KEY_PARAM_VALUE "value"
24#define INPUT_KEY_NODE_NAME "node"
32 HasParameter(
const std::string & instance_name,
const Config & config,
const Context & context)
36 config.input_ports.find(INPUT_KEY_NODE_NAME) == config.input_ports.end() ||
37 config.input_ports.at(INPUT_KEY_NODE_NAME).empty()) {
39 createClient(context_.getFullyQualifiedRosNodeName() +
"/list_parameters");
43 static BT::PortsList providedPorts()
47 BT::InputPort<std::string>(
48 INPUT_KEY_NODE_NAME,
"Name of the targeted ROS 2 node. Leave empty to target this executor's node."),
49 BT::InputPort<std::string>(INPUT_KEY_PARAM_NAME,
"Name of the parameter.")};
52 bool setRequest(Request::SharedPtr & request)
override final
54 const BT::Expected<std::string> expected_name = getInput<std::string>(INPUT_KEY_PARAM_NAME);
55 if (!expected_name || expected_name.value().empty()) {
57 logger_,
"%s - Parameter name must not be empty.", context_.getFullyQualifiedTreeNodeName(
this).c_str());
58 RCLCPP_DEBUG_EXPRESSION(
59 logger_, !expected_name,
"%s - Error message: %s", context_.getFullyQualifiedTreeNodeName(
this).c_str(),
60 expected_name.error().c_str());
63 has_parameter_name_ = expected_name.value();
64 request->depth = Request::DEPTH_RECURSIVE;
65 request->prefixes = {};
69 BT::NodeStatus onResponseReceived(
const Response::SharedPtr & response)
override final
72 return BT::NodeStatus::FAILURE;
76 std::string has_parameter_name_;
Generic behavior tree node wrapper for a ROS 2 service client.
RosServiceNode(const std::string &instance_name, const Config &config, Context context)
#define AUTO_APMS_BEHAVIOR_TREE_DECLARE_NODE(type)
Macro for registering a behavior tree node plugin.
bool contains(const ContainerT< ValueT, AllocatorT > &c, const ValueT &val)
Check whether a particular container structure contains a value.
Useful tooling for incorporating behavior trees for task development.