Skip to content

Commit 4e1f997

Browse files
authored
Merge pull request #1611 from tier4/feature/set_route
2 parents f26565b + e10d6fa commit 4e1f997

File tree

9 files changed

+531
-108
lines changed

9 files changed

+531
-108
lines changed

external/concealer/include/concealer/field_operator_application.hpp

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <autoware_adapi_v1_msgs/srv/change_operation_mode.hpp>
2222
#include <autoware_adapi_v1_msgs/srv/clear_route.hpp>
2323
#include <autoware_adapi_v1_msgs/srv/initialize_localization.hpp>
24+
#include <autoware_adapi_v1_msgs/srv/set_route.hpp>
2425
#include <autoware_adapi_v1_msgs/srv/set_route_points.hpp>
2526
#include <autoware_control_msgs/msg/control.hpp>
2627
#include <autoware_vehicle_msgs/msg/gear_command.hpp>
@@ -83,6 +84,7 @@ struct FieldOperatorApplication : public rclcpp::Node
8384
using CooperateCommands = tier4_rtc_msgs::srv::CooperateCommands;
8485
using Engage = tier4_external_api_msgs::srv::Engage;
8586
using InitializeLocalization = autoware_adapi_v1_msgs::srv::InitializeLocalization;
87+
using SetRoute = autoware_adapi_v1_msgs::srv::SetRoute;
8688
using SetRoutePoints = autoware_adapi_v1_msgs::srv::SetRoutePoints;
8789
using AutoModeWithModule = tier4_rtc_msgs::srv::AutoModeWithModule;
8890
using SetVelocityLimit = tier4_external_api_msgs::srv::SetVelocityLimit;
@@ -109,6 +111,7 @@ struct FieldOperatorApplication : public rclcpp::Node
109111
Service<CooperateCommands> requestCooperateCommands;
110112
Service<Engage> requestEngage;
111113
Service<InitializeLocalization> requestInitialPose;
114+
Service<SetRoute> requestSetRoute;
112115
Service<SetRoutePoints> requestSetRoutePoints;
113116
Service<AutoModeWithModule> requestSetRtcAutoMode;
114117
Service<SetVelocityLimit> requestSetVelocityLimit;
@@ -159,7 +162,24 @@ struct FieldOperatorApplication : public rclcpp::Node
159162

160163
auto initialize(const geometry_msgs::msg::Pose &) -> void;
161164

162-
auto plan(const std::vector<geometry_msgs::msg::PoseStamped> &, const bool) -> void;
165+
[[deprecated(
166+
"This function was deprecated since version 16.5.0 (released on 20250603). It will be deleted "
167+
"after a half-year transition period (~20251203). Please use other overloads instead.")]] auto
168+
plan(const std::vector<geometry_msgs::msg::PoseStamped> &, const bool) -> void;
169+
170+
#if __has_include(<autoware_adapi_v1_msgs/msg/route_option.hpp>)
171+
using RouteOption = autoware_adapi_v1_msgs::msg::RouteOption;
172+
#else
173+
using RouteOption = void;
174+
#endif
175+
176+
auto plan(
177+
const geometry_msgs::msg::Pose & goal, const std::vector<geometry_msgs::msg::Pose> &,
178+
const RouteOption &) -> void;
179+
180+
auto plan(
181+
const geometry_msgs::msg::Pose & goal,
182+
const std::vector<autoware_adapi_v1_msgs::msg::RouteSegment> &, const RouteOption &) -> void;
163183

164184
auto clearRoute() -> void;
165185

external/concealer/src/field_operator_application.cpp

