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.
localization_manager::Node Class Reference

Core execution node for this package. More...

#include <localization_manager_node.hpp>

Inheritance diagram for localization_manager::Node:
Inheritance graph
Collaboration diagram for localization_manager::Node:
Collaboration graph

Public Member Functions

 Node (const rclcpp::NodeOptions &)
 Node constructor. More...
 
void publishPoseStamped (const geometry_msgs::msg::PoseStamped &msg) const
 Callback to publish the selected pose. More...
 
void publishStatus (const carma_localization_msgs::msg::LocalizationStatusReport &msg) const
 Callback to publish the provided localization status report. More...
 
void publishManagedInitialPose (const geometry_msgs::msg::PoseWithCovarianceStamped &msg) const
 Callback to publish the initial pose deemed suitable to intialize NDT. More...
 
void poseAndStatsCallback (const geometry_msgs::msg::PoseStamped::ConstPtr pose, const autoware_msgs::msg::NDTStat::ConstPtr stats)
 Synchronized callback for pose and stats data for usage with message_filters. Provides exception handling. More...
 
rcl_interfaces::msg::SetParametersResult parameter_update_callback (const std::vector< rclcpp::Parameter > &parameters)
 Callback for dynamic parameter updates. More...
 
carma_ros2_utils::CallbackReturn handle_on_configure (const rclcpp_lifecycle::State &)
 

Private Types

typedef message_filters::TimeSynchronizer< geometry_msgs::msg::PoseStamped, autoware_msgs::msg::NDTStat > TimeSynchronizer
 

Private Attributes

message_filters::Subscriber< geometry_msgs::msg::PoseStamped, Nodendt_pose_sub_
 
message_filters::Subscriber< autoware_msgs::msg::NDTStat, Nodendt_score_sub_
 
carma_ros2_utils::SubPtr< geometry_msgs::msg::PoseStamped > gnss_pose_sub_
 
carma_ros2_utils::SubPtr< geometry_msgs::msg::PoseWithCovarianceStamped > initialpose_sub_
 
carma_ros2_utils::SubPtr< carma_msgs::msg::SystemAlert > system_alert_sub_
 
carma_ros2_utils::PubPtr< geometry_msgs::msg::PoseStamped > pose_pub_
 
carma_ros2_utils::PubPtr< carma_localization_msgs::msg::LocalizationStatusReport > state_pub_
 
carma_ros2_utils::PubPtr< geometry_msgs::msg::PoseWithCovarianceStamped > managed_initial_pose_pub_
 
rclcpp::TimerBase::SharedPtr pose_timer_
 
LocalizationManagerConfig config_
 
std::unique_ptr< LocalizationManagermanager_
 
std::shared_ptr< TimeSynchronizerpose_stats_synchronizer_
 

Detailed Description

Core execution node for this package.

Definition at line 45 of file localization_manager_node.hpp.

Member Typedef Documentation

◆ TimeSynchronizer

typedef message_filters::TimeSynchronizer<geometry_msgs::msg::PoseStamped, autoware_msgs::msg::NDTStat> localization_manager::Node::TimeSynchronizer
private

Definition at line 70 of file localization_manager_node.hpp.

Constructor & Destructor Documentation

◆ Node()

localization_manager::Node::Node ( const rclcpp::NodeOptions &  options)
explicit

Node constructor.

Definition at line 25 of file localization_manager_node.cpp.

