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.
TrafficControl.cpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 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 */
16
17#include <boost/archive/binary_iarchive.hpp>
18#include <boost/archive/binary_oarchive.hpp>
20
21namespace carma_wm
22{
23
24void toBinMsg(std::shared_ptr<carma_wm::TrafficControl> gf_ptr, autoware_lanelet2_msgs::msg::MapBin* msg)
25{
26 if (msg == nullptr)
27 {
28 RCLCPP_ERROR_STREAM(rclcpp::get_logger("carma_wm::TrafficControl"), __FUNCTION__ << ": msg is null pointer!");
29 return;
30 }
31 std::stringstream ss;
32 boost::archive::binary_oarchive oa(ss);
33 oa << *gf_ptr;
34 std::string data_str(ss.str());
35
36 msg->data.clear();
37 msg->data.assign(data_str.begin(), data_str.end());
38}
39
40void fromBinMsg(const autoware_lanelet2_msgs::msg::MapBin& msg, std::shared_ptr<carma_wm::TrafficControl> gf_ptr, lanelet::LaneletMapPtr lanelet_map)
41{
42 if (!gf_ptr)
43 {
44 RCLCPP_ERROR_STREAM(rclcpp::get_logger("carma_wm::TrafficControl"), __FUNCTION__ << ": gf_ptr is null pointer!");
45 return;
46 }
47
48 std::string data_str;
49 data_str.assign(msg.data.begin(), msg.data.end());
50
51 std::stringstream ss;
52 ss << data_str;
53 boost::archive::binary_iarchive oa(ss);
54
55 oa >> *gf_ptr;
56
57 if (!lanelet_map)
58 return;
59
60 RCLCPP_DEBUG_STREAM(rclcpp::get_logger("carma_wm::TrafficControl"), "Lanelet Map is provided to match memory addresses of received binary map update");
61
62 lanelet::utils::OverwriteParameterVisitor memory_visitor(lanelet_map);
63 // It is sufficient to check single regem as carma_wm_ctrl sends only one type of regem in each list
64 if (!gf_ptr->update_list_.empty())
65 gf_ptr->update_list_.front().second->applyVisitor(memory_visitor);
66 if (!gf_ptr->remove_list_.empty())
67 gf_ptr->remove_list_.front().second->applyVisitor(memory_visitor);
68
69 RCLCPP_DEBUG_STREAM(rclcpp::get_logger("carma_wm::TrafficControl"), "Done resolving memory addresses of received regulatory elements!");
70}
71
72} // namespace carma_wm
void fromBinMsg(const autoware_lanelet2_msgs::msg::MapBin &msg, std::shared_ptr< carma_wm::TrafficControl > gf_ptr, lanelet::LaneletMapPtr lanelet_map=nullptr)
void toBinMsg(std::shared_ptr< carma_wm::TrafficControl > gf_ptr, autoware_lanelet2_msgs::msg::MapBin *msg)