15#include "pyrobosim_msgs/srv/set_location_state.hpp"
17#include "auto_apms_behavior_tree_core/node.hpp"
18#include "auto_apms_simulation/util.hpp"
20#define INPUT_KEY_LOCATION "location"
21#define INPUT_KEY_OPEN "open"
22#define INPUT_KEY_LOCK "lock"
24namespace auto_apms_simulation
27class SetLocationState :
public auto_apms_behavior_tree::core::RosServiceNode<pyrobosim_msgs::srv::SetLocationState>
30 using RosServiceNode::RosServiceNode;
32 static BT::PortsList providedPorts()
35 BT::InputPort<bool>(INPUT_KEY_LOCK,
false,
"Lock/Unlock the location."),
36 BT::InputPort<bool>(INPUT_KEY_OPEN,
true,
"Open/Close the location."),
37 BT::InputPort<std::string>(INPUT_KEY_LOCATION,
"Name of the location.")};
40 bool setRequest(Request::SharedPtr & request)
override final
42 const BT::Expected<std::string> expected_location = getInput<std::string>(INPUT_KEY_LOCATION);
43 if (!expected_location || expected_location.value().empty()) {
45 logger_,
"%s - You must provide a non-empty location name.",
46 context_.getFullyQualifiedTreeNodeName(
this).c_str());
47 RCLCPP_DEBUG_EXPRESSION(
48 logger_, !expected_location,
"%s - Error message: %s", context_.getFullyQualifiedTreeNodeName(
this).c_str(),
49 expected_location.error().c_str());
52 request->location_name = expected_location.value();
53 request->open = getInput<bool>(INPUT_KEY_OPEN).value();
54 request->lock = getInput<bool>(INPUT_KEY_LOCK).value();
58 BT::NodeStatus onResponseReceived(
const Response::SharedPtr & response)
override final
60 const BT::NodeStatus base_status = RosServiceNode::onResponseReceived(response);
61 if (base_status != BT::NodeStatus::SUCCESS)
return base_status;
62 if (response->result.status != ExecutionResultMsg::SUCCESS) {
64 logger_,
"%s - %s", context_.getFullyQualifiedTreeNodeName(
this).c_str(),
toStr(response->result).c_str());
65 return BT::NodeStatus::FAILURE;
67 return BT::NodeStatus::SUCCESS;
#define AUTO_APMS_BEHAVIOR_TREE_DECLARE_NODE(type)
Macro for registering a behavior tree node plugin.
const char * toStr(const ActionNodeErrorCode &err)
Convert the action error code to string.