SMACC2
Loading...
Searching...
No Matches
cl_lifecycle_node::ClLifecycleNode Class Reference

#include <cl_lifecycle_node.hpp>

Inheritance diagram for cl_lifecycle_node::ClLifecycleNode:
Inheritance graph
Collaboration diagram for cl_lifecycle_node::ClLifecycleNode:
Collaboration graph

Public Types

using CancelPredicate = std::function<bool()>
 

Public Member Functions

 ClLifecycleNode (std::string nodeName)
 
virtual ~ClLifecycleNode ()
 
void onInitialize () override
 
bool changeState (uint8_t transition, const CancelPredicate &cancelled=CancelPredicate())
 
bool configure (const CancelPredicate &cancelled=CancelPredicate())
 
bool activate (const CancelPredicate &cancelled=CancelPredicate())
 
bool deactivate (const CancelPredicate &cancelled=CancelPredicate())
 
bool cleanup (const CancelPredicate &cancelled=CancelPredicate())
 
bool shutdown (const CancelPredicate &cancelled=CancelPredicate())
 
bool getState (uint8_t &state, const CancelPredicate &cancelled=CancelPredicate())
 
template<typename TOrthogonal , typename TSourceObject >
void onStateOrthogonalAllocation ()
 Configure component for event posting during orthogonal allocation.
 
- Public Member Functions inherited from smacc2::ISmaccClient
 ISmaccClient ()
 
virtual ~ISmaccClient ()
 
 ISmaccClient (const ISmaccClient &)=delete
 
ISmaccClient & operator= (const ISmaccClient &)=delete
 
 ISmaccClient (ISmaccClient &&)=delete
 
ISmaccClient & operator= (ISmaccClient &&)=delete
 
virtual std::string getName () const
 
template<typename TComponent >
TComponent * getComponent ()
 
template<typename TComponent >
TComponent * getComponent (const std::string &name)
 
template<typename TComponent >
TComponent * getComponent (int index)
 
virtual smacc2::introspection::TypeInfo::Ptr getType ()
 
ISmaccStateMachine * getStateMachine ()
 
template<typename TSmaccSignal , typename T >
void connectSignal (TSmaccSignal &signal, void(T::*callback)(), T *object)
 
template<typename SmaccClientType >
void requiresClient (SmaccClientType *&storage)
 
void getComponents (std::vector< std::shared_ptr< ISmaccComponent > > &components)
 
const std::vector< std::shared_ptr< ISmaccComponent > > & iterateComponents () const
 
template<typename EventType >
void postEvent (const EventType &ev)
 
template<typename EventType >
void postEvent ()
 

Private Attributes

rclcpp::Client< lifecycle_msgs::srv::GetState >::SharedPtr client_get_state_
 
rclcpp::Client< lifecycle_msgs::srv::ChangeState >::SharedPtr client_change_state_
 
std::string nodeName_
 
CpLifecycleEventMonitor * eventMonitor_
 
const std::string node_get_state_topic = "/get_state"
 
const std::string node_change_state_topic = "/change_state"
 
lifecycle_msgs::msg::TransitionEvent::SharedPtr lastTransitionEvent_
 

Additional Inherited Members

- Protected Member Functions inherited from smacc2::ISmaccClient
template<typename TOrthogonal , typename TClient >
void onComponentInitialization ()
 
template<typename TOrthogonal , typename TSourceObject >
void onStateOrthogonalAllocation ()
 
template<typename SmaccComponentType , typename TOrthogonal , typename TClient , typename... TArgs>
SmaccComponentType * createComponent (const TArgs &... targs)
 
template<typename SmaccComponentType , typename TOrthogonal , typename TClient , typename... TArgs>
SmaccComponentType * createNamedComponent (const std::string &name, const TArgs &... targs)
 
rclcpp::Node::SharedPtr getNode ()
 
rclcpp::Logger getLogger ()
 
- Protected Attributes inherited from smacc2::ISmaccClient
std::map< ComponentKey, std::shared_ptr< smacc2::ISmaccComponent > > components_
 

Detailed Description

Definition at line 196 of file cl_lifecycle_node.hpp.

Member Typedef Documentation

◆ CancelPredicate

Definition at line 208 of file cl_lifecycle_node.hpp.

Constructor & Destructor Documentation

◆ ClLifecycleNode()

cl_lifecycle_node::ClLifecycleNode::ClLifecycleNode ( std::string nodeName)

Definition at line 28 of file cl_lifecycle_node.cpp.

29: nodeName_(node_name), eventMonitor_(nullptr)
30{
31}
CpLifecycleEventMonitor * eventMonitor_

