Carma-platform v4.2.0
CARMA Platform is built on robot operating system (ROS) and utilizes open source software (OSS) that enables Cooperative Driving Automation (CDA) features to allow Automated Driving Systems to interact and cooperate with infrastructure and other vehicles through communication.
subsystem_controllers::DriversControllerNode Class Reference

#include <drivers_controller_node.hpp>

Inheritance diagram for subsystem_controllers::DriversControllerNode:
Inheritance graph
Collaboration diagram for subsystem_controllers::DriversControllerNode:
Collaboration graph

Public Member Functions

 DriversControllerNode ()=delete
 
 ~DriversControllerNode ()=default
 
 DriversControllerNode (const rclcpp::NodeOptions &options)
 Constructor. Set explicitly to support node composition. More...
 
- Public Member Functions inherited from subsystem_controllers::BaseSubsystemController
 BaseSubsystemController ()=delete
 
 BaseSubsystemController (const rclcpp::NodeOptions &options)
 Constructor. Set explicitly to support node composition. More...
 
 ~BaseSubsystemController ()=default
 
void set_config (BaseSubSystemControllerConfig config)
 
virtual void on_system_alert (const carma_msgs::msg::SystemAlert::UniquePtr msg)
 
virtual carma_ros2_utils::CallbackReturn handle_on_configure (const rclcpp_lifecycle::State &prev_state)
 
virtual carma_ros2_utils::CallbackReturn handle_on_activate (const rclcpp_lifecycle::State &prev_state)
 
virtual carma_ros2_utils::CallbackReturn handle_on_deactivate (const rclcpp_lifecycle::State &prev_state)
 
virtual carma_ros2_utils::CallbackReturn handle_on_cleanup (const rclcpp_lifecycle::State &prev_state)
 
virtual carma_ros2_utils::CallbackReturn handle_on_error (const rclcpp_lifecycle::State &prev_state, const std::string &exception_string)
 
virtual carma_ros2_utils::CallbackReturn handle_on_shutdown (const rclcpp_lifecycle::State &prev_state)
 

Private Member Functions

void driver_discovery_cb (const carma_driver_msgs::msg::DriverStatus::SharedPtr msg)
 
void critical_drivers_check_callback ()
 Timer callback function to check status of required ros1 drivers. More...
 
carma_ros2_utils::CallbackReturn handle_on_configure (const rclcpp_lifecycle::State &prev_state)
 
carma_ros2_utils::CallbackReturn handle_on_activate (const rclcpp_lifecycle::State &prev_state)
 

Private Attributes

std::shared_ptr< SSCDriverManagerssc_driver_manager_
 
DriversControllerConfig config_
 Config for user provided parameters. More...
 
carma_ros2_utils::SubPtr< carma_driver_msgs::msg::DriverStatus > driver_status_sub_
 ROS handles. More...
 
std::vector< std::string > ros1_ssc_driver_name_
 ROS parameters. More...
 
long start_up_timestamp_
 
rclcpp::TimerBase::SharedPtr ssc_status_check_timer_
 
boost::optional< carma_msgs::msg::SystemAlert > prev_alert
 

Additional Inherited Members

- Protected Member Functions inherited from subsystem_controllers::BaseSubsystemController
std::vector< std::string > get_nodes_in_namespace (const std::string &node_namespace) const
 Returns the list of fully qualified node names for all ROS2 nodes in the provided namespace. More...
 
std::vector< std::string > get_non_intersecting_set (const std::vector< std::string > &set_a, const std::vector< std::string > &set_b) const
 Returns all elements of the provided set_a which are NOT contained in the provided set_b. More...
 
- Protected Attributes inherited from subsystem_controllers::BaseSubsystemController
ros2_lifecycle_manager::Ros2LifecycleManager lifecycle_mgr_
 Lifecycle Manager which will track the managed nodes and call their lifecycle services on request. More...
 
rclcpp::Subscription< carma_msgs::msg::SystemAlert >::SharedPtr system_alert_sub_
 The subscriber for the system alert topic. More...
 
BaseSubSystemControllerConfig base_config_
 The configuration struct. More...
 
