37 this->
getNode() ->create_subscription<lifecycle_msgs::msg::TransitionEvent>(
44 auto request = std::make_shared<lifecycle_msgs::srv::ChangeState::Request>();
45 request->transition.id = state;
52 changeState(lifecycle_msgs::msg::Transition::TRANSITION_ACTIVATE);
57 changeState(lifecycle_msgs::msg::Transition::TRANSITION_DEACTIVATE);
62 changeState(lifecycle_msgs::msg::Transition::TRANSITION_CONFIGURE);
67 changeState(lifecycle_msgs::msg::Transition::TRANSITION_CLEANUP);
72 changeState(lifecycle_msgs::msg::Transition::TRANSITION_UNCONFIGURED_SHUTDOWN);
78 this->
getNode()->get_logger(),
"[ClLifecycleNode] Transition event received: %d -> %d",
79 msg->start_state.id, msg->goal_state.id);
94 msg->start_state.id == lifecycle_msgs::msg::State::PRIMARY_STATE_UNCONFIGURED &&
95 msg->goal_state.id == lifecycle_msgs::msg::State::TRANSITION_STATE_CONFIGURING)
97 RCLCPP_INFO(this->
getNode()->get_logger(),
"TRANSITION_CONFIGURE");
102 msg->start_state.id == lifecycle_msgs::msg::State::PRIMARY_STATE_INACTIVE &&
103 msg->goal_state.id == lifecycle_msgs::msg::State::TRANSITION_STATE_CLEANINGUP)
105 RCLCPP_INFO(this->
getNode()->get_logger(),
"TRANSITION_CLEANUP");
110 msg->start_state.id == lifecycle_msgs::msg::State::PRIMARY_STATE_INACTIVE &&
111 msg->goal_state.id == lifecycle_msgs::msg::State::TRANSITION_STATE_ACTIVATING)
113 RCLCPP_INFO(this->
getNode()->get_logger(),
"TRANSITION_ACTIVATE");
118 msg->start_state.id == lifecycle_msgs::msg::State::PRIMARY_STATE_ACTIVE &&
119 msg->goal_state.id == lifecycle_msgs::msg::State::TRANSITION_STATE_DEACTIVATING)
121 RCLCPP_INFO(this->
getNode()->get_logger(),
"TRANSITION_DEACTIVATE");
126 msg->start_state.id == lifecycle_msgs::msg::State::PRIMARY_STATE_UNCONFIGURED &&
127 msg->goal_state.id == lifecycle_msgs::msg::State::TRANSITION_STATE_SHUTTINGDOWN)
129 RCLCPP_INFO(this->
getNode()->get_logger(),
"TRANSITION_UNCONFIGURED_SHUTDOWN");
134 msg->start_state.id == lifecycle_msgs::msg::State::PRIMARY_STATE_INACTIVE &&
135 msg->goal_state.id == lifecycle_msgs::msg::State::TRANSITION_STATE_SHUTTINGDOWN)
137 RCLCPP_INFO(this->
getNode()->get_logger(),
"TRANSITION_INACTIVE_SHUTDOWN");
142 msg->start_state.id == lifecycle_msgs::msg::State::PRIMARY_STATE_ACTIVE &&
143 msg->goal_state.id == lifecycle_msgs::msg::State::TRANSITION_STATE_SHUTTINGDOWN)
145 RCLCPP_INFO(this->
getNode()->get_logger(),
"TRANSITION_ACTIVE_SHUTDOWN");
149 else if (msg->start_state.id == lifecycle_msgs::msg::State::PRIMARY_STATE_FINALIZED)
153 RCLCPP_INFO(this->
getNode()->get_logger(),
"TRANSITION_DESTROY");
159 msg->start_state.id == lifecycle_msgs::msg::State::TRANSITION_STATE_CONFIGURING &&
160 msg->goal_state.id == lifecycle_msgs::msg::State::PRIMARY_STATE_INACTIVE)
162 RCLCPP_INFO(this->
getNode()->get_logger(),
"TRANSITION_ON_CONFIGURE_SUCCESS");
167 msg->start_state.id == lifecycle_msgs::msg::State::TRANSITION_STATE_CONFIGURING &&
168 msg->goal_state.id == lifecycle_msgs::msg::State::PRIMARY_STATE_UNCONFIGURED)
170 RCLCPP_INFO(this->
getNode()->get_logger(),
"TRANSITION_ON_CONFIGURE_FAILURE");
175 msg->start_state.id == lifecycle_msgs::msg::State::TRANSITION_STATE_CONFIGURING &&
176 msg->goal_state.id == lifecycle_msgs::msg::State::TRANSITION_STATE_ERRORPROCESSING)
178 RCLCPP_INFO(this->
getNode()->get_logger(),
"TRANSITION_ON_CONFIGURE_ERROR");
184 msg->start_state.id == lifecycle_msgs::msg::State::TRANSITION_STATE_CLEANINGUP &&
185 msg->goal_state.id == lifecycle_msgs::msg::State::PRIMARY_STATE_UNCONFIGURED)
187 RCLCPP_INFO(this->
getNode()->get_logger(),
"TRANSITION_ON_CLEANUP_SUCCESS");
199 msg->start_state.id == lifecycle_msgs::msg::State::TRANSITION_STATE_CLEANINGUP &&
200 msg->goal_state.id == lifecycle_msgs::msg::State::TRANSITION_STATE_ERRORPROCESSING)
202 RCLCPP_INFO(this->
getNode()->get_logger(),
"TRANSITION_ON_CLEANUP_ERROR");
208 msg->start_state.id == lifecycle_msgs::msg::State::TRANSITION_STATE_ACTIVATING &&
209 msg->goal_state.id == lifecycle_msgs::msg::State::PRIMARY_STATE_ACTIVE)
211 RCLCPP_INFO(this->
getNode()->get_logger(),
"TRANSITION_ON_ACTIVATE_SUCCESS");
216 msg->start_state.id == lifecycle_msgs::msg::State::TRANSITION_STATE_ACTIVATING &&
217 msg->goal_state.id == lifecycle_msgs::msg::State::PRIMARY_STATE_INACTIVE)
219 RCLCPP_INFO(this->
getNode()->get_logger(),
"TRANSITION_ON_ACTIVATE_FAILURE");
224 msg->start_state.id == lifecycle_msgs::msg::State::TRANSITION_STATE_ACTIVATING &&
225 msg->goal_state.id == lifecycle_msgs::msg::State::TRANSITION_STATE_ERRORPROCESSING)
227 RCLCPP_INFO(this->
getNode()->get_logger(),
"TRANSITION_ON_ACTIVATE_ERROR");
233 msg->start_state.id == lifecycle_msgs::msg::State::TRANSITION_STATE_DEACTIVATING &&
234 msg->goal_state.id == lifecycle_msgs::msg::State::PRIMARY_STATE_INACTIVE)
236 RCLCPP_INFO(this->
getNode()->get_logger(),
"TRANSITION_ON_DEACTIVATE_SUCCESS");
247 msg->start_state.id == lifecycle_msgs::msg::State::TRANSITION_STATE_DEACTIVATING &&
248 msg->goal_state.id == lifecycle_msgs::msg::State::TRANSITION_STATE_ERRORPROCESSING)
250 RCLCPP_INFO(this->
getNode()->get_logger(),
"TRANSITION_ON_DEACTIVATE_ERROR");
256 msg->start_state.id == lifecycle_msgs::msg::State::TRANSITION_STATE_SHUTTINGDOWN &&
257 msg->goal_state.id == lifecycle_msgs::msg::State::PRIMARY_STATE_FINALIZED)
259 RCLCPP_INFO(this->
getNode()->get_logger(),
"TRANSITION_ON_SHUTDOWN_SUCCESS");
270 msg->start_state.id == lifecycle_msgs::msg::State::TRANSITION_STATE_SHUTTINGDOWN &&
271 msg->goal_state.id == lifecycle_msgs::msg::State::TRANSITION_STATE_ERRORPROCESSING)
273 RCLCPP_INFO(this->
getNode()->get_logger(),
"TRANSITION_ON_SHUTDOWN_ERROR");
279 msg->start_state.id == lifecycle_msgs::msg::State::TRANSITION_STATE_ERRORPROCESSING &&
280 msg->goal_state.id == lifecycle_msgs::msg::State::PRIMARY_STATE_UNCONFIGURED)
282 RCLCPP_INFO(this->
getNode()->get_logger(),
"TRANSITION_ON_ERROR_SUCCESS");
287 msg->start_state.id == lifecycle_msgs::msg::State::TRANSITION_STATE_ERRORPROCESSING &&
288 msg->goal_state.id == lifecycle_msgs::msg::State::PRIMARY_STATE_FINALIZED)
290 RCLCPP_INFO(this->
getNode()->get_logger(),
"TRANSITION_ON_ERROR_FAILURE");
303 RCLCPP_INFO(this->
getNode()->get_logger(),
"TRANSITION_UNKNOWN");
std::function< void()> postOnTransitionActivate_
virtual void onTransitionEvent(const lifecycle_msgs::msg::TransitionEvent::SharedPtr msg)
std::function< void()> postOnTransitionOnConfigureFailure_
virtual ~ClLifecycleNode()
const std::string node_change_state_topic
std::function< void()> postOnTransitionConfigure_
std::function< void()> postOnTransitionUnconfiguredShutdown_
void changeState(uint8_t state)
rclcpp::Client< lifecycle_msgs::srv::GetState >::SharedPtr client_get_state_
std::function< void()> postOnTransitionOnConfigureSuccess_
rclcpp::Subscription< lifecycle_msgs::msg::TransitionEvent >::SharedPtr subscription_transition_event_
const std::string node_transition_event_topic
lifecycle_msgs::msg::TransitionEvent::SharedPtr lastTransitionEvent_
rclcpp::Client< lifecycle_msgs::srv::ChangeState >::SharedPtr client_change_state_
std::function< void()> postOnTransitionOnErrorSuccess_
std::function< void()> postOnTransitionOnCleanupSuccess_
std::function< void()> postOnTransitionOnCleanupError_
ClLifecycleNode(std::string nodeName)
std::function< void()> postOnTransitionInactiveShutdown_
void onInitialize() override
std::function< void()> postOnTransitionCleanup_
std::function< void()> postOnTransitionOnShutdownError_
std::function< void()> postOnTransitionOnErrorFailure_
std::function< void()> postOnTransitionOnDeactivateSuccess_
std::function< void()> postOnTransitionDeactivate_
const std::string node_get_state_topic
std::function< void()> postOnTransitionOnConfigureError_
std::function< void()> postOnTransitionOnActivateFailure_
std::function< void()> postOnTransitionOnShutdownSuccess_
std::function< void()> postOnTransitionDestroy_
std::function< void()> postOnTransitionActiveShutdown_
std::function< void()> postOnTransitionOnActivateSuccess_
std::function< void()> postOnTransitionOnDeactivateError_
std::function< void()> postOnTransitionOnActivateError_
rclcpp::Node::SharedPtr getNode()