Skip to content

Commit d5a6c54

Browse files
authored
feat(lane_change): apply new RTC state (#7152)
* feat(lane_change): support for new RTC state transition Signed-off-by: Fumiya Watanabe <rej55.g@gmail.com> * fix: distance at aborting Signed-off-by: Fumiya Watanabe <rej55.g@gmail.com> * fix(lane_change): empty check Signed-off-by: Fumiya Watanabe <rej55.g@gmail.com> * fix(rtc_interface):update activation depends on RTC state Signed-off-by: Fumiya Watanabe <rej55.g@gmail.com> --------- Signed-off-by: Fumiya Watanabe <rej55.g@gmail.com>
1 parent 88c50b4 commit d5a6c54

File tree

4 files changed

+56
-10
lines changed

4 files changed

+56
-10
lines changed

planning/behavior_path_lane_change_module/include/behavior_path_lane_change_module/interface.hpp

+12
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,18 @@ class LaneChangeInterface : public SceneModuleInterface
125125

126126
ModuleStatus setInitState() const override { return ModuleStatus::WAITING_APPROVAL; };
127127

128+
void updateRTCStatus(
129+
const double start_distance, const double finish_distance, const bool safe,
130+
const uint8_t & state)
131+
{
132+
for (const auto & [module_name, ptr] : rtc_interface_ptr_map_) {
133+
if (ptr) {
134+
ptr->updateCooperateStatus(
135+
uuid_map_.at(module_name), safe, state, start_distance, finish_distance, clock_->now());
136+
}
137+
}
138+
}
139+
128140
void updateDebugMarker() const;
129141

130142
void updateSteeringFactorPtr(const BehaviorModuleOutput & output);

planning/behavior_path_lane_change_module/src/interface.cpp

+18-4
Original file line numberDiff line numberDiff line change
@@ -117,13 +117,18 @@ BehaviorModuleOutput LaneChangeInterface::plan()
117117
updateSteeringFactorPtr(output);
118118
if (module_type_->isAbortState()) {
119119
waitApproval();
120-
removeRTCStatus();
121120
const auto candidate = planCandidate();
122121
path_candidate_ = std::make_shared<PathWithLaneId>(candidate.path_candidate);
123122
updateRTCStatus(
124-
candidate.start_distance_to_path_change, candidate.finish_distance_to_path_change);
123+
std::numeric_limits<double>::lowest(), std::numeric_limits<double>::lowest(), true,
124+
State::ABORTING);
125125
} else {
126126
clearWaitingApproval();
127+
const auto path =
128+
assignToCandidate(module_type_->getLaneChangePath(), module_type_->getEgoPosition());
129+
updateRTCStatus(
130+
path.start_distance_to_path_change, path.finish_distance_to_path_change, true,
131+
State::RUNNING);
127132
}
128133

129134
return output;
@@ -147,7 +152,9 @@ BehaviorModuleOutput LaneChangeInterface::planWaitingApproval()
147152
stop_pose_ = module_type_->getStopPose();
148153

149154
if (!module_type_->isValidPath()) {
150-
removeRTCStatus();
155+
updateRTCStatus(
156+
std::numeric_limits<double>::lowest(), std::numeric_limits<double>::lowest(), true,
157+
State::FAILED);
151158
path_candidate_ = std::make_shared<PathWithLaneId>();
152159
return out;
153160
}
@@ -156,7 +163,8 @@ BehaviorModuleOutput LaneChangeInterface::planWaitingApproval()
156163
path_candidate_ = std::make_shared<PathWithLaneId>(candidate.path_candidate);
157164

158165
updateRTCStatus(
159-
candidate.start_distance_to_path_change, candidate.finish_distance_to_path_change);
166+
candidate.start_distance_to_path_change, candidate.finish_distance_to_path_change,
167+
isExecutionReady(), State::WAITING_FOR_EXECUTION);
160168
is_abort_path_approved_ = false;
161169

162170
return out;
@@ -239,6 +247,9 @@ bool LaneChangeInterface::canTransitFailureState()
239247
if (module_type_->isStoppedAtRedTrafficLight()) {
240248
log_debug_throttled("Stopping at traffic light while in prepare phase. Cancel lane change");
241249
module_type_->toCancelState();
250+
updateRTCStatus(
251+
std::numeric_limits<double>::lowest(), std::numeric_limits<double>::lowest(), true,
252+
State::FAILED);
242253
return true;
243254
}
244255

