17#include <rclcpp/rclcpp.hpp>
18#include <rclcpp_components/register_node_macro.hpp>
26: CarmaLifecycleNode{options}
33 const rclcpp_lifecycle::State & ) -> carma_ros2_utils::CallbackReturn
35 RCLCPP_INFO(get_logger(),
"Life cycle state transition: configuring");
37 sdsm_publisher_ = create_publisher<sdsm_msg_type>(
"output/sdsms", 1);
39 external_objects_subscription_ = create_subscription<external_objects_msg_type>(
40 "input/external_objects", 1, [
this](
const external_objects_msg_type::SharedPtr msg_ptr) {
41 const auto current_state{this->get_current_state().label()};
43 if (current_state ==
"active") {
44 publish_as_sdsm(*msg_ptr);
48 "Trying to receive message on the topic '%s', but the containing node is not activated. "
49 "Current node state: '%s'",
50 this->georeference_subscription_->get_topic_name(), current_state.c_str());
54 georeference_subscription_ = create_subscription<georeference_msg_type>(
55 "input/georeference", 1, [
this](
const georeference_msg_type::SharedPtr msg_ptr) {
56 const auto current_state{this->get_current_state().label()};
58 if (current_state ==
"active") {
59 update_georeference(*msg_ptr);
63 "Trying to receive message on the topic '%s', but the containing node is not "
65 "Current node state: '%s'",
66 this->georeference_subscription_->get_topic_name(), current_state.c_str());
70 current_pose_subscription_ = create_subscription<pose_msg_type>(
71 "input/pose_stamped", 1, [
this](
const pose_msg_type::SharedPtr msg_ptr) {
72 const auto current_state{this->get_current_state().label()};
74 if (current_state ==
"active") {
75 update_current_pose(*msg_ptr);
79 "Trying to recieve message on topic '%s', but the containing node is not activated."
80 "current node state: '%s'",
81 this->current_pose_subscription_->get_topic_name(), current_state.c_str());
85 RCLCPP_INFO(get_logger(),
"Lifecycle transition: successfully configured");
87 return carma_ros2_utils::CallbackReturn::SUCCESS;
91 const rclcpp_lifecycle::State & ) -> carma_ros2_utils::CallbackReturn
93 RCLCPP_INFO(get_logger(),
"Life cycle state transition: cleaning up");
95 sdsm_publisher_.reset();
96 external_objects_subscription_.reset();
97 georeference_subscription_.reset();
99 current_pose_subscription_.reset();
101 return carma_ros2_utils::CallbackReturn::SUCCESS;
105 const rclcpp_lifecycle::State & ) -> carma_ros2_utils::CallbackReturn
107 RCLCPP_INFO(get_logger(),
"Life cycle state transition: shutting down");
109 sdsm_publisher_.reset();
110 external_objects_subscription_.reset();
111 georeference_subscription_.reset();
113 current_pose_subscription_.reset();
115 return carma_ros2_utils::CallbackReturn::SUCCESS;
121 if (!map_projector_) {
125 this->get_logger(),
"Could not convert external object list to SDSM: unknown georeference");
131 const auto sdsm_output{
to_sdsm_msg(msg, current_pose_, map_projector_)};
133 sdsm_publisher_->publish(sdsm_output);
134 }
catch (
const std::invalid_argument & e) {
136 this->get_logger(),
"Could not convert external object list to SDSM: %s", e.what());
142 if (map_georeference_ != msg.data)
144 map_georeference_ = msg.data;
145 map_projector_ = std::make_shared<lanelet::projection::LocalFrameProjector>(map_georeference_.c_str());
160RCLCPP_COMPONENTS_REGISTER_NODE(
ExternalObjectListToSdsmNode(const rclcpp::NodeOptions &options)
std_msgs::msg::String georeference_msg_type
carma_perception_msgs::msg::ExternalObjectList external_objects_msg_type
auto update_current_pose(const pose_msg_type &pose) -> void
OnSetParametersCallbackHandle::SharedPtr on_set_parameters_callback_
geometry_msgs::msg::PoseStamped pose_msg_type
auto publish_as_sdsm(const external_objects_msg_type &msg) const -> void
auto handle_on_shutdown(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_configure(const rclcpp_lifecycle::State &) -> carma_ros2_utils::CallbackReturn override
auto update_georeference(const georeference_msg_type &proj_string) -> void
rclcpp_lifecycle::LifecyclePublisher< sdsm_msg_type >::SharedPtr sdsm_publisher_
auto to_sdsm_msg(const carma_perception_msgs::msg::ExternalObjectList &external_object_list, const geometry_msgs::msg::PoseStamped ¤t_pose, const std::shared_ptr< lanelet::projection::LocalFrameProjector > &map_projection) -> carma_v2x_msgs::msg::SensorDataSharingMessage