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.
traffic_incident_parser_node.cpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2020-2022 LEIDOS.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 * use this file except in compliance with the License. You may obtain a copy of
6 * the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 * License for the specific language governing permissions and limitations under
14 * the License.
15 */
17
19{
20 namespace std_ph = std::placeholders;
21
22 TrafficIncidentParserNode::TrafficIncidentParserNode(const rclcpp::NodeOptions &options)
23 : carma_ros2_utils::CarmaLifecycleNode(options)
24 {
25 }
26
27 carma_ros2_utils::CallbackReturn TrafficIncidentParserNode::handle_on_configure(const rclcpp_lifecycle::State &)
28 {
29
30 wm_listener_ = std::make_shared<carma_wm::WMListener>(get_node_base_interface(), get_node_logging_interface(),
31 get_node_topics_interface(), get_node_parameters_interface());
32
33 traffic_parser_worker_ = std::make_shared<TrafficIncidentParserWorker>(wm_listener_->getWorldModel(), std::bind(&TrafficIncidentParserNode::publishTrafficControlMessage, this, std_ph::_1), get_node_logging_interface(), get_clock());
34
35
36 // Setup subscribers
37 projection_sub_ = create_subscription<std_msgs::msg::String>("georeference", 1,
39 mobility_operation_sub_ = create_subscription<carma_v2x_msgs::msg::MobilityOperation>("incoming_mobility_operation", 1,
41
42 // Setup publishers
43
44 // NOTE: Currently, intra-process comms must be disabled for publishers that are transient_local: https://github.com/ros2/rclcpp/issues/1753
45 rclcpp::PublisherOptions traffic_control_msg_pub_options;
46 traffic_control_msg_pub_options.use_intra_process_comm = rclcpp::IntraProcessSetting::Disable; // Disable intra-process comms for this PublisherOptions object
47
48 auto traffic_control_msg_pub_qos = rclcpp::QoS(rclcpp::KeepAll()); // A publisher with this QoS will store all messages that it has sent on the topic
49 traffic_control_msg_pub_qos.transient_local(); // A publisher with this QoS will re-send all (when KeepAll is used) messages to all late-joining subscribers
50 // NOTE: The subscriber's QoS must be set to transient_local() as well for earlier messages to be resent to the later-joiner.
51
52
53 // Create a publisher that will send all previously published messages to late-joining subscribers ONLY If the subscriber is transient_local too
54 traffic_control_msg_pub_ = create_publisher<carma_v2x_msgs::msg::TrafficControlMessage>("geofence", traffic_control_msg_pub_qos, traffic_control_msg_pub_options);
55
56 // Return success if everthing initialized successfully
57 return CallbackReturn::SUCCESS;
58 }
59
60 void TrafficIncidentParserNode::publishTrafficControlMessage(const carma_v2x_msgs::msg::TrafficControlMessage& traffic_control_msg) const
61 {
62 traffic_control_msg_pub_->publish(traffic_control_msg);
63 }
64
65} // traffic_incident_parser
66
67#include "rclcpp_components/register_node_macro.hpp"
68
69// Register the component with class_loader
70RCLCPP_COMPONENTS_REGISTER_NODE(traffic_incident_parser::TrafficIncidentParserNode)
The class responsible for processing incoming MobilityOperation messages with strategy "carma3/Incide...
carma_ros2_utils::SubPtr< std_msgs::msg::String > projection_sub_
void publishTrafficControlMessage(const carma_v2x_msgs::msg::TrafficControlMessage &traffic_control_msg) const
Publish traffic control message.
carma_ros2_utils::PubPtr< carma_v2x_msgs::msg::TrafficControlMessage > traffic_control_msg_pub_
std::shared_ptr< TrafficIncidentParserWorker > traffic_parser_worker_
TrafficIncidentParserNode(const rclcpp::NodeOptions &)
TrafficIncidentParserNode constructor.
carma_ros2_utils::SubPtr< carma_v2x_msgs::msg::MobilityOperation > mobility_operation_sub_
carma_ros2_utils::CallbackReturn handle_on_configure(const rclcpp_lifecycle::State &)
void georeferenceCallback(std_msgs::msg::String::UniquePtr projection_msg)
Callback for the georeference subscriber used to set the map projection.
void mobilityOperationCallback(carma_v2x_msgs::msg::MobilityOperation::UniquePtr mobility_msg)
Function to receive the incoming mobility operation message from the message node and publish the geo...