26 : carma_ros2_utils::CarmaLifecycleNode(options)
27
28 {
29 // Create initial config
30 config_ = LocalizationManagerConfig();
31
32 // Declare parameters
33 config_.fitness_score_degraded_threshold = declare_parameter<double>("fitness_score_degraded_threshold", config_.fitness_score_degraded_threshold);
34 config_.fitness_score_fault_threshold = declare_parameter<double>("fitness_score_fault_threshold", config_.fitness_score_fault_threshold);
35 config_.ndt_frequency_degraded_threshold = declare_parameter<double>("ndt_frequency_degraded_threshold", config_.ndt_frequency_degraded_threshold);
36 config_.ndt_frequency_fault_threshold = declare_parameter<double>("ndt_frequency_fault_threshold", config_.ndt_frequency_fault_threshold);
37 config_.auto_initialization_timeout = declare_parameter<int>("auto_initialization_timeout", config_.auto_initialization_timeout);
38 config_.gnss_only_operation_timeout = declare_parameter<int>("gnss_only_operation_timeout", config_.gnss_only_operation_timeout);
39 config_.sequential_timesteps_until_gps_operation = declare_parameter<int>("sequential_timesteps_until_gps_operation", config_.sequential_timesteps_until_gps_operation);
40 config_.gnss_data_timeout = declare_parameter<int>("gnss_data_timeout", config_.gnss_data_timeout);
41 config_.localization_mode = declare_parameter<int>("localization_mode", config_.localization_mode);
42 config_.pose_pub_rate = declare_parameter<double>("pose_pub_rate", config_.pose_pub_rate);
43 config_.x_offset = declare_parameter<double>("x_offset", config_.x_offset);
44 config_.y_offset = declare_parameter<double>("y_offset", config_.y_offset);
45 config_.z_offset = declare_parameter<double>("z_offset", config_.z_offset);
46 }
LocalizationManagerConfig config_
int gnss_only_operation_timeout
Timeout in ms for GNSS only operation. Ignored when in GNSS mode.
double fitness_score_degraded_threshold
NDT Fitness score above which the localization is considered in a degraded state.
double pose_pub_rate
Selected pose publication rate.
double x_offset
GPS Offset to apply if that mode is enabled.
int gnss_data_timeout
GNSS Data timeout. If exceeded the system will assume the GNSS is no longer functional....
double ndt_frequency_degraded_threshold
NDT solution frequency below which the localization is considered in a degraded state.

References localization_manager::LocalizationManagerConfig::auto_initialization_timeout, config_, localization_manager::LocalizationManagerConfig::fitness_score_degraded_threshold, localization_manager::LocalizationManagerConfig::fitness_score_fault_threshold, localization_manager::LocalizationManagerConfig::gnss_data_timeout, localization_manager::LocalizationManagerConfig::gnss_only_operation_timeout, localization_manager::LocalizationManagerConfig::localization_mode, localization_manager::LocalizationManagerConfig::ndt_frequency_degraded_threshold, localization_manager::LocalizationManagerConfig::ndt_frequency_fault_threshold, localization_manager::LocalizationManagerConfig::pose_pub_rate, localization_manager::LocalizationManagerConfig::sequential_timesteps_until_gps_operation, localization_manager::LocalizationManagerConfig::x_offset, localization_manager::LocalizationManagerConfig::y_offset, and localization_manager::LocalizationManagerConfig::z_offset.

Member Function Documentation

◆ handle_on_configure()

carma_ros2_utils::CallbackReturn localization_manager::Node::handle_on_configure ( const rclcpp_lifecycle::State &  )

Definition at line 48 of file localization_manager_node.cpp.

