@@ -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
}
@@ -1525,6 +1524,11 @@ void AvoidanceModule::insertWaitPoint(
1525
1524
{
1526
1525
const auto & data = avoid_data_;
1527
1526
1527
+ // If avoidance path is NOT valid, don't insert any stop points.
1528
+ if (!data.valid ) {
1529
+ return ;
1530
+ }
1531
+
1528
1532
if (!data.stop_target_object ) {
1529
1533
return ;
1530
1534
}
@@ -1611,28 +1615,20 @@ void AvoidanceModule::insertStopPoint(
1611
1615
getEgoPosition (), stop_distance - MARGIN, 0.0 , shifted_path.path , stop_pose_);
1612
1616
}
1613
1617
1614
- void AvoidanceModule::insertYieldVelocity (ShiftedPath & shifted_path) const
1618
+ void AvoidanceModule::insertPrepareVelocity (ShiftedPath & shifted_path) const
1615
1619
{
1616
- const auto & p = parameters_;
1617
1620
const auto & data = avoid_data_;
1618
1621
1619
- if (data.target_objects .empty ()) {
1622
+ // If avoidance path is NOT safe, don't insert any slow down sections.
1623
+ if (!data.safe && !data.stop_target_object ) {
1620
1624
return ;
1621
1625
}
1622
1626
1623
- if (helper_->isShifted ()) {
1627
+ // If avoidance path is NOT safe, don't insert any slow down sections.
1628
+ if (!data.valid ) {
1624
1629
return ;
1625
1630
}
1626
1631
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
- void AvoidanceModule::insertPrepareVelocity (ShiftedPath & shifted_path) const
1633
- {
1634
- const auto & data = avoid_data_;
1635
-
1636
1632
// do nothing if there is no avoidance target.
1637
1633
if (data.target_objects .empty ()) {
1638
1634
return ;
@@ -1648,34 +1644,53 @@ void AvoidanceModule::insertPrepareVelocity(ShiftedPath & shifted_path) const
1648
1644
return ;
1649
1645
}
1650
1646
1651
- const auto object = data.target_objects .front ();
1647
+ const auto itr = std::find_if (
1648
+ data.target_objects .begin (), data.target_objects .end (),
1649
+ [](const auto & o) { return o.avoid_required ; });
1650
+
1651
+ const auto object = [&]() -> std::optional<ObjectData> {
1652
+ if (!data.yield_required ) {
1653
+ return data.target_objects .front ();
1654
+ }
1655
+
1656
+ if (itr == data.target_objects .end ()) {
1657
+ return std::nullopt;
1658
+ }
1659
+
1660
+ return *itr;
1661
+ }();
1662
+
1663
+ // do nothing if it can't avoid at the moment and avoidance is NOT definitely necessary.
1664
+ if (!object.has_value ()) {
1665
+ return ;
1666
+ }
1652
1667
1653
1668
const auto enough_space =
1654
- object.is_avoidable || object.reason == AvoidanceDebugFactor::TOO_LARGE_JERK;
1669
+ object.value (). is_avoidable || object. value () .reason == AvoidanceDebugFactor::TOO_LARGE_JERK;
1655
1670
if (!enough_space) {
1656
1671
return ;
1657
1672
}
1658
1673
1659
1674
// calculate shift length for front object.
1660
1675
const auto & vehicle_width = planner_data_->parameters .vehicle_width ;
1661
- const auto object_type = utils::getHighestProbLabel (object.object .classification );
1676
+ const auto object_type = utils::getHighestProbLabel (object.value (). object .classification );
1662
1677
const auto object_parameter = parameters_->object_parameters .at (object_type);
1663
- const auto avoid_margin = object_parameter.lateral_hard_margin * object.distance_factor +
1678
+ const auto avoid_margin = object_parameter.lateral_hard_margin * object.value (). distance_factor +
1664
1679
object_parameter.lateral_soft_margin + 0.5 * vehicle_width;
1665
- const auto shift_length =
1666
- helper_-> getShiftLength ( object, utils::avoidance::isOnRight (object), avoid_margin);
1680
+ const auto shift_length = helper_-> getShiftLength (
1681
+ object. value () , utils::avoidance::isOnRight (object. value () ), avoid_margin);
1667
1682
1668
1683
// check slow down feasibility
1669
1684
const auto min_avoid_distance = helper_->getMinAvoidanceDistance (shift_length);
1670
- const auto distance_to_object = object.longitudinal ;
1685
+ const auto distance_to_object = object.value (). longitudinal ;
1671
1686
const auto remaining_distance = distance_to_object - min_avoid_distance;
1672
1687
const auto decel_distance = helper_->getFeasibleDecelDistance (parameters_->velocity_map .front ());
1673
1688
if (remaining_distance < decel_distance) {
1674
1689
return ;
1675
1690
}
1676
1691
1677
1692
// decide slow down lower limit.
1678
- const auto lower_speed = object.avoid_required ? 0.0 : parameters_->min_slow_down_speed ;
1693
+ const auto lower_speed = object.value (). avoid_required ? 0.0 : parameters_->min_slow_down_speed ;
1679
1694
1680
1695
// insert slow down speed.
1681
1696
const double current_target_velocity = PathShifter::calcFeasibleVelocityFromJerk (
0 commit comments