Skip to content

Commit b624c37

Browse files
update
Signed-off-by: Yuki Takagi <yuki.takagi@tier4.jp>
1 parent 58ff7b5 commit b624c37

File tree

2 files changed

+78
-108
lines changed
  • planning/behavior_path_dynamic_avoidance_module

2 files changed

+78
-108
lines changed

planning/behavior_path_dynamic_avoidance_module/include/behavior_path_dynamic_avoidance_module/scene.hpp

+13-6
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,9 @@ enum class PolygonGenerationMethod {
7878
};
7979

8080
enum class ObjectBehaviorType {
81-
NOT_TO_AVOID = 0,
81+
OutOfTarget = 0,
8282
RegulatedObject,
83-
NonRegulatedObject,
83+
PrioritizedObject,
8484
};
8585

8686
struct DynamicAvoidanceParameters
@@ -367,17 +367,22 @@ class DynamicAvoidanceModule : public SceneModuleInterface
367367
const double max_lon_offset;
368368
const double min_lon_offset;
369369
};
370+
struct EgoPathReservePoly
371+
{
372+
const tier4_autoware_utils::MultiPolygon2d left_avoid;
373+
const tier4_autoware_utils::MultiPolygon2d right_avoid;
374+
};
370375

371376
bool canTransitSuccessState() override;
372377

373378
bool canTransitFailureState() override { return false; }
374379

375380
ObjectBehaviorType getLabelAsTargetObstacle(const uint8_t label) const;
376381
void registerLaneDriveObjects(const std::vector<DynamicAvoidanceObject> & prev_objects);
377-
void registerFreeRunObjects(const std::vector<DynamicAvoidanceObject> & prev_objects);
382+
void registerPrioritizedObjects(const std::vector<DynamicAvoidanceObject> & prev_objects);
378383
void determineWhetherToAvoidAgainstLaneDriveObjects(
379384
const std::vector<DynamicAvoidanceObject> & prev_objects);
380-
void determineWhetherToAvoidAgainstFreeRunObjects(
385+
void determineWhetherToAvoidAgainstPrioritizedObjects(
381386
const std::vector<DynamicAvoidanceObject> & prev_objects);
382387
LatFeasiblePaths generateLateralFeasiblePaths(
383388
const geometry_msgs::msg::Pose & ego_pose, const double ego_vel) const;
@@ -425,8 +430,10 @@ class DynamicAvoidanceModule : public SceneModuleInterface
425430
const DynamicAvoidanceObject & object) const;
426431
std::optional<tier4_autoware_utils::Polygon2d> calcObjectPathBasedDynamicObstaclePolygon(
427432
const DynamicAvoidanceObject & object) const;
428-
std::optional<tier4_autoware_utils::Polygon2d> calcFreeRunObstaclePolygon(
429-
const DynamicAvoidanceObject & object, const PathWithLaneId & ego_path) const;
433+
std::optional<tier4_autoware_utils::Polygon2d> calcPrioritizedObstaclePolygon(
434+
const DynamicAvoidanceObject & object, const EgoPathReservePoly & ego_path_poly) const;
435+
EgoPathReservePoly calcEgoPathReservePoly(
436+
const PathWithLaneId & ego_path) const;
430437

431438
void printIgnoreReason(const std::string & obj_uuid, const std::string & reason)
432439
{

planning/behavior_path_dynamic_avoidance_module/src/scene.cpp

+65-102
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,8 @@ bool DynamicAvoidanceModule::isExecutionReady() const
400400

401401
void DynamicAvoidanceModule::updateData()
402402
{
403+
// stop_watch_.tic(std::string(__func__));
404+
403405
info_marker_.markers.clear();
404406
debug_marker_.markers.clear();
405407

@@ -408,14 +410,14 @@ void DynamicAvoidanceModule::updateData()
408410

409411
// 1. Rough filtering of target objects with small computing cost
410412
registerLaneDriveObjects(prev_objects);
411-
registerFreeRunObjects(prev_objects);
413+
registerPrioritizedObjects(prev_objects);
412414

413415
const auto & ego_lat_feasible_paths = generateLateralFeasiblePaths(getEgoPose(), getEgoSpeed());
414416
target_objects_manager_.finalize(ego_lat_feasible_paths);
415417

416418
// 2. Precise filtering of target objects and check if they should be avoided
417419
determineWhetherToAvoidAgainstLaneDriveObjects(prev_objects);
418-
determineWhetherToAvoidAgainstFreeRunObjects(prev_objects);
420+
determineWhetherToAvoidAgainstPrioritizedObjects(prev_objects);
419421

420422
const auto target_objects_candidate = target_objects_manager_.getValidObjects();
421423
target_objects_.clear();
@@ -424,6 +426,10 @@ void DynamicAvoidanceModule::updateData()
424426
target_objects_.push_back(target_object_candidate);
425427
}
426428
}
429+
430+
// const double calculation_time = stop_watch_.toc(std::string(__func__));
431+
// RCLCPP_INFO_STREAM_EXPRESSION(
432+
// getLogger(), parameters_->enable_debug_info, __func__ << ":=" << calculation_time << " [ms]");
427433
}
428434