bool trigger_managed_nodes_configure_from_base_class_ = true
 Collection of flags which, if true, will cause the base class to make lifecycle service calls to managed nodes. More...
 
bool trigger_managed_nodes_activate_from_base_class_ = true
 
bool trigger_managed_nodes_deactivate_from_base_class_ = true
 
bool trigger_managed_nodes_cleanup_from_base_class_ = true
 

Detailed Description

Definition at line 33 of file drivers_controller_node.hpp.

Constructor & Destructor Documentation

◆ DriversControllerNode() [1/2]

subsystem_controllers::DriversControllerNode::DriversControllerNode ( )
delete

◆ ~DriversControllerNode()

subsystem_controllers::DriversControllerNode::~DriversControllerNode ( )
default

◆ DriversControllerNode() [2/2]

subsystem_controllers::DriversControllerNode::DriversControllerNode ( const rclcpp::NodeOptions &  options)
explicit

Constructor. Set explicitly to support node composition.

Parameters
optionsThe node options to use for configuring this node

Definition at line 22 of file drivers_controller_node.cpp.

24{
25 // Don't automatically trigger state transitions from base class on configure
26 // In this class the managed nodes list first needs to be modified then the transition will be
27 // triggered manually
29
30 config_.startup_duration_ = declare_parameter<int>("startup_duration", config_.startup_duration_);
32 declare_parameter<double>("ros1_ssc_driver_timeout ", config_.driver_timeout_);
33
34 // carma-config parameters
36 declare_parameter<std::string>("ros1_ssc_driver_name", config_.ros1_ssc_driver_name_);
37 config_.excluded_namespace_nodes_ = declare_parameter<std::vector<std::string>>(
38 "excluded_namespace_nodes", config_.excluded_namespace_nodes_);
39}
bool trigger_managed_nodes_configure_from_base_class_
Collection of flags which, if true, will cause the base class to make lifecycle service calls to mana...
DriversControllerConfig config_
Config for user provided parameters.
double driver_timeout_
The timeout threshold for essential drivers in ms.
int startup_duration_
The time allocated for system startup in seconds.
std::vector< std::string > excluded_namespace_nodes_
List of nodes in the namespace which will not be managed by this subsystem controller.

References config_, subsystem_controllers::DriversControllerConfig::driver_timeout_, subsystem_controllers::DriversControllerConfig::excluded_namespace_nodes_, subsystem_controllers::DriversControllerConfig::ros1_ssc_driver_name_, subsystem_controllers::DriversControllerConfig::startup_duration_, and subsystem_controllers::BaseSubsystemController::trigger_managed_nodes_configure_from_base_class_.

Member Function Documentation

◆ critical_drivers_check_callback()

void subsystem_controllers::DriversControllerNode::critical_drivers_check_callback ( )
private

Timer callback function to check status of required ros1 drivers.

Definition at line 129 of file drivers_controller_node.cpp.

130{
131 if (get_current_state().id() != lifecycle_msgs::msg::State::PRIMARY_STATE_ACTIVE) {
132 return; // Exit early if node is not active
133 }
134
135 long time_now = this->now().nanoseconds() / 1e6;
136 long start_duration = rclcpp::Duration(config_.startup_duration_, 0).nanoseconds() / 1e6;
137
138 auto sys_alert_msg_from_ssc =
139 ssc_driver_manager_->get_latest_system_alert(time_now, start_up_timestamp_, start_duration);
140
141 // Only publish if it is first time publishing
142 // or if its type or description changed
143 if (
144 !prev_alert || prev_alert->type != sys_alert_msg_from_ssc.type ||
145 prev_alert->description != sys_alert_msg_from_ssc.description) {
146 prev_alert = sys_alert_msg_from_ssc;
147 publish_system_alert(sys_alert_msg_from_ssc);
148 } else {
149 RCLCPP_DEBUG_STREAM(get_logger(), "No change to alert status");
150 }
151}
std::shared_ptr< SSCDriverManager > ssc_driver_manager_
boost::optional< carma_msgs::msg::SystemAlert > prev_alert

References config_, prev_alert, ssc_driver_manager_, start_up_timestamp_, and subsystem_controllers::DriversControllerConfig::startup_duration_.

