Skip to content

Commit 182c967

Browse files
JianKangEgonpre-commit-ci[bot]NorahXiong
authored
feat(autoware_utils): porting from autoware_universe_utils (#23)
Signed-off-by: JianKangEgon <egon.kang@autocore.ai> Signed-off-by: NorahXiong <norah.xiong@autocore.ai> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: NorahXiong <norah.xiong@autocore.ai>
1 parent 50ca63f commit 182c967

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+15463
-13
lines changed

.github/workflows/build-and-test-differential.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ jobs:
5757
with:
5858
rosdistro: ${{ matrix.rosdistro }}
5959
target-packages: ${{ steps.get-modified-packages.outputs.modified-packages }}
60+
build-depends-repos: build_depends.repos
6061

6162
- name: Test
6263
id: test
@@ -65,6 +66,7 @@ jobs:
6566
with:
6667
rosdistro: ${{ matrix.rosdistro }}
6768
target-packages: ${{ steps.get-modified-packages.outputs.modified-packages }}
69+
build-depends-repos: build_depends.repos
6870

6971
- name: Upload coverage to CodeCov
7072
if: ${{ steps.test.outputs.coverage-report-files != '' }}

.github/workflows/build-and-test.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ jobs:
4545
with:
4646
rosdistro: ${{ matrix.rosdistro }}
4747
target-packages: ${{ steps.get-self-packages.outputs.self-packages }}
48+
build-depends-repos: build_depends.repos
4849

4950
- name: Test
5051
if: ${{ steps.get-self-packages.outputs.self-packages != '' }}
@@ -53,6 +54,7 @@ jobs:
5354
with:
5455
rosdistro: ${{ matrix.rosdistro }}
5556
target-packages: ${{ steps.get-self-packages.outputs.self-packages }}
57+
build-depends-repos: build_depends.repos
5658

5759
- name: Upload coverage to CodeCov
5860
if: ${{ steps.test.outputs.coverage-report-files != '' }}

autoware_utils/CMakeLists.txt

+9-1
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,16 @@ project(autoware_utils)
44
find_package(autoware_cmake REQUIRED)
55
autoware_package()
66

7+
file(GLOB_RECURSE src_files
8+
src/*.cpp
9+
src/geometry/*.cpp
10+
src/math/*.cpp
11+
src/ros/*.cpp
12+
src/system/*.cpp
13+
)
14+
715
ament_auto_add_library(autoware_utils SHARED
8-
src/autoware_utils.cpp
16+
${src_files}
917
)
1018

1119
if(BUILD_TESTING)

autoware_utils/README.md

+291-12
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,304 @@
1-
# autoware_utils
1+
# autoware_utils Library
22

3-
Common utilities for Autoware.
3+
## Overview
4+
5+
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.
6+
7+
### Design
8+
9+
#### Geometry Module
10+
11+
The geometry module provides classes and functions for handling 2D and 3D points, vectors, polygons, and performing geometric operations:
12+
13+
- **`boost_geometry.hpp`**: Integrates Boost.Geometry for advanced geometric computations, defining point, segment, box, linestring, ring, and polygon types.
14+
- **`alt_geometry.hpp`**: Implements alternative geometric types and operations for 2D vectors and polygons, including vector arithmetic, polygon creation, and various geometric predicates.
15+
- **`ear_clipping.hpp`**: Provides algorithms for triangulating polygons using the ear clipping method.
16+
- **`gjk_2d.hpp`**: Implements the GJK algorithm for fast intersection detection between convex polygons.
17+
- **`sat_2d.hpp`**: Implements the SAT (Separating Axis Theorem) algorithm for detecting intersections between convex polygons.
18+
- **`random_concave_polygon.hpp` and `random_convex_polygon.hpp`**: Generate random concave and convex polygons for testing purposes.
19+
- **`pose_deviation.hpp`**: Calculates deviations between poses in terms of lateral, longitudinal, and yaw angles.
20+
- **`boost_polygon_utils.hpp`**: Utility functions for manipulating polygons, including:
21+
- Checking if a polygon is clockwise.
22+
- Rotating polygons around the origin.
23+
- Converting poses and shapes to polygons.
24+
- Expanding polygons by an offset.
25+
- **`geometry.hpp`**: Comprehensive geometric operations, including:
26+
- Distance calculations between points and segments.
27+
- Curvature computation.
28+
- Pose transformations and interpolations.
29+
- Intersection checks for convex polygons using GJK.
30+
- Conversion between different coordinate systems.
31+
32+
#### Math Module
33+
34+
The math module offers a variety of mathematical utilities:
35+
36+
- **`accumulator.hpp`**: A class for accumulating statistical data, supporting min, max, and mean calculations.
37+
- **`constants.hpp`**: Defines commonly used mathematical constants like π and gravity.
38+
- **`normalization.hpp`**: Functions for normalizing angles and degrees.
39+
- **`range.hpp`**: Functions for generating sequences of numbers (arange, linspace).
40+
- **`trigonometry.hpp`**: Optimized trigonometric functions for faster computation.
41+
- **`unit_conversion.hpp`**: Functions for converting between different units (e.g., degrees to radians, km/h to m/s).
42+
43+
#### ROS Module
44+
45+
The ROS module provides utilities for working with ROS messages and nodes:
46+
47+
- **`debug_publisher.hpp`**: A helper class for publishing debug messages with timestamps.
48+
- **`diagnostics_interface.hpp`**: An interface for publishing diagnostic messages.
49+
- **`logger_level_configure.hpp`**: Utility for configuring logger levels dynamically.
50+
- **`managed_transform_buffer.hpp`**: A managed buffer for handling static and dynamic transforms.
51+
- **`marker_helper.hpp`**: Helper functions for creating and manipulating visualization markers.
52+
- **`msg_covariance.hpp`**: Indices for accessing covariance matrices in ROS messages.
53+
- **`msg_operation.hpp`**: Overloaded operators for quaternion messages.
54+
- **`parameter.hpp`**: Simplifies parameter retrieval and declaration.
55+
- **`polling_subscriber.hpp`**: A subscriber class with different polling policies (latest, newest, all).
56+
- **`processing_time_publisher.hpp`**: Publishes processing times as diagnostic messages.
57+
- **`published_time_publisher.hpp`**: Tracks and publishes the time when messages are published.
58+
- **`self_pose_listener.hpp`**: Listens to the self-pose of the vehicle.
59+
- **`transform_listener.hpp`**: Manages transformation listeners.
60+
- **`update_param.hpp`**: Updates parameters from remote nodes.
61+
- **`uuid_helper.hpp`**: Utilities for generating and managing UUIDs.
62+
- **`wait_for_param.hpp`**: Waits for parameters from remote nodes.
63+
- **`debug_traits.hpp`**: Traits for identifying debug message types.
64+
- **`pcl_conversion.hpp`**: Efficient conversion and transformation of PointCloud2 messages to PCL point clouds.
65+
66+
#### System Module
67+
68+
The system module provides low-level utilities for performance monitoring and error handling:
69+
70+
- **`backtrace.hpp`**: Prints backtraces for debugging.
71+
- **`lru_cache.hpp`**: Implements an LRU (Least Recently Used) cache.
72+
- **`stop_watch.hpp`**: Measures elapsed time for profiling.
73+
- **`time_keeper.hpp`**: Tracks and reports the processing time of various functions.
74+
75+
#### Transform Module
76+
77+
Efficient methods for transforming and manipulating point clouds.
478

579
## Usage
680

7-
To use all features, include `autoware_utils/autoware_utils.hpp`:
81+
### Including Headers
82+
83+
To use the Autoware Utils library in your project, include the necessary headers at the top of your source files:
84+
85+
```cpp
86+
#include "autoware_utils/geometry/boost_geometry.hpp"
87+
#include "autoware_utils/math/accumulator.hpp"
88+
#include "autoware_utils/ros/debug_publisher.hpp"
89+
```
90+
91+
or you can include `autoware_utils/autoware_utils.hpp` for all features:
92+
93+
```cpp
94+
#include "autoware_utils/autoware_utils.hpp"
95+
```
96+
97+
### Example Code Snippets
98+
99+
#### Using Vector2d from alt_geometry.hpp
100+
101+
```cpp
102+
#include "autoware_utils/geometry/alt_geometry.hpp"
103+
104+
using namespace autoware_utils::alt;
105+
106+
int main() {
107+
Vector2d vec1(3.0, 4.0);
108+
Vector2d vec2(1.0, 2.0);
109+
110+
// Compute the dot product
111+
double dot_product = vec1.dot(vec2);
112+
113+
// Compute the norm
114+
double norm = vec1.norm();
115+
116+
return 0;
117+
}
118+
```
119+
120+
#### Using Accumulator from accumulator.hpp
8121
9122
```cpp
10-
#include <autoware_utils/autoware_utils.hpp>
123+
#include "autoware_utils/math/accumulator.hpp"
124+
125+
int main() {
126+
autoware_utils::Accumulator<double> acc;
11127
12-
using autoware_utils::deg2rad;
13-
using autoware_utils::normalize_degree;
14-
using autoware_utils::pi;
128+
acc.add(1.0);
129+
acc.add(2.0);
130+
acc.add(3.0);
131+
132+
std::cout << "Mean: " << acc.mean() << "\n";
133+
std::cout << "Min: " << acc.min() << "\n";
134+
std::cout << "Max: " << acc.max() << "\n";
135+
std::cout << "Count: " << acc.count() << "\n";
136+
137+
return 0;
138+
}
15139
```
16140

17-
To select features, include necessary header files:
141+
### Detailed Usage Examples
142+
143+
#### Transform Point Clouds with ManagedTransformBuffer
18144

19145
```cpp
20-
#include <autoware_utils/math/constants.hpp>
21-
#include <autoware_utils/math/normalization.hpp>
146+
#include "autoware_utils/ros/managed_transform_buffer.hpp"
147+
#include "sensor_msgs/msg/point_cloud2.hpp"
148+
#include <rclcpp/rclcpp.hpp>
149+
150+
int main(int argc, char * argv[]) {
151+
rclcpp::init(argc, argv);
152+
auto node = rclcpp::Node::make_shared("transform_node");
153+
154+
// Initialize ManagedTransformBuffer
155+
autoware_utils::ManagedTransformBuffer transform_buffer(node, false);
156+
157+
// Load point cloud data
158+
sensor_msgs::msg::PointCloud2 cloud_in; // Assume this is populated with data
159+
sensor_msgs::msg::PointCloud2 cloud_out;
160+
161+
// Transform point cloud from "base_link" to "map" frame
162+
if (transform_buffer.transform_pointcloud("map", cloud_in, cloud_out)) {
163+
RCLCPP_INFO(node->get_logger(), "Point cloud transformed successfully.");
164+
} else {
165+
RCLCPP_ERROR(node->get_logger(), "Failed to transform point cloud.");
166+
}
167+
168+
rclcpp::shutdown();
169+
return 0;
170+
}
171+
```
172+
173+
#### Update Parameters Dynamically with update_param.hpp
174+
175+
```cpp
176+
#include "autoware_utils/ros/update_param.hpp"
177+
#include <rclcpp/rclcpp.hpp>
178+
179+
int main(int argc, char * argv[]) {
180+
rclcpp::init(argc, argv);
181+
auto node = rclcpp::Node::make_shared("param_node");
182+
183+
double param_value = 0.0;
184+
std::vector<rclcpp::Parameter> params = node->get_parameters({"my_param"});
185+
186+
if (autoware_utils::update_param(params, "my_param", param_value)) {
187+
RCLCPP_INFO(node->get_logger(), "Updated parameter value: %f", param_value);
188+
} else {
189+
RCLCPP_WARN(node->get_logger(), "Parameter 'my_param' not found.");
190+
}
191+
192+
rclcpp::shutdown();
193+
return 0;
194+
}
195+
```
196+
197+
#### Logging Processing Times with ProcessingTimePublisher
198+
199+
```cpp
200+
#include "autoware_utils/ros/processing_time_publisher.hpp"
201+
#include <rclcpp/rclcpp.hpp>
202+
#include <map>
203+
204+
int main(int argc, char * argv[]) {
205+
rclcpp::init(argc, argv);
206+
auto node = rclcpp::Node::make_shared("processing_time_node");
207+
208+
// Initialize ProcessingTimePublisher
209+
autoware_utils::ProcessingTimePublisher processing_time_pub(node.get(), "~/debug/processing_time_ms");
210+
211+
// Simulate some processing times
212+
std::map<std::string, double> processing_times = {
213+
{"node1", 0.1}, {"node2", 0.2}, {"node3", 0.3}
214+
};
215+
216+
// Publish processing times
217+
processing_time_pub.publish(processing_times);
218+
219+
rclcpp::shutdown();
220+
return 0;
221+
}
222+
```
223+
224+
#### Manipulating Polygons with boost_polygon_utils.hpp
225+
226+
```cpp
227+
#include "autoware_utils/geometry/boost_polygon_utils.hpp"
228+
#include "autoware_utils/geometry/boost_geometry.hpp"
229+
#include <rclcpp/rclcpp.hpp>
230+
231+
int main(int argc, char * argv[]) {
232+
rclcpp::init(argc, argv);
233+
auto node = rclcpp::Node::make_shared("polygon_node");
234+
235+
// Create a polygon
236+
autoware_utils::Polygon2d polygon;
237+
// Assume polygon is populated with points
238+
239+
// Rotate the polygon by 90 degrees
240+
autoware_utils::Polygon2d rotated_polygon = autoware_utils::rotate_polygon(polygon, M_PI / 2);
241+
242+
// Expand the polygon by an offset
243+
autoware_utils::Polygon2d expanded_polygon = autoware_utils::expand_polygon(polygon, 1.0);
244+
245+
// Check if the polygon is clockwise
246+
bool is_clockwise = autoware_utils::is_clockwise(polygon);
247+
248+
rclcpp::shutdown();
249+
return 0;
250+
}
251+
```
252+
253+
#### Efficient Point Cloud Conversion with pcl_conversion.hpp
254+
255+
```cpp
256+
#include "autoware_utils/ros/pcl_conversion.hpp"
257+
#include "sensor_msgs/msg/point_cloud2.hpp"
258+
#include <pcl/point_types.h>
259+
#include <pcl/PCLPointCloud2.h>
260+
#include <Eigen/Core>
261+
#include <rclcpp/rclcpp.hpp>
262+
263+
int main(int argc, char * argv[]) {
264+
rclcpp::init(argc, argv);
265+
auto node = rclcpp::Node::make_shared("pcl_conversion_node");
266+
267+
// Load point cloud data
268+
sensor_msgs::msg::PointCloud2 cloud_in; // Assume this is populated with data
269+
pcl::PointCloud<pcl::PointXYZ> pcl_cloud;
270+
271+
// Define transformation matrix
272+
Eigen::Matrix4f transform = Eigen::Matrix4f::Identity();
273+
// Populate transform matrix with actual values
274+
275+
// Convert and transform point cloud
276+
autoware_utils::transform_point_cloud_from_ros_msg(cloud_in, pcl_cloud, transform);
277+
278+
rclcpp::shutdown();
279+
return 0;
280+
}
281+
```
282+
283+
#### Handling Debug Message Types with debug_traits.hpp
284+
285+
```cpp
286+
#include "autoware_utils/ros/debug_publisher.hpp"
287+
#include "autoware_utils/ros/debug_traits.hpp"
288+
#include <rclcpp/rclcpp.hpp>
289+
290+
int main(int argc, char * argv[]) {
291+
rclcpp::init(argc, argv);
292+
auto node = rclcpp::Node::make_shared("debug_node");
293+
294+
// Initialize DebugPublisher
295+
autoware_utils::DebugPublisher debug_pub(node, "/debug");
296+
297+
// Publish a debug message with custom type
298+
float debug_data = 42.0;
299+
debug_pub.publish<autoware_internal_debug_msgs::msg::Float32Stamped>("example", debug_data);
22300
23-
using autoware_utils::normalize_degree;
24-
using autoware_utils::pi;
301+
rclcpp::shutdown();
302+
return 0;
303+
}
25304
```

0 commit comments

Comments
 (0)