Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(rtc_interface, lane_change): check state transition for cooperate status #8855

Merged
merged 5 commits into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 38 additions & 7 deletions planning/autoware_rtc_interface/src/rtc_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -258,20 +258,51 @@
status.module = module_;
status.safe = safe;
status.command_status.type = Command::DEACTIVATE;
status.state.type = state;
status.state.type = State::WAITING_FOR_EXECUTION;
status.start_distance = start_distance;
status.finish_distance = finish_distance;
status.auto_mode = is_auto_mode_enabled_;
registered_status_.statuses.push_back(status);

if (state != State::WAITING_FOR_EXECUTION)
RCLCPP_WARN_STREAM(
getLogger(), "[updateCooperateStatus] Cannot register "
<< state_to_string(state) << " as initial state" << std::endl);

return;
}

auto update_status = [&](auto & status) {
status.stamp = stamp;
status.safe = safe;
status.state.type = state;
status.start_distance = start_distance;
status.finish_distance = finish_distance;
};

// If the registered status is found, update status by considering the state transition
if (
itr->state.type == State::WAITING_FOR_EXECUTION &&
(state == State::WAITING_FOR_EXECUTION || state == State::RUNNING || state == State::FAILED)) {
update_status(*itr);
return;
}

if (itr->state.type == State::RUNNING && state != State::WAITING_FOR_EXECUTION) {
update_status(*itr);
return;
}

// If the registered status is found, update status
itr->stamp = stamp;
itr->safe = safe;
itr->state.type = state;
itr->start_distance = start_distance;
itr->finish_distance = finish_distance;
if (itr->state.type == State::ABORTING && (state == State::ABORTING || state == State::FAILED)) {

Check warning on line 296 in planning/autoware_rtc_interface/src/rtc_interface.cpp

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

❌ New issue: Complex Conditional

RTCInterface::updateCooperateStatus has 2 complex conditionals with 5 branches, threshold = 2. A complex conditional is an expression inside a branch (e.g. if, for, while) which consists of multiple, logical operators such as AND/OR. The more logical operators in an expression, the more severe the code smell.
update_status(*itr);
return;
}

RCLCPP_WARN_STREAM(
getLogger(), "[updateCooperateStatus] uuid : " << uuid_to_string(uuid)
<< " cannot transit from "
<< state_to_string(itr->state.type) << " to "
<< state_to_string(state) << std::endl);

Check notice on line 305 in planning/autoware_rtc_interface/src/rtc_interface.cpp

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

ℹ New issue: Complex Method

RTCInterface::updateCooperateStatus has a cyclomatic complexity of 12, threshold = 9. This function has many conditional statements (e.g. if, for, while), leading to lower code health. Avoid adding more conditionals and code to it without refactoring.
}

void RTCInterface::removeCooperateStatus(const UUID & uuid)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,6 @@ BehaviorModuleOutput LaneChangeInterface::planWaitingApproval()
stop_pose_ = module_type_->getStopPose();

if (!module_type_->isValidPath()) {
updateRTCStatus(
std::numeric_limits<double>::lowest(), std::numeric_limits<double>::lowest(), false,
State::FAILED);
path_candidate_ = std::make_shared<PathWithLaneId>();
return out;
}
Expand Down
Loading