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