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.
carma_cooperative_perception::HostVehicleFilterNode Class Reference

#include <host_vehicle_filter_component.hpp>

Inheritance diagram for carma_cooperative_perception::HostVehicleFilterNode:
Inheritance graph
Collaboration diagram for carma_cooperative_perception::HostVehicleFilterNode:
Collaboration graph

Public Member Functions

auto handle_on_configure (const rclcpp_lifecycle::State &) -> carma_ros2_utils::CallbackReturn override
 
auto handle_on_activate (const rclcpp_lifecycle::State &) -> carma_ros2_utils::CallbackReturn override
 
auto handle_on_deactivate (const rclcpp_lifecycle::State &) -> carma_ros2_utils::CallbackReturn override
 
auto handle_on_cleanup (const rclcpp_lifecycle::State &) -> carma_ros2_utils::CallbackReturn override
 
auto handle_on_shutdown (const rclcpp_lifecycle::State &) -> carma_ros2_utils::CallbackReturn override
 
auto update_host_vehicle_pose (const geometry_msgs::msg::PoseStamped &msg) -> void
 
auto attempt_filter_and_republish (carma_cooperative_perception_interfaces::msg::DetectionList msg) -> void
 

Private Attributes

rclcpp::Subscription< carma_cooperative_perception_interfaces::msg::DetectionList >::SharedPtr detection_list_sub_ {nullptr}
 
rclcpp::Subscription< geometry_msgs::msg::PoseStamped >::SharedPtr host_vehicle_pose_sub_ {nullptr}
 
rclcpp_lifecycle::LifecyclePublisher< carma_cooperative_perception_interfaces::msg::DetectionList >::SharedPtr detection_list_pub_
 
std::optional< geometry_msgs::msg::PoseStamped > host_vehicle_pose_ {std::nullopt}
 
OnSetParametersCallbackHandle::SharedPtr on_set_parameters_callback_ {nullptr}
 
double squared_distance_threshold_meters_ {0.0}
 

Detailed Description

Definition at line 26 of file host_vehicle_filter_component.hpp.

Member Function Documentation

◆ attempt_filter_and_republish()

auto carma_cooperative_perception::HostVehicleFilterNode::attempt_filter_and_republish ( carma_cooperative_perception_interfaces::msg::DetectionList  msg) -> void

Definition at line 162 of file host_vehicle_filter_component.cpp.

164{
165 if (!host_vehicle_pose_.has_value()) {
166 RCLCPP_WARN(get_logger(), "Could not filter detection list: host vehicle pose unknown");
167 return;
168 }
169
170 const auto is_within_distance = [this](const auto & detection) {
171 if (
172 detection.semantic_class != detection.SEMANTIC_CLASS_UNKNOWN &&
173 detection.semantic_class != detection.SEMANTIC_CLASS_SMALL_VEHICLE) {
174 return false;
175 }
176
177 return euclidean_distance_squared(host_vehicle_pose_.value().pose, detection.pose.pose) <=
179 };
180
181 const auto new_end{
182 std::remove_if(std::begin(msg.detections), std::end(msg.detections), is_within_distance)};
183
184 msg.detections.erase(new_end, std::end(msg.detections));
185
186 this->detection_list_pub_->publish(msg);
187}
std::optional< geometry_msgs::msg::PoseStamped > host_vehicle_pose_
rclcpp_lifecycle::LifecyclePublisher< carma_cooperative_perception_interfaces::msg::DetectionList >::SharedPtr detection_list_pub_
auto euclidean_distance_squared(const geometry_msgs::msg::Pose &a, const geometry_msgs::msg::Pose &b) -> double

References carma_cooperative_perception::euclidean_distance_squared().

Here is the call graph for this function:

◆ handle_on_activate()

auto carma_cooperative_perception::HostVehicleFilterNode::handle_on_activate ( const rclcpp_lifecycle::State &  ) -> carma_ros2_utils::CallbackReturn
override

Definition at line 110 of file host_vehicle_filter_component.cpp.

