@@ -156,7 +156,8 @@ FieldOperatorApplication::FieldOperatorApplication(const pid_t pid)
156
156
requestCooperateCommands(" /api/external/set/rtc_commands" , *this ),
157
157
requestEngage(" /api/external/set/engage" , *this ),
158
158
requestInitialPose(" /api/localization/initialize" , *this ),
159
- // NOTE: /api/routing/set_route_points takes a long time to return. But the specified duration is not decided by any technical reasons.
159
+ // NOTE: routing takes a long time to return. But the specified duration is not decided by any technical reasons.
160
+ requestSetRoute(" /api/routing/set_route" , *this , std::chrono::seconds(10 )),
160
161
requestSetRoutePoints(" /api/routing/set_route_points" , *this , std::chrono::seconds(10 )),
161
162
requestSetRtcAutoMode(" /api/external/set/rtc_auto_mode" , *this ),
162
163
requestSetVelocityLimit(" /api/autoware/set/velocity_limit" , *this ),
@@ -357,7 +358,67 @@ auto FieldOperatorApplication::plan(
357
358
{
358
359
assert (not route.empty ());
359
360
360
- task_queue.delay ([this , route, allow_goal_modification]() {
361
+ std::vector<geometry_msgs::msg::Pose> waypoints;
362
+ if (route.size () > 1 ) {
363
+ std::transform (
364
+ route.begin (), route.end () - 1 , std::back_inserter (waypoints),
365
+ [](const auto & stamped_pose) { return stamped_pose.pose ; });
366
+ }
367
+
368
+ RouteOption route_option;
369
+ if (DetectMember_allow_goal_modification<RouteOption>::value) {
370
+ route_option.allow_goal_modification = allow_goal_modification;
371
+ }
372
+
373
+ plan (route.back ().pose , waypoints, route_option);
374
+ }
375
+
376
+ template <
377
+ typename Request, typename Waypoint,
378
+ typename = std::enable_if_t <
379
+ std::is_same_v<Request, autoware_adapi_v1_msgs::srv::SetRoutePoints::Request> ||
380
+ std::is_same_v<Request, autoware_adapi_v1_msgs::srv::SetRoute::Request> > >
381
+ static auto make (
382
+ const geometry_msgs::msg::Pose & goal, const std::vector<Waypoint> & waypoints,
383
+ const FieldOperatorApplication::RouteOption & option) -> std::shared_ptr<Request>
384
+ {
385
+ auto request = std::make_shared<Request>();
386
+
387
+ request->header .frame_id = " map" ;
388
+ request->goal = goal;
389
+
390
+ if constexpr (std::is_same_v<Request, autoware_adapi_v1_msgs::srv::SetRoutePoints::Request>) {
391
+ request->waypoints .assign (waypoints.begin (), waypoints.end ());
392
+ } else if constexpr (std::is_same_v<Request, autoware_adapi_v1_msgs::srv::SetRoute::Request>) {
393
+ request->segments .assign (waypoints.begin (), waypoints.end ());
394
+ }
395
+
396
+ /*
397
+ NOTE: The autoware_adapi_v1_msgs::srv::SetRoutePoints::Request
398
+ type was created on 2022/09/05 [1], and the
399
+ autoware_adapi_v1_msgs::msg::Option type data member was added
400
+ to the autoware_adapi_v1_msgs::srv::SetRoutePoints::Request type
401
+ on 2023/04/12 [2]. Therefore, we cannot expect
402
+ autoware_adapi_v1_msgs::srv::SetRoutePoints::Request to always
403
+ have a data member `option`.
404
+
405
+ [1] https://github.com/autowarefoundation/autoware_adapi_msgs/commit/805f8ebd3ca24564844df9889feeaf183101fbef
406
+ [2] https://github.com/autowarefoundation/autoware_adapi_msgs/commit/cf310bd038673b6cbef3ae3b61dfe607212de419
407
+ */
408
+ if constexpr (
409
+ DetectMember_option<Request>::value and
410
+ DetectMember_allow_goal_modification<decltype (std::declval<Request>().option )>::value) {
411
+ request->option .allow_goal_modification = option.allow_goal_modification ;
412
+ }
413
+
414
+ return request;
415
+ }
416
+
417
+ auto FieldOperatorApplication::plan (
418
+ const geometry_msgs::msg::Pose & goal, const std::vector<geometry_msgs::msg::Pose> & waypoints,
419
+ const RouteOption & option) -> void
420
+ {
421
+ task_queue.delay ([this , goal, waypoints, option]() {
361
422
switch (const auto state = getLegacyAutowareState (); state.value ) {
362
423
default :
363
424
throw common::AutowareError (
@@ -370,39 +431,35 @@ auto FieldOperatorApplication::plan(
370
431
waitForAutowareStateToBe (state, LegacyAutowareState::waiting_for_route);
371
432
[[fallthrough]];
372
433
case LegacyAutowareState::waiting_for_route:
373
- requestSetRoutePoints (
374
- [&]() {
375
- auto request = std::make_shared<SetRoutePoints::Request>();
376
-
377
- request->header = route.back ().header ;
378
- request->goal = route.back ().pose ;
379
-
380
- for (const auto & each : route | boost::adaptors::sliced (0 , route.size () - 1 )) {
381
- request->waypoints .push_back (each.pose );
382
- }
383
-
384
- /*
385
- NOTE: The autoware_adapi_v1_msgs::srv::SetRoutePoints::Request
386
- type was created on 2022/09/05 [1], and the
387
- autoware_adapi_v1_msgs::msg::Option type data member was added
388
- to the autoware_adapi_v1_msgs::srv::SetRoutePoints::Request type
389
- on 2023/04/12 [2]. Therefore, we cannot expect
390
- autoware_adapi_v1_msgs::srv::SetRoutePoints::Request to always
391
- have a data member `option`.
392
-
393
- [1] https://github.com/autowarefoundation/autoware_adapi_msgs/commit/805f8ebd3ca24564844df9889feeaf183101fbef
394
- [2] https://github.com/autowarefoundation/autoware_adapi_msgs/commit/cf310bd038673b6cbef3ae3b61dfe607212de419
395
- */
396
- if constexpr (
397
- DetectMember_option<SetRoutePoints::Request>::value and
398
- DetectMember_allow_goal_modification<
399
- decltype (std::declval<SetRoutePoints::Request>().option )>::value) {
400
- request->option .allow_goal_modification = allow_goal_modification;
401
- }
434
+ requestSetRoutePoints (make<SetRoutePoints::Request>(goal, waypoints, option), 30 );
435
+ waitForAutowareStateToBe (
436
+ LegacyAutowareState::waiting_for_route, LegacyAutowareState::planning);
437
+ waitForAutowareStateToBe (
438
+ LegacyAutowareState::planning, LegacyAutowareState::waiting_for_engage);
439
+ break ;
440
+ }
441
+ });
442
+ }
402
443
403
- return request;
404
- }(),
405
- 30 );
444
+ auto FieldOperatorApplication::plan (
445
+ const geometry_msgs::msg::Pose & goal,
446
+ const std::vector<autoware_adapi_v1_msgs::msg::RouteSegment> & waypoints,
447
+ const RouteOption & option) -> void
448
+ {
449
+ task_queue.delay ([this , goal, waypoints, option]() {
450
+ switch (const auto state = getLegacyAutowareState (); state.value ) {
451
+ default :
452
+ throw common::AutowareError (
453
+ " The simulator attempted to send a goal to Autoware, but was aborted because Autoware's "
454
+ " current state is " ,
455
+ state, " ." );
456
+ case LegacyAutowareState::initializing:
457
+ // The initial pose has been sent but has not yet reached Autoware.
458
+ case LegacyAutowareState::arrived_goal:
459
+ waitForAutowareStateToBe (state, LegacyAutowareState::waiting_for_route);
460
+ [[fallthrough]];
461
+ case LegacyAutowareState::waiting_for_route:
462
+ requestSetRoute (make<SetRoute::Request>(goal, waypoints, option), 30 );
406
463
waitForAutowareStateToBe (
407
464
LegacyAutowareState::waiting_for_route, LegacyAutowareState::planning);
408
465
waitForAutowareStateToBe (
0 commit comments