Skip to content

Commit 4ba9dd4

Browse files
authored
test(bpp_common): add unit test for safety check (#9223)
* add test for object collision Signed-off-by: Go Sakayori <go.sakayori@tier4.jp> * add test for more functions Signed-off-by: Go Sakayori <go.sakayori@tier4.jp> * add docstring Signed-off-by: Go Sakayori <gsakayori@gmail.com> * fix lane change Signed-off-by: Go Sakayori <gsakayori@gmail.com> --------- Signed-off-by: Go Sakayori <go.sakayori@tier4.jp> Signed-off-by: Go Sakayori <gsakayori@gmail.com>
1 parent 06ecc67 commit 4ba9dd4

File tree

5 files changed

+381
-106
lines changed

5 files changed

+381
-106
lines changed

planning/behavior_path_planner/autoware_behavior_path_lane_change_module/src/scene.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -1940,10 +1940,10 @@ bool NormalLaneChange::is_collided(
19401940
const auto & bpp_param = *common_data_ptr_->bpp_param_ptr;
19411941

19421942
for (const auto & obj_path : obj_predicted_paths) {
1943-
const auto collided_polygons = utils::path_safety_checker::getCollidedPolygons(
1944-
lane_change_path, ego_predicted_path, obj, obj_path, bpp_param, selected_rss_param,
1945-
hysteresis_factor, safety_check_max_vel, collision_check_yaw_diff_threshold,
1946-
current_debug_data.second);
1943+
const auto collided_polygons = utils::path_safety_checker::get_collided_polygons(
1944+
lane_change_path, ego_predicted_path, obj, obj_path, bpp_param.vehicle_info,
1945+
selected_rss_param, hysteresis_factor, safety_check_max_vel,
1946+
collision_check_yaw_diff_threshold, current_debug_data.second);
19471947

19481948
if (collided_polygons.empty()) {
19491949
utils::path_safety_checker::updateCollisionCheckDebugMap(

planning/behavior_path_planner/autoware_behavior_path_planner_common/include/autoware/behavior_path_planner_common/utils/path_safety_checker/safety_check.hpp

+59-15
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,27 @@ using autoware_perception_msgs::msg::Shape;
4545
using geometry_msgs::msg::Pose;
4646
using geometry_msgs::msg::Twist;
4747

48+
/**
49+
* @brief Checks if the object is coming toward the ego vehicle judging by yaw deviation
50+
* @param vehicle_pose Ego vehicle pose.
51+
* @param object_pose Object pose.
52+
* @param angle_threshold Angle threshold.
53+
* @return True if the object vehicle is coming towards the ego vehicle
54+
*/
4855
bool isTargetObjectOncoming(
4956
const geometry_msgs::msg::Pose & vehicle_pose, const geometry_msgs::msg::Pose & object_pose,
5057
const double angle_threshold = M_PI_2);
5158

59+
/**
60+
* @brief Checks if the object is in front of the ego vehicle.
61+
* @param ego_pose Ego vehicle pose.
62+
* @param obj_polygon Polygon of object.
63+
* @param base_to_front Base link to vehicle front.
64+
* @return True if object is in front.
65+
*/
5266
bool isTargetObjectFront(
5367
const geometry_msgs::msg::Pose & ego_pose, const Polygon2d & obj_polygon,
54-
const autoware::vehicle_info_utils::VehicleInfo & vehicle_info);
55-
bool isTargetObjectFront(
56-
const PathWithLaneId & path, const geometry_msgs::msg::Pose & ego_pose,
57-
const autoware::vehicle_info_utils::VehicleInfo & vehicle_info, const Polygon2d & obj_polygon);
68+
const double base_to_front);
5869

5970
Polygon2d createExtendedPolygon(
6071
const Pose & base_link_pose, const autoware::vehicle_info_utils::VehicleInfo & vehicle_info,
@@ -72,7 +83,15 @@ double calcRssDistance(
7283
const double front_object_velocity, const double rear_object_velocity,
7384
const RSSparams & rss_params);
7485

75-
double calcMinimumLongitudinalLength(
86+
/**
87+
* @brief Calculates the minimum longitudinal length using rss parameter. The object is either ego
88+
* vehicle or target object.
89+
* @param front_object_velocity Front object velocity.
90+
* @param rear_object_velocity Front object velocity.
91+
* @param RSSparams RSS parameters
92+
* @return Maximum distance.
93+
*/
94+
double calc_minimum_longitudinal_length(
7695
const double front_object_velocity, const double rear_object_velocity,
7796
const RSSparams & rss_params);
7897

@@ -84,15 +103,19 @@ double calcMinimumLongitudinalLength(
84103
* it contains the interpolated pose, velocity, and time. If the interpolation fails
85104
* (e.g., empty path, negative time, or time beyond the path), it returns std::nullopt.
86105
*/
87-
std::optional<PoseWithVelocityStamped> calcInterpolatedPoseWithVelocity(
106+
std::optional<PoseWithVelocityStamped> calc_interpolated_pose_with_velocity(
88107
const std::vector<PoseWithVelocityStamped> & path, const double relative_time);
89108

90-
std::optional<PoseWithVelocityAndPolygonStamped> getInterpolatedPoseWithVelocityAndPolygonStamped(
109+
std::optional<PoseWithVelocityAndPolygonStamped>
110+
get_interpolated_pose_with_velocity_and_polygon_stamped(
91111
const std::vector<PoseWithVelocityStamped> & pred_path, const double current_time,
92112
const VehicleInfo & ego_info);
93-
std::optional<PoseWithVelocityAndPolygonStamped> getInterpolatedPoseWithVelocityAndPolygonStamped(
113+
114+
std::optional<PoseWithVelocityAndPolygonStamped>
115+
get_interpolated_pose_with_velocity_and_polygon_stamped(
94116
const std::vector<PoseWithVelocityStamped> & pred_path, const double current_time,
95117
const Shape & shape);
118+
96119
template <typename T, typename F>
97120
std::vector<T> filterPredictedPathByTimeHorizon(
98121
const std::vector<T> & path, const double time_horizon, const F & interpolateFunc);
@@ -151,14 +174,13 @@ bool checkCollision(
151174
* @param debug The debug information for collision checking.
152175
* @return a list of polygon when collision is expected.
153176
*/
154-
std::vector<Polygon2d> getCollidedPolygons(
177+
std::vector<Polygon2d> get_collided_polygons(
155178
const PathWithLaneId & planned_path,
156179
const std::vector<PoseWithVelocityStamped> & predicted_ego_path,
157180
const ExtendedPredictedObject & target_object,
158-
const PredictedPathWithPolygon & target_object_path,
159-
const BehaviorPathPlannerParameters & common_parameters, const RSSparams & rss_parameters,
160-
const double hysteresis_factor, const double max_velocity_limit, const double yaw_difference_th,
161-
CollisionCheckDebug & debug);
181+
const PredictedPathWithPolygon & target_object_path, const VehicleInfo & vehicle_info,
182+
const RSSparams & rss_parameters, const double hysteresis_factor, const double max_velocity_limit,
183+
const double yaw_difference_th, CollisionCheckDebug & debug);
162184

163185
bool checkPolygonsIntersects(
164186
const std::vector<Polygon2d> & polys_1, const std::vector<Polygon2d> & polys_2);
@@ -167,8 +189,30 @@ bool checkSafetyWithIntegralPredictedPolygon(
167189
const ExtendedPredictedObjects & objects, const bool check_all_predicted_path,
168190
const IntegralPredictedPolygonParams & params, CollisionCheckDebugMap & debug_map);
169191

170-
double calcObstacleMinLength(const Shape & shape);
171-
double calcObstacleMaxLength(const Shape & shape);
192+
/**
193+
* @brief Calculates the minimum length from obstacle centroid to outer point.
194+
* @param shape Object shape.
195+
* @return Minimum distance.
196+
*/
197+
double calc_obstacle_min_length(const Shape & shape);
198+
199+
/**
200+
* @brief Calculates the maximum length from obstacle centroid to outer point.
201+
* @param shape Object shape.
202+
* @return Maximum distance.
203+
*/
204+
double calc_obstacle_max_length(const Shape & shape);
205+
206+
/**
207+
* @brief Calculate collision roughly by comparing minimum/maximum distance with margin.
208+
* @param path The path of the ego vehicle.
209+
* @param objects The predicted objects.
210+
* @param margin Distance margin to judge collision.
211+
* @param parameters The common parameters used in behavior path planner.
212+
* @param use_offset_ego_point If true, the closest point to the object is calculated by
213+
* interpolating the path points.
214+
* @return Collision (rough) between minimum distance and maximum distance
215+
*/
172216
std::pair<bool, bool> checkObjectsCollisionRough(
173217
const PathWithLaneId & path, const PredictedObjects & objects, const double margin,
174218
const BehaviorPathPlannerParameters & parameters, const bool use_offset_ego_point);

0 commit comments

Comments
 (0)