429435
bool DynamicAvoidanceModule::canTransitSuccessState()
@@ -433,15 +439,18 @@ bool DynamicAvoidanceModule::canTransitSuccessState()
433439

434440
BehaviorModuleOutput DynamicAvoidanceModule::plan()
435441
{
442+
// stop_watch_.tic(std::string(__func__));
443+
436444
const auto & input_path = getPreviousModuleOutput().path;
445+
const auto ego_path_reserve_poly = calcEgoPathReservePoly(input_path);
437446

438447
// create obstacles to avoid (= extract from the drivable area)
439448
std::vector<DrivableAreaInfo::Obstacle> obstacles_for_drivable_area;
440449
for (const auto & object : target_objects_) {
441450
const auto obstacle_poly = [&]() {
442451
if (parameters_->polygon_generation_method == PolygonGenerationMethod::EGO_PATH_BASE) {
443-
if (getLabelAsTargetObstacle(object.label) == ObjectBehaviorType::NonRegulatedObject) {
444-
return calcFreeRunObstaclePolygon(object, input_path);
452+
if (getLabelAsTargetObstacle(object.label) == ObjectBehaviorType::PrioritizedObject) {
453+
return calcPrioritizedObstaclePolygon(object, ego_path_reserve_poly);
445454
} else {
446455
return calcEgoPathBasedDynamicObstaclePolygon(object);
447456
}
@@ -475,6 +484,11 @@ BehaviorModuleOutput DynamicAvoidanceModule::plan()
475484
output.turn_signal_info = getPreviousModuleOutput().turn_signal_info;
476485
output.modified_goal = getPreviousModuleOutput().modified_goal;
477486

487+
// const double calculation_time = stop_watch_.toc(std::string(__func__));
488+
// RCLCPP_INFO_STREAM_EXPRESSION(
489+
// getLogger(), parameters_->enable_debug_info, __func__ << ":=" << calculation_time << "
490+
// [ms]");
491+
478492
return output;
479493
}
480494

@@ -507,18 +521,18 @@ ObjectBehaviorType DynamicAvoidanceModule::getLabelAsTargetObstacle(const uint8_
507521
return ObjectBehaviorType::RegulatedObject;
508522
}
509523
if (label == ObjectClassification::UNKNOWN && parameters_->avoid_unknown) {
510-
return ObjectBehaviorType::NonRegulatedObject;
524+
return ObjectBehaviorType::PrioritizedObject;
511525
}
512526
if (label == ObjectClassification::BICYCLE && parameters_->avoid_bicycle) {
513-
return ObjectBehaviorType::NonRegulatedObject;
527+
return ObjectBehaviorType::PrioritizedObject;
514528
}
515529
if (label == ObjectClassification::MOTORCYCLE && parameters_->avoid_motorcycle) {
516530
return ObjectBehaviorType::RegulatedObject;
517531
}
518532
if (label == ObjectClassification::PEDESTRIAN && parameters_->avoid_pedestrian) {
519-
return ObjectBehaviorType::NonRegulatedObject;
533+
return ObjectBehaviorType::PrioritizedObject;
520534
}
521-
return ObjectBehaviorType::NOT_TO_AVOID;
535+
return ObjectBehaviorType::OutOfTarget;
522536
}
523537

524538
void DynamicAvoidanceModule::registerLaneDriveObjects(
@@ -616,7 +630,7 @@ void DynamicAvoidanceModule::registerLaneDriveObjects(
616630
}
617631
}
618632

619-
void DynamicAvoidanceModule::registerFreeRunObjects(
633+
void DynamicAvoidanceModule::registerPrioritizedObjects(
620634
const std::vector<DynamicAvoidanceObject> & prev_objects)
621635
{
622636
const auto input_path = getPreviousModuleOutput().path;
@@ -637,7 +651,7 @@ void DynamicAvoidanceModule::registerFreeRunObjects(
637651
// 1.a. check label
638652
if (
639653
getLabelAsTargetObstacle(predicted_object.classification.front().label) !=
640-
ObjectBehaviorType::NonRegulatedObject) {
654+
ObjectBehaviorType::PrioritizedObject) {
641655
continue;
642656
}
643657

@@ -661,25 +675,11 @@ void DynamicAvoidanceModule::registerFreeRunObjects(
661675
continue;
662676
}
663677

664-
constexpr double time = 3.0;
665-
constexpr double margin = 2.0;
666-
667678
// 1.e. check if object lateral distance to ego's path is small enough
679+
constexpr double max_ped_obj_lat_offset_to_ego_path{30.0};
668680
const double dist_obj_center_to_path =
669681
std::abs(motion_utils::calcLateralOffset(input_path.points, obj_pose.position));
670-
const double obj_long_radius = calcObstacleMaxLength(predicted_object.shape);
671-
672-
const double space_between_obj_and_ego = dist_obj_center_to_path - obj_long_radius -
673-
planner_data_->parameters.vehicle_width / 2.0 -
674-
obj_vel_norm * time;
675-
676-
debug(dist_obj_center_to_path);
677-
debug(obj_long_radius);
678-
debug(planner_data_->parameters.vehicle_width / 2.0);
679-
debug(obj_vel_norm * time);
680-
debug(space_between_obj_and_ego);
681-
682-
if (space_between_obj_and_ego > margin * 3.0) {
682+
if (dist_obj_center_to_path > max_ped_obj_lat_offset_to_ego_path) {
683683
RCLCPP_INFO_EXPRESSION(
684684
getLogger(), parameters_->enable_debug_info,
685685
"[DynamicAvoidance] Ignore obstacle (%s) since lateral distance (%7.3f) is large.",
@@ -710,7 +710,6 @@ void DynamicAvoidanceModule::registerFreeRunObjects(
710710
predicted_object, obj_tangent_vel, obj_normal_vel, is_object_on_ego_path,
711711
latest_time_inside_ego_path);
712712
target_objects_manager_.updateObject(obj_uuid, target_object);
713-
// std::cerr << "register object: " << obj_uuid << std::endl;
714713
}
715714
}
716715

@@ -874,13 +873,13 @@ void DynamicAvoidanceModule::determineWhetherToAvoidAgainstLaneDriveObjects(
874873
// prev_input_ref_path_points_ = input_ref_path_points;
875874
}
876875

877-
void DynamicAvoidanceModule::determineWhetherToAvoidAgainstFreeRunObjects(
876+
void DynamicAvoidanceModule::determineWhetherToAvoidAgainstPrioritizedObjects(
878877
const std::vector<DynamicAvoidanceObject> & prev_objects)
879878
{
880879
const auto & input_path = getPreviousModuleOutput().path;
881880

882881
for (const auto & object : target_objects_manager_.getValidObjects()) {
883-
if (getLabelAsTargetObstacle(object.label) != ObjectBehaviorType::NonRegulatedObject) {
882+
if (getLabelAsTargetObstacle(object.label) != ObjectBehaviorType::PrioritizedObject) {
884883
continue;
885884
}
886885

@@ -897,52 +896,6 @@ void DynamicAvoidanceModule::determineWhetherToAvoidAgainstFreeRunObjects(
897896
const auto lat_lon_offset =
898897
getLateralLongitudinalOffset(input_path.points, object.pose, object.shape);
899898

900-
// 2.e. check time to collision
901-
// const auto time_while_collision =
902-
// calcTimeWhileCollision(input_path.points, object.vel, lat_lon_offset);
903-
// const double time_to_collision = time_while_collision.time_to_start_collision;
904-
// if (parameters_->max_stopped_object_vel < std::hypot(object.vel, object.lat_vel)) {
905-
// // NOTE: Only not stopped object is filtered by time to collision.
906-
// if (
907-
// (0 <= object.vel &&
908-
// parameters_->max_time_to_collision_overtaking_object < time_to_collision) ||
909-
// (object.vel <= 0 &&
910-
// parameters_->max_time_to_collision_oncoming_object < time_to_collision)) {
911-
// const auto time_to_collision_str = time_to_collision ==
912-
// std::numeric_limits<double>::max()
913-
// ? "infinity"
914-
// : std::to_string(time_to_collision);
915-
// RCLCPP_INFO_EXPRESSION(
916-
// getLogger(), parameters_->enable_debug_info,
917-
// "[DynamicAvoidance] Ignore obstacle (%s) since time to collision (%s) is large.",
918-
// obj_uuid.c_str(), time_to_collision_str.c_str());
919-
// continue;
920-
// }
921-
// if (time_to_collision < -parameters_->duration_to_hold_avoidance_overtaking_object) {
922-
// const auto time_to_collision_str = time_to_collision ==
923-
// std::numeric_limits<double>::max()
924-
// ? "infinity"
925-
// : std::to_string(time_to_collision);
926-
// RCLCPP_INFO_EXPRESSION(
927-
// getLogger(), parameters_->enable_debug_info,
928-
// "[DynamicAvoidance] Ignore obstacle (%s) since time to collision (%s) is a small "
929-
// "negative value.",
930-
// obj_uuid.c_str(), time_to_collision_str.c_str());
931-
// continue;
932-
// }
933-
// }
934-
935-
// 2.f. calculate which side object will be against ego's path
936-
// const bool is_collision_left = [&]() {
937-
// if (0.0 < object.vel) {
938-
// return is_object_left;
939-
// }
940-
// const auto future_obj_pose =
941-
// object_recognition_utils::calcInterpolatedPose(obj_path, time_to_collision);
942-
// return future_obj_pose ? isLeft(input_path.points, future_obj_pose->position)
943-
// : is_object_left;
944-
// }();
945-
946899
// 2.g. check if the ego is not ahead of the object.
947900
const double signed_dist_ego_to_obj = [&]() {
948901
const size_t ego_seg_idx = planner_data_->findEgoSegmentIndex(input_path.points);
@@ -980,19 +933,12 @@ void DynamicAvoidanceModule::determineWhetherToAvoidAgainstFreeRunObjects(
980933
}
981934

982935
const bool is_collision_left = (lat_offset_to_avoid.value().max_value > 0.0);
983-
984-
// const auto obj_points = tier4_autoware_utils::toPolygon2d(object.pose, object.shape);
985-
// const auto lon_offset_to_avoid = calcMinMaxLongitudinalOffsetToAvoid(
986-
// ref_path_points_for_obj_poly, object.pose, obj_points, object.vel, obj_path, object.shape,
987-
// time_while_collision);
988-
989936
const auto lon_offset_to_avoid = MinMaxValue{0.0, 1.0}; // not used. dummy value
990937

991938
const bool should_be_avoided = true;
992939
target_objects_manager_.updateObjectVariables(
993940
obj_uuid, lon_offset_to_avoid, *lat_offset_to_avoid, is_collision_left, should_be_avoided,
994941
ref_path_points_for_obj_poly);
995-
// std::cerr << "labeling as avoid object: " << obj_uuid << std::endl;
996942
}
997943
}
998944

@@ -1842,11 +1788,10 @@ DynamicAvoidanceModule::calcObjectPathBasedDynamicObstaclePolygon(
18421788
return obj_poly;
18431789
}
18441790

1845-
std::optional<tier4_autoware_utils::Polygon2d> DynamicAvoidanceModule::calcFreeRunObstaclePolygon(
1846-
const DynamicAvoidanceObject & object, const PathWithLaneId & ego_path) const
1791+
std::optional<tier4_autoware_utils::Polygon2d>
1792+
DynamicAvoidanceModule::calcPrioritizedObstaclePolygon(
1793+
const DynamicAvoidanceObject & object, const EgoPathReservePoly & ego_path_poly) const
18471794
{
1848-
stop_watch_.tic(__func__);
1849-
18501795
constexpr double end_time_to_consider = 3.0;
18511796
constexpr double required_confidence = 0.3;
18521797

@@ -1862,7 +1807,7 @@ std::optional<tier4_autoware_utils::Polygon2d> DynamicAvoidanceModule::calcFreeR
18621807
}
18631808
}
18641809

1865-
constexpr double deviation_scale = 1.0;
1810+
constexpr double deviation_scale = 0.0;
18661811

18671812
tier4_autoware_utils::Polygon2d obj_points_as_poly;
18681813
const double obj_half_length =
@@ -1900,33 +1845,51 @@ std::optional<tier4_autoware_utils::Polygon2d> DynamicAvoidanceModule::calcFreeR
19001845
strategy::point_circle());
19011846
if (expanded_poly.empty()) return {};
19021847

1903-
// chack intersects and overwrite by the ego's path
1848+
tier4_autoware_utils::MultiPolygon2d output_poly;
1849+
boost::geometry::difference(
1850+
expanded_poly[0],
1851+
object.is_collision_left ? ego_path_poly.right_avoid : ego_path_poly.left_avoid, output_poly);
1852+
if (output_poly.empty()) return {};
1853+
1854+
return output_poly[0];
1855+
}
1856+
1857+
DynamicAvoidanceModule::EgoPathReservePoly DynamicAvoidanceModule::calcEgoPathReservePoly(
1858+
const PathWithLaneId & ego_path) const
1859+
{
1860+
// stop_watch_.tic(std::string(__func__));
1861+
19041862
tier4_autoware_utils::LineString2d ego_path_lines;
19051863
for (const auto & path_point : ego_path.points) {
19061864
ego_path_lines.push_back(tier4_autoware_utils::fromMsg(path_point.point.pose.position).to_2d());
19071865
}
1908-
// if (boost::geometry::intersects(expanded_poly[0], ego_path_lines)) return {};
19091866

19101867
const double path_half_width =
19111868
planner_data_->parameters.vehicle_width / 2.0 - parameters_->max_lat_offset_to_avoid;
1912-
strategy::distance_asymmetric<double> distance_strategy(
1913-
object.is_collision_left ? path_half_width : 10.0,
1914-
object.is_collision_left ? 10.0 : path_half_width);
1869+
constexpr double reserve_width = 3.0;
1870+
namespace strategy = boost::geometry::strategy::buffer;
19151871

1916-
tier4_autoware_utils::MultiPolygon2d ego_path_restriction_poly;
1872+
strategy::distance_asymmetric<double> left_avoid_distance_strategy{
1873+
reserve_width, path_half_width};
1874+
strategy::distance_asymmetric<double> right_avoid_distance_strategy{
1875+
path_half_width, reserve_width};
1876+
1877+
tier4_autoware_utils::MultiPolygon2d left_avoid_poly;
19171878
boost::geometry::buffer(
1918-
ego_path_lines, ego_path_restriction_poly, distance_strategy, strategy::side_straight(),
1919-
strategy::join_miter(), strategy::end_flat(), strategy::point_square());
1879+
ego_path_lines, left_avoid_poly, left_avoid_distance_strategy, strategy::side_straight(),
1880+
strategy::join_round(), strategy::end_flat(), strategy::point_square());
19201881

1921-
tier4_autoware_utils::MultiPolygon2d output_poly;
1922-
boost::geometry::difference(expanded_poly[0], ego_path_restriction_poly, output_poly);
1923-
if (output_poly.empty()) return {};
1882+
tier4_autoware_utils::MultiPolygon2d right_avoid_poly;
1883+
boost::geometry::buffer(
1884+
ego_path_lines, right_avoid_poly, right_avoid_distance_strategy, strategy::side_straight(),
1885+
strategy::join_round(), strategy::end_flat(), strategy::point_square());
19241886

1925-
const double calculation_time = stop_watch_.toc(__func__);
1926-
RCLCPP_INFO_EXPRESSION(
1927-
getLogger(), parameters_->enable_debug_info, " %s := %f [ms]", __func__, calculation_time);
1887+
// const double calculation_time = stop_watch_.toc(std::string(__func__));
1888+
// RCLCPP_INFO_STREAM_EXPRESSION(
1889+
// getLogger(), parameters_->enable_debug_info, __func__ << ":=" << calculation_time << "
1890+
// [ms]");
19281891

1929-
return output_poly[0];
1892+
return {left_avoid_poly, right_avoid_poly};
19301893
}
19311894

19321895
} // namespace behavior_path_planner

0 commit comments

Comments
 (0)