@@ -249,6 +260,9 @@ bool LaneChangeInterface::canTransitFailureState()
249260

250261
if (module_type_->isAbleToReturnCurrentLane()) {
251262
log_debug_throttled("It's possible to return to current lane. Cancel lane change.");
263+
updateRTCStatus(
264+
std::numeric_limits<double>::lowest(), std::numeric_limits<double>::lowest(), true,
265+
State::FAILED);
252266
return true;
253267
}
254268
}

planning/behavior_path_lane_change_module/src/utils/utils.cpp

+8-2
Original file line numberDiff line numberDiff line change
@@ -646,8 +646,14 @@ std::vector<DrivableLanes> generateDrivableLanes(
646646

647647
double getLateralShift(const LaneChangePath & path)
648648
{
649-
const auto start_idx = path.info.shift_line.start_idx;
650-
const auto end_idx = path.info.shift_line.end_idx;
649+
if (path.shifted_path.shift_length.empty()) {
650+
return 0.0;
651+
}
652+
653+
const auto start_idx =
654+
std::min(path.info.shift_line.start_idx, path.shifted_path.shift_length.size() - 1);
655+
const auto end_idx =
656+
std::min(path.info.shift_line.end_idx, path.shifted_path.shift_length.size() - 1);
651657

652658
return path.shifted_path.shift_length.at(end_idx) - path.shifted_path.shift_length.at(start_idx);
653659
}

planning/rtc_interface/src/rtc_interface.cpp

+18-4
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,16 @@ std::vector<CooperateResponse> RTCInterface::validateCooperateCommands(
153153
registered_status_.statuses.begin(), registered_status_.statuses.end(),
154154
[command](auto & s) { return s.uuid == command.uuid; });
155155
if (itr != registered_status_.statuses.end()) {
156-
response.success = true;
156+
if (itr->state.type == State::WAITING_FOR_EXECUTION || itr->state.type == State::RUNNING) {
157+
response.success = true;
158+
} else {
159+
RCLCPP_WARN_STREAM(
160+
getLogger(), "[validateCooperateCommands] uuid : "
161+
<< to_string(command.uuid)
162+
<< " state is not WAITING_FOR_EXECUTION or RUNNING. state : "
163+
<< itr->state.type << std::endl);
164+
response.success = false;
165+
}
157166
} else {
158167
RCLCPP_WARN_STREAM(
159168
getLogger(), "[validateCooperateCommands] uuid : " << to_string(command.uuid)
@@ -175,8 +184,10 @@ void RTCInterface::updateCooperateCommandStatus(const std::vector<CooperateComma
175184

176185
// Update command if the command has been already received
177186
if (itr != registered_status_.statuses.end()) {
178-
itr->command_status = command.command;
179-
itr->auto_mode = false;
187+
if (itr->state.type == State::WAITING_FOR_EXECUTION || itr->state.type == State::RUNNING) {
188+
itr->command_status = command.command;
189+
itr->auto_mode = false;
190+
}
180191
}
181192
}
182193
}
@@ -219,7 +230,7 @@ void RTCInterface::updateCooperateStatus(
219230
status.module = module_;
220231
status.safe = safe;
221232
status.command_status.type = Command::DEACTIVATE;
222-
status.state.type = State::WAITING_FOR_EXECUTION;
233+
status.state.type = state;
223234
status.start_distance = start_distance;
224235
status.finish_distance = finish_distance;
225236
status.auto_mode = is_auto_mode_enabled_;
@@ -291,6 +302,9 @@ bool RTCInterface::isActivated(const UUID & uuid) const
291302
[uuid](auto & s) { return s.uuid == uuid; });
292303

293304
if (itr != registered_status_.statuses.end()) {
305+
if (itr->state.type == State::FAILED || itr->state.type == State::SUCCEEDED) {
306+
return false;
307+
}
294308
if (itr->auto_mode) {
295309
return itr->safe;
296310
} else {

0 commit comments

Comments
 (0)