@@ -692,7 +692,6 @@ void AvoidanceModule::updateEgoBehavior(const AvoidancePlanningData & data, Shif
692
692
break ;
693
693
}
694
694
case AvoidanceState::YIELD: {
695
- insertYieldVelocity (path);
696
695
insertWaitPoint (isBestEffort (parameters_->policy_deceleration ), path);
697
696
break ;
698
697
}
@@ -1611,24 +1610,6 @@ void AvoidanceModule::insertStopPoint(
1611
1610
getEgoPosition (), stop_distance - MARGIN, 0.0 , shifted_path.path , stop_pose_);
1612
1611
}
1613
1612
1614
- void AvoidanceModule::insertYieldVelocity (ShiftedPath & shifted_path) const
1615
- {
1616
- const auto & p = parameters_;
1617
- const auto & data = avoid_data_;
1618
-
1619
- if (data.target_objects .empty ()) {
1620
- return ;
1621
- }
1622
-
1623
- if (helper_->isShifted ()) {
1624
- return ;
1625
- }
1626
-
1627
- const auto decel_distance = helper_->getFeasibleDecelDistance (p->yield_velocity , false );
1628
- utils::avoidance::insertDecelPoint (
1629
- getEgoPosition (), decel_distance, p->yield_velocity , shifted_path.path , slow_pose_);
1630
- }
1631
-
1632
1613
void AvoidanceModule::insertPrepareVelocity (ShiftedPath & shifted_path) const
1633
1614
{
1634
1615
const auto & data = avoid_data_;
@@ -1648,34 +1629,53 @@ void AvoidanceModule::insertPrepareVelocity(ShiftedPath & shifted_path) const
1648
1629
return ;
1649
1630
}
1650
1631
1651
- const auto object = data.target_objects .front ();
1632
+ const auto itr = std::find_if (
1633
+ data.target_objects .begin (), data.target_objects .end (),
1634
+ [](const auto & o) { return o.avoid_required ; });
1635
+
1636
+ const auto object = [&]() -> std::optional<ObjectData> {
1637
+ if (!data.yield_required ) {
1638
+ return data.target_objects .front ();
1639
+ }
1640
+
1641
+ if (itr == data.target_objects .end ()) {
1642
+ return std::nullopt;
1643
+ }
1644
+
1645
+ return *itr;
1646
+ }();
1647
+
1648
+ // do nothing if it can't avoid at the moment and avoidance is NOT definitely necessary.
1649
+ if (!object.has_value ()) {
1650
+ return ;
1651
+ }
1652
1652
1653
1653
const auto enough_space =
1654
- object.is_avoidable || object.reason == AvoidanceDebugFactor::TOO_LARGE_JERK;
1654
+ object.value (). is_avoidable || object. value () .reason == AvoidanceDebugFactor::TOO_LARGE_JERK;
1655
1655
if (!enough_space) {
1656
1656
return ;
1657
1657
}
1658
1658
1659
1659
// calculate shift length for front object.
1660
1660
const auto & vehicle_width = planner_data_->parameters .vehicle_width ;
1661
- const auto object_type = utils::getHighestProbLabel (object.object .classification );
1661
+ const auto object_type = utils::getHighestProbLabel (object.value (). object .classification );
1662
1662
const auto object_parameter = parameters_->object_parameters .at (object_type);
1663
- const auto avoid_margin = object_parameter.lateral_hard_margin * object.distance_factor +
1663
+ const auto avoid_margin = object_parameter.lateral_hard_margin * object.value (). distance_factor +
1664
1664
object_parameter.lateral_soft_margin + 0.5 * vehicle_width;
1665
- const auto shift_length =
1666
- helper_-> getShiftLength ( object, utils::avoidance::isOnRight (object), avoid_margin);
1665
+ const auto shift_length = helper_-> getShiftLength (
1666
+ object. value () , utils::avoidance::isOnRight (object. value () ), avoid_margin);
1667
1667
1668
1668
// check slow down feasibility
1669
1669
const auto min_avoid_distance = helper_->getMinAvoidanceDistance (shift_length);
1670
- const auto distance_to_object = object.longitudinal ;
1670
+ const auto distance_to_object = object.value (). longitudinal ;
1671
1671
const auto remaining_distance = distance_to_object - min_avoid_distance;
1672
1672
const auto decel_distance = helper_->getFeasibleDecelDistance (parameters_->velocity_map .front ());
1673
1673
if (remaining_distance < decel_distance) {
1674
1674
return ;
1675
1675
}
1676
1676
1677
1677
// decide slow down lower limit.
1678
- const auto lower_speed = object.avoid_required ? 0.0 : parameters_->min_slow_down_speed ;
1678
+ const auto lower_speed = object.value (). avoid_required ? 0.0 : parameters_->min_slow_down_speed ;
1679
1679
1680
1680
// insert slow down speed.
1681
1681
const double current_target_velocity = PathShifter::calcFeasibleVelocityFromJerk (
0 commit comments