Skip to content

Commit

Permalink
Merge branch 'main' into feat/move-autoware-utils-tf
Browse files Browse the repository at this point in the history
  • Loading branch information
isamu-takagi committed Mar 7, 2025
2 parents 8fa5012 + 685b8b2 commit 12439f1
Show file tree
Hide file tree
Showing 10 changed files with 191 additions and 45 deletions.
1 change: 0 additions & 1 deletion autoware_utils/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ The geometry module provides classes and functions for handling 2D and 3D points

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

- **`diagnostics_interface.hpp`**: An interface for publishing diagnostic messages.
- **`msg_covariance.hpp`**: Indices for accessing covariance matrices in ROS messages.
- **`msg_operation.hpp`**: Overloaded operators for quaternion messages.
- **`self_pose_listener.hpp`**: Listens to the self-pose of the vehicle.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2023 Autoware Foundation
// 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,47 +15,14 @@
#ifndef AUTOWARE_UTILS__ROS__DIAGNOSTICS_INTERFACE_HPP_
#define AUTOWARE_UTILS__ROS__DIAGNOSTICS_INTERFACE_HPP_

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

#include <diagnostic_msgs/msg/diagnostic_array.hpp>
#pragma message("#include <autoware_utils/ros/diagnostics_interface.hpp> is deprecated. Use #include <autoware_utils_diagnostics/diagnostics_interface.hpp> instead.")
#include <autoware_utils_diagnostics/diagnostics_interface.hpp>
namespace autoware_utils { using namespace autoware_utils_diagnostics; }

#include <string>
#include <vector>

namespace autoware_utils
{
class DiagnosticsInterface
{
public:
DiagnosticsInterface(rclcpp::Node * node, const std::string & diagnostic_name);
void clear();
void add_key_value(const diagnostic_msgs::msg::KeyValue & key_value_msg);
template <typename T>
void add_key_value(const std::string & key, const T & value);
void add_key_value(const std::string & key, const std::string & value);
void add_key_value(const std::string & key, bool value);
void update_level_and_message(const int8_t level, const std::string & message);
void publish(const rclcpp::Time & publish_time_stamp);

private:
[[nodiscard]] diagnostic_msgs::msg::DiagnosticArray create_diagnostics_array(
const rclcpp::Time & publish_time_stamp) const;

rclcpp::Clock::SharedPtr clock_;
rclcpp::Publisher<diagnostic_msgs::msg::DiagnosticArray>::SharedPtr diagnostics_pub_;

diagnostic_msgs::msg::DiagnosticStatus diagnostics_status_msg_;
};

template <typename T>
void DiagnosticsInterface::add_key_value(const std::string & key, const T & value)
{
diagnostic_msgs::msg::KeyValue key_value;
key_value.key = key;
key_value.value = std::to_string(value);
add_key_value(key_value);
}

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

#endif // AUTOWARE_UTILS__ROS__DIAGNOSTICS_INTERFACE_HPP_
1 change: 1 addition & 0 deletions autoware_utils/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
<depend>autoware_perception_msgs</depend>
<depend>autoware_planning_msgs</depend>
<depend>autoware_utils_debug</depend>
<depend>autoware_utils_diagnostics</depend>
<depend>autoware_utils_logging</depend>
<depend>autoware_utils_math</depend>
<depend>autoware_utils_pcl</depend>
Expand Down
19 changes: 19 additions & 0 deletions autoware_utils_diagnostics/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
cmake_minimum_required(VERSION 3.14)
project(autoware_utils_diagnostics)

find_package(autoware_cmake REQUIRED)
autoware_package()

ament_auto_add_library(${PROJECT_NAME} SHARED
"src/diagnostics_interface.cpp"
)

if(BUILD_TESTING)
ament_add_ros_isolated_gtest(test_${PROJECT_NAME}
"test/main.cpp"
"test/cases/diagnostics_interface.cpp"
)
target_link_libraries(test_${PROJECT_NAME} ${PROJECT_NAME})
endif()

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

## Overview

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

## Design

- **`diagnostics_interface.hpp`**: An interface for publishing diagnostic messages.
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// Copyright 2023 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 AUTOWARE_UTILS_DIAGNOSTICS__DIAGNOSTICS_INTERFACE_HPP_
#define AUTOWARE_UTILS_DIAGNOSTICS__DIAGNOSTICS_INTERFACE_HPP_

#include <rclcpp/rclcpp.hpp>

#include <diagnostic_msgs/msg/diagnostic_array.hpp>

#include <string>
#include <vector>

namespace autoware_utils_diagnostics
{
class DiagnosticsInterface
{
public:
DiagnosticsInterface(rclcpp::Node * node, const std::string & diagnostic_name);
void clear();
void add_key_value(const diagnostic_msgs::msg::KeyValue & key_value_msg);
template <typename T>
void add_key_value(const std::string & key, const T & value);
void add_key_value(const std::string & key, const std::string & value);
void add_key_value(const std::string & key, bool value);
void update_level_and_message(const int8_t level, const std::string & message);
void publish(const rclcpp::Time & publish_time_stamp);

private:
[[nodiscard]] diagnostic_msgs::msg::DiagnosticArray create_diagnostics_array(
const rclcpp::Time & publish_time_stamp) const;

rclcpp::Clock::SharedPtr clock_;
rclcpp::Publisher<diagnostic_msgs::msg::DiagnosticArray>::SharedPtr diagnostics_pub_;

diagnostic_msgs::msg::DiagnosticStatus diagnostics_status_msg_;
};

template <typename T>
void DiagnosticsInterface::add_key_value(const std::string & key, const T & value)
{
diagnostic_msgs::msg::KeyValue key_value;
key_value.key = key;
key_value.value = std::to_string(value);
add_key_value(key_value);
}

} // namespace autoware_utils_diagnostics

#endif // AUTOWARE_UTILS_DIAGNOSTICS__DIAGNOSTICS_INTERFACE_HPP_
27 changes: 27 additions & 0 deletions autoware_utils_diagnostics/package.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?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_diagnostics</name>
<version>1.1.0</version>
<description>The autoware_utils_diagnostics 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>diagnostic_msgs</depend>
<depend>rclcpp</depend>

<test_depend>ament_cmake_ros</test_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/diagnostics_interface.hpp"
#include "autoware_utils_diagnostics/diagnostics_interface.hpp"

#include <rclcpp/rclcpp.hpp>

Expand All @@ -21,7 +21,7 @@
#include <algorithm>
#include <string>

namespace autoware_utils
namespace autoware_utils_diagnostics
{
DiagnosticsInterface::DiagnosticsInterface(rclcpp::Node * node, const std::string & diagnostic_name)
: clock_(node->get_clock())
Expand Down Expand Up @@ -103,4 +103,4 @@ diagnostic_msgs::msg::DiagnosticArray DiagnosticsInterface::create_diagnostics_a

return diagnostics_msg;
}
} // namespace autoware_utils
} // namespace autoware_utils_diagnostics
25 changes: 25 additions & 0 deletions autoware_utils_diagnostics/test/cases/diagnostics_interface.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// 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_diagnostics/diagnostics_interface.hpp"

#include <gtest/gtest.h>

#include <memory>

TEST(TestDiagnosticsInterface, Instantiation)
{
const auto node = std::make_shared<rclcpp::Node>("test_node");
autoware_utils_diagnostics::DiagnosticsInterface(node.get(), "diag_name");
}
36 changes: 36 additions & 0 deletions autoware_utils_diagnostics/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();
}

0 comments on commit 12439f1

Please sign in to comment.