◆ ~ClLifecycleNode()

cl_lifecycle_node::ClLifecycleNode::~ClLifecycleNode ( )
virtual

Definition at line 33 of file cl_lifecycle_node.cpp.

33{}

Member Function Documentation

◆ activate()

bool cl_lifecycle_node::ClLifecycleNode::activate ( const CancelPredicate & cancelled = CancelPredicate())

Definition at line 137 of file cl_lifecycle_node.cpp.

138{
139 return changeState(lifecycle_msgs::msg::Transition::TRANSITION_ACTIVATE, cancelled);
140}
bool changeState(uint8_t transition, const CancelPredicate &cancelled=CancelPredicate())

References changeState().

Referenced by cl_lifecycle_node::CbActivate::onEntry().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ changeState()

bool cl_lifecycle_node::ClLifecycleNode::changeState ( uint8_t transition,
const CancelPredicate & cancelled = CancelPredicate() )

Definition at line 97 of file cl_lifecycle_node.cpp.

98{
99 auto logger = this->getNode()->get_logger();
100 auto request = std::make_shared<lifecycle_msgs::srv::ChangeState::Request>();
101 request->transition.id = transition;
102 auto response = callService<lifecycle_msgs::srv::ChangeState>(
103 logger, client_change_state_, request, cancelled, "transition " + std::to_string(transition));
104 if (!response)
105 {
106 return false;
107 }
108
109 const std::string serviceName = client_change_state_->get_service_name();
110 if (response->success)
111 {
112 RCLCPP_INFO(
113 logger, "[ClLifecycleNode] transition %d accepted by %s", transition, serviceName.c_str());
114 }
115 else
116 {
117 RCLCPP_ERROR(
118 logger, "[ClLifecycleNode] transition %d rejected by %s; no transition event will follow",
119 transition, serviceName.c_str());
120 }
121 return response->success;
122}
rclcpp::Client< lifecycle_msgs::srv::ChangeState >::SharedPtr client_change_state_
rclcpp::Node::SharedPtr getNode()
Definition client.cpp:60

References client_change_state_, and smacc2::ISmaccClient::getNode().

Referenced by activate(), cleanup(), configure(), deactivate(), and shutdown().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ cleanup()

bool cl_lifecycle_node::ClLifecycleNode::cleanup ( const CancelPredicate & cancelled = CancelPredicate())

Definition at line 152 of file cl_lifecycle_node.cpp.

153{
154 return changeState(lifecycle_msgs::msg::Transition::TRANSITION_CLEANUP, cancelled);
155}

References changeState().

Referenced by cl_lifecycle_node::CbCleanup::onEntry().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ configure()

bool cl_lifecycle_node::ClLifecycleNode::configure ( const CancelPredicate & cancelled = CancelPredicate())

Definition at line 147 of file cl_lifecycle_node.cpp.

148{
149 return changeState(lifecycle_msgs::msg::Transition::TRANSITION_CONFIGURE, cancelled);
150}

References changeState().

Referenced by cl_lifecycle_node::CbConfigure::onEntry().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ deactivate()

bool cl_lifecycle_node::ClLifecycleNode::deactivate ( const CancelPredicate & cancelled = CancelPredicate())

Definition at line 142 of file cl_lifecycle_node.cpp.

143{
144 return changeState(lifecycle_msgs::msg::Transition::TRANSITION_DEACTIVATE, cancelled);
145}

References changeState().

Referenced by cl_lifecycle_node::CbDeactivate::onEntry(), and cl_lifecycle_node::CbDeactivateOnExit::onExit().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getState()

bool cl_lifecycle_node::ClLifecycleNode::getState ( uint8_t & state,
const CancelPredicate & cancelled = CancelPredicate() )

Definition at line 124 of file cl_lifecycle_node.cpp.

125{
126 auto request = std::make_shared<lifecycle_msgs::srv::GetState::Request>();
127 auto response = callService<lifecycle_msgs::srv::GetState>(
128 this->getNode()->get_logger(), client_get_state_, request, cancelled, "get_state");
129 if (!response)
130 {
131 return false;
132 }
133 state = response->current_state.id;
134 return true;
135}
rclcpp::Client< lifecycle_msgs::srv::GetState >::SharedPtr client_get_state_

References client_get_state_, and smacc2::ISmaccClient::getNode().

Referenced by shutdown().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ onInitialize()

void cl_lifecycle_node::ClLifecycleNode::onInitialize ( )
overridevirtual

Reimplemented from smacc2::ISmaccClient.

Definition at line 35 of file cl_lifecycle_node.cpp.

