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.
track_list_to_external_object_list_component.cpp
Go to the documentation of this file.
1// Copyright 2023 Leidos
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
16
17#include <rclcpp_components/register_node_macro.hpp>
18#include <string>
19#include <utility>
20#include <vector>
21
25
27{
29 const rclcpp::NodeOptions & options)
30: CarmaLifecycleNode{options}
31{
32 lifecycle_publishers_.push_back(publisher_);
33 param_callback_handles_.push_back(on_set_parameters_callback_);
34}
35
37 const rclcpp_lifecycle::State & /* previous_state */) -> carma_ros2_utils::CallbackReturn
38{
39 publisher_ = create_publisher<carma_perception_msgs::msg::ExternalObjectList>(
40 "output/external_object_list", 1);
41
42 track_list_subscription_ = create_subscription<
43 carma_cooperative_perception_interfaces::msg::TrackList>(
44 "input/track_list", 1,
45 [this](const carma_cooperative_perception_interfaces::msg::TrackList::SharedPtr msg_ptr) {
46 if (const auto current_state{this->get_current_state().label()}; current_state == "active") {
47 publish_as_external_object_list(*msg_ptr);
48 } else {
49 RCLCPP_WARN(
50 this->get_logger(),
51 "Trying to receive message on the topic '%s', but the containing node is not activated. "
52 "Current node state: '%s'",
53 this->track_list_subscription_->get_topic_name(), current_state.c_str());
54 }
55 });
56
57 return carma_ros2_utils::CallbackReturn::SUCCESS;
58}
59
61 const rclcpp_lifecycle::State & /* previous_state */) -> carma_ros2_utils::CallbackReturn
62{
63 // CarmaLifecycleNode does not handle subscriber pointer reseting for us
64 track_list_subscription_.reset();
65
66 return carma_ros2_utils::CallbackReturn::SUCCESS;
67}
68
70 const rclcpp_lifecycle::State & /* previous_state */) -> carma_ros2_utils::CallbackReturn
71{
72 // CarmaLifecycleNode does not handle subscriber pointer reseting for us
73 track_list_subscription_.reset();
74
75 return carma_ros2_utils::CallbackReturn::SUCCESS;
76}
77
79 const carma_cooperative_perception_interfaces::msg::TrackList & msg) const -> void
80{
81 auto external_object_list{to_external_object_list_msg(msg)};
82 external_object_list.header.stamp = now();
83 external_object_list.header.frame_id = "map";
84
85 publisher_->publish(external_object_list);
86}
87
88} // namespace carma_cooperative_perception
89
90// This is not our macro, so we should not worry about linting it.
91// clang-tidy added support for ignoring system macros in release 14.0.0 (see the release notes
92// here: https://releases.llvm.org/14.0.0/tools/clang/tools/extra/docs/ReleaseNotes.html), but
93// ament_clang_tidy for ROS 2 Foxy specifically looks for clang-tidy-6.0.
94RCLCPP_COMPONENTS_REGISTER_NODE(
rclcpp_lifecycle::LifecyclePublisher< carma_perception_msgs::msg::ExternalObjectList >::SharedPtr publisher_
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 publish_as_external_object_list(const carma_cooperative_perception_interfaces::msg::TrackList &msg) const -> void
auto handle_on_configure(const rclcpp_lifecycle::State &) -> carma_ros2_utils::CallbackReturn override
auto to_external_object_list_msg(const carma_cooperative_perception_interfaces::msg::TrackList &track_list) -> carma_perception_msgs::msg::ExternalObjectList