112{
113 RCLCPP_INFO(get_logger(), "Lifecycle transition: activating");
114 RCLCPP_INFO(get_logger(), "Lifecycle transition: successfully activated");
115
116 return carma_ros2_utils::CallbackReturn::SUCCESS;
117}

◆ handle_on_cleanup()

auto carma_cooperative_perception::HostVehicleFilterNode::handle_on_cleanup ( const rclcpp_lifecycle::State &  ) -> carma_ros2_utils::CallbackReturn
override

Definition at line 128 of file host_vehicle_filter_component.cpp.

130{
131 RCLCPP_INFO(get_logger(), "Lifecycle transition: cleaning up");
132
133 // CarmaLifecycleNode does not handle subscriber pointer reseting for us
134 detection_list_sub_.reset();
136
137 RCLCPP_INFO(get_logger(), "Lifecycle transition: successfully cleaned up");
138
139 return carma_ros2_utils::CallbackReturn::SUCCESS;
140}
rclcpp::Subscription< carma_cooperative_perception_interfaces::msg::DetectionList >::SharedPtr detection_list_sub_
rclcpp::Subscription< geometry_msgs::msg::PoseStamped >::SharedPtr host_vehicle_pose_sub_

◆ handle_on_configure()

auto carma_cooperative_perception::HostVehicleFilterNode::handle_on_configure ( const rclcpp_lifecycle::State &  ) -> carma_ros2_utils::CallbackReturn
override

Definition at line 25 of file host_vehicle_filter_component.cpp.

27{
28 RCLCPP_INFO(get_logger(), "Lifecycle transition: configuring");
29
30 detection_list_sub_ = create_subscription<
31 carma_cooperative_perception_interfaces::msg::DetectionList>(
32 "input/detection_list", 1,
33 [this](const carma_cooperative_perception_interfaces::msg::DetectionList::SharedPtr msg_ptr) {
34 if (const auto current_state{this->get_current_state().label()}; current_state == "active") {
36 } else {
37 RCLCPP_WARN(
38 this->get_logger(),
39 "Trying to receive message on the topic '%s', but the containing node is not activated. "
40 "Current node state: '%s'",
41 this->detection_list_sub_->get_topic_name(), current_state.c_str());
42 }
43 });
44
45 host_vehicle_pose_sub_ = create_subscription<geometry_msgs::msg::PoseStamped>(
46 "input/host_vehicle_pose", 1, [this](const geometry_msgs::msg::PoseStamped::SharedPtr msg_ptr) {
47 if (const auto current_state{this->get_current_state().label()}; current_state == "active") {
49 } else {
50 RCLCPP_WARN(
51 this->get_logger(),
52 "Trying to receive message on the topic '%s', but the containing node is not activated. "
53 "Current node state: '%s'",
54 this->detection_list_sub_->get_topic_name(), current_state.c_str());
55 }
56 });
57
59 create_publisher<carma_cooperative_perception_interfaces::msg::DetectionList>(
60 "output/detection_list", 1);
61
62 RCLCPP_INFO(get_logger(), "Lifecycle transition: successfully configured");
63
65 add_on_set_parameters_callback([this](const std::vector<rclcpp::Parameter> & parameters) {
66 rcl_interfaces::msg::SetParametersResult result;
67 result.successful = true;
68 result.reason = "success";
69
70 for (const auto & parameter : parameters) {
71 if (parameter.get_name() == "distance_threshold_meters") {
72 if (this->get_current_state().label() == "active") {
73 result.successful = false;
74 result.reason = "parameter is read-only while node is in 'Active' state";
75
76 RCLCPP_ERROR(
77 get_logger(),
78 "Cannot change parameter 'distance_threshold_meters': " + result.reason);
79
80 break;
81 }
82
83 if (const auto value{parameter.as_double()}; value < 0) {
84 result.successful = false;
85 result.reason = "parameter must be nonnegative";
86
87 RCLCPP_ERROR(
88 get_logger(),
89 "Cannot change parameter 'distance_threshold_meters': " + result.reason);
90
91 break;
92 } else {
93 this->squared_distance_threshold_meters_ = std::pow(value, 2);
94 }
95 } else {
96 result.successful = false;
97 result.reason = "Unexpected parameter name '" + parameter.get_name() + '\'';
98 break;
99 }
100 }
101
102 return result;
103 });
104
105 declare_parameter("distance_threshold_meters", 0.0);
106
107 return carma_ros2_utils::CallbackReturn::SUCCESS;
108}
OnSetParametersCallbackHandle::SharedPtr on_set_parameters_callback_
auto attempt_filter_and_republish(carma_cooperative_perception_interfaces::msg::DetectionList msg) -> void
auto update_host_vehicle_pose(const geometry_msgs::msg::PoseStamped &msg) -> void

