Skip to content

Commit 9fe0af2

Browse files
committed
try to resume planned route
Signed-off-by: Takagi, Isamu <isamu.takagi@tier4.jp>
1 parent 4951e1b commit 9fe0af2

File tree

2 files changed

+47
-13
lines changed

2 files changed

+47
-13
lines changed

planning/mission_planner/src/mission_planner/route_selector.cpp

+43-10
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,16 @@ RouteState::_state_type RouteInterface::get_state() const
4545
return state_.state;
4646
}
4747

48+
std::optional<LaneletRoute> RouteInterface::get_route() const
49+
{
50+
return route_;
51+
}
52+
53+
void RouteInterface::change_route()
54+
{
55+
route_ = std::nullopt;
56+
}
57+
4858
void RouteInterface::change_state(RouteState::_state_type state)
4959
{
5060
state_.stamp = clock_->now();
@@ -136,8 +146,9 @@ void RouteSelector::on_route(const LaneletRoute::ConstSharedPtr msg)
136146
void RouteSelector::on_clear_route_main(
137147
ClearRoute::Request::SharedPtr req, ClearRoute::Response::SharedPtr res)
138148
{
139-
// Save the request to resume from MRM.
149+
// Save the request and clear old route to resume from MRM.
140150
main_request_ = std::monostate{};
151+
main_.change_route();
141152

142153
// During MRM, only change the state.
143154
if (mrm_operating_) {
@@ -153,9 +164,10 @@ void RouteSelector::on_clear_route_main(
153164
void RouteSelector::on_set_waypoint_route_main(
154165
SetWaypointRoute::Request::SharedPtr req, SetWaypointRoute::Response::SharedPtr res)
155166
{
156-
// Save the request to resume from MRM.
167+
// Save the request and clear old route to resume from MRM.
157168
req->uuid = uuid::generate_if_empty(req->uuid);
158169
main_request_ = req;
170+
main_.change_route();
159171

160172
// During MRM, only change the state.
161173
if (mrm_operating_) {
@@ -171,9 +183,10 @@ void RouteSelector::on_set_waypoint_route_main(
171183
void RouteSelector::on_set_lanelet_route_main(
172184
SetLaneletRoute::Request::SharedPtr req, SetLaneletRoute::Response::SharedPtr res)
173185
{
174-
// Save the request to resume from MRM.
186+
// Save the request and clear old route to resume from MRM.
175187
req->uuid = uuid::generate_if_empty(req->uuid);
176188
main_request_ = req;
189+
main_.change_route();
177190

178191
// During MRM, only change the state.
179192
if (mrm_operating_) {
@@ -227,7 +240,18 @@ void RouteSelector::on_set_lanelet_route_mrm(
227240

228241
ResponseStatus RouteSelector::resume_main_route(ClearRoute::Request::SharedPtr req)
229242
{
230-
const auto create_resume_request = [](const auto request) {
243+
const auto create_lanelet_request = [](const LaneletRoute & route) {
244+
// NOTE: The start_pose.is not included in the request.
245+
const auto r = std::make_shared<SetLaneletRoute::Request>();
246+
r->header = route.header;
247+
r->goal_pose = route.goal_pose;
248+
r->segments = route.segments;
249+
r->uuid = route.uuid;
250+
r->allow_modification = route.allow_modification;
251+
return r;
252+
};
253+
254+
const auto create_goal_request = [](const auto & request) {
231255
const auto r = std::make_shared<SetWaypointRoute::Request>();
232256
r->header = request->header;
233257
r->goal_pose = request->goal_pose;
@@ -236,18 +260,27 @@ ResponseStatus RouteSelector::resume_main_route(ClearRoute::Request::SharedPtr r
236260
return r;
237261
};
238262

239-
// Resume main route using the saved request.
263+
// Clear the route if there is no request for the main route.
240264
if (std::holds_alternative<std::monostate>(main_request_)) {
241265
return service_utils::sync_call(cli_clear_route_, req);
242266
}
267+
268+
// Attempt to resume the main route if there is a planned route.
269+
if (const auto route = main_.get_route()) {
270+
const auto r = create_lanelet_request(route.value());
271+
const auto status = service_utils::sync_call(cli_set_lanelet_route_, r);
272+
RCLCPP_INFO_STREAM(get_logger(), "lanelet resume: " << std::boolalpha << status.success);
273+
if (status.success) return status;
274+
}
275+
276+
// If resuming fails, replan main route using the goal.
243277
// NOTE: Clear the waypoints to avoid returning. Remove this once resuming is supported.
244-
if (auto request = std::get_if<WaypointRequest>(&main_request_)) {
245-
const auto r = create_resume_request(*request);
278+
if (const auto request = std::get_if<WaypointRequest>(&main_request_)) {
279+
const auto r = create_goal_request(*request);
246280
return service_utils::sync_call(cli_set_waypoint_route_, r);
247281
}
248-
// NOTE: Clear the segments to avoid returning. Remove this once resuming is supported.
249-
if (auto request = std::get_if<LaneletRequest>(&main_request_)) {
250-
const auto r = create_resume_request(*request);
282+
if (const auto request = std::get_if<LaneletRequest>(&main_request_)) {
283+
const auto r = create_goal_request(*request);
251284
return service_utils::sync_call(cli_set_waypoint_route_, r);
252285
}
253286
throw std::logic_error("route_selector: unknown main route request");

planning/mission_planner/src/mission_planner/route_selector.hpp

+4-3
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ class RouteInterface
3030
{
3131
public:
3232
explicit RouteInterface(rclcpp::Clock::SharedPtr clock);
33+
RouteState::_state_type get_state() const;
34+
std::optional<LaneletRoute> get_route() const;
35+
void change_route();
36+
void change_state(RouteState::_state_type state);
3337
void update_state(const RouteState & state);
3438
void update_route(const LaneletRoute & route);
3539

@@ -39,9 +43,6 @@ class RouteInterface
3943
rclcpp::Publisher<RouteState>::SharedPtr pub_state_;
4044
rclcpp::Publisher<LaneletRoute>::SharedPtr pub_route_;
4145

42-
RouteState::_state_type get_state() const;
43-
void change_state(RouteState::_state_type state);
44-
4546
private:
4647
RouteState state_;
4748
std::optional<LaneletRoute> route_;

0 commit comments

Comments
 (0)