@@ -115,14 +115,14 @@ bool AvoidanceModule::isExecutionReady() const
115
115
return avoid_data_.safe && avoid_data_.comfortable && avoid_data_.valid && avoid_data_.ready ;
116
116
}
117
117
118
- bool AvoidanceModule::isSatisfiedSuccessCondition (const AvoidancePlanningData & data) const
118
+ AvoidanceState AvoidanceModule::getCurrentModuleState (const AvoidancePlanningData & data) const
119
119
{
120
120
const bool has_avoidance_target = std::any_of (
121
121
data.target_objects .begin (), data.target_objects .end (),
122
122
[this ](const auto & o) { return !helper_->isAbsolutelyNotAvoidable (o); });
123
123
124
124
if (has_avoidance_target) {
125
- return false ;
125
+ return AvoidanceState::RUNNING ;
126
126
}
127
127
128
128
// If the ego is on the shift line, keep RUNNING.
@@ -133,7 +133,7 @@ bool AvoidanceModule::isSatisfiedSuccessCondition(const AvoidancePlanningData &
133
133
};
134
134
for (const auto & shift_line : path_shifter_.getShiftLines ()) {
135
135
if (within (shift_line, idx)) {
136
- return false ;
136
+ return AvoidanceState::RUNNING ;
137
137
}
138
138
}
139
139
}
@@ -142,17 +142,21 @@ bool AvoidanceModule::isSatisfiedSuccessCondition(const AvoidancePlanningData &
142
142
const bool has_base_offset =
143
143
std::abs (path_shifter_.getBaseOffset ()) > parameters_->lateral_execution_threshold ;
144
144
145
+ if (has_base_offset) {
146
+ return AvoidanceState::RUNNING;
147
+ }
148
+
145
149
// Nothing to do. -> EXIT.
146
- if (!has_shift_point && !has_base_offset ) {
147
- return true ;
150
+ if (!has_shift_point) {
151
+ return AvoidanceState::SUCCEEDED ;
148
152
}
149
153
150
154
// Be able to canceling avoidance path. -> EXIT.
151
155
if (!helper_->isShifted () && parameters_->enable_cancel_maneuver ) {
152
- return true ;
156
+ return AvoidanceState::CANCEL ;
153
157
}
154
158
155
- return false ;
159
+ return AvoidanceState::RUNNING ;
156
160
}
157
161
158
162
bool AvoidanceModule::canTransitSuccessState ()
@@ -183,7 +187,7 @@ bool AvoidanceModule::canTransitSuccessState()
183
187
}
184
188
}
185
189
186
- return data.success ;
190
+ return data.state == AvoidanceState::CANCEL || data. state == AvoidanceState::SUCCEEDED ;
187
191
}
188
192
189
193
void AvoidanceModule::fillFundamentalData (AvoidancePlanningData & data, DebugData & debug)
@@ -502,7 +506,7 @@ void AvoidanceModule::fillShiftLine(AvoidancePlanningData & data, DebugData & de
502
506
void AvoidanceModule::fillEgoStatus (
503
507
AvoidancePlanningData & data, [[maybe_unused]] DebugData & debug) const
504
508
{
505
- data.success = isSatisfiedSuccessCondition (data);
509
+ data.state = getCurrentModuleState (data);
506
510
507
511
/* *
508
512
* Find the nearest object that should be avoid. When the ego follows reference path,
@@ -633,27 +637,6 @@ void AvoidanceModule::fillDebugData(
633
637
}
634
638
}
635
639
636
- AvoidanceState AvoidanceModule::updateEgoState (const AvoidancePlanningData & data) const
637
- {
638
- if (data.yield_required ) {
639
- return AvoidanceState::YIELD;
640
- }
641
-
642
- if (!data.avoid_required ) {
643
- return AvoidanceState::NOT_AVOID;
644
- }
645
-
646
- if (!data.found_avoidance_path ) {
647
- return AvoidanceState::AVOID_PATH_NOT_READY;
648
- }
649
-
650
- if (isWaitingApproval () && path_shifter_.getShiftLines ().empty ()) {
651
- return AvoidanceState::AVOID_PATH_READY;
652
- }
653
-
654
- return AvoidanceState::AVOID_EXECUTE;
655
- }
656
-
657
640
void AvoidanceModule::updateEgoBehavior (const AvoidancePlanningData & data, ShiftedPath & path)
658
641
{
659
642
if (parameters_->disable_path_update ) {
@@ -663,29 +646,30 @@ void AvoidanceModule::updateEgoBehavior(const AvoidancePlanningData & data, Shif
663
646
insertPrepareVelocity (path);
664
647
insertAvoidanceVelocity (path);
665
648
666
- switch (data.state ) {
667
- case AvoidanceState::NOT_AVOID: {
668
- break ;
669
- }
670
- case AvoidanceState::YIELD: {
649
+ const auto insert_velocity = [this , &data, &path]() {
650
+ if (data.yield_required ) {
671
651
insertWaitPoint (isBestEffort (parameters_->policy_deceleration ), path);
672
- break ;
652
+ return ;
673
653
}
674
- case AvoidanceState::AVOID_PATH_NOT_READY: {
675
- insertWaitPoint ( isBestEffort (parameters_-> policy_deceleration ), path);
676
- break ;
654
+
655
+ if (!data. avoid_required ) {
656
+ return ;
677
657
}
678
- case AvoidanceState::AVOID_PATH_READY: {
658
+
659
+ if (!data.found_avoidance_path ) {
679
660
insertWaitPoint (isBestEffort (parameters_->policy_deceleration ), path);
680
- break ;
661
+ return ;
681
662
}
682
- case AvoidanceState::AVOID_EXECUTE: {
683
- insertStopPoint (isBestEffort (parameters_->policy_deceleration ), path);
684
- break ;
663
+
664
+ if (isWaitingApproval () && path_shifter_.getShiftLines ().empty ()) {
665
+ insertWaitPoint (isBestEffort (parameters_->policy_deceleration ), path);
666
+ return ;
685
667
}
686
- default :
687
- throw std::domain_error (" invalid behavior" );
688
- }
668
+
669
+ insertStopPoint (isBestEffort (parameters_->policy_deceleration ), path);
670
+ };
671
+
672
+ insert_velocity ();
689
673
690
674
insertReturnDeadLine (isBestEffort (parameters_->policy_deceleration ), path);
691
675
@@ -869,12 +853,16 @@ BehaviorModuleOutput AvoidanceModule::plan()
869
853
870
854
updatePathShifter (data.safe_shift_line );
871
855
872
- if (data.success ) {
873
- removeRegisteredShiftLines ();
856
+ if (data.state == AvoidanceState::SUCCEEDED) {
857
+ removeRegisteredShiftLines (State::SUCCEEDED);
858
+ }
859
+
860
+ if (data.state == AvoidanceState::CANCEL) {
861
+ removeRegisteredShiftLines (State::FAILED);
874
862
}
875
863
876
864
if (data.yield_required ) {
877
- removeRegisteredShiftLines ();
865
+ removeRegisteredShiftLines (State::FAILED );
878
866
}
879
867
880
868
// generate path with shift points that have been inserted.
@@ -941,8 +929,6 @@ BehaviorModuleOutput AvoidanceModule::plan()
941
929
spline_shift_path.path , parameters_->resample_interval_for_output );
942
930
}
943
931
944
- avoid_data_.state = updateEgoState (data);
945
-
946
932
// update output data
947
933
{
948
934
updateEgoBehavior (data, spline_shift_path);
0 commit comments