Skip to content

Commit fb4b21c

Browse files
committed
refactor(avoidance): filtering logic for vehicle type objects
Signed-off-by: satoshi-ota <satoshi.ota928@gmail.com>
1 parent ddd8066 commit fb4b21c

File tree

3 files changed

+134
-66
lines changed

3 files changed

+134
-66
lines changed

planning/behavior_path_avoidance_module/src/debug.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -579,6 +579,8 @@ MarkerArray createDebugMarkerArray(
579579
addObjects(data.other_objects, std::string("ParallelToEgoLane"));
580580
addObjects(data.other_objects, std::string("MergingToEgoLane"));
581581
addObjects(data.other_objects, std::string("UnstableObject"));
582+
addObjects(data.other_objects, std::string("AmbiguousStoppedVehicle"));
583+
addObjects(data.other_objects, std::string("AmbiguousStoppedVehicle(wait-and-see)"));
582584
}
583585

584586
// shift line pre-process

planning/behavior_path_avoidance_module/src/shift_line_generator.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ AvoidOutlines ShiftLineGenerator::generateAvoidOutline(
277277
// calculate feasible shift length based on behavior policy
278278
const auto feasible_shift_profile = get_shift_profile(o, desire_shift_length);
279279

280-
if (o.is_ambiguous && o.behavior == ObjectData::Behavior::MERGING) {
280+
if (o.is_ambiguous) {
281281
const auto prepare_distance = helper_->getMinimumPrepareDistance();
282282
const auto constant_distance = helper_->getFrontConstantDistance(o);
283283
const auto avoidance_distance = helper_->getMinAvoidanceDistance(desire_shift_length);

planning/behavior_path_avoidance_module/src/utils.cpp

+131-65
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,8 @@ bool isMergingToEgoLane(const ObjectData & object)
525525
}
526526

527527
bool isParkedVehicle(
528-
ObjectData & object, const std::shared_ptr<RouteHandler> & route_handler,
528+
ObjectData & object, const AvoidancePlanningData & data,
529+
const std::shared_ptr<RouteHandler> & route_handler,
529530
const std::shared_ptr<AvoidanceParameters> & parameters)
530531
{
531532
using lanelet::geometry::distance2d;
@@ -622,57 +623,36 @@ bool isParkedVehicle(
622623
object.shiftable_ratio > parameters->object_check_shiftable_ratio;
623624
}
624625

625-
return is_left_side_parked_vehicle || is_right_side_parked_vehicle;
626-
}
627-
628-
bool isAmbiguousStoppedVehicle(
629-
ObjectData & object, const AvoidancePlanningData & data,
630-
const std::shared_ptr<const PlannerData> & planner_data,
631-
const std::shared_ptr<AvoidanceParameters> & parameters)
632-
{
633-
const auto stop_time_longer_than_threshold =
634-
object.stop_time > parameters->threshold_time_force_avoidance_for_stopped_vehicle;
635-
636-
if (!stop_time_longer_than_threshold) {
626+
if (!is_left_side_parked_vehicle && !is_right_side_parked_vehicle) {
637627
return false;
638628
}
639629

640630
const auto & object_pose = object.object.kinematics.initial_pose_with_covariance.pose;
641-
const auto is_moving_distance_longer_than_threshold =
642-
tier4_autoware_utils::calcDistance2d(object.init_pose, object_pose) >
643-
parameters->force_avoidance_distance_threshold;
644-
645-
if (is_moving_distance_longer_than_threshold) {
646-
return false;
647-
}
648-
649-
if (object.is_within_intersection) {
650-
RCLCPP_DEBUG(rclcpp::get_logger(__func__), "object is in the intersection area.");
651-
return false;
652-
}
653-
654-
const auto rh = planner_data->route_handler;
655-
656-
if (
657-
!!rh->getRoutingGraphPtr()->right(object.overhang_lanelet) &&
658-
!!rh->getRoutingGraphPtr()->left(object.overhang_lanelet)) {
659-
RCLCPP_DEBUG(rclcpp::get_logger(__func__), "object isn't on the edge lane.");
631+
object.to_centerline =
632+
lanelet::utils::getArcCoordinates(data.current_lanelets, object_pose).distance;
633+
if (std::abs(object.to_centerline) < parameters->threshold_distance_object_is_on_center) {
660634
return false;
661635
}
662636

663-
if (!object.is_on_ego_lane) {
664-
return true;
665-
}
637+
return true;
638+
}
666639

640+
bool isCloseToStopFactor(
641+
ObjectData & object, const AvoidancePlanningData & data,
642+
const std::shared_ptr<const PlannerData> & planner_data,
643+
const std::shared_ptr<AvoidanceParameters> & parameters)
644+
{
645+
const auto & rh = planner_data->route_handler;
667646
const auto & ego_pose = planner_data->self_odometry->pose.pose;
647+
const auto & object_pose = object.object.kinematics.initial_pose_with_covariance.pose;
668648

669649
// force avoidance for stopped vehicle
670-
bool not_parked_object = true;
650+
bool is_close_to_stop_factor = false;
671651

672652
// check traffic light
673653
const auto to_traffic_light = getDistanceToNextTrafficLight(object_pose, data.extend_lanelets);
674654
{
675-
not_parked_object =
655+
is_close_to_stop_factor =
676656
to_traffic_light < parameters->object_ignore_section_traffic_light_in_front_distance;
677657
}
678658

@@ -684,12 +664,89 @@ bool isAmbiguousStoppedVehicle(
684664
const auto stop_for_crosswalk =
685665
to_crosswalk < parameters->object_ignore_section_crosswalk_in_front_distance &&
686666
to_crosswalk > -1.0 * parameters->object_ignore_section_crosswalk_behind_distance;
687-
not_parked_object = not_parked_object || stop_for_crosswalk;
667+
is_close_to_stop_factor = is_close_to_stop_factor || stop_for_crosswalk;
688668
}
689669

690670
object.to_stop_factor_distance = std::min(to_traffic_light, to_crosswalk);
691671

692-
return !not_parked_object;
672+
return is_close_to_stop_factor;
673+
}
674+
675+
bool isNeverAvoidanceTarget(
676+
ObjectData & object, const AvoidancePlanningData & data,
677+
const std::shared_ptr<const PlannerData> & planner_data,
678+
const std::shared_ptr<AvoidanceParameters> & parameters)
679+
{
680+
const auto & object_pose = object.object.kinematics.initial_pose_with_covariance.pose;
681+
const auto is_moving_distance_longer_than_threshold =
682+
tier4_autoware_utils::calcDistance2d(object.init_pose, object_pose) >
683+
parameters->force_avoidance_distance_threshold;
684+
if (is_moving_distance_longer_than_threshold) {
685+
object.reason = AvoidanceDebugFactor::MOVING_OBJECT;
686+
return true;
687+
}
688+
689+
if (object.is_within_intersection) {
690+
if (object.behavior == ObjectData::Behavior::NONE) {
691+
object.reason = "ParallelToEgoLane";
692+
RCLCPP_DEBUG(rclcpp::get_logger(__func__), "object belongs to ego lane. never avoid it.");
693+
return true;
694+
}
695+
696+
if (object.behavior == ObjectData::Behavior::MERGING) {
697+
object.reason = "MergingToEgoLane";
698+
RCLCPP_DEBUG(rclcpp::get_logger(__func__), "object belongs to ego lane. never avoid it.");
699+
return true;
700+
}
701+
}
702+
703+
if (object.is_on_ego_lane) {
704+
if (
705+
!!planner_data->route_handler->getRoutingGraphPtr()->right(object.overhang_lanelet) &&
706+
!!planner_data->route_handler->getRoutingGraphPtr()->left(object.overhang_lanelet)) {
707+
object.reason = AvoidanceDebugFactor::NOT_PARKING_OBJECT;
708+
RCLCPP_DEBUG(rclcpp::get_logger(__func__), "object isn't on the edge lane. never avoid it.");
709+
return true;
710+
}
711+
}
712+
713+
if (isCloseToStopFactor(object, data, planner_data, parameters)) {
714+
if (object.is_on_ego_lane && !object.is_parked) {
715+
object.reason = AvoidanceDebugFactor::NOT_PARKING_OBJECT;
716+
RCLCPP_DEBUG(rclcpp::get_logger(__func__), "object is close to stop factor. never avoid it.");
717+
return true;
718+
}
719+
}
720+
721+
return false;
722+
}
723+
724+
bool isObviousAvoidanceTarget(
725+
ObjectData & object, [[maybe_unused]] const AvoidancePlanningData & data,
726+
[[maybe_unused]] const std::shared_ptr<const PlannerData> & planner_data,
727+
[[maybe_unused]] const std::shared_ptr<AvoidanceParameters> & parameters)
728+
{
729+
if (!object.is_within_intersection) {
730+
if (object.is_parked && object.behavior == ObjectData::Behavior::NONE) {
731+
RCLCPP_DEBUG(rclcpp::get_logger(__func__), "object is obvious parked vehicle.");
732+
return true;
733+
}
734+
735+
if (!object.is_on_ego_lane && object.behavior == ObjectData::Behavior::NONE) {
736+
RCLCPP_DEBUG(rclcpp::get_logger(__func__), "object is adjacent vehicle.");
737+
return true;
738+
}
739+
}
740+
741+
if (!object.is_parked) {
742+
object.reason = AvoidanceDebugFactor::NOT_PARKING_OBJECT;
743+
}
744+
745+
if (object.behavior == ObjectData::Behavior::MERGING) {
746+
object.reason = "MergingToEgoLane";
747+
}
748+
749+
return false;
693750
}
694751

695752
bool isSatisfiedWithCommonCondition(
@@ -792,45 +849,53 @@ bool isSatisfiedWithVehicleCondition(
792849
{
793850
object.behavior = getObjectBehavior(object, parameters);
794851
object.is_on_ego_lane = isOnEgoLane(object);
795-
object.is_ambiguous = isAmbiguousStoppedVehicle(object, data, planner_data, parameters);
796852

797-
// from here condition check for vehicle type objects.
798-
if (object.is_ambiguous && parameters->enable_force_avoidance_for_stopped_vehicle) {
853+
if (isNeverAvoidanceTarget(object, data, planner_data, parameters)) {
854+
return false;
855+
}
856+
857+
if (isObviousAvoidanceTarget(object, data, planner_data, parameters)) {
799858
return true;
800859
}
801860

802-
// check vehicle shift ratio
803-
if (object.is_on_ego_lane) {
804-
if (object.is_parked) {
805-
return true;
806-
} else {
807-
object.reason = AvoidanceDebugFactor::NOT_PARKING_OBJECT;
808-
return false;
809-
}
861+
// from here, filtering for ambiguous vehicle.
862+
863+
if (!parameters->enable_force_avoidance_for_stopped_vehicle) {
864+
object.reason = "AmbiguousStoppedVehicle";
865+
return false;
810866
}
811867

812-
// Object is on center line -> ignore.
813-
const auto & object_pose = object.object.kinematics.initial_pose_with_covariance.pose;
814-
object.to_centerline =
815-
lanelet::utils::getArcCoordinates(data.current_lanelets, object_pose).distance;
816-
if (std::abs(object.to_centerline) < parameters->threshold_distance_object_is_on_center) {
817-
object.reason = AvoidanceDebugFactor::TOO_NEAR_TO_CENTERLINE;
868+
const auto stop_time_longer_than_threshold =
869+
object.stop_time > parameters->threshold_time_force_avoidance_for_stopped_vehicle;
870+
if (!stop_time_longer_than_threshold) {
871+
object.reason = "AmbiguousStoppedVehicle(wait-and-see)";
818872
return false;
819873
}
820874

821875
if (object.is_within_intersection) {
822-
if (object.behavior == ObjectData::Behavior::NONE) {
823-
object.reason = "ParallelToEgoLane";
824-
return false;
876+
if (object.behavior == ObjectData::Behavior::DEVIATING) {
877+
object.is_ambiguous = true;
878+
return true;
879+
}
880+
} else {
881+
if (object.behavior == ObjectData::Behavior::MERGING) {
882+
object.is_ambiguous = true;
883+
return true;
825884
}
826-
}
827885

828-
if (object.behavior == ObjectData::Behavior::MERGING) {
829-
object.reason = "MergingToEgoLane";
830-
return false;
886+
if (object.behavior == ObjectData::Behavior::DEVIATING) {
887+
object.is_ambiguous = true;
888+
return true;
889+
}
890+
891+
if (object.behavior == ObjectData::Behavior::NONE) {
892+
object.is_ambiguous = false;
893+
return true;
894+
}
831895
}
832896

833-
return true;
897+
object.reason = AvoidanceDebugFactor::NOT_PARKING_OBJECT;
898+
return false;
834899
}
835900

836901
bool isNoNeedAvoidanceBehavior(
@@ -1757,7 +1822,8 @@ void filterTargetObjects(
17571822
if (filtering_utils::isVehicleTypeObject(o)) {
17581823
o.is_within_intersection =
17591824
filtering_utils::isWithinIntersection(o, planner_data->route_handler);
1760-
o.is_parked = filtering_utils::isParkedVehicle(o, planner_data->route_handler, parameters);
1825+
o.is_parked =
1826+
filtering_utils::isParkedVehicle(o, data, planner_data->route_handler, parameters);
17611827
o.avoid_margin = filtering_utils::getAvoidMargin(o, planner_data, parameters);
17621828

17631829
if (filtering_utils::isNoNeedAvoidanceBehavior(o, parameters)) {

0 commit comments

Comments
 (0)