Skip to content

Commit 016adba

Browse files
committed
Revert "fix(avoidance): fix RTC state transition (autowarefoundation#7142)"
This reverts commit d128e47.
1 parent 8199a7b commit 016adba

File tree

4 files changed

+79
-68
lines changed

4 files changed

+79
-68
lines changed

planning/behavior_path_avoidance_module/include/behavior_path_avoidance_module/data_structs.hpp

+8-4
Original file line numberDiff line numberDiff line change
@@ -501,9 +501,11 @@ using AvoidOutlines = std::vector<AvoidOutline>;
501501
* avoidance state
502502
*/
503503
enum class AvoidanceState {
504-
RUNNING = 0,
505-
CANCEL,
506-
SUCCEEDED,
504+
NOT_AVOID = 0,
505+
AVOID_EXECUTE,
506+
YIELD,
507+
AVOID_PATH_READY,
508+
AVOID_PATH_NOT_READY,
507509
};
508510

509511
/*
@@ -512,7 +514,7 @@ enum class AvoidanceState {
512514
struct AvoidancePlanningData
513515
{
514516
// ego final state
515-
AvoidanceState state{AvoidanceState::RUNNING};
517+
AvoidanceState state{AvoidanceState::NOT_AVOID};
516518

517519
// un-shifted pose (for current lane detection)
518520
Pose reference_pose;
@@ -564,6 +566,8 @@ struct AvoidancePlanningData
564566

565567
bool ready{false};
566568

569+
bool success{false};
570+
567571
bool comfortable{false};
568572

569573
bool avoid_required{false};

planning/behavior_path_avoidance_module/include/behavior_path_avoidance_module/scene.hpp

+16-20
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
#include <memory>
3131
#include <string>
3232
#include <unordered_map>
33-
#include <utility>
3433
#include <vector>
3534

3635
namespace behavior_path_planner
@@ -65,14 +64,7 @@ class AvoidanceModule : public SceneModuleInterface
6564
std::shared_ptr<AvoidanceDebugMsgArray> get_debug_msg_array() const;
6665

6766
private:
68-
/**
69-
* @brief return the result whether the module can stop path generation process.
70-
* @param avoidance data.
71-
* @return it will return AvoidanceState::RUNNING when there are obstacles ego should avoid.
72-
* it will return AvoidanceState::CANCEL when all obstacles have gone.
73-
* it will return AvoidanceState::SUCCEEDED when the ego avoid all obstacles.
74-
*/
75-
AvoidanceState getCurrentModuleState(const AvoidancePlanningData & data) const;
67+
bool isSatisfiedSuccessCondition(const AvoidancePlanningData & data) const;
7668

7769
bool canTransitSuccessState() override;
7870

@@ -196,6 +188,14 @@ class AvoidanceModule : public SceneModuleInterface
196188
*/
197189
void updateRTCData();
198190

191+
// ego state check
192+
193+
/**
194+
* @brief update ego status based on avoidance path and surround condition.
195+
* @param ego status. (NOT_AVOID, AVOID, YIELD, AVOID_EXECUTE, AVOID_PATH_NOT_READY)
196+
*/
197+
AvoidanceState updateEgoState(const AvoidancePlanningData & data) const;
198+
199199
// ego behavior update
200200