49 {
50 // Reset config
51 config_ = LocalizationManagerConfig();
52
53 // Load parameters
54 get_parameter<double>("fitness_score_degraded_threshold", config_.fitness_score_degraded_threshold);
55 get_parameter<double>("fitness_score_fault_threshold", config_.fitness_score_fault_threshold);
56 get_parameter<double>("ndt_frequency_degraded_threshold", config_.ndt_frequency_degraded_threshold);
57 get_parameter<double>("ndt_frequency_fault_threshold", config_.ndt_frequency_fault_threshold);
58 get_parameter<int>("auto_initialization_timeout", config_.auto_initialization_timeout);
59 get_parameter<int>("gnss_only_operation_timeout", config_.gnss_only_operation_timeout);
60 get_parameter<int>("sequential_timesteps_until_gps_operation", config_.sequential_timesteps_until_gps_operation);
61 get_parameter<int>("gnss_data_timeout", config_.gnss_data_timeout);
62 get_parameter<int>("localization_mode", config_.localization_mode);
63 get_parameter<double>("pose_pub_rate", config_.pose_pub_rate);
64 get_parameter<double>("x_offset", config_.x_offset);
65 get_parameter<double>("y_offset", config_.y_offset);
66 get_parameter<double>("z_offset", config_.z_offset);
67
68 RCLCPP_INFO_STREAM(rclcpp::get_logger("localization_manager"), "Loaded params: ");
69
70 // Initialize worker object
71 manager_.reset(new LocalizationManager(std::bind(&Node::publishPoseStamped, this, std_ph::_1),
72 std::bind(&Node::publishStatus, this, std_ph::_1),
73 std::bind(&Node::publishManagedInitialPose, this, std_ph::_1),
74 config_,
75 get_node_logging_interface(),
76 std::make_unique<carma_ros2_utils::timers::ROSTimerFactory>(shared_from_this())));
77
78 // Register runtime parameter update callback
79 add_on_set_parameters_callback(std::bind(&Node::parameter_update_callback, this, std_ph::_1));
80
81 // Setup subscribers
82 gnss_pose_sub_ = create_subscription<geometry_msgs::msg::PoseStamped>("gnss_pose", 5,
83 std::bind(&LocalizationManager::gnssPoseCallback, manager_.get(), std_ph::_1));
84 initialpose_sub_ = create_subscription<geometry_msgs::msg::PoseWithCovarianceStamped>("initialpose", 1,
85 std::bind(&LocalizationManager::initialPoseCallback, manager_.get(), std_ph::_1));
86
87 // Setup synchronized message_filters subscribers
88 rclcpp::QoS qos(5);
89 ndt_pose_sub_.subscribe(this, "ndt_pose", qos.get_rmw_qos_profile());
90 ndt_score_sub_.subscribe(this, "ndt_stat", qos.get_rmw_qos_profile());
91
92 pose_stats_synchronizer_ = std::make_shared<TimeSynchronizer>(ndt_pose_sub_, ndt_score_sub_, 5);
93 pose_stats_synchronizer_->registerCallback(std::bind(&Node::poseAndStatsCallback, this, std_ph::_1, std_ph::_2));
94
95 // system_alert_topic_ protected member of CarmaLifecycleNode
96 system_alert_sub_ = create_subscription<carma_msgs::msg::SystemAlert>(system_alert_topic_, 1,
97 std::bind(&LocalizationManager::systemAlertCallback, manager_.get(), std_ph::_1));
98 // Setup publishers
99 pose_pub_ = create_publisher<geometry_msgs::msg::PoseStamped>("selected_pose", 5);
100 state_pub_ = create_publisher<carma_localization_msgs::msg::LocalizationStatusReport>("localization_status", 5);
101
102 // Create a publisher that will send all previously published messages to late-joining subscribers ONLY If the subscriber is transient_local too
103 rclcpp::PublisherOptions intra_proc_disabled;
104 intra_proc_disabled.use_intra_process_comm = rclcpp::IntraProcessSetting::Disable; // Disable intra-process comms for this PublisherOptions object
105
106 auto pub_qos_transient_local = rclcpp::QoS(rclcpp::KeepLast(1)); // A publisher with this QoS will store all messages that it has sent on the topic
107 pub_qos_transient_local.transient_local(); // A publisher with this QoS will re-send all (when KeepAll is used) messages to all late-joining subscribers
108 // NOTE: The subscriber's QoS must be set to transient_local() as well for earlier messages to be resent to the later-joiner.
109 managed_initial_pose_pub_ = create_publisher<geometry_msgs::msg::PoseWithCovarianceStamped>("managed_initialpose", pub_qos_transient_local, intra_proc_disabled);
110
111 // Setup timer
112 pose_timer_ = create_timer(get_clock(), std::chrono::milliseconds(int(1 / config_.pose_pub_rate * 1000)),
113 std::bind(&LocalizationManager::posePubTick, manager_.get()));
114
115 // Return success if everything initialized successfully
116 return CallbackReturn::SUCCESS;
117 }
void posePubTick()
Timer callback that controls the publication of the selected pose and status report.
void gnssPoseCallback(const geometry_msgs::msg::PoseStamped::SharedPtr msg)
Callback for new GNSS messages.
void initialPoseCallback(const geometry_msgs::msg::PoseWithCovarianceStamped::SharedPtr msg)
Callback for the initial pose provided by Rviz or some external localization initializer.
void systemAlertCallback(const carma_msgs::msg::SystemAlert::SharedPtr alert)
Callback for SystemAlert data. Used to check for lidar failure.
void publishStatus(const carma_localization_msgs::msg::LocalizationStatusReport &msg) const
Callback to publish the provided localization status report.
std::unique_ptr< LocalizationManager > manager_
carma_ros2_utils::SubPtr< geometry_msgs::msg::PoseStamped > gnss_pose_sub_
carma_ros2_utils::PubPtr< geometry_msgs::msg::PoseStamped > pose_pub_
rcl_interfaces::msg::SetParametersResult parameter_update_callback(const std::vector< rclcpp::Parameter > &parameters)
Callback for dynamic parameter updates.
carma_ros2_utils::PubPtr< carma_localization_msgs::msg::LocalizationStatusReport > state_pub_
carma_ros2_utils::SubPtr< geometry_msgs::msg::PoseWithCovarianceStamped > initialpose_sub_
void publishPoseStamped(const geometry_msgs::msg::PoseStamped &msg) const
Callback to publish the selected pose.
message_filters::Subscriber< geometry_msgs::msg::PoseStamped, Node > ndt_pose_sub_
void publishManagedInitialPose(const geometry_msgs::msg::PoseWithCovarianceStamped &msg) const
Callback to publish the initial pose deemed suitable to intialize NDT.
carma_ros2_utils::SubPtr< carma_msgs::msg::SystemAlert > system_alert_sub_
rclcpp::TimerBase::SharedPtr pose_timer_
message_filters::Subscriber< autoware_msgs::msg::NDTStat, Node > ndt_score_sub_
void poseAndStatsCallback(const geometry_msgs::msg::PoseStamped::ConstPtr pose, const autoware_msgs::msg::NDTStat::ConstPtr stats)
Synchronized callback for pose and stats data for usage with message_filters. Provides exception hand...
carma_ros2_utils::PubPtr< geometry_msgs::msg::PoseWithCovarianceStamped > managed_initial_pose_pub_
std::shared_ptr< TimeSynchronizer > pose_stats_synchronizer_