◆ handle_on_deactivate()

auto carma_cooperative_perception::HostVehicleFilterNode::handle_on_deactivate ( const rclcpp_lifecycle::State &  ) -> carma_ros2_utils::CallbackReturn
override

Definition at line 119 of file host_vehicle_filter_component.cpp.

121{
122 RCLCPP_INFO(get_logger(), "Lifecycle transition: deactivating");
123 RCLCPP_INFO(get_logger(), "Lifecycle transition: successfully deactivated");
124
125 return carma_ros2_utils::CallbackReturn::SUCCESS;
126}

◆ handle_on_shutdown()

auto carma_cooperative_perception::HostVehicleFilterNode::handle_on_shutdown ( const rclcpp_lifecycle::State &  ) -> carma_ros2_utils::CallbackReturn
override

Definition at line 142 of file host_vehicle_filter_component.cpp.

144{
145 RCLCPP_INFO(get_logger(), "Lifecycle transition: shutting down");
146
147 // CarmaLifecycleNode does not handle subscriber pointer reseting for us
148 detection_list_sub_.reset();
150
151 RCLCPP_INFO(get_logger(), "Lifecycle transition: successfully shut down");
152
153 return carma_ros2_utils::CallbackReturn::SUCCESS;
154}

◆ update_host_vehicle_pose()

auto carma_cooperative_perception::HostVehicleFilterNode::update_host_vehicle_pose ( const geometry_msgs::msg::PoseStamped &  msg) -> void

Definition at line 156 of file host_vehicle_filter_component.cpp.

158{
159 host_vehicle_pose_ = msg;
160}

Member Data Documentation

◆ detection_list_pub_

rclcpp_lifecycle::LifecyclePublisher<carma_cooperative_perception_interfaces::msg::DetectionList>::SharedPtr carma_cooperative_perception::HostVehicleFilterNode::detection_list_pub_
private
Initial value:
{
nullptr}

Definition at line 58 of file host_vehicle_filter_component.hpp.

◆ detection_list_sub_

rclcpp::Subscription<carma_cooperative_perception_interfaces::msg::DetectionList>::SharedPtr carma_cooperative_perception::HostVehicleFilterNode::detection_list_sub_ {nullptr}
private

Definition at line 53 of file host_vehicle_filter_component.hpp.

◆ host_vehicle_pose_

std::optional<geometry_msgs::msg::PoseStamped> carma_cooperative_perception::HostVehicleFilterNode::host_vehicle_pose_ {std::nullopt}
private

Definition at line 61 of file host_vehicle_filter_component.hpp.

◆ host_vehicle_pose_sub_

rclcpp::Subscription<geometry_msgs::msg::PoseStamped>::SharedPtr carma_cooperative_perception::HostVehicleFilterNode::host_vehicle_pose_sub_ {nullptr}
private

Definition at line 55 of file host_vehicle_filter_component.hpp.

◆ on_set_parameters_callback_

OnSetParametersCallbackHandle::SharedPtr carma_cooperative_perception::HostVehicleFilterNode::on_set_parameters_callback_ {nullptr}
private

Definition at line 63 of file host_vehicle_filter_component.hpp.

◆ squared_distance_threshold_meters_

double carma_cooperative_perception::HostVehicleFilterNode::squared_distance_threshold_meters_ {0.0}
private

Definition at line 65 of file host_vehicle_filter_component.hpp.


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