scenario_simulator_v2 C++ API
field_operator_application_for_autoware_universe.hpp
Go to the documentation of this file.
1 // Copyright 2015 TIER IV, Inc. All rights reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef CONCEALER__AUTOWARE_UNIVERSE_USER_HPP_
16 #define CONCEALER__AUTOWARE_UNIVERSE_USER_HPP_
17 
18 #if __has_include(<autoware_adapi_v1_msgs/msg/localization_initialization_state.hpp>)
19 #include <autoware_adapi_v1_msgs/msg/localization_initialization_state.hpp>
20 #endif
21 
22 #include <autoware_adapi_v1_msgs/msg/mrm_state.hpp>
23 #include <autoware_adapi_v1_msgs/srv/clear_route.hpp>
24 #include <autoware_adapi_v1_msgs/srv/initialize_localization.hpp>
25 #include <autoware_adapi_v1_msgs/srv/set_route_points.hpp>
26 #include <autoware_auto_control_msgs/msg/ackermann_control_command.hpp>
27 #include <autoware_auto_perception_msgs/msg/traffic_signal_array.hpp>
28 #include <autoware_auto_planning_msgs/msg/path_with_lane_id.hpp>
29 #include <autoware_auto_system_msgs/msg/emergency_state.hpp>
30 #include <autoware_auto_vehicle_msgs/msg/gear_command.hpp>
36 #include <concealer/task_queue.hpp>
37 #include <geometry_msgs/msg/pose_with_covariance_stamped.hpp>
38 #include <tier4_external_api_msgs/msg/emergency.hpp>
39 #include <tier4_external_api_msgs/srv/engage.hpp>
40 #include <tier4_external_api_msgs/srv/set_velocity_limit.hpp>
41 #include <tier4_planning_msgs/msg/trajectory.hpp>
42 #include <tier4_rtc_msgs/msg/cooperate_status_array.hpp>
43 #include <tier4_rtc_msgs/srv/auto_mode_with_module.hpp>
44 #include <tier4_rtc_msgs/srv/cooperate_commands.hpp>
45 #include <tier4_system_msgs/msg/autoware_state.hpp>
46 
47 namespace concealer
48 {
49 template <>
52  public TransitionAssertion<FieldOperatorApplicationFor<AutowareUniverse>>
53 {
55 
56  // clang-format off
61 #if __has_include(<autoware_adapi_v1_msgs/msg/localization_initialization_state.hpp>)
63 #endif
67 
75  // clang-format on
76 
77  tier4_rtc_msgs::msg::CooperateStatusArray latest_cooperate_status_array;
78 
79  std::string minimum_risk_maneuver_state;
80 
81  std::string minimum_risk_maneuver_behavior;
82 
83  auto receiveMrmState(const autoware_adapi_v1_msgs::msg::MrmState & msg) -> void;
84 
85  auto receiveEmergencyState(const tier4_external_api_msgs::msg::Emergency & msg) -> void;
86 
87 #define DEFINE_STATE_PREDICATE(NAME, VALUE) \
88  auto is##NAME() const noexcept \
89  { \
90  using tier4_system_msgs::msg::AutowareState; \
91  return getAutowareState().state == AutowareState::VALUE; \
92  } \
93  static_assert(true, "")
94 
95  DEFINE_STATE_PREDICATE(Initializing, INITIALIZING_VEHICLE);
96  DEFINE_STATE_PREDICATE(WaitingForRoute, WAITING_FOR_ROUTE);
97  DEFINE_STATE_PREDICATE(Planning, PLANNING);
98  DEFINE_STATE_PREDICATE(WaitingForEngage, WAITING_FOR_ENGAGE);
99  DEFINE_STATE_PREDICATE(Driving, DRIVING);
100  DEFINE_STATE_PREDICATE(ArrivedGoal, ARRIVAL_GOAL);
101  DEFINE_STATE_PREDICATE(Emergency, EMERGENCY);
102  DEFINE_STATE_PREDICATE(Finalizing, FINALIZING);
103 
104 #undef DEFINE_STATE_PREDICATE
105 
106 protected:
107  auto sendSIGINT() -> void override;
108 
109 public:
111 
112 public:
113  template <typename... Ts>
115  : FieldOperatorApplication(std::forward<decltype(xs)>(xs)...),
116  // clang-format off
117  getAckermannControlCommand("/control/command/control_cmd", *this),
118  getAutowareState("/api/iv_msgs/autoware/state", *this),
119  getCooperateStatusArray("/api/external/get/rtc_status", *this, [this](const auto & v) { latest_cooperate_status_array = v; }),
120  getEmergencyState("/api/external/get/emergency", *this, [this](const auto & v) { receiveEmergencyState(v); }),
121 #if __has_include(<autoware_adapi_v1_msgs/msg/localization_initialization_state.hpp>)
122  getLocalizationState("/api/localization/initialization_state", *this),
123 #endif
124  getMrmState("/api/fail_safe/mrm_state", *this, [this](const auto & v) { receiveMrmState(v); }),
125  getPathWithLaneId("/planning/scenario_planning/lane_driving/behavior_planning/path_with_lane_id", *this),
126  getTrajectory("/api/iv_msgs/planning/scenario_planning/trajectory", *this),
127  getTurnIndicatorsCommandImpl("/control/command/turn_indicators_cmd", *this),
128  requestClearRoute("/api/routing/clear_route", *this),
129  requestCooperateCommands("/api/external/set/rtc_commands", *this),
130  requestEngage("/api/external/set/engage", *this),
131  requestInitialPose("/api/localization/initialize", *this),
132  // NOTE: /api/routing/set_route_points takes a long time to return. But the specified duration is not decided by any technical reasons.
133  requestSetRoutePoints("/api/routing/set_route_points", *this, std::chrono::seconds(10)),
134  requestSetRtcAutoMode("/api/external/set/rtc_auto_mode", *this),
135  requestSetVelocityLimit("/api/autoware/set/velocity_limit", *this)
136  // clang-format on
137  {
138  }
139 
140  ~FieldOperatorApplicationFor() override;
141 
142  auto engage() -> void override;
143 
144  auto engageable() const -> bool override;
145 
146  auto engaged() const -> bool override;
147 
148  auto getAutowareStateName() const -> std::string override;
149 
150  auto getWaypoints() const -> traffic_simulator_msgs::msg::WaypointsArray override;
151 
152  auto getTurnIndicatorsCommand() const
153  -> autoware_auto_vehicle_msgs::msg::TurnIndicatorsCommand override;
154 
155  auto getEmergencyStateName() const -> std::string override;
156 
157  auto getMinimumRiskManeuverBehaviorName() const -> std::string override;
158 
159  auto getMinimumRiskManeuverStateName() const -> std::string override;
160 
161  auto initialize(const geometry_msgs::msg::Pose &) -> void override;
162 
163  auto plan(const std::vector<geometry_msgs::msg::PoseStamped> &) -> void override;
164 
165  auto clearRoute() -> void override;
166 
167  auto requestAutoModeForCooperation(const std::string &, bool) -> void override;
168 
169  auto restrictTargetSpeed(double) const -> double override;
170 
171  auto sendCooperateCommand(const std::string &, const std::string &) -> void override;
172 
173  auto setVelocityLimit(double) -> void override;
174 };
175 } // namespace concealer
176 
177 #endif // CONCEALER__AUTOWARE_UNIVERSE_USER_HPP_
Definition: autoware_universe.hpp:38
SubscriberWrapper< autoware_auto_planning_msgs::msg::PathWithLaneId > getPathWithLaneId
Definition: field_operator_application_for_autoware_universe.hpp:110
CONCEALER_PUBLIC FieldOperatorApplicationFor(Ts &&... xs)
Definition: field_operator_application_for_autoware_universe.hpp:114
Definition: field_operator_application.hpp:44
Definition: field_operator_application.hpp:60
#define CONCEALER_PUBLIC
Definition: visibility.hpp:49
#define DEFINE_STATE_PREDICATE(NAME, VALUE)
Definition: field_operator_application_for_autoware_universe.hpp:87
Definition: field_operator_application.hpp:161
Definition: autoware.hpp:30
Definition: cache.hpp:27
Definition: junit5.hpp:25
std::string string
Definition: junit5.hpp:26
Definition: transition_assertion.hpp:39