Skip to content

Commit 7d7baef

Browse files
xtk8532704k-uta
authored andcommitted
feat(autoware_planning_evaluator): new obstacle metrics (autowarefoundation#11761)
* tmp save Signed-off-by: xtk8532704 <1041084556@qq.com> * remove some draft code Signed-off-by: xtk8532704 <1041084556@qq.com> * add new implements Signed-off-by: xtk8532704 <1041084556@qq.com> * polish code, need to update readme Signed-off-by: xtk8532704 <1041084556@qq.com> * pre-commit Signed-off-by: xtk8532704 <1041084556@qq.com> * update readme Signed-off-by: xtk8532704 <1041084556@qq.com> * fix cppcheck Signed-off-by: xtk8532704 <1041084556@qq.com> * fix unit test bug, and add test cases for ttc, drac. Signed-off-by: xtk8532704 <1041084556@qq.com> * cry to fix ci building error Signed-off-by: xtk8532704 <1041084556@qq.com> * refactor code Signed-off-by: xtk8532704 <1041084556@qq.com> --------- Signed-off-by: xtk8532704 <1041084556@qq.com>
1 parent 4f7eb09 commit 7d7baef

17 files changed

+1314
-364
lines changed

evaluator/autoware_planning_evaluator/README.md

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -158,23 +158,48 @@ The following information are used to calculate metrics:
158158

159159
Evaluate the safety of `T(0)` with respect to obstacles.
160160

161-
Metrics are calculated and publish only when the node receives a trajectory.
161+
Metrics are calculated and published only when the node receives a trajectory and perception results.
162162

163163
The following information are used to calculate metrics:
164164

165165
- the trajectory `T(0)`.
166166
- the set of objects in the environment.
167167

168+
By default, metrics are published for each object individually using the object's UUID as the identifier,
169+
along with the worst value across all objects. You can set `obstacle.worst_only` to `true` to publish only the worst value.
170+
168171
#### Implemented metrics
169172

170-
- **`obstacle_distance`**: Statistics of the distance between each object and the closest trajectory point.
171-
- Sub-metrics to publish: `/mean`, `/min`, `/max`.
172-
- Sub-metrics to output: The same as above but take the published data as data point instead of each trajectory point.
173+
- **`obstacle_distance`**: Distance from the object's center point to the ego's future trajectory (closest point).
174+
- Parameters: None.
175+
- Sub-metrics to publish (per object): `/{object_uuid}` or `/worst` (worst value across all objects).
176+
- Sub-metrics to output: `/mean`, `/min`, `/max` for the published data.
173177

174-
- **`obstacle_ttc`**: Statistics of the time-to-collision (TTC) of objects and ego. Predicted path of objects and ego trajectory are considered.
175-
- Parameters: `obstacle.dist_thr_m` (distance margin to consider a collision occurs between object footprints and ego trajectory footprints).
176-
- Sub-metrics to publish: `/mean`, `/min`, `/max`.
177-
- Sub-metrics to output: The same as above but take the published data as data point instead of each trajectory point.
178+
- **`obstacle_ttc`**: Time To Collision (TTC) with the target object. Considers predicted paths of objects and ego trajectory.
179+
- TTC is calculated for objects that will actually collide with ego (overlap at the same time).
180+
- Parameters:
181+
- `obstacle.collision_thr_m`: distance margin to consider a collision occurs between object footprints and ego trajectory footprints.
182+
- `obstacle.use_ego_traj_vel`: if true, use planned trajectory velocity; otherwise use current ego velocity.
183+
- `obstacle.stop_velocity_mps`: velocity threshold to consider the object or ego as static.
184+
- `obstacle.min_time_interval_s`: minimum time interval for ego trajectory resampling.
185+
- `obstacle.min_spatial_interval_m`: minimum spatial interval for ego trajectory resampling.
186+
- Sub-metrics to publish (per object): `/{object_uuid}` or `/worst` (worst value across all objects).
187+
- Sub-metrics to output: `/mean`, `/min`, `/max` for the published data.
188+
189+
- **`obstacle_pet`**: Post Encroachment Time (PET) with the target object.
190+
- PET is the time difference between the target object leaving the overlap region and ego entering it.
191+
- Only calculated for objects whose future trajectory overlaps with ego's but do not collide at the same time.
192+
- An object cannot have both TTC and PET simultaneously (if TTC exists, PET is zero).
193+
- Parameters: Same as `obstacle_ttc`.
194+
- Sub-metrics to publish (per object): `/{object_uuid}` or `/worst` (worst value across all objects).
195+
- Sub-metrics to output: `/mean`, `/min`, `/max` for the published data.
196+
197+
- **`obstacle_drac`**: Deceleration Rate to Avoid Collision (DRAC) with the target object.
198+
- The minimum deceleration required to avoid collision with the target object.
199+
- Published alongside TTC for potential collision targets.
200+
- Parameters: Same as `obstacle_ttc`.
201+
- Sub-metrics to publish (per object): `/{object_uuid}` or `/worst` (worst value across all objects).
202+
- Sub-metrics to output: `/mean`, `/min`, `/max` for the published data.
178203

179204
### Modified Goal Metrics
180205

evaluator/autoware_planning_evaluator/config/planning_evaluator.param.yaml

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
- stability_frechet
2222
- obstacle_distance
2323
- obstacle_ttc
24+
- obstacle_pet
25+
- obstacle_drac
2426
- modified_goal_longitudinal_deviation
2527
- modified_goal_lateral_deviation
2628
- modified_goal_yaw_deviation
@@ -48,6 +50,8 @@
4850
- stability_frechet
4951
- obstacle_distance
5052
- obstacle_ttc
53+
- obstacle_pet
54+
- obstacle_drac
5155
- modified_goal_longitudinal_deviation
5256
- modified_goal_lateral_deviation
5357
- modified_goal_yaw_deviation
@@ -63,8 +67,14 @@
6367
max_dist_m: 5.0 # [m] maximum distance from ego along the trajectory to use for calculation
6468
max_time_s: 3.0 # [s] maximum time ahead of ego along the trajectory to use for calculation
6569

66-
obstacle:
67-
dist_thr_m: 0.0 # [m] distance between ego and the obstacle below which a collision is considered
70+
obstacle: # parameters for obstacle metrics calculation
71+
worst_only: false # if true, only the worst obstacle metric value is published
72+
use_ego_traj_vel: false # if true, the planned trajectory velocity is used
73+
collision_thr_m: 0.0 # [m] distance threshold to consider a collision occurs between object footprints and ego trajectory footprints
74+
stop_velocity_mps: 0.2777 # [m/s] velocity threshold to consider the object or ego is static, used for speed up the calculation
75+
76+
min_time_interval_s: 0.05 # [s] minimum time interval between two successive points to use for ego trajectory resampling to save calculation.
77+
min_spatial_interval_m: 0.1 # [m] minimum spatial interval between two successive points to use for ego trajectory resampling to save calculation.
6878

6979
stop_decision:
7080
topic_prefix: /planning/planning_factors/ # topic prefix for planning factors

evaluator/autoware_planning_evaluator/include/autoware/planning_evaluator/metrics/metric.hpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ enum class Metric {
4646
stability_frechet,
4747
obstacle_distance,
4848
obstacle_ttc,
49+
obstacle_pet,
50+
obstacle_drac,
4951
modified_goal_longitudinal_deviation,
5052
modified_goal_lateral_deviation,
5153
modified_goal_yaw_deviation,
@@ -78,6 +80,8 @@ static const std::unordered_map<std::string, Metric> str_to_metric = {
7880
{"stability_frechet", Metric::stability_frechet},
7981
{"obstacle_distance", Metric::obstacle_distance},
8082
{"obstacle_ttc", Metric::obstacle_ttc},
83+
{"obstacle_pet", Metric::obstacle_pet},
84+
{"obstacle_drac", Metric::obstacle_drac},
8185
{"modified_goal_longitudinal_deviation", Metric::modified_goal_longitudinal_deviation},
8286
{"modified_goal_lateral_deviation", Metric::modified_goal_lateral_deviation},
8387
{"modified_goal_yaw_deviation", Metric::modified_goal_yaw_deviation},
@@ -105,6 +109,8 @@ static const std::unordered_map<Metric, std::string> metric_to_str = {
105109
{Metric::stability_frechet, "stability_frechet"},
106110
{Metric::obstacle_distance, "obstacle_distance"},
107111
{Metric::obstacle_ttc, "obstacle_ttc"},
112+
{Metric::obstacle_pet, "obstacle_pet"},
113+
{Metric::obstacle_drac, "obstacle_drac"},
108114
{Metric::modified_goal_longitudinal_deviation, "modified_goal_longitudinal_deviation"},
109115
{Metric::modified_goal_lateral_deviation, "modified_goal_lateral_deviation"},
110116
{Metric::modified_goal_yaw_deviation, "modified_goal_yaw_deviation"},
@@ -132,7 +138,9 @@ static const std::unordered_map<Metric, std::string> metric_descriptions = {
132138
{Metric::stability, "Stability[m]"},
133139
{Metric::stability_frechet, "StabilityFrechet[m]"},
134140
{Metric::obstacle_distance, "Obstacle_distance[m]"},
135-
{Metric::obstacle_ttc, "Obstacle_time_to_collision[s]"},
141+
{Metric::obstacle_ttc, "Obstacle Time To Collision[s]"},
142+
{Metric::obstacle_pet, "Obstacle Post Encroaching Time[s]"},
143+
{Metric::obstacle_drac, "Deceleration Rate to Avoid Collision[m/s²]"},
136144
{Metric::modified_goal_longitudinal_deviation, "Modified_goal_longitudinal_deviation[m]"},
137145
{Metric::modified_goal_lateral_deviation, "Modified_goal_lateral_deviation[m]"},
138146
{Metric::modified_goal_yaw_deviation, "Modified_goal_yaw_deviation[rad]"},

evaluator/autoware_planning_evaluator/include/autoware/planning_evaluator/metrics/metrics_utils.hpp

Lines changed: 43 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@
2222
#include "autoware_perception_msgs/msg/predicted_object.hpp"
2323
#include "autoware_planning_msgs/msg/trajectory.hpp"
2424
#include "autoware_planning_msgs/msg/trajectory_point.hpp"
25+
#include "unique_identifier_msgs/msg/uuid.hpp"
26+
27+
#include <iomanip>
28+
#include <sstream>
29+
#include <string>
30+
#include <utility>
2531

2632
namespace planning_diagnostics
2733
{
@@ -35,14 +41,30 @@ using autoware_planning_msgs::msg::Trajectory;
3541
using autoware_planning_msgs::msg::TrajectoryPoint;
3642
using geometry_msgs::msg::Pose;
3743

44+
/**
45+
* @brief convert UUID to string representation
46+
* @param [in] uuid UUID message
47+
* @return hex string representation of UUID
48+
*/
49+
inline std::string uuid_to_string(const unique_identifier_msgs::msg::UUID & uuid)
50+
{
51+
std::stringstream ss;
52+
ss << std::hex << std::setfill('0');
53+
for (const auto & byte : uuid.uuid) {
54+
ss << std::setw(2) << static_cast<int>(byte);
55+
}
56+
return ss.str();
57+
}
58+
3859
/**
3960
* @brief find the index in the trajectory at the given distance of the given index
4061
* @param [in] traj input trajectory
4162
* @param [in] curr_id index
4263
* @param [in] distance distance
4364
* @return index of the trajectory point at distance ahead of traj[curr_id]
4465
*/
45-
size_t getIndexAfterDistance(const Trajectory & traj, const size_t curr_id, const double distance);
66+
size_t get_index_after_distance(
67+
const Trajectory & traj, const size_t curr_id, const double distance);
4668

4769
/**
4870
* @brief trim a trajectory from the current ego pose to some fixed time or distance
@@ -68,15 +90,27 @@ Trajectory get_lookahead_trajectory(
6890
double calc_lookahead_trajectory_distance(const Trajectory & traj, const Pose & ego_pose);
6991

7092
/**
71-
* @brief calculate the distance between ego vehicle footprint and a predicted object
72-
* @param [in] local_ego_footprint ego vehicle footprint in local coordinates
73-
* @param [in] ego_pose current ego vehicle pose in world coordinates
74-
* @param [in] object predicted object with pose and shape information
75-
* @return minimum distance between ego footprint and object footprint in meters
93+
* @brief Fast polygon intersection check using Separating Axis Theorem (SAT)
94+
* @details Efficiently checks if two convex polygons intersect, faster than boost::geometry's
95+
* generic intersection check. Uses SAT with early exit for non-intersecting cases.
96+
*
97+
* @param [in] poly1 First polygon (typically ego vehicle footprint)
98+
* @param [in] poly2 Second polygon (typically obstacle footprint)
99+
* @return true if polygons intersect, false otherwise
100+
*/
101+
bool polygon_intersects(
102+
const autoware_utils::Polygon2d & poly1, const autoware_utils::Polygon2d & poly2);
103+
104+
/**
105+
* @brief Calculate min and max distance from a pose to polygon edges
106+
* @param [in] pose The reference pose (position is used as the point)
107+
* @param [in] polygon The polygon to calculate distance to
108+
* @return pair of (min_dist, max_dist) where:
109+
* - min_dist: Minimum distance from pose position to polygon edges (nearest edge segment)
110+
* - max_dist: Maximum distance from pose position to polygon vertices (farthest vertex)
76111
*/
77-
double calc_ego_object_distance(
78-
const autoware_utils::LinearRing2d & local_ego_footprint, const Pose & ego_pose,
79-
const PredictedObject & object);
112+
std::pair<double, double> calculate_point_to_polygon_boundary_distances(
113+
const Pose & pose, const autoware_utils::Polygon2d & polygon);
80114

81115
} // namespace utils
82116
} // namespace metrics

evaluator/autoware_planning_evaluator/include/autoware/planning_evaluator/metrics/obstacle_metrics.hpp

Lines changed: 0 additions & 59 deletions
This file was deleted.

evaluator/autoware_planning_evaluator/include/autoware/planning_evaluator/metrics/output_metric.hpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ enum class OutputMetric {
4444
stability_frechet,
4545
obstacle_distance,
4646
obstacle_ttc,
47+
obstacle_pet,
48+
obstacle_drac,
4749
modified_goal_longitudinal_deviation,
4850
modified_goal_lateral_deviation,
4951
modified_goal_yaw_deviation,
@@ -77,6 +79,8 @@ static const std::unordered_map<std::string, OutputMetric> str_to_output_metric
7779
{"stability_frechet", OutputMetric::stability_frechet},
7880
{"obstacle_distance", OutputMetric::obstacle_distance},
7981
{"obstacle_ttc", OutputMetric::obstacle_ttc},
82+
{"obstacle_pet", OutputMetric::obstacle_pet},
83+
{"obstacle_drac", OutputMetric::obstacle_drac},
8084
{"modified_goal_longitudinal_deviation", OutputMetric::modified_goal_longitudinal_deviation},
8185
{"modified_goal_lateral_deviation", OutputMetric::modified_goal_lateral_deviation},
8286
{"modified_goal_yaw_deviation", OutputMetric::modified_goal_yaw_deviation},
@@ -105,6 +109,8 @@ static const std::unordered_map<OutputMetric, std::string> output_metric_to_str
105109
{OutputMetric::stability_frechet, "stability_frechet"},
106110
{OutputMetric::obstacle_distance, "obstacle_distance"},
107111
{OutputMetric::obstacle_ttc, "obstacle_ttc"},
112+
{OutputMetric::obstacle_pet, "obstacle_pet"},
113+
{OutputMetric::obstacle_drac, "obstacle_drac"},
108114
{OutputMetric::modified_goal_longitudinal_deviation, "modified_goal_longitudinal_deviation"},
109115
{OutputMetric::modified_goal_lateral_deviation, "modified_goal_lateral_deviation"},
110116
{OutputMetric::modified_goal_yaw_deviation, "modified_goal_yaw_deviation"},
@@ -133,8 +139,10 @@ static const std::unordered_map<OutputMetric, std::string> output_metric_descrip
133139
"Statics of published lateral_trajectory_displacement_lookahead metrics"},
134140
{OutputMetric::stability, "Statics of published stability metrics"},
135141
{OutputMetric::stability_frechet, "Statics of published stability_frechet metrics"},
136-
{OutputMetric::obstacle_distance, "Statics of published obstacle_distance metrics"},
137-
{OutputMetric::obstacle_ttc, "Statics of published obstacle_ttc metrics"},
142+
{OutputMetric::obstacle_distance, "Statics of worst published obstacle_distance metrics"},
143+
{OutputMetric::obstacle_ttc, "Statics of worst published obstacle_ttc metrics"},
144+
{OutputMetric::obstacle_pet, "Statics of worst published obstacle_pet metrics"},
145+
{OutputMetric::obstacle_drac, "Statics of worst published obstacle_drac metrics"},
138146
{OutputMetric::modified_goal_longitudinal_deviation,
139147
"Statics of published modified_goal_longitudinal_deviation metrics"},
140148
{OutputMetric::modified_goal_lateral_deviation,

evaluator/autoware_planning_evaluator/include/autoware/planning_evaluator/metrics_calculator.hpp

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919

2020
#include <autoware_vehicle_info_utils/vehicle_info_utils.hpp>
2121

22-
#include "autoware_perception_msgs/msg/predicted_objects.hpp"
2322
#include "autoware_planning_msgs/msg/pose_with_uuid_stamped.hpp"
2423
#include "autoware_planning_msgs/msg/trajectory.hpp"
2524
#include "autoware_planning_msgs/msg/trajectory_point.hpp"
@@ -31,7 +30,6 @@
3130
namespace planning_diagnostics
3231
{
3332
using autoware::vehicle_info_utils::VehicleInfo;
34-
using autoware_perception_msgs::msg::PredictedObjects;
3533
using autoware_planning_msgs::msg::PoseWithUuidStamped;
3634
using autoware_planning_msgs::msg::Trajectory;
3735
using autoware_planning_msgs::msg::TrajectoryPoint;
@@ -54,12 +52,6 @@ class MetricsCalculator
5452
double max_time_s = 3.0;
5553
} lookahead;
5654
} trajectory;
57-
58-
struct
59-
{
60-
double dist_thr_m = 0.0;
61-
double limit_min_accel = -2.5;
62-
} obstacle;
6355
} parameters; // struct Parameters for those metrics calculated by the MetricsCalculator
6456

6557
MetricsCalculator() = default;
@@ -92,12 +84,6 @@ class MetricsCalculator
9284
*/
9385
void setPreviousTrajectory(const Trajectory & traj);
9486

95-
/**
96-
* @brief set the dynamic objects used to calculate obstacle metrics
97-
* @param [in] traj input previous trajectory
98-
*/
99-
void setPredictedObjects(const PredictedObjects & objects);
100-
10187
/**
10288
* @brief set the ego pose
10389
* @param [in] traj input previous trajectory
@@ -115,7 +101,6 @@ class MetricsCalculator
115101
Trajectory reference_trajectory_lookahead_;
116102
Trajectory previous_trajectory_;
117103
Trajectory previous_trajectory_lookahead_;
118-
PredictedObjects dynamic_objects_;
119104
geometry_msgs::msg::Pose ego_pose_;
120105
nav_msgs::msg::Odometry ego_odometry_;
121106
PoseWithUuidStamped modified_goal_;

0 commit comments

Comments
 (0)