References localization_manager::LocalizationManagerConfig::auto_initialization_timeout, config_, localization_manager::LocalizationManagerConfig::fitness_score_degraded_threshold, localization_manager::LocalizationManagerConfig::fitness_score_fault_threshold, localization_manager::LocalizationManagerConfig::gnss_data_timeout, localization_manager::LocalizationManagerConfig::gnss_only_operation_timeout, gnss_pose_sub_, localization_manager::LocalizationManager::gnssPoseCallback(), initialpose_sub_, localization_manager::LocalizationManager::initialPoseCallback(), localization_manager::LocalizationManagerConfig::localization_mode, managed_initial_pose_pub_, manager_, localization_manager::LocalizationManagerConfig::ndt_frequency_degraded_threshold, localization_manager::LocalizationManagerConfig::ndt_frequency_fault_threshold, ndt_pose_sub_, ndt_score_sub_, parameter_update_callback(), pose_pub_, localization_manager::LocalizationManagerConfig::pose_pub_rate, pose_stats_synchronizer_, pose_timer_, poseAndStatsCallback(), localization_manager::LocalizationManager::posePubTick(), publishManagedInitialPose(), publishPoseStamped(), publishStatus(), localization_manager::LocalizationManagerConfig::sequential_timesteps_until_gps_operation, state_pub_, system_alert_sub_, localization_manager::LocalizationManager::systemAlertCallback(), localization_manager::LocalizationManagerConfig::x_offset, localization_manager::LocalizationManagerConfig::y_offset, and localization_manager::LocalizationManagerConfig::z_offset.

