42 using RosServiceNode::RosServiceNode;
44 static BT::PortsList providedPorts()
49 BT::InputPort<std::string>(INPUT_KEY_NODE_NAME,
"Name of the targeted lifecycle node."),
50 BT::OutputPort<uint8_t>(OUTPUT_KEY_STATE_ID,
"Numeric ID of the current lifecycle state."),
51 BT::OutputPort<std::string>(OUTPUT_KEY_STATE_LABEL,
"Human-readable label of the current lifecycle state."),
55 bool setRequest(Request::SharedPtr & )
override final
58 setOutput(OUTPUT_KEY_STATE_ID, uint8_t{lifecycle_msgs::msg::State::PRIMARY_STATE_UNKNOWN});
59 setOutput(OUTPUT_KEY_STATE_LABEL, std::string{});
63 BT::NodeStatus onResponseReceived(
const Response::SharedPtr & response)
override final
65 if (
const BT::Result res = setOutput(OUTPUT_KEY_STATE_ID, response->current_state.id); !res) {
66 RCLCPP_ERROR(logger_,
"%s - %s", context_.getFullyQualifiedTreeNodeName(
this).c_str(), res.error().c_str());
67 return BT::NodeStatus::FAILURE;
69 if (
const BT::Result res = setOutput(OUTPUT_KEY_STATE_LABEL, response->current_state.label); !res) {
70 RCLCPP_ERROR(logger_,
"%s - %s", context_.getFullyQualifiedTreeNodeName(
this).c_str(), res.error().c_str());
71 return BT::NodeStatus::FAILURE;
73 return BT::NodeStatus::SUCCESS;
96 using RosServiceNode::RosServiceNode;
98 static BT::PortsList providedPorts()
102 BT::PortsList ports = {
103 BT::InputPort<std::string>(INPUT_KEY_NODE_NAME,
"Name of the targeted lifecycle node."),
105 if constexpr (TRANSITION_ID < 0) {
108 INPUT_KEY_TRANSITION,
109 "ID of the lifecycle state machine transition to execute. Refer to lifecycle_msgs/msg/Transition for "
110 "available values (configure=1, cleanup=2, activate=3, deactivate=4, "
111 "unconfigured_shutdown=5, inactive_shutdown=6, active_shutdown=7)."));
116 bool setRequest(Request::SharedPtr & request)
override final
118 if constexpr (TRANSITION_ID >= 0) {
119 requested_transition_id_ =
static_cast<uint8_t
>(TRANSITION_ID);
121 const BT::Expected<int> expected = getInput<int>(INPUT_KEY_TRANSITION);
124 logger_,
"%s - %s", context_.getFullyQualifiedTreeNodeName(
this).c_str(), expected.error().c_str());
127 if (expected.value() < 0 || expected.value() > 255) {
129 logger_,
"%s - Transition ID %d is out of the valid range [0, 255].",
130 context_.getFullyQualifiedTreeNodeName(
this).c_str(), expected.value());
133 requested_transition_id_ =
static_cast<uint8_t
>(expected.value());
135 request->transition.id = requested_transition_id_;
139 BT::NodeStatus onResponseReceived(
const Response::SharedPtr & response)
override final
141 if (!response->success) {
143 logger_,
"%s - Failed to execute lifecycle transition (id: %u) via service '%s'.",
144 context_.getFullyQualifiedTreeNodeName(
this).c_str(),
static_cast<unsigned>(requested_transition_id_),
146 return BT::NodeStatus::FAILURE;
148 return BT::NodeStatus::SUCCESS;
152 uint8_t requested_transition_id_{0};