Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(autoware_utils_uuid): split package #39

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion autoware_utils/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ The ROS module provides utilities for working with ROS messages and nodes:
- **`published_time_publisher.hpp`**: Tracks and publishes the time when messages are published.
- **`self_pose_listener.hpp`**: Listens to the self-pose of the vehicle.
- **`update_param.hpp`**: Updates parameters from remote nodes.
- **`uuid_helper.hpp`**: Utilities for generating and managing UUIDs.
- **`wait_for_param.hpp`**: Waits for parameters from remote nodes.
- **`debug_traits.hpp`**: Traits for identifying debug message types.

Expand Down
60 changes: 8 additions & 52 deletions autoware_utils/include/autoware_utils/ros/uuid_helper.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2022 Tier IV, Inc.
// Copyright 2025 The Autoware Contributors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -15,58 +15,14 @@
#ifndef AUTOWARE_UTILS__ROS__UUID_HELPER_HPP_
#define AUTOWARE_UTILS__ROS__UUID_HELPER_HPP_

#include <unique_identifier_msgs/msg/uuid.hpp>
// NOLINTBEGIN(build/namespaces, whitespace/line_length)
// clang-format off

#include <boost/uuid/uuid.hpp>
#pragma message("#include <autoware_utils/ros/uuid_helper.hpp> is deprecated. Use #include <autoware_utils_uuid/uuid_helper.hpp> instead.")
#include <autoware_utils_uuid/uuid_helper.hpp>
namespace autoware_utils { using namespace autoware_utils_uuid; }

#include <algorithm>
#include <random>
#include <string>

namespace autoware_utils
{
inline unique_identifier_msgs::msg::UUID generate_uuid()
{
// Generate random number
unique_identifier_msgs::msg::UUID uuid;
std::mt19937 gen(std::random_device{}());
std::independent_bits_engine<std::mt19937, 8, uint8_t> bit_eng(gen);
std::generate(uuid.uuid.begin(), uuid.uuid.end(), bit_eng);

return uuid;
}
inline unique_identifier_msgs::msg::UUID generate_default_uuid()
{
// Generate UUID with all zeros
unique_identifier_msgs::msg::UUID default_uuid;
// Use std::generate to fill the UUID with zeros
std::generate(default_uuid.uuid.begin(), default_uuid.uuid.end(), []() { return 0; });

return default_uuid;
}
inline std::string to_hex_string(const unique_identifier_msgs::msg::UUID & id)
{
std::stringstream ss;
for (auto i = 0; i < 16; ++i) {
ss << std::hex << std::setfill('0') << std::setw(2) << +id.uuid[i];
}
return ss.str();
}

inline boost::uuids::uuid to_boost_uuid(const unique_identifier_msgs::msg::UUID & id)
{
boost::uuids::uuid boost_uuid{};
std::copy(id.uuid.begin(), id.uuid.end(), boost_uuid.begin());
return boost_uuid;
}

inline unique_identifier_msgs::msg::UUID to_uuid_msg(const boost::uuids::uuid & id)
{
unique_identifier_msgs::msg::UUID ros_uuid{};
std::copy(id.begin(), id.end(), ros_uuid.uuid.begin());
return ros_uuid;
}

} // namespace autoware_utils
// clang-format on
// NOLINTEND

#endif // AUTOWARE_UTILS__ROS__UUID_HELPER_HPP_
1 change: 1 addition & 0 deletions autoware_utils/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
<depend>autoware_utils_math</depend>
<depend>autoware_utils_pcl</depend>
<depend>autoware_utils_system</depend>
<depend>autoware_utils_uuid</depend>
<depend>autoware_utils_visualization</depend>
<depend>autoware_vehicle_msgs</depend>
<depend>builtin_interfaces</depend>
Expand Down
12 changes: 12 additions & 0 deletions autoware_utils_uuid/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
cmake_minimum_required(VERSION 3.14)
project(autoware_utils_uuid)

find_package(autoware_cmake REQUIRED)
autoware_package()