201201
/**
@@ -359,7 +359,7 @@ class AvoidanceModule : public SceneModuleInterface
359359
* @brief reset registered shift lines.
360360
* @details reset only when the base offset is zero. Otherwise, sudden steering will be caused;
361361
*/
362-
void removeRegisteredShiftLines(const uint8_t state)
362+
void removeRegisteredShiftLines()
363363
{
364364
constexpr double threshold = 0.1;
365365
if (std::abs(path_shifter_.getBaseOffset()) > threshold) {
@@ -370,19 +370,15 @@ class AvoidanceModule : public SceneModuleInterface
370370
unlockNewModuleLaunch();
371371

372372
for (const auto & left_shift : left_shift_array_) {
373-
if (rtc_interface_ptr_map_.at("left")->isRegistered(left_shift.uuid)) {
374-
rtc_interface_ptr_map_.at("left")->updateCooperateStatus(
375-
left_shift.uuid, true, state, std::numeric_limits<double>::lowest(),
376-
std::numeric_limits<double>::lowest(), clock_->now());
377-
}
373+
rtc_interface_ptr_map_.at("left")->updateCooperateStatus(
374+
left_shift.uuid, true, State::FAILED, std::numeric_limits<double>::lowest(),
375+
std::numeric_limits<double>::lowest(), clock_->now());
378376
}
379377

380378
for (const auto & right_shift : right_shift_array_) {
381-
if (rtc_interface_ptr_map_.at("right")->isRegistered(right_shift.uuid)) {
382-
rtc_interface_ptr_map_.at("right")->updateCooperateStatus(
383-
right_shift.uuid, true, state, std::numeric_limits<double>::lowest(),
384-
std::numeric_limits<double>::lowest(), clock_->now());
385-
}
379+
rtc_interface_ptr_map_.at("right")->updateCooperateStatus(
380+
right_shift.uuid, true, State::FAILED, std::numeric_limits<double>::lowest(),
381+
std::numeric_limits<double>::lowest(), clock_->now());
386382
}
387383

388384
if (!path_shifter_.getShiftLines().empty()) {

planning/behavior_path_avoidance_module/src/scene.cpp

+52-38
Original file line numberDiff line numberDiff line change
@@ -115,14 +115,14 @@ bool AvoidanceModule::isExecutionReady() const
115115
return avoid_data_.safe && avoid_data_.comfortable && avoid_data_.valid && avoid_data_.ready;
116116
}
117117

118-
AvoidanceState AvoidanceModule::getCurrentModuleState(const AvoidancePlanningData & data) const
118+
bool AvoidanceModule::isSatisfiedSuccessCondition(const AvoidancePlanningData & data) const
119119
{
120120
const bool has_avoidance_target = std::any_of(
121121
data.target_objects.begin(), data.target_objects.end(),
122122
[this](const auto & o) { return !helper_->isAbsolutelyNotAvoidable(o); });
123123

124124
if (has_avoidance_target) {
125-
return AvoidanceState::RUNNING;
125+
return false;
126126
}
127127

128128
// If the ego is on the shift line, keep RUNNING.
@@ -133,7 +133,7 @@ AvoidanceState AvoidanceModule::getCurrentModuleState(const AvoidancePlanningDat
133133
};
134134
for (const auto & shift_line : path_shifter_.getShiftLines()) {
135135
if (within(shift_line, idx)) {
136-
return AvoidanceState::RUNNING;
136+
return false;
137137
}
138138
}
139139
}
@@ -142,21 +142,17 @@ AvoidanceState AvoidanceModule::getCurrentModuleState(const AvoidancePlanningDat
142142
const bool has_base_offset =
143143
std::abs(path_shifter_.getBaseOffset()) > parameters_->lateral_execution_threshold;
144144

145-
if (has_base_offset) {
146-
return AvoidanceState::RUNNING;
147-
}
148-
149145
// Nothing to do. -> EXIT.
150-
if (!has_shift_point) {
151-
return AvoidanceState::SUCCEEDED;
146+
if (!has_shift_point && !has_base_offset) {
147+
return true;
152148
}
153149

154150
// Be able to canceling avoidance path. -> EXIT.
155151
if (!helper_->isShifted() && parameters_->enable_cancel_maneuver) {
156-
return AvoidanceState::CANCEL;
152+
return true;
157153
}
158154

159-
return AvoidanceState::RUNNING;
155+
return false;
160156
}
161157

162158
bool AvoidanceModule::canTransitSuccessState()
@@ -187,7 +183,7 @@ bool AvoidanceModule::canTransitSuccessState()
187183
}
188184
}
189185

190-
return data.state == AvoidanceState::CANCEL || data.state == AvoidanceState::SUCCEEDED;
186+
return data.success;
191187
}
192188