Here is the call graph for this function:

◆ parameter_update_callback()

rcl_interfaces::msg::SetParametersResult localization_manager::Node::parameter_update_callback ( const std::vector< rclcpp::Parameter > &  parameters)

Callback for dynamic parameter updates.

Definition at line 129 of file localization_manager_node.cpp.

130 {
131 auto error = update_params<double>(
132 {{"pose_pub_rate", config_.pose_pub_rate},
133 {"fitness_score_degraded_threshold", config_.fitness_score_degraded_threshold},
134 {"fitness_score_fault_threshold", config_.fitness_score_fault_threshold},
135 {"ndt_frequency_degraded_threshold", config_.ndt_frequency_degraded_threshold},
136 {"ndt_frequency_fault_threshold", config_.ndt_frequency_fault_threshold},
137 {"x_offset", config_.x_offset},
138 {"y_offset", config_.y_offset},
139 {"z_offset", config_.z_offset}}, parameters);
140
141 auto error_2 = update_params<int>(
142 {{"auto_initialization_timeout", config_.auto_initialization_timeout},
143 {"gnss_only_operation_timeout", config_.gnss_only_operation_timeout},
144 {"gnss_data_timeout", config_.gnss_data_timeout},
145 {"sequential_timesteps_until_gps_operation", config_.sequential_timesteps_until_gps_operation}
146 }, parameters);
147
148 rcl_interfaces::msg::SetParametersResult result;
149
150 result.successful = !error && !error_2;
151
152 if (result.successful)
153 {
154 manager_->setConfig(config_);
155 }
156
157 return result;
158 }

References localization_manager::LocalizationManagerConfig::auto_initialization_timeout, config_, localization_manager::LocalizationManagerConfig::fitness_score_degraded_threshold, localization_manager::LocalizationManagerConfig::fitness_score_fault_threshold, localization_manager::LocalizationManagerConfig::gnss_data_timeout, localization_manager::LocalizationManagerConfig::gnss_only_operation_timeout, manager_, localization_manager::LocalizationManagerConfig::ndt_frequency_degraded_threshold, localization_manager::LocalizationManagerConfig::ndt_frequency_fault_threshold, localization_manager::LocalizationManagerConfig::pose_pub_rate, localization_manager::LocalizationManagerConfig::sequential_timesteps_until_gps_operation, localization_manager::LocalizationManagerConfig::x_offset, localization_manager::LocalizationManagerConfig::y_offset, and localization_manager::LocalizationManagerConfig::z_offset.

Referenced by handle_on_configure().

Here is the caller graph for this function:

◆ poseAndStatsCallback()

void localization_manager::Node::poseAndStatsCallback ( const geometry_msgs::msg::PoseStamped::ConstPtr  pose,
const autoware_msgs::msg::NDTStat::ConstPtr  stats 
)

Synchronized callback for pose and stats data for usage with message_filters. Provides exception handling.

Parameters
poseThe received pose message
statsThe received stats message

Definition at line 165 of file localization_manager_node.cpp.

167 {
168 try
169 {
170 manager_->poseAndStatsCallback(pose, stats);
171 }
172 catch (const std::exception &e)
173 {
174 RCLCPP_ERROR_STREAM(rclcpp::get_logger("localization_manager"), "Uncaught Exception in localization_manager. Exception: " << e.what());
175 handle_primary_state_exception(e);
176 }
177 }

References manager_.

Referenced by handle_on_configure().

Here is the caller graph for this function:

◆ publishManagedInitialPose()

void localization_manager::Node::publishManagedInitialPose ( const geometry_msgs::msg::PoseWithCovarianceStamped &  msg) const

Callback to publish the initial pose deemed suitable to intialize NDT.

Parameters
msgThe msg to publish

