Skip to content

Commit

Permalink
feat(autoware_utils_uuid): split package
Browse files Browse the repository at this point in the history
Signed-off-by: Takagi, Isamu <isamu.takagi@tier4.jp>
  • Loading branch information
isamu-takagi committed Mar 3, 2025
1 parent 62b5953 commit 69de883
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 14 deletions.
1 change: 0 additions & 1 deletion autoware_utils/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,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
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.
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#ifndef AUTOWARE_UTILS__ROS__UUID_HELPER_HPP_
#define AUTOWARE_UTILS__ROS__UUID_HELPER_HPP_
#ifndef AUTOWARE_UTILS_UUID__UUID_HELPER_HPP_
#define AUTOWARE_UTILS_UUID__UUID_HELPER_HPP_

#include <unique_identifier_msgs/msg/uuid.hpp>

Expand All @@ -23,8 +23,9 @@
#include <random>
#include <string>

namespace autoware_utils
namespace autoware_utils_uuid
{

inline unique_identifier_msgs::msg::UUID generate_uuid()
{
// Generate random number
Expand Down Expand Up @@ -67,6 +68,6 @@ inline unique_identifier_msgs::msg::UUID to_uuid_msg(const boost::uuids::uuid &
return ros_uuid;
}

} // namespace autoware_utils
} // namespace autoware_utils_uuid

#endif // AUTOWARE_UTILS__ROS__UUID_HELPER_HPP_
#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();
}

0 comments on commit 69de883

Please sign in to comment.