Referenced by handle_on_configure().

Here is the caller graph for this function:

◆ driver_discovery_cb()

void subsystem_controllers::DriversControllerNode::driver_discovery_cb ( const carma_driver_msgs::msg::DriverStatus::SharedPtr  msg)
private

Definition at line 153 of file drivers_controller_node.cpp.

155{
156 // Driver discovery only published by ros1 drivers
157 ssc_driver_manager_->update_driver_status(msg, this->now().nanoseconds() / 1e6);
158}

References ssc_driver_manager_.

Referenced by handle_on_configure().

Here is the caller graph for this function:

◆ handle_on_activate()

carma_ros2_utils::CallbackReturn subsystem_controllers::DriversControllerNode::handle_on_activate ( const rclcpp_lifecycle::State &  prev_state)
privatevirtual

Reimplemented from subsystem_controllers::BaseSubsystemController.

Definition at line 107 of file drivers_controller_node.cpp.

109{
110 // Reset to automatically trigger state transitions from base class
112
113 // return only either SUCCESS or FAILURE
115 prev_state); // This will activate all base_managed_nodes
116
117 if (base_return == CallbackReturn::SUCCESS) {
118 RCLCPP_INFO(get_logger(), "Driver Controller activated!");
119 } else if (base_return == CallbackReturn::FAILURE) {
120 RCLCPP_ERROR(
121 get_logger(),
122 "Driver Controller encountered FAILURE when trying to activate the subsystems... please "
123 "check which driver failed to activate...");
124 }
125
126 return base_return;
127}
virtual carma_ros2_utils::CallbackReturn handle_on_activate(const rclcpp_lifecycle::State &prev_state)

References subsystem_controllers::BaseSubsystemController::handle_on_activate(), and subsystem_controllers::BaseSubsystemController::trigger_managed_nodes_configure_from_base_class_.

Here is the call graph for this function:

◆ handle_on_configure()

carma_ros2_utils::CallbackReturn subsystem_controllers::DriversControllerNode::handle_on_configure ( const rclcpp_lifecycle::State &  prev_state)
privatevirtual

Reimplemented from subsystem_controllers::BaseSubsystemController.

Definition at line 41 of file drivers_controller_node.cpp.

