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.
roadway_objects_component.cpp
Go to the documentation of this file.
1// Copyright 2019-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 <memory>
18
19namespace roadway_objects
20{
21namespace std_ph = std::placeholders;
22
23RoadwayObjectsNode::RoadwayObjectsNode(const rclcpp::NodeOptions & options)
24: carma_ros2_utils::CarmaLifecycleNode(options)
25{
26}
27
28auto RoadwayObjectsNode::handle_on_configure(const rclcpp_lifecycle::State &)
29 -> carma_ros2_utils::CallbackReturn
30{
31 RCLCPP_INFO_STREAM(get_logger(), "RoadwayObjectsNode trying to configure");
32
33 wm_listener_ = std::make_shared<carma_wm::WMListener>(
34 get_node_base_interface(), get_node_logging_interface(), get_node_topics_interface(),
35 get_node_parameters_interface());
36
37 roadway_obs_pub_ =
38 create_publisher<carma_perception_msgs::msg::RoadwayObstacleList>("roadway_objects", 10);
39
40 external_objects_sub_ = create_subscription<carma_perception_msgs::msg::ExternalObjectList>(
41 "external_objects", 10,
42 [this](const carma_perception_msgs::msg::ExternalObjectList::SharedPtr msg_ptr) {
43 publish_obstacles(*msg_ptr);
44 });
45
46 return CallbackReturn::SUCCESS;
47}
48
50 const carma_perception_msgs::msg::ExternalObjectList & msg) -> void
51{
52 carma_perception_msgs::msg::RoadwayObstacleList obstacle_list;
53
54 const auto map{wm_listener_->getWorldModel()->getMap()};
55
56 if (map == nullptr) {
57 RCLCPP_WARN(
58 get_logger(),
59 "roadway_objects could not process external objects as no semantic map was available");
60
61 return;
62 }
63
64 if (std::size(map->laneletLayer) == 0) {
65 RCLCPP_WARN(
66 get_logger(),
67 "roadway_objects could not process external objects as the semantic map does not contain any "
68 "lanelets");
69
70 return;
71 }
72
73 const auto world_model{wm_listener_->getWorldModel()};
74 for (auto object : msg.objects) {
75 const auto obstacle{world_model->toRoadwayObstacle(object)};
76
77 if (!obstacle.has_value()) {
78 RCLCPP_DEBUG_STREAM(
79 get_logger(), "roadway_objects dropping detected object with id: "
80 << object.id << " as it is off the road.");
81
82 continue;
83 }
84
85 obstacle_list.roadway_obstacles.emplace_back(obstacle.get());
86 }
87
88 roadway_obs_pub_->publish(obstacle_list);
89}
90
91} // namespace roadway_objects
92
93#include "rclcpp_components/register_node_macro.hpp"
94
95// Register the component with class_loader
96RCLCPP_COMPONENTS_REGISTER_NODE(roadway_objects::RoadwayObjectsNode)
The class responsible for converting detected objects into objects that are mapped onto specific lane...
auto publish_obstacles(const carma_perception_msgs::msg::ExternalObjectList &msg) -> void
auto handle_on_configure(const rclcpp_lifecycle::State &) -> carma_ros2_utils::CallbackReturn override
RoadwayObjectsNode(const rclcpp::NodeOptions &)