if(BUILD_TESTING)
file(GLOB_RECURSE test_files test/*.cpp)
ament_auto_add_gtest(test_${PROJECT_NAME} ${test_files})
endif()

ament_auto_package()
11 changes: 11 additions & 0 deletions autoware_utils_uuid/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# autoware_utils_uuid

## Overview

The **autoware_utils** library is a comprehensive toolkit designed to facilitate the development of autonomous driving applications.
This package provides essential utilities for UUID.
It is extensively used in the Autoware project to handle common tasks such as generation and conversion of UUID.

## Design

- **`uuid_helper.hpp`**: Utilities for generating and managing UUIDs.
73 changes: 73 additions & 0 deletions autoware_utils_uuid/include/autoware_utils_uuid/uuid_helper.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
// Copyright 2022 Tier IV, Inc.
//
// 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 AUTOWARE_UTILS_UUID__UUID_HELPER_HPP_
#define AUTOWARE_UTILS_UUID__UUID_HELPER_HPP_

#include <unique_identifier_msgs/msg/uuid.hpp>

#include <boost/uuid/uuid.hpp>

#include <algorithm>
#include <random>
#include <string>

namespace autoware_utils_uuid
{

inline unique_identifier_msgs::msg::UUID generate_uuid()
{
// Generate random number
unique_identifier_msgs::msg::UUID uuid;
std::mt19937 gen(std::random_device{}());
std::independent_bits_engine<std::mt19937, 8, uint8_t> bit_eng(gen);
std::generate(uuid.uuid.begin(), uuid.uuid.end(), bit_eng);

return uuid;
}
inline unique_identifier_msgs::msg::UUID generate_default_uuid()
{
// Generate UUID with all zeros
unique_identifier_msgs::msg::UUID default_uuid;
// Use std::generate to fill the UUID with zeros
std::generate(default_uuid.uuid.begin(), default_uuid.uuid.end(), []() { return 0; });

return default_uuid;
}
inline std::string to_hex_string(const unique_identifier_msgs::msg::UUID & id)
{
std::stringstream ss;
for (auto i = 0; i < 16; ++i) {
ss << std::hex << std::setfill('0') << std::setw(2) << +id.uuid[i];
}
return ss.str();
}

inline boost::uuids::uuid to_boost_uuid(const unique_identifier_msgs::msg::UUID & id)
{
boost::uuids::uuid boost_uuid{};
std::copy(id.uuid.begin(), id.uuid.end(), boost_uuid.begin());
return boost_uuid;
}

inline unique_identifier_msgs::msg::UUID to_uuid_msg(const boost::uuids::uuid & id)
{
unique_identifier_msgs::msg::UUID ros_uuid{};
std::copy(id.begin(), id.end(), ros_uuid.uuid.begin());
return ros_uuid;
}

} // namespace autoware_utils_uuid

#endif // AUTOWARE_UTILS_UUID__UUID_HELPER_HPP_
26 changes: 26 additions & 0 deletions autoware_utils_uuid/package.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0"?>
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
<package format="3">
<name>autoware_utils_uuid</name>
<version>1.1.0</version>
<description>The autoware_utils_uuid package</description>
<maintainer email="egon.kang@autocore.ai">Jian Kang</maintainer>
<maintainer email="ryohsuke.mitsudome@tier4.jp">Ryohsuke Mitsudome</maintainer>
<maintainer email="esteve.fernandez@tier4.jp">Esteve Fernandez</maintainer>
<maintainer email="yutaka.kondo@tier4.jp">Yutaka Kondo</maintainer>
<maintainer email="isamu.takagi@tier4.jp">Takagi, Isamu</maintainer>
<license>Apache License 2.0</license>

<buildtool_depend>ament_cmake_auto</buildtool_depend>
<buildtool_depend>autoware_cmake</buildtool_depend>

<depend>libboost-system-dev</depend>
<depend>unique_identifier_msgs</depend>

<test_depend>ament_lint_auto</test_depend>
<test_depend>autoware_lint_common</test_depend>

<export>
<build_type>ament_cmake</build_type>
</export>
</package>
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#include "autoware_utils/ros/uuid_helper.hpp"
#include "autoware_utils_uuid/uuid_helper.hpp"

#include <boost/uuid/uuid_generators.hpp>

Expand All @@ -24,18 +24,18 @@ TEST(UUIDHelperTest, generate_uuid)
{
// Generate two UUIDs and ensure they are all different

unique_identifier_msgs::msg::UUID uuid1 = autoware_utils::generate_uuid();
unique_identifier_msgs::msg::UUID uuid2 = autoware_utils::generate_uuid();
unique_identifier_msgs::msg::UUID uuid1 = autoware_utils_uuid::generate_uuid();
unique_identifier_msgs::msg::UUID uuid2 = autoware_utils_uuid::generate_uuid();

EXPECT_FALSE(uuid1 == uuid2) << "Duplicate UUID generated: "
<< autoware_utils::to_hex_string(uuid2);
<< autoware_utils_uuid::to_hex_string(uuid2);
}

TEST(UUIDHelperTest, generate_default_uuid)
{
// Generate two UUIDs and ensure they are all different

unique_identifier_msgs::msg::UUID default_uuid = autoware_utils::generate_default_uuid();
unique_identifier_msgs::msg::UUID default_uuid = autoware_utils_uuid::generate_default_uuid();
unique_identifier_msgs::msg::UUID zero_uuid;
std::fill(zero_uuid.uuid.begin(), zero_uuid.uuid.end(), 0x00);

Expand All @@ -48,7 +48,7 @@ TEST(UUIDHelperTest, to_hex_string)
// Populate the UUID with some values
std::fill(uuid.uuid.begin(), uuid.uuid.end(), 0x42);

std::string hex_string = autoware_utils::to_hex_string(uuid);
std::string hex_string = autoware_utils_uuid::to_hex_string(uuid);

// Check if the generated hex string is correct
EXPECT_EQ(hex_string, "42424242424242424242424242424242");
Expand All @@ -64,14 +64,14 @@ TEST(UUIDHelperTest, to_boost_uuid)
std::fill(boost_uuid.begin(), boost_uuid.end(), 0x42);

// Check if the conversion from ROS UUID to Boost UUID is correct
EXPECT_TRUE(boost_uuid == autoware_utils::to_boost_uuid(uuid));
EXPECT_TRUE(boost_uuid == autoware_utils_uuid::to_boost_uuid(uuid));
}

TEST(UUIDHelperTest, to_uuid_msg)
{
boost::uuids::random_generator generator;
boost::uuids::uuid boost_uuid = generator();
unique_identifier_msgs::msg::UUID ros_uuid = autoware_utils::to_uuid_msg(boost_uuid);
unique_identifier_msgs::msg::UUID ros_uuid = autoware_utils_uuid::to_uuid_msg(boost_uuid);

// Check if the conversion from Boost UUID to ROS UUID is correct
EXPECT_TRUE(std::equal(boost_uuid.begin(), boost_uuid.end(), ros_uuid.uuid.begin()));
Expand Down
21 changes: 21 additions & 0 deletions autoware_utils_uuid/test/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright 2025 The Autoware Contributors
//
// 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 <gtest/gtest.h>

int main(int argc, char ** argv)
{
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
Loading