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_tf): split package #49

Merged
8 changes: 0 additions & 8 deletions autoware_utils/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,3 @@
## Overview

The **autoware_utils** library is a comprehensive toolkit designed to facilitate the development of autonomous driving applications. This library provides essential utilities for geometry, mathematics, ROS (Robot Operating System) expansions, diagnostics, and more. It is extensively used in the Autoware project to handle common tasks such as geometric calculations, data normalization, message conversions, performance monitoring, and point cloud transformations.

### Design

#### ROS Module

The ROS module provides utilities for working with ROS messages and nodes:

- **`self_pose_listener.hpp`**: Listens to the self-pose of the vehicle.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2020 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,44 +15,13 @@
#ifndef AUTOWARE_UTILS__ROS__SELF_POSE_LISTENER_HPP_
#define AUTOWARE_UTILS__ROS__SELF_POSE_LISTENER_HPP_

#include "autoware_utils/geometry/geometry.hpp"
#include "autoware_utils/ros/transform_listener.hpp"
// NOLINTBEGIN(build/namespaces, whitespace/line_length)
// clang-format off

#include <rclcpp/rclcpp.hpp>
#include <autoware_utils_tf/self_pose_listener.hpp>
namespace autoware_utils { using namespace autoware_utils_tf; }

#include <memory>

namespace autoware_utils
{
class SelfPoseListener
{
public:
explicit SelfPoseListener(rclcpp::Node * node) : transform_listener_(node) {}

void wait_for_first_pose()
{
while (rclcpp::ok()) {
if (get_current_pose()) {
return;
}
RCLCPP_INFO(transform_listener_.get_logger(), "waiting for self pose...");
rclcpp::Rate(0.2).sleep();
}
}

geometry_msgs::msg::PoseStamped::ConstSharedPtr get_current_pose()
{
const auto tf = transform_listener_.get_latest_transform("map", "base_link");
if (!tf) {
return {};
}

return std::make_shared<const geometry_msgs::msg::PoseStamped>(transform2pose(*tf));
}

private:
TransformListener transform_listener_;
};
} // namespace autoware_utils
// clang-format on
// NOLINTEND

#endif // AUTOWARE_UTILS__ROS__SELF_POSE_LISTENER_HPP_
7 changes: 7 additions & 0 deletions autoware_utils_tf/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ find_package(autoware_cmake REQUIRED)
autoware_package()

if(BUILD_TESTING)
file(GLOB_RECURSE test_files test/*.cpp)
ament_add_ros_isolated_gtest(test_${PROJECT_NAME} ${test_files})
ament_target_dependencies(test_${PROJECT_NAME}
${${PROJECT_NAME}_FOUND_BUILD_DEPENDS}
${${PROJECT_NAME}_FOUND_TEST_DEPENDS}
)
target_include_directories(test_${PROJECT_NAME} PRIVATE include)
endif()

ament_auto_package()
1 change: 1 addition & 0 deletions autoware_utils_tf/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ It is extensively used in the Autoware project to handle common tasks such as ma
## Design

- **`transform_listener.hpp`**: Manages transformation listeners.
- **`self_pose_listener.hpp`**: Listens to the self-pose of the vehicle.
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// Copyright 2020 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_TF__SELF_POSE_LISTENER_HPP_
#define AUTOWARE_UTILS_TF__SELF_POSE_LISTENER_HPP_

#include <autoware_utils_geometry/geometry.hpp>
#include <autoware_utils_tf/transform_listener.hpp>
#include <rclcpp/rclcpp.hpp>

#include <geometry_msgs/msg/pose_stamped.hpp>

#include <memory>

namespace autoware_utils_tf
{
class SelfPoseListener
{
public:
explicit SelfPoseListener(rclcpp::Node * node) : transform_listener_(node) {}

void wait_for_first_pose()
{
while (rclcpp::ok()) {
if (get_current_pose()) {
return;
}
RCLCPP_INFO(transform_listener_.get_logger(), "waiting for self pose...");
rclcpp::Rate(0.2).sleep();
}
}

geometry_msgs::msg::PoseStamped::ConstSharedPtr get_current_pose()
{
const auto tf = transform_listener_.get_latest_transform("map", "base_link");
if (!tf) {
return {};
}

return std::make_shared<const geometry_msgs::msg::PoseStamped>(
autoware_utils_geometry::transform2pose(*tf));
}

private:
TransformListener transform_listener_;
};
} // namespace autoware_utils_tf

#endif // AUTOWARE_UTILS_TF__SELF_POSE_LISTENER_HPP_
2 changes: 2 additions & 0 deletions autoware_utils_tf/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@
<buildtool_depend>ament_cmake_auto</buildtool_depend>
<buildtool_depend>autoware_cmake</buildtool_depend>

<depend>autoware_utils_geometry</depend>
<depend>geometry_msgs</depend>
<depend>rclcpp</depend>
<depend>tf2_ros</depend>

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

Expand Down
22 changes: 22 additions & 0 deletions autoware_utils_tf/test/cases/self_pose_listener.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// 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 "autoware_utils_tf/self_pose_listener.hpp"

#include <gtest/gtest.h>

TEST(TestSelfPoseListener, Main)
{
// TODO(Takagi, Isamu): Add test cases. Currently, we are only checking whether it can be built.
}
22 changes: 22 additions & 0 deletions autoware_utils_tf/test/cases/transform_listener.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// 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 "autoware_utils_tf/transform_listener.hpp"

#include <gtest/gtest.h>

TEST(TestTransformListener, Main)
{
// TODO(Takagi, Isamu): Add test cases. Currently, we are only checking whether it can be built.
}
36 changes: 36 additions & 0 deletions autoware_utils_tf/test/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// 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 <rclcpp/rclcpp.hpp>

#include <gtest/gtest.h>

class RclcppEnvironment : public testing::Environment
{
public:
RclcppEnvironment(int argc, char ** argv) : argc(argc), argv(argv) {}
void SetUp() override { rclcpp::init(argc, argv); }
void TearDown() override { rclcpp::shutdown(); }

private:
int argc;
char ** argv;
};

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