Lines changed: 91 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,8 @@ FieldOperatorApplication::FieldOperatorApplication(const pid_t pid)
156156
requestCooperateCommands("/api/external/set/rtc_commands", *this),
157157
requestEngage("/api/external/set/engage", *this),
158158
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)),
160161
requestSetRoutePoints("/api/routing/set_route_points", *this, std::chrono::seconds(10)),
161162
requestSetRtcAutoMode("/api/external/set/rtc_auto_mode", *this),
162163
requestSetVelocityLimit("/api/autoware/set/velocity_limit", *this),
@@ -357,7 +358,67 @@ auto FieldOperatorApplication::plan(
357358
{
358359
assert(not route.empty());
359360

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]() {
361422
switch (const auto state = getLegacyAutowareState(); state.value) {
362423
default:
363424
throw common::AutowareError(
@@ -370,39 +431,35 @@ auto FieldOperatorApplication::plan(
370431
waitForAutowareStateToBe(state, LegacyAutowareState::waiting_for_route);
371432
[[fallthrough]];
372433
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+
}
402443

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);
406463
waitForAutowareStateToBe(
407464
LegacyAutowareState::waiting_for_route, LegacyAutowareState::planning);
408465
waitForAutowareStateToBe(

openscenario/openscenario_interpreter/src/syntax/acquire_position_action.cpp

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -53,45 +53,43 @@ auto AcquirePositionAction::start() -> void
5353
return applyAcquirePositionAction(actor, static_cast<NativeLanePosition>(position), options);
5454
});
5555

56-
auto allow_goal_modification_from_parameter = [&]() -> bool {
57-
try {
58-
return ref<Boolean>(std::string("AcquirePositionAction.allow_goal_modification"));
59-
} catch (const SyntaxError &) {
60-
// default value of allow_goal_modification
61-
return false;
62-
}
63-
}();
64-
65-
auto get_allow_goal_modification_from_property =
66-
[this](const EntityRef & entity_ref) -> std::optional<bool> {
56+
auto get_from_controller_property =
57+
[this](const EntityRef & entity_ref, const std::string & property_name) -> std::optional<bool> {
6758
if (const auto & entity = global().entities->ref(entity_ref);
6859
entity.template is<ScenarioObject>()) {
6960
const auto & object_controller = entity.as<ScenarioObject>().object_controller;
7061
if (object_controller.isAutoware() && object_controller.is<Controller>()) {
7162
auto controller = object_controller.as<Controller>();
72-
if (controller.properties.contains("allowGoalModification")) {
73-
return controller.properties.template get<Boolean>("allowGoalModification");
63+
if (controller.properties.contains(property_name)) {
64+
return controller.properties.template get<Boolean>(property_name);
7465
}
7566
}
7667
}
7768
return std::nullopt;
7869
};
7970

71+
auto get_from_parameter =
72+
[&](const std::string & parameter_name, const bool default_value) -> bool {
73+
try {
74+
return ref<Boolean>(parameter_name);
75+
} catch (const SyntaxError &) {
76+
return default_value;
77+
}
78+
};
79+
8080
for (const auto & actor : actors) {
8181
actor.apply([&](const auto & object) {
82-
traffic_simulator::RouteOption options;
83-
options.allow_goal_modification = [&]() {
84-
if (auto allow_goal_modification_from_property =
85-
get_allow_goal_modification_from_property(object);
86-
allow_goal_modification_from_property.has_value()) {
82+
traffic_simulator::v2::RouteOption route_option;
83+
route_option.allow_goal_modification = [&]() {
84+
if (auto from_property = get_from_controller_property(object, "allowGoalModification")) {
8785
// property specification takes precedence
88-
return allow_goal_modification_from_property.value();
86+
return from_property.value();
8987
} else {
90-
return allow_goal_modification_from_parameter;
88+
return get_from_parameter("RoutingAction__allow_goal_modification", false);
9189
}
9290
}();
9391

94-
apply<void>(acquire_position, position, object, options);
92+
apply<void>(acquire_position, position, object, route_option);
9593
});
9694
}
9795
}

openscenario/openscenario_interpreter/src/syntax/assign_route_action.cpp

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,11 @@
1616
#include <openscenario_interpreter/simulator_core.hpp>
1717
#include <openscenario_interpreter/syntax/assign_route_action.hpp>
1818
#include <openscenario_interpreter/syntax/catalog_reference.hpp>
19+
#include <openscenario_interpreter/syntax/controller.hpp>
20+
#include <openscenario_interpreter/syntax/entities.hpp>
1921
#include <openscenario_interpreter/syntax/object_type.hpp>
2022
#include <openscenario_interpreter/syntax/route.hpp>
23+
#include <openscenario_interpreter/syntax/scenario_object.hpp>
2124
#include <vector>
2225

2326
namespace openscenario_interpreter
@@ -53,10 +56,47 @@ auto AssignRouteAction::run() -> void {}
5356

5457
auto AssignRouteAction::start() -> void
5558
{
59+
auto get_from_controller_property =
60+
[this](const EntityRef & entity_ref, const std::string & property_name) -> std::optional<bool> {
61+
if (const auto & entity = global().entities->ref(entity_ref);
62+
entity.template is<ScenarioObject>()) {
63+
const auto & object_controller = entity.as<ScenarioObject>().object_controller;
64+
if (object_controller.isAutoware() && object_controller.is<Controller>()) {
65+
auto controller = object_controller.as<Controller>();
66+
if (controller.properties.contains(property_name)) {
67+
return controller.properties.template get<Boolean>(property_name);
68+
}
69+
}
70+
}
71+
return std::nullopt;
72+
};
73+
74+
auto get_from_parameter =
75+
[&](const std::string & parameter_name, const bool default_value) -> bool {
76+
try {
77+
return ref<Boolean>(parameter_name);
78+
} catch (const SyntaxError &) {
79+
return default_value;
80+
}
81+
};
82+
83+
traffic_simulator::v2::RouteOption route_option;
84+
route_option.use_lane_ids_for_routing =
85+
get_from_parameter("RoutingAction__use_lane_ids_for_routing", false);
86+
5687
for (const auto & actor : actors) {
5788
actor.apply([&](const auto & object) {
89+
route_option.allow_goal_modification = [&]() {
90+
if (auto from_property = get_from_controller_property(object, "allowGoalModification")) {
91+
// property specification takes precedence
92+
return from_property.value();
93+
} else {
94+
return get_from_parameter("RoutingAction__allow_goal_modification", false);
95+
}
96+
}();
5897
applyAssignRouteAction(
59-
object, static_cast<std::vector<NativeLanePosition>>(route.as<const Route>()));
98+
object, static_cast<std::vector<NativeLanePosition>>(route.as<const Route>()),
99+
route_option);
60100
});
61101
}
62102
}

simulation/traffic_simulator/include/traffic_simulator/data_type/route_option.hpp

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,29 @@ namespace traffic_simulator
1919
{
2020
inline namespace route_option
2121
{
22-
inline namespace v1
22+
inline namespace v2
2323
{
2424
struct RouteOption
2525
{
2626
bool allow_goal_modification = false;
27+
bool use_lane_ids_for_routing = false;
28+
};
29+
} // namespace v2
30+
31+
namespace v1
32+
{
33+
struct RouteOption
34+
{
35+
bool allow_goal_modification = false;
36+
37+
// conversion without loss of information
38+
operator v2::RouteOption() const
39+
{
40+
v2::RouteOption v2;
41+
v2.allow_goal_modification = allow_goal_modification;
42+
v2.use_lane_ids_for_routing = false;
43+
return v2;
44+
}
2745
};
2846
} // namespace v1
2947
} // namespace route_option

simulation/traffic_simulator/include/traffic_simulator/entity/ego_entity.hpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,21 +82,23 @@ class EgoEntity : public VehicleEntity, private concealer::FieldOperatorApplicat
8282

8383
void requestAcquirePosition(const CanonicalizedLaneletPose &) override;
8484

85-
void requestAcquirePosition(const CanonicalizedLaneletPose &, const RouteOption &) override;
85+
void requestAcquirePosition(
86+
const CanonicalizedLaneletPose &, const traffic_simulator::RouteOption &) override;
8687

8788
void requestAcquirePosition(const geometry_msgs::msg::Pose &) override;
8889

89-
void requestAcquirePosition(const geometry_msgs::msg::Pose &, const RouteOption &) override;
90+
void requestAcquirePosition(
91+
const geometry_msgs::msg::Pose &, const traffic_simulator::RouteOption &) override;
9092

9193
void requestAssignRoute(const std::vector<CanonicalizedLaneletPose> &) override;
9294

9395
void requestAssignRoute(
94-
const std::vector<CanonicalizedLaneletPose> &, const RouteOption &) override;
96+
const std::vector<CanonicalizedLaneletPose> &, const traffic_simulator::RouteOption &) override;
9597

9698
void requestAssignRoute(const std::vector<geometry_msgs::msg::Pose> &) override;
9799

98100
void requestAssignRoute(
99-
const std::vector<geometry_msgs::msg::Pose> &, const RouteOption &) override;
101+
const std::vector<geometry_msgs::msg::Pose> &, const traffic_simulator::RouteOption &) override;
100102

101103
auto requestFollowTrajectory(
102104
const std::shared_ptr<traffic_simulator_msgs::msg::PolylineTrajectory> &) -> void override;

0 commit comments

Comments
 (0)