36{
37 // Create service clients
38 client_get_state_ = this->getNode()->create_client<lifecycle_msgs::srv::GetState>(
40 client_change_state_ = this->getNode()->create_client<lifecycle_msgs::srv::ChangeState>(
42}

References client_change_state_, client_get_state_, smacc2::ISmaccClient::getNode(), node_change_state_topic, node_get_state_topic, and nodeName_.

Here is the call graph for this function:

◆ onStateOrthogonalAllocation()

template<typename TOrthogonal , typename TSourceObject >
void cl_lifecycle_node::ClLifecycleNode::onStateOrthogonalAllocation ( )
inline

Configure component for event posting during orthogonal allocation.

Definition at line 241 of file cl_lifecycle_node.hpp.

242 {
243 // Create and register component with orthogonal
244 if (!eventMonitor_)
245 {
248 nodeName_);
249 }
250
251 // Configure component for this orthogonal
253 }
void onStateOrthogonalAllocation()
Configure component for event posting during orthogonal allocation.
SmaccComponentType * createComponent(const TArgs &... targs)

References smacc2::ISmaccClient::createComponent(), eventMonitor_, nodeName_, and onStateOrthogonalAllocation().

Referenced by onStateOrthogonalAllocation().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ shutdown()

bool cl_lifecycle_node::ClLifecycleNode::shutdown ( const CancelPredicate & cancelled = CancelPredicate())

Definition at line 157 of file cl_lifecycle_node.cpp.

158{
159 // Each primary state has its own shutdown transition id, so ask the node which state it is in.
160 using lifecycle_msgs::msg::State;
161 using lifecycle_msgs::msg::Transition;
162 uint8_t state;
163 if (!getState(state, cancelled))
164 {
165 return false;
166 }
167 switch (state)
168 {
169 case State::PRIMARY_STATE_UNCONFIGURED:
170 return changeState(Transition::TRANSITION_UNCONFIGURED_SHUTDOWN, cancelled);
171 case State::PRIMARY_STATE_INACTIVE:
172 return changeState(Transition::TRANSITION_INACTIVE_SHUTDOWN, cancelled);
173 case State::PRIMARY_STATE_ACTIVE:
174 return changeState(Transition::TRANSITION_ACTIVE_SHUTDOWN, cancelled);
175 default:
176 RCLCPP_ERROR(
177 this->getNode()->get_logger(),
178 "[ClLifecycleNode] %s is in lifecycle state %d, which has no shutdown transition",
179 nodeName_.c_str(), state);
180 return false;
181 }
182}
bool getState(uint8_t &state, const CancelPredicate &cancelled=CancelPredicate())

References changeState(), smacc2::ISmaccClient::getNode(), getState(), and nodeName_.

Referenced by cl_lifecycle_node::CbShutdown::onEntry().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ client_change_state_

rclcpp::Client<lifecycle_msgs::srv::ChangeState>::SharedPtr cl_lifecycle_node::ClLifecycleNode::client_change_state_
private

Definition at line 258 of file cl_lifecycle_node.hpp.

Referenced by changeState(), and onInitialize().

◆ client_get_state_

rclcpp::Client<lifecycle_msgs::srv::GetState>::SharedPtr cl_lifecycle_node::ClLifecycleNode::client_get_state_
private

Definition at line 257 of file cl_lifecycle_node.hpp.

Referenced by getState(), and onInitialize().

◆ eventMonitor_

CpLifecycleEventMonitor* cl_lifecycle_node::ClLifecycleNode::eventMonitor_
private

Definition at line 263 of file cl_lifecycle_node.hpp.

Referenced by onStateOrthogonalAllocation().

◆ lastTransitionEvent_

lifecycle_msgs::msg::TransitionEvent::SharedPtr cl_lifecycle_node::ClLifecycleNode::lastTransitionEvent_
private

Definition at line 267 of file cl_lifecycle_node.hpp.

◆ node_change_state_topic

const std::string cl_lifecycle_node::ClLifecycleNode::node_change_state_topic = "/change_state"
private

Definition at line 265 of file cl_lifecycle_node.hpp.

Referenced by onInitialize().

◆ node_get_state_topic

const std::string cl_lifecycle_node::ClLifecycleNode::node_get_state_topic = "/get_state"
private

Definition at line 264 of file cl_lifecycle_node.hpp.

Referenced by onInitialize().

◆ nodeName_

std::string cl_lifecycle_node::ClLifecycleNode::nodeName_
private

Definition at line 260 of file cl_lifecycle_node.hpp.

Referenced by onInitialize(), onStateOrthogonalAllocation(), and shutdown().


The documentation for this class was generated from the following files: