Nav2 Navigation Stack - rolling  main
ROS 2 Navigation Stack
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
nav2_lifecycle_manager::LifecycleManager Class Reference

Implements service interface to transition the lifecycle nodes of Nav2 stack. It receives transition request and then uses lifecycle interface to change lifecycle node's state. More...

#include <nav2_lifecycle_manager/include/nav2_lifecycle_manager/lifecycle_manager.hpp>

Inheritance diagram for nav2_lifecycle_manager::LifecycleManager:
Inheritance graph
[legend]
Collaboration diagram for nav2_lifecycle_manager::LifecycleManager:
Collaboration graph
[legend]

Public Member Functions

 LifecycleManager (const rclcpp::NodeOptions &options=rclcpp::NodeOptions())
 A constructor for nav2_lifecycle_manager::LifecycleManager. More...
 
 ~LifecycleManager ()
 A destructor for nav2_lifecycle_manager::LifecycleManager.
 

Protected Member Functions

void managerCallback (const std::shared_ptr< rmw_request_id_t > request_header, const std::shared_ptr< ManageLifecycleNodes::Request > request, std::shared_ptr< ManageLifecycleNodes::Response > response)
 Lifecycle node manager callback function. More...
 
void isActiveCallback (const std::shared_ptr< rmw_request_id_t > request_header, const std::shared_ptr< std_srvs::srv::Trigger::Request > request, std::shared_ptr< std_srvs::srv::Trigger::Response > response)
 Trigger callback function checks if the managed nodes are in active state. More...
 
bool startup ()
 Start up managed nodes. More...
 
bool configure ()
 Configures the managed nodes. More...
 
bool cleanup ()
 Cleanups the managed nodes. More...
 
bool shutdown ()
 Deactivate, clean up and shut down all the managed nodes. More...
 
bool reset (bool hard_reset=false)
 Reset all the managed nodes. More...
 
bool pause ()
 Pause all the managed nodes. More...
 
bool resume ()
 Resume all the managed nodes. More...
 
void onRclPreshutdown ()
 Perform preshutdown activities before our Context is shutdown. Note that this is related to our Context's shutdown sequence, not the lifecycle node state machine or shutdown().
 
void createLifecycleServiceClients ()
 Support function for creating service clients.
 
void createLifecycleServiceServers ()
 Support function for creating service servers.
 
void shutdownAllNodes ()
 Support function for shutdown.
 
void destroyLifecycleServiceClients ()
 Destroy all the lifecycle service clients.
 
void createBondTimer ()
 Support function for creating bond timer.
 
bool createBondConnection (const std::string &node_name)
 Support function for creating bond connections.
 
void destroyBondTimer ()
 Support function for killing bond connections.
 
void checkBondConnections ()
 
void checkBondRespawnConnection ()
 
bool changeStateForNode (const std::string &node_name, std::uint8_t transition)
 For a node, transition to the new target state.
 
bool changeStateForAllNodes (std::uint8_t transition, bool hard_change=false)
 For each node in the map, transition to the new target state.
 
void message (const std::string &msg)
 Helper function to highlight the output on the console.
 
void CreateDiagnostic (diagnostic_updater::DiagnosticStatusWrapper &stat)
 function to check the state of Nav2 nodes
 
void registerRclPreshutdownCallback ()
 
bool isActive ()
 function to check if managed nodes are active
 

Protected Attributes

rclcpp::CallbackGroup::SharedPtr callback_group_
 
std::unique_ptr< nav2::NodeThreadservice_thread_
 
nav2::ServiceServer< ManageLifecycleNodes >::SharedPtr manager_srv_
 
nav2::ServiceServer< std_srvs::srv::Trigger >::SharedPtr is_active_srv_
 
rclcpp::TimerBase::SharedPtr init_timer_
 
rclcpp::TimerBase::SharedPtr bond_timer_
 
rclcpp::TimerBase::SharedPtr bond_respawn_timer_
 
std::chrono::milliseconds bond_timeout_
 
std::chrono::milliseconds service_timeout_
 
std::map< std::string, std::shared_ptr< bond::Bond > > bond_map_
 
std::map< std::string, std::shared_ptr< nav2_util::LifecycleServiceClient > > node_map_
 
std::map< std::uint8_t, std::string > transition_label_map_
 
std::unordered_map< std::uint8_t, std::uint8_t > transition_state_map_
 
std::vector< std::string > node_names_
 
bool autostart_
 
bool attempt_respawn_reconnection_
 
NodeState managed_nodes_state_ {NodeState::UNCONFIGURED}
 
diagnostic_updater::Updater diagnostics_updater_
 
rclcpp::Time bond_respawn_start_time_ {0}
 
rclcpp::Duration bond_respawn_max_duration_ {10s}
 

Detailed Description

Implements service interface to transition the lifecycle nodes of Nav2 stack. It receives transition request and then uses lifecycle interface to change lifecycle node's state.

Definition at line 60 of file lifecycle_manager.hpp.

Constructor & Destructor Documentation

◆ LifecycleManager()

nav2_lifecycle_manager::LifecycleManager::LifecycleManager ( const rclcpp::NodeOptions &  options = rclcpp::NodeOptions())
explicit

A constructor for nav2_lifecycle_manager::LifecycleManager.

Parameters
optionsAdditional options to control creation of the node.

Definition at line 35 of file lifecycle_manager.cpp.

References CreateDiagnostic(), createLifecycleServiceClients(), createLifecycleServiceServers(), registerRclPreshutdownCallback(), and startup().

Here is the call graph for this function:

Member Function Documentation

◆ checkBondConnections()

void nav2_lifecycle_manager::LifecycleManager::checkBondConnections ( )
protected

@ brief Support function for checking on bond connections will take down system if there's something non-responsive

Definition at line 494 of file lifecycle_manager.cpp.

References checkBondRespawnConnection(), isActive(), message(), and reset().

Referenced by createBondTimer().

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

◆ checkBondRespawnConnection()

void nav2_lifecycle_manager::LifecycleManager::checkBondRespawnConnection ( )
protected

@ brief Support function for checking on bond connections will bring back the system if something goes from non-responsive to responsive

Definition at line 534 of file lifecycle_manager.cpp.

References isActive(), message(), and startup().

Referenced by checkBondConnections().

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

◆ cleanup()

bool nav2_lifecycle_manager::LifecycleManager::cleanup ( )
protected

Cleanups the managed nodes.

Returns
true or false

Definition at line 360 of file lifecycle_manager.cpp.

References changeStateForAllNodes(), and message().

Referenced by managerCallback().

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

◆ configure()

bool nav2_lifecycle_manager::LifecycleManager::configure ( )
protected

Configures the managed nodes.

Returns
true or false

Definition at line 346 of file lifecycle_manager.cpp.

References changeStateForAllNodes(), and message().

Referenced by managerCallback().

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

◆ isActiveCallback()

void nav2_lifecycle_manager::LifecycleManager::isActiveCallback ( const std::shared_ptr< rmw_request_id_t >  request_header,
const std::shared_ptr< std_srvs::srv::Trigger::Request >  request,
std::shared_ptr< std_srvs::srv::Trigger::Response >  response 
)
protected

Trigger callback function checks if the managed nodes are in active state.

Parameters
request_headerHeader of the request
requestService request
responseService response

Definition at line 152 of file lifecycle_manager.cpp.

References isActive().

Referenced by createLifecycleServiceServers().

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

◆ managerCallback()

void nav2_lifecycle_manager::LifecycleManager::managerCallback ( const std::shared_ptr< rmw_request_id_t >  request_header,
const std::shared_ptr< ManageLifecycleNodes::Request >  request,
std::shared_ptr< ManageLifecycleNodes::Response >  response 
)
protected

Lifecycle node manager callback function.

Parameters
request_headerHeader of the service request
requestService request
responseService response

Definition at line 115 of file lifecycle_manager.cpp.

References cleanup(), configure(), pause(), reset(), resume(), shutdown(), and startup().

Referenced by createLifecycleServiceServers().

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

◆ pause()

bool nav2_lifecycle_manager::LifecycleManager::pause ( )
protected

Pause all the managed nodes.

Returns
true or false

Definition at line 408 of file lifecycle_manager.cpp.

References changeStateForAllNodes(), destroyBondTimer(), and message().

Referenced by managerCallback().

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

◆ registerRclPreshutdownCallback()

void nav2_lifecycle_manager::LifecycleManager::registerRclPreshutdownCallback ( )
protected

Register our preshutdown callback for this Node's rcl Context. The callback fires before this Node's Context is shutdown. Note this is not directly related to the lifecycle state machine or the shutdown() instance function.

Definition at line 484 of file lifecycle_manager.cpp.

References onRclPreshutdown().

Referenced by LifecycleManager().

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

◆ reset()

bool nav2_lifecycle_manager::LifecycleManager::reset ( bool  hard_reset = false)
protected

Reset all the managed nodes.

Returns
true or false

Definition at line 386 of file lifecycle_manager.cpp.

References changeStateForAllNodes(), destroyBondTimer(), and message().

Referenced by checkBondConnections(), and managerCallback().

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

◆ resume()

bool nav2_lifecycle_manager::LifecycleManager::resume ( )
protected

Resume all the managed nodes.

Returns
true or false

Definition at line 425 of file lifecycle_manager.cpp.

References changeStateForAllNodes(), createBondTimer(), and message().

Referenced by managerCallback().

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

◆ shutdown()

bool nav2_lifecycle_manager::LifecycleManager::shutdown ( )
protected

Deactivate, clean up and shut down all the managed nodes.

Returns
true or false

Definition at line 374 of file lifecycle_manager.cpp.

References destroyBondTimer(), destroyLifecycleServiceClients(), message(), and shutdownAllNodes().

Referenced by managerCallback().

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

◆ startup()

bool nav2_lifecycle_manager::LifecycleManager::startup ( )
protected

Start up managed nodes.

Returns
true or false

Definition at line 329 of file lifecycle_manager.cpp.

References changeStateForAllNodes(), createBondTimer(), and message().

Referenced by checkBondRespawnConnection(), LifecycleManager(), and managerCallback().

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

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