Skip to content

Commit 6b25dcb

Browse files
authored
Merge pull request #1584 from tier4/fix/concealer-7/transition
2 parents 9eb16c3 + eb3293f commit 6b25dcb

File tree

3 files changed

+38
-7
lines changed

3 files changed

+38
-7
lines changed

external/concealer/include/concealer/field_operator_application.hpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,14 +124,19 @@ struct FieldOperatorApplication : public rclcpp::Node
124124

125125
template <typename Thunk = void (*)()>
126126
auto waitForAutowareStateToBe(
127-
const LegacyAutowareState & state, Thunk thunk = [] {})
127+
const LegacyAutowareState & from_state, const LegacyAutowareState & to_state,
128+
Thunk thunk = [] {})
128129
{
129130
thunk();
130131

131-
while (not finalized.load() and getLegacyAutowareState().value != state.value) {
132+
auto not_to_be = [&](auto current_state) {
133+
return from_state.value <= current_state.value and current_state.value < to_state.value;
134+
};
135+
136+
while (not finalized.load() and not_to_be(getLegacyAutowareState())) {
132137
if (time_limit <= std::chrono::steady_clock::now()) {
133138
throw common::AutowareError(
134-
"Simulator waited for the Autoware state to transition to ", state,
139+
"Simulator waited for the Autoware state to transition to ", to_state,
135140
", but time is up. The current Autoware state is ", getLegacyAutowareState());
136141
} else {
137142
thunk();

external/concealer/include/concealer/service.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class Service
4141
template <typename Node>
4242
explicit Service(
4343
const std::string & name, Node & node,
44-
const std::chrono::nanoseconds & interval = std::chrono::seconds(1))
44+
const std::chrono::nanoseconds & interval = std::chrono::seconds(3))
4545
: name(name),
4646
client(node.template create_client<T>(name, rmw_qos_profile_default)),
4747
interval(interval)

external/concealer/src/field_operator_application.cpp

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -269,8 +269,19 @@ auto FieldOperatorApplication::engage() -> void
269269
"The simulator attempted to request Autoware to engage, but was aborted because "
270270
"Autoware's current state is ",
271271
state, ".");
272+
case LegacyAutowareState::initializing:
273+
// The initial pose has been sent but has not yet reached Autoware.
274+
waitForAutowareStateToBe(
275+
LegacyAutowareState::initializing, LegacyAutowareState::waiting_for_route);
276+
[[fallthrough]];
277+
case LegacyAutowareState::waiting_for_route:
278+
// The route has been sent but has not yet reached Autoware.
279+
waitForAutowareStateToBe(
280+
LegacyAutowareState::waiting_for_route, LegacyAutowareState::planning);
281+
[[fallthrough]];
272282
case LegacyAutowareState::planning:
273-
waitForAutowareStateToBe(LegacyAutowareState::waiting_for_engage);
283+
waitForAutowareStateToBe(
284+
LegacyAutowareState::planning, LegacyAutowareState::waiting_for_engage);
274285
[[fallthrough]];
275286
case LegacyAutowareState::waiting_for_engage:
276287
requestEngage(
@@ -280,8 +291,12 @@ auto FieldOperatorApplication::engage() -> void
280291
return request;
281292
}(),
282293
30);
294+
waitForAutowareStateToBe(
295+
LegacyAutowareState::waiting_for_engage, LegacyAutowareState::driving);
283296
time_limit = std::decay_t<decltype(time_limit)>::max();
284297
break;
298+
case LegacyAutowareState::driving:
299+
break;
285300
}
286301
});
287302
}
@@ -309,6 +324,10 @@ auto FieldOperatorApplication::initialize(const geometry_msgs::msg::Pose & initi
309324
"The simulator attempted to initialize Autoware, but aborted because Autoware's "
310325
"current state is ",
311326
state, ".");
327+
case LegacyAutowareState::undefined:
328+
waitForAutowareStateToBe(
329+
LegacyAutowareState::undefined, LegacyAutowareState::initializing);
330+
[[fallthrough]];
312331
case LegacyAutowareState::initializing:
313332
requestInitialPose(
314333
[&]() {
@@ -324,6 +343,8 @@ auto FieldOperatorApplication::initialize(const geometry_msgs::msg::Pose & initi
324343
return request;
325344
}(),
326345
30);
346+
waitForAutowareStateToBe(
347+
LegacyAutowareState::initializing, LegacyAutowareState::waiting_for_route);
327348
break;
328349
}
329350
});
@@ -343,8 +364,9 @@ auto FieldOperatorApplication::plan(const std::vector<geometry_msgs::msg::PoseSt
343364
"current state is ",
344365
state, ".");
345366
case LegacyAutowareState::initializing:
367+
// The initial pose has been sent but has not yet reached Autoware.
346368
case LegacyAutowareState::arrived_goal:
347-
waitForAutowareStateToBe(LegacyAutowareState::waiting_for_route);
369+
waitForAutowareStateToBe(state, LegacyAutowareState::waiting_for_route);
348370
[[fallthrough]];
349371
case LegacyAutowareState::waiting_for_route:
350372
requestSetRoutePoints(
@@ -369,7 +391,7 @@ auto FieldOperatorApplication::plan(const std::vector<geometry_msgs::msg::PoseSt
369391
370392
[1] https://github.com/autowarefoundation/autoware_adapi_msgs/commit/805f8ebd3ca24564844df9889feeaf183101fbef
371393
[2] https://github.com/autowarefoundation/autoware_adapi_msgs/commit/cf310bd038673b6cbef3ae3b61dfe607212de419
372-
*/
394+
*/
373395
if constexpr (
374396
DetectMember_option<SetRoutePoints::Request>::value and
375397
DetectMember_allow_goal_modification<
@@ -381,6 +403,10 @@ auto FieldOperatorApplication::plan(const std::vector<geometry_msgs::msg::PoseSt
381403
return request;
382404
}(),
383405
30);
406+
waitForAutowareStateToBe(
407+
LegacyAutowareState::waiting_for_route, LegacyAutowareState::planning);
408+
waitForAutowareStateToBe(
409+
LegacyAutowareState::planning, LegacyAutowareState::waiting_for_engage);
384410
break;
385411
}
386412
});

0 commit comments

Comments
 (0)