17#include <rclcpp/rclcpp.hpp>
19#include <autoware_lanelet2_msgs/msg/map_bin.hpp>
20#include <carma_v2x_msgs/msg/traffic_control_request.hpp>
21#include <carma_ros2_utils/carma_ros2_utils.hpp>
22#include <autoware_lanelet2_ros2_interface/utility/message_conversion.hpp>
24#include <carma_debug_ros2_msgs/msg/map_update_readable.hpp>
25#include <carma_debug_ros2_msgs/msg/lanelet_id_regulatory_element_pair.hpp>
26#include <boost/uuid/uuid.hpp>
27#include <boost/uuid/uuid_io.hpp>
28#include <boost/variant.hpp>
30#include <lanelet2_extension/regulatory_elements/DigitalMinimumGap.h>
31#include <lanelet2_extension/regulatory_elements/DigitalSpeedLimit.h>
32#include <lanelet2_extension/regulatory_elements/DirectionOfTravel.h>
33#include <lanelet2_extension/regulatory_elements/PassingControlLine.h>
34#include <lanelet2_extension/regulatory_elements/RegionAccessRule.h>
35#include <lanelet2_extension/regulatory_elements/StopRule.h>
53 rclcpp::Publisher<carma_debug_ros2_msgs::msg::MapUpdateReadable>::SharedPtr
readable_pub_;
54 rclcpp::Subscription<autoware_lanelet2_msgs::msg::MapBin>::SharedPtr
update_sub_;
63 carma_debug_ros2_msgs::msg::LaneletIdRegulatoryElementPair
pairToDebugMessage(
const std::pair<lanelet::Id, lanelet::RegulatoryElementPtr>& id_reg_pair);
72 carma_debug_ros2_msgs::msg::MapUpdateReadable
mapUpdateCallback(
const autoware_lanelet2_msgs::msg::MapBin& update);
74 void raw_callback(
const autoware_lanelet2_msgs::msg::MapBin::SharedPtr msg) {
80 : Node(
"map_update_logger")
85 rclcpp::PublisherOptions readable_pub_options;
86 readable_pub_options.use_intra_process_comm = rclcpp::IntraProcessSetting::Disable;
88 auto readable_pub_qos = rclcpp::QoS(rclcpp::KeepAll());
89 readable_pub_qos.transient_local();
93 readable_pub_ = this->create_publisher<carma_debug_ros2_msgs::msg::MapUpdateReadable>(
"map_update_debug", readable_pub_qos, readable_pub_options);
98 rclcpp::SubscriptionOptions update_sub_options;
99 update_sub_options.use_intra_process_comm = rclcpp::IntraProcessSetting::Disable;
101 auto update_sub_qos = rclcpp::QoS(rclcpp::KeepLast(100));
102 update_sub_qos.transient_local();
106 update_sub_ = this->create_subscription<autoware_lanelet2_msgs::msg::MapBin>(
"/environment/map_update", update_sub_qos,
111 carma_debug_ros2_msgs::msg::LaneletIdRegulatoryElementPair pair;
112 pair.lanelet_id = std::get<0>(id_reg_pair);
113 auto element = std::get<1>(id_reg_pair);
114 std::string rule_name = element->attribute(lanelet::AttributeName::Subtype).value();
115 pair.element.rule_name = rule_name;
117 if (rule_name.compare(
"digital_minimum_gap") == 0) {
119 auto cast = std::static_pointer_cast<lanelet::DigitalMinimumGap>(element);
120 pair.element.min_gap = cast->getMinimumGap();
121 pair.element.participants.insert(pair.element.participants.begin(), cast->participants_.begin(), cast->participants_.end());
123 }
else if (rule_name.compare(
"digital_speed_limit") == 0) {
125 auto cast = std::static_pointer_cast<lanelet::DigitalSpeedLimit>(element);
126 pair.element.speed_limit = cast->getSpeedLimit().value();
127 pair.element.participants.insert(pair.element.participants.begin(), cast->participants_.begin(), cast->participants_.end());
129 }
else if (rule_name.compare(
"direction_of_travel") == 0) {
131 auto cast = std::static_pointer_cast<lanelet::DirectionOfTravel>(element);
132 pair.element.direction = cast->direction_;
133 pair.element.participants.insert(pair.element.participants.begin(), cast->participants_.begin(), cast->participants_.end());
135 }
else if (rule_name.compare(
"passing_control_line") == 0) {
137 auto cast = std::static_pointer_cast<lanelet::PassingControlLine>(element);
138 pair.element.left_participants.insert(pair.element.left_participants.begin(), cast->left_participants_.begin(), cast->left_participants_.end());
139 pair.element.right_participants.insert(pair.element.right_participants.begin(), cast->right_participants_.begin(), cast->right_participants_.end());
141 }
else if (rule_name.compare(
"region_access_rule") == 0) {
143 auto cast = std::static_pointer_cast<lanelet::RegionAccessRule>(element);
144 pair.element.reason = cast->getReason();
145 pair.element.participants.insert(pair.element.participants.begin(), cast->participants_.begin(), cast->participants_.end());
147 }
else if (rule_name.compare(
"stop_rule") == 0) {
149 auto cast = std::static_pointer_cast<lanelet::StopRule>(element);
150 pair.element.participants.insert(pair.element.participants.begin(), cast->participants_.begin(), cast->participants_.end());
154 RCLCPP_WARN_STREAM(rclcpp::get_logger(
"map_update_debug"),
"MapUpdateLogger recieved unsupported regulatory element in map update.");
155 pair.element.unsupported_type =
true;
164 RCLCPP_INFO_STREAM(get_logger(),
"Recieved map update ");
169 carma_debug_ros2_msgs::msg::MapUpdateReadable msg;
170 msg.header = update.header;
171 msg.format_version = update.format_version;
172 msg.map_version = update.map_version;
173 msg.route_id = update.route_id;
174 msg.route_version = update.route_version;
175 msg.invalidates_route = update.invalidates_route;
177 msg.traffic_control_id = boost::lexical_cast<std::string>(control->id_);
179 for (
auto id_reg_pair : control->update_list_) {
184 for (
auto id_reg_pair : control->remove_list_) {
192#include "rclcpp_components/register_node_macro.hpp"
200 rclcpp::init(argc, argv);
202 rclcpp::spin(std::make_shared<MapUpdateLogger>(rclcpp::NodeOptions()));
int main(int argc, char **argv)
MapUpdateLogger(const rclcpp::NodeOptions &options)
carma_debug_ros2_msgs::msg::LaneletIdRegulatoryElementPair pairToDebugMessage(const std::pair< lanelet::Id, lanelet::RegulatoryElementPtr > &id_reg_pair)
Converts a TrafficControl pair into the corresponding debug message type.
rclcpp::Publisher< carma_debug_ros2_msgs::msg::MapUpdateReadable >::SharedPtr readable_pub_
void raw_callback(const autoware_lanelet2_msgs::msg::MapBin::SharedPtr msg)
rclcpp::Subscription< autoware_lanelet2_msgs::msg::MapBin >::SharedPtr update_sub_
carma_debug_ros2_msgs::msg::MapUpdateReadable mapUpdateCallback(const autoware_lanelet2_msgs::msg::MapBin &update)
Callback for map updates that converts them to a human readable format.
void fromBinMsg(const autoware_lanelet2_msgs::msg::MapBin &msg, std::shared_ptr< carma_wm::TrafficControl > gf_ptr, lanelet::LaneletMapPtr lanelet_map=nullptr)