-
Notifications
You must be signed in to change notification settings - Fork 668
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(autoware_auto_msgs_adapter): add map adapter (#4700)
* feat(autoware_auto_msgs_adapter): add map adapter Signed-off-by: Cynthia Liu <[email protected]> * feat(autoware_auto_msgs_adapter): add map adapter Signed-off-by: Cynthia Liu <[email protected]> * feat(autoware_auto_msgs_adapter): add map adapter Signed-off-by: Cynthia Liu <[email protected]> * feat(autoware_auto_msgs_adapter): add map adapter Signed-off-by: Cynthia Liu <[email protected]> * feat(autoware_auto_msgs_adapter): add map adapter Signed-off-by: Cynthia Liu <[email protected]> * style(pre-commit): autofix --------- Signed-off-by: Cynthia Liu <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
- Loading branch information
1 parent
b36bc09
commit 45339f6
Showing
9 changed files
with
182 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
system/autoware_auto_msgs_adapter/config/adapter_map.param.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
/**: | ||
ros__parameters: | ||
msg_type_target: "autoware_auto_mapping_msgs/msg/HADMapBin" | ||
topic_name_source: "/map/vector_map" | ||
topic_name_target: "/map/vector_map_auto" |
4 changes: 4 additions & 0 deletions
4
system/autoware_auto_msgs_adapter/launch/autoware_auto_msgs_adapter.launch.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,8 +10,6 @@ | |
|
||
<license>Apache License 2.0</license> | ||
|
||
<author email="[email protected]">M. Fatih Cırıt</author> | ||
|
||
<buildtool_depend>ament_cmake_auto</buildtool_depend> | ||
<buildtool_depend>autoware_cmake</buildtool_depend> | ||
|
||
|
@@ -22,8 +20,10 @@ | |
<test_depend>autoware_lint_common</test_depend> | ||
|
||
<depend>autoware_auto_control_msgs</depend> | ||
<depend>autoware_auto_mapping_msgs</depend> | ||
<depend>autoware_auto_perception_msgs</depend> | ||
<depend>autoware_control_msgs</depend> | ||
<depend>autoware_map_msgs</depend> | ||
<depend>autoware_perception_msgs</depend> | ||
<depend>rclcpp</depend> | ||
<depend>rclcpp_components</depend> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
system/autoware_auto_msgs_adapter/src/include/adapter_map.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// Copyright 2023 The Autoware Foundation | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
#ifndef ADAPTER_MAP_HPP_ | ||
#define ADAPTER_MAP_HPP_ | ||
|
||
#include "adapter_base.hpp" | ||
|
||
#include <rclcpp/rclcpp.hpp> | ||
|
||
#include <autoware_auto_mapping_msgs/msg/had_map_bin.hpp> | ||
#include <autoware_map_msgs/msg/lanelet_map_bin.hpp> | ||
|
||
#include <string> | ||
|
||
namespace autoware_auto_msgs_adapter | ||
{ | ||
using autoware_auto_mapping_msgs::msg::HADMapBin; | ||
using autoware_map_msgs::msg::LaneletMapBin; | ||
|
||
class AdapterMap : public autoware_auto_msgs_adapter::AdapterBase<LaneletMapBin, HADMapBin> | ||
{ | ||
public: | ||
AdapterMap( | ||
rclcpp::Node & node, const std::string & topic_name_source, | ||
const std::string & topic_name_target, const rclcpp::QoS & qos = rclcpp::QoS{1}) | ||
: AdapterBase(node, topic_name_source, topic_name_target, qos) | ||
{ | ||
RCLCPP_DEBUG( | ||
node.get_logger(), "AdapterMap is initialized to convert: %s -> %s", | ||
topic_name_source.c_str(), topic_name_target.c_str()); | ||
} | ||
|
||
protected: | ||
HADMapBin convert(const LaneletMapBin & msg_source) override | ||
{ | ||
autoware_auto_mapping_msgs::msg::HADMapBin msg_auto; | ||
msg_auto.header = msg_source.header; | ||
msg_auto.format_version = msg_source.version_map_format; | ||
msg_auto.map_version = msg_source.version_map; | ||
msg_auto.map_format = 0; | ||
msg_auto.data = msg_source.data; | ||
|
||
return msg_auto; | ||
} | ||
}; | ||
} // namespace autoware_auto_msgs_adapter | ||
|
||
#endif // ADAPTER_MAP_HPP_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
104 changes: 104 additions & 0 deletions
104
system/autoware_auto_msgs_adapter/test/test_msg_had_map_bin.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
// Copyright 2023 The Autoware Foundation | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#include <autoware_auto_msgs_adapter_core.hpp> | ||
|
||
#include <gtest/gtest.h> | ||
|
||
#include <random> | ||
|
||
autoware_map_msgs::msg::LaneletMapBin generate_map_msg() | ||
{ | ||
// generate deterministic random int | ||
std::mt19937 gen(0); | ||
std::uniform_int_distribution<> dis_int(0, 1000000); | ||
auto rand_int = [&dis_int, &gen]() { return dis_int(gen); }; | ||
|
||
autoware_map_msgs::msg::LaneletMapBin msg_map; | ||
msg_map.header.stamp = rclcpp::Time(rand_int()); | ||
msg_map.header.frame_id = "test_frame"; | ||
|
||
msg_map.version_map_format = "1.1.1"; | ||
msg_map.version_map = "1.0.0"; | ||
msg_map.name_map = "florence-prato-city-center"; | ||
msg_map.data.push_back(rand_int()); | ||
|
||
return msg_map; | ||
} | ||
|
||
TEST(AutowareAutoMsgsAdapter, TestHADMapBin) // NOLINT for gtest | ||
{ | ||
const std::string msg_type_target = "autoware_auto_mapping_msgs/msg/HADMapBin"; | ||
const std::string topic_name_source = "topic_name_source"; | ||
const std::string topic_name_target = "topic_name_target"; | ||
|
||
std::cout << "Creating the adapter node..." << std::endl; | ||
|
||
rclcpp::NodeOptions node_options; | ||
node_options.append_parameter_override("msg_type_target", msg_type_target); | ||
node_options.append_parameter_override("topic_name_source", topic_name_source); | ||
node_options.append_parameter_override("topic_name_target", topic_name_target); | ||
|
||
using autoware_auto_msgs_adapter::AutowareAutoMsgsAdapterNode; | ||
AutowareAutoMsgsAdapterNode::SharedPtr node_adapter; | ||
node_adapter = std::make_shared<AutowareAutoMsgsAdapterNode>(node_options); | ||
|
||
std::cout << "Creating the subscriber node..." << std::endl; | ||
|
||
auto node_subscriber = std::make_shared<rclcpp::Node>("node_subscriber", rclcpp::NodeOptions{}); | ||
|
||
bool test_completed = false; | ||
|
||
const auto msg_map = generate_map_msg(); | ||
auto sub = node_subscriber->create_subscription<autoware_auto_mapping_msgs::msg::HADMapBin>( | ||
topic_name_target, rclcpp::QoS{1}, | ||
[&msg_map, &test_completed](const autoware_auto_mapping_msgs::msg::HADMapBin::SharedPtr msg) { | ||
EXPECT_EQ(msg->header.stamp, msg_map.header.stamp); | ||
EXPECT_EQ(msg->header.frame_id, msg_map.header.frame_id); | ||
|
||
EXPECT_EQ(msg->map_format, 0); | ||
EXPECT_EQ(msg->format_version, msg_map.version_map_format); | ||
EXPECT_EQ(msg->map_version, msg_map.version_map); | ||
EXPECT_EQ(msg->data, msg_map.data); | ||
|
||
test_completed = true; | ||
}); | ||
|
||
std::cout << "Creating the publisher node..." << std::endl; | ||
|
||
auto node_publisher = std::make_shared<rclcpp::Node>("node_publisher", rclcpp::NodeOptions{}); | ||
auto pub = node_publisher->create_publisher<autoware_map_msgs::msg::LaneletMapBin>( | ||
topic_name_source, rclcpp::QoS{1}); | ||
pub->publish(msg_map); | ||
|
||
auto start_time = std::chrono::system_clock::now(); | ||
auto max_test_dur = std::chrono::seconds(5); | ||
auto timed_out = false; | ||
|
||
while (rclcpp::ok() && !test_completed) { | ||
rclcpp::spin_some(node_subscriber); | ||
rclcpp::spin_some(node_adapter); | ||
rclcpp::spin_some(node_publisher); | ||
rclcpp::sleep_for(std::chrono::milliseconds(50)); | ||
if (std::chrono::system_clock::now() - start_time > max_test_dur) { | ||
timed_out = true; | ||
break; | ||
} | ||
} | ||
|
||
EXPECT_TRUE(test_completed); | ||
EXPECT_FALSE(timed_out); | ||
|
||
// rclcpp::shutdown(); | ||
} |