Definition at line 160 of file localization_manager_node.cpp.

161 {
162 managed_initial_pose_pub_->publish(msg);
163 }

References managed_initial_pose_pub_.

Referenced by handle_on_configure().

Here is the caller graph for this function:

◆ publishPoseStamped()

void localization_manager::Node::publishPoseStamped ( const geometry_msgs::msg::PoseStamped &  msg) const

Callback to publish the selected pose.

Parameters
msgThe pose to publish

Definition at line 119 of file localization_manager_node.cpp.

120 {
121 pose_pub_->publish(msg);
122 }

References pose_pub_.

Referenced by handle_on_configure().

Here is the caller graph for this function:

◆ publishStatus()

void localization_manager::Node::publishStatus ( const carma_localization_msgs::msg::LocalizationStatusReport &  msg) const

Callback to publish the provided localization status report.

Parameters
msgThe report to publish

Definition at line 124 of file localization_manager_node.cpp.

125 {
126 state_pub_->publish(msg);
127 }

References state_pub_.

Referenced by handle_on_configure().

Here is the caller graph for this function:

Member Data Documentation

◆ config_

LocalizationManagerConfig localization_manager::Node::config_
private

◆ gnss_pose_sub_

carma_ros2_utils::SubPtr<geometry_msgs::msg::PoseStamped> localization_manager::Node::gnss_pose_sub_
private

Definition at line 51 of file localization_manager_node.hpp.

Referenced by handle_on_configure().

◆ initialpose_sub_

carma_ros2_utils::SubPtr<geometry_msgs::msg::PoseWithCovarianceStamped> localization_manager::Node::initialpose_sub_
private

Definition at line 52 of file localization_manager_node.hpp.

Referenced by handle_on_configure().

◆ managed_initial_pose_pub_

carma_ros2_utils::PubPtr<geometry_msgs::msg::PoseWithCovarianceStamped> localization_manager::Node::managed_initial_pose_pub_
private

Definition at line 58 of file localization_manager_node.hpp.

Referenced by handle_on_configure(), and publishManagedInitialPose().

◆ manager_

std::unique_ptr<LocalizationManager> localization_manager::Node::manager_
private

◆ ndt_pose_sub_

message_filters::Subscriber<geometry_msgs::msg::PoseStamped, Node> localization_manager::Node::ndt_pose_sub_
private

Definition at line 49 of file localization_manager_node.hpp.

Referenced by handle_on_configure().

◆ ndt_score_sub_

message_filters::Subscriber<autoware_msgs::msg::NDTStat, Node> localization_manager::Node::ndt_score_sub_
private

Definition at line 50 of file localization_manager_node.hpp.

Referenced by handle_on_configure().

◆ pose_pub_

carma_ros2_utils::PubPtr<geometry_msgs::msg::PoseStamped> localization_manager::Node::pose_pub_
private

Definition at line 56 of file localization_manager_node.hpp.

Referenced by handle_on_configure(), and publishPoseStamped().

◆ pose_stats_synchronizer_

std::shared_ptr<TimeSynchronizer> localization_manager::Node::pose_stats_synchronizer_
private

Definition at line 71 of file localization_manager_node.hpp.

Referenced by handle_on_configure().

◆ pose_timer_

rclcpp::TimerBase::SharedPtr localization_manager::Node::pose_timer_
private

Definition at line 61 of file localization_manager_node.hpp.

Referenced by handle_on_configure().

◆ state_pub_

carma_ros2_utils::PubPtr<carma_localization_msgs::msg::LocalizationStatusReport> localization_manager::Node::state_pub_
private

Definition at line 57 of file localization_manager_node.hpp.

Referenced by handle_on_configure(), and publishStatus().

◆ system_alert_sub_

carma_ros2_utils::SubPtr<carma_msgs::msg::SystemAlert> localization_manager::Node::system_alert_sub_
private

Definition at line 53 of file localization_manager_node.hpp.

Referenced by handle_on_configure().


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