193189
void AvoidanceModule::fillFundamentalData(AvoidancePlanningData & data, DebugData & debug)
@@ -506,7 +502,7 @@ void AvoidanceModule::fillShiftLine(AvoidancePlanningData & data, DebugData & de
506502
void AvoidanceModule::fillEgoStatus(
507503
AvoidancePlanningData & data, [[maybe_unused]] DebugData & debug) const
508504
{
509-
data.state = getCurrentModuleState(data);
505+
data.success = isSatisfiedSuccessCondition(data);
510506

511507
/**
512508
* Find the nearest object that should be avoid. When the ego follows reference path,
@@ -637,6 +633,27 @@ void AvoidanceModule::fillDebugData(
637633
}
638634
}
639635

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+
640657
void AvoidanceModule::updateEgoBehavior(const AvoidancePlanningData & data, ShiftedPath & path)
641658
{
642659
if (parameters_->disable_path_update) {
@@ -646,30 +663,29 @@ void AvoidanceModule::updateEgoBehavior(const AvoidancePlanningData & data, Shif
646663
insertPrepareVelocity(path);
647664
insertAvoidanceVelocity(path);
648665

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;
653669
}
654-
655-
if (!data.avoid_required) {
656-
return;
670+
case AvoidanceState::YIELD: {
671+
insertWaitPoint(isBestEffort(parameters_->policy_deceleration), path);
672+
break;
657673
}
658-
659-
if (!data.found_avoidance_path) {
674+
case AvoidanceState::AVOID_PATH_NOT_READY: {
660675
insertWaitPoint(isBestEffort(parameters_->policy_deceleration), path);
661-
return;
676+
break;
662677
}
663-
664-
if (isWaitingApproval() && path_shifter_.getShiftLines().empty()) {
678+
case AvoidanceState::AVOID_PATH_READY: {
665679
insertWaitPoint(isBestEffort(parameters_->policy_deceleration), path);
666-
return;
680+
break;
667681
}
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+
}
673689

674690
insertReturnDeadLine(isBestEffort(parameters_->policy_deceleration), path);
675691

@@ -853,16 +869,12 @@ BehaviorModuleOutput AvoidanceModule::plan()
853869

854870
updatePathShifter(data.safe_shift_line);
855871

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();
862874
}
863875

864876
if (data.yield_required) {
865-
removeRegisteredShiftLines(State::FAILED);
877+
removeRegisteredShiftLines();
866878
}
867879

868880
// generate path with shift points that have been inserted.
@@ -929,6 +941,8 @@ BehaviorModuleOutput AvoidanceModule::plan()
929941
spline_shift_path.path, parameters_->resample_interval_for_output);
930942
}
931943

944+
avoid_data_.state = updateEgoState(data);
945+
932946
// update output data
933947
{
934948
updateEgoBehavior(data, spline_shift_path);

planning/behavior_path_planner_common/include/behavior_path_planner_common/interface/scene_module_interface.hpp

+3-6
Original file line numberDiff line numberDiff line change
@@ -522,12 +522,9 @@ class SceneModuleInterface
522522
{
523523
for (const auto & [module_name, ptr] : rtc_interface_ptr_map_) {
524524
if (ptr) {
525-
if (ptr->isRegistered(uuid_map_.at(module_name))) {
526-
ptr->updateCooperateStatus(
527-
uuid_map_.at(module_name), true, State::SUCCEEDED,
528-
std::numeric_limits<double>::lowest(), std::numeric_limits<double>::lowest(),
529-
clock_->now());
530-
}
525+
ptr->updateCooperateStatus(
526+
uuid_map_.at(module_name), true, State::SUCCEEDED, std::numeric_limits<double>::lowest(),
527+
std::numeric_limits<double>::lowest(), clock_->now());
531528
}
532529
}
533530
}

0 commit comments

Comments
 (0)