43{
44 auto base_return = BaseSubsystemController::handle_on_configure(prev_state);
45
46 if (base_return != carma_ros2_utils::CallbackReturn::SUCCESS) {
47 RCLCPP_ERROR(get_logger(), "Drivers Controller could not configure");
48 return base_return;
49 }
50
51 config_ = DriversControllerConfig();
52
53 // Load required plugins and default enabled plugins
54 get_parameter<std::string>("ros1_ssc_driver_name", config_.ros1_ssc_driver_name_);
55 get_parameter<int>("startup_duration", config_.startup_duration_);
56 get_parameter<double>("ros1_ssc_driver_timeout ", config_.driver_timeout_);
57 get_parameter<std::vector<std::string>>(
58 "excluded_namespace_nodes", config_.excluded_namespace_nodes_);
59
60 RCLCPP_INFO_STREAM(get_logger(), "Config: " << config_);
61
62 // Handle fact that parameter vectors cannot be empty
63 if (
66 }
67
68 auto base_managed_nodes = lifecycle_mgr_.get_managed_nodes();
69 // Update managed nodes
70 // Collect namespace nodes not managed by other subsystem controllers - manually specified in
71 // carma-config
72 auto updated_managed_nodes =
74
75 lifecycle_mgr_.set_managed_nodes(updated_managed_nodes);
76
78 std::make_shared<SSCDriverManager>(config_.ros1_ssc_driver_name_, config_.driver_timeout_);
79
80 // record starup time
81 start_up_timestamp_ = this->now().nanoseconds() / 1e6;
82
83 driver_status_sub_ = create_subscription<carma_driver_msgs::msg::DriverStatus>(
84 "driver_discovery", 20,
85 std::bind(&DriversControllerNode::driver_discovery_cb, this, std::placeholders::_1));
86
87 ssc_status_check_timer_ = create_timer(
88 get_clock(), std::chrono::milliseconds(1000),
90
91 // Configure our drivers
92 bool success = lifecycle_mgr_
93 .configure(
94 std::chrono::milliseconds(base_config_.service_timeout_ms),
95 std::chrono::milliseconds(base_config_.call_timeout_ms))
96 .empty();
97
98 if (success) {
99 RCLCPP_INFO_STREAM(get_logger(), "Subsystem able to configure");
100 return CallbackReturn::SUCCESS;
101 } else {
102 RCLCPP_INFO_STREAM(get_logger(), "Subsystem unable to configure");
103 return CallbackReturn::FAILURE;
104 }
105}
BaseSubSystemControllerConfig base_config_
The configuration struct.
virtual carma_ros2_utils::CallbackReturn handle_on_configure(const rclcpp_lifecycle::State &prev_state)
std::vector< std::string > get_non_intersecting_set(const std::vector< std::string > &set_a, const std::vector< std::string > &set_b) const
Returns all elements of the provided set_a which are NOT contained in the provided set_b.
ros2_lifecycle_manager::Ros2LifecycleManager lifecycle_mgr_
Lifecycle Manager which will track the managed nodes and call their lifecycle services on request.
void critical_drivers_check_callback()
Timer callback function to check status of required ros1 drivers.
carma_ros2_utils::SubPtr< carma_driver_msgs::msg::DriverStatus > driver_status_sub_
ROS handles.
void driver_discovery_cb(const carma_driver_msgs::msg::DriverStatus::SharedPtr msg)

References subsystem_controllers::BaseSubsystemController::base_config_, subsystem_controllers::BaseSubSystemControllerConfig::call_timeout_ms, config_, critical_drivers_check_callback(), driver_discovery_cb(), driver_status_sub_, subsystem_controllers::DriversControllerConfig::driver_timeout_, subsystem_controllers::DriversControllerConfig::excluded_namespace_nodes_, subsystem_controllers::BaseSubsystemController::get_non_intersecting_set(), subsystem_controllers::BaseSubsystemController::handle_on_configure(), subsystem_controllers::BaseSubsystemController::lifecycle_mgr_, subsystem_controllers::DriversControllerConfig::ros1_ssc_driver_name_, subsystem_controllers::BaseSubSystemControllerConfig::service_timeout_ms, ssc_driver_manager_, ssc_status_check_timer_, start_up_timestamp_, and subsystem_controllers::DriversControllerConfig::startup_duration_.

Here is the call graph for this function:

Member Data Documentation

◆ config_

DriversControllerConfig subsystem_controllers::DriversControllerNode::config_
private

Config for user provided parameters.

Definition at line 52 of file drivers_controller_node.hpp.

Referenced by DriversControllerNode(), critical_drivers_check_callback(), and handle_on_configure().

◆ driver_status_sub_

carma_ros2_utils::SubPtr<carma_driver_msgs::msg::DriverStatus> subsystem_controllers::DriversControllerNode::driver_status_sub_
private

ROS handles.

Definition at line 55 of file drivers_controller_node.hpp.

Referenced by handle_on_configure().

◆ prev_alert

boost::optional<carma_msgs::msg::SystemAlert> subsystem_controllers::DriversControllerNode::prev_alert
private

Definition at line 75 of file drivers_controller_node.hpp.

Referenced by critical_drivers_check_callback().

◆ ros1_ssc_driver_name_

std::vector<std::string> subsystem_controllers::DriversControllerNode::ros1_ssc_driver_name_
private

ROS parameters.

Definition at line 67 of file drivers_controller_node.hpp.

◆ ssc_driver_manager_

std::shared_ptr<SSCDriverManager> subsystem_controllers::DriversControllerNode::ssc_driver_manager_
private

◆ ssc_status_check_timer_

rclcpp::TimerBase::SharedPtr subsystem_controllers::DriversControllerNode::ssc_status_check_timer_
private

Definition at line 72 of file drivers_controller_node.hpp.

Referenced by handle_on_configure().

◆ start_up_timestamp_

long subsystem_controllers::DriversControllerNode::start_up_timestamp_
private

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