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 #if __has_include(<autoware_system_msgs/msg/autoware_state.hpp>)
23 #include <autoware_system_msgs/msg/autoware_state.hpp>
24 #endif
25 
26 #if __has_include(<autoware_auto_system_msgs/msg/autoware_state.hpp>)
27 #include <autoware_auto_system_msgs/msg/autoware_state.hpp>
28 #endif
29 
30 #include <autoware_adapi_v1_msgs/msg/mrm_state.hpp>
31 #include <autoware_adapi_v1_msgs/srv/clear_route.hpp>
32 #include <autoware_adapi_v1_msgs/srv/initialize_localization.hpp>
33 #include <autoware_adapi_v1_msgs/srv/set_route_points.hpp>
34 #include <autoware_auto_control_msgs/msg/ackermann_control_command.hpp>
35 #include <autoware_auto_perception_msgs/msg/traffic_signal_array.hpp>
36 #include <autoware_auto_planning_msgs/msg/path_with_lane_id.hpp>
37 #include <autoware_auto_system_msgs/msg/emergency_state.hpp>
38 #include <autoware_auto_vehicle_msgs/msg/gear_command.hpp>
44 #include <concealer/task_queue.hpp>
45 #include <geometry_msgs/msg/pose_with_covariance_stamped.hpp>
46 #include <tier4_external_api_msgs/msg/emergency.hpp>
47 #include <tier4_external_api_msgs/srv/engage.hpp>
48 #include <tier4_external_api_msgs/srv/set_velocity_limit.hpp>
49 #include <tier4_planning_msgs/msg/trajectory.hpp>
50 #include <tier4_rtc_msgs/msg/cooperate_status_array.hpp>
51 #include <tier4_rtc_msgs/srv/auto_mode_with_module.hpp>
52 #include <tier4_rtc_msgs/srv/cooperate_commands.hpp>
53 
54 namespace concealer
55 {
56 template <>
59  public TransitionAssertion<FieldOperatorApplicationFor<AutowareUniverse>>
60 {
62 
63  // clang-format off
65 #if __has_include(<autoware_system_msgs/msg/autoware_state.hpp>)
67 #endif
68 #if __has_include(<autoware_auto_system_msgs/msg/autoware_state.hpp>)
70 #endif
73 #if __has_include(<autoware_adapi_v1_msgs/msg/localization_initialization_state.hpp>)
75 #endif
79 
87  // clang-format on
88 
89  tier4_rtc_msgs::msg::CooperateStatusArray latest_cooperate_status_array;
90 
91  std::string autoware_state;
92 
93  std::string minimum_risk_maneuver_state;
94 
95  std::string minimum_risk_maneuver_behavior;
96 
97  auto receiveMrmState(const autoware_adapi_v1_msgs::msg::MrmState & msg) -> void;
98 
99  auto receiveEmergencyState(const tier4_external_api_msgs::msg::Emergency & msg) -> void;
100 
101  /*
102  NOTE: This predicate should not take the state being compared as an
103  argument or template parameter. Otherwise, code using this class would
104  need to have knowledge of the Autoware state type.
105  */
106 #define DEFINE_STATE_PREDICATE(NAME, VALUE) \
107  auto is##NAME() const noexcept { return autoware_state == #VALUE; } \
108  static_assert(true, "")
109 
110  DEFINE_STATE_PREDICATE(Initializing, INITIALIZING_VEHICLE);
111  DEFINE_STATE_PREDICATE(WaitingForRoute, WAITING_FOR_ROUTE);
112  DEFINE_STATE_PREDICATE(Planning, PLANNING);
113  DEFINE_STATE_PREDICATE(WaitingForEngage, WAITING_FOR_ENGAGE);
114  DEFINE_STATE_PREDICATE(Driving, DRIVING);
115  DEFINE_STATE_PREDICATE(ArrivedGoal, ARRIVAL_GOAL);
116  DEFINE_STATE_PREDICATE(Finalizing, FINALIZING);
117 
118 #undef DEFINE_STATE_PREDICATE
119 
120 protected:
121  template <typename T>
122  auto getAutowareStateString(std::uint8_t state) const -> char const *
123  {
124 #define CASE(IDENTIFIER) \
125  case T::IDENTIFIER: \
126  return #IDENTIFIER
127 
128  switch (state) {
129  CASE(INITIALIZING);
130  CASE(WAITING_FOR_ROUTE);
131  CASE(PLANNING);
132  CASE(WAITING_FOR_ENGAGE);
133  CASE(DRIVING);
134  CASE(ARRIVED_GOAL);
135  CASE(FINALIZING);
136 
137  default:
138  return "";
139  }
140 
141 #undef CASE
142  }
143  auto sendSIGINT() -> void override;
144 
145 public:
147 
148 public:
149  template <typename... Ts>
151  : FieldOperatorApplication(std::forward<decltype(xs)>(xs)...),
152  // clang-format off
153  getAckermannControlCommand("/control/command/control_cmd", rclcpp::QoS(1), *this),
154 #if __has_include(<autoware_system_msgs/msg/autoware_state.hpp>)
155  getAutowareState("/autoware/state", rclcpp::QoS(1), *this, [this](const auto & v) {
156  /*
157  There are multiple places that assignments to `autoware_state` in the callback for the /autoware/state topic to accommodate multiple messages.
158  But only one of them is used as long as correct configuration Autoware is.
159  Even if the topic comes in multiple types, as long as the content is the same,
160  there is basically no problem, but there is a possibility that potential problems may occur.
161  */
162  autoware_state = getAutowareStateString<autoware_system_msgs::msg::AutowareState>(v.state); }),
163 #endif
164 #if __has_include(<autoware_auto_system_msgs/msg/autoware_state.hpp>)
165  getAutowareAutoState("/autoware/state", rclcpp::QoS(1), *this, [this](const auto & v) {
166  /*
167  There are multiple places that assignments to `autoware_state` in the callback for the /autoware/state topic to accommodate multiple messages.
168  But only one of them is used as long as correct configuration Autoware is.
169  Even if the topic comes in multiple types, as long as the content is the same,
170  there is basically no problem, but there is a possibility that potential problems may occur.
171  */
172  autoware_state = getAutowareStateString<autoware_auto_system_msgs::msg::AutowareState>(v.state);
173  }),
174 #endif
175  getCooperateStatusArray("/api/external/get/rtc_status", rclcpp::QoS(1), *this, [this](const auto & v) { latest_cooperate_status_array = v; }),
176  getEmergencyState("/api/external/get/emergency", rclcpp::QoS(1), *this, [this](const auto & v) { receiveEmergencyState(v); }),
177 #if __has_include(<autoware_adapi_v1_msgs/msg/localization_initialization_state.hpp>)
178  getLocalizationState("/api/localization/initialization_state", rclcpp::QoS(1).transient_local(), *this),
179 #endif
180  getMrmState("/api/fail_safe/mrm_state", rclcpp::QoS(1), *this, [this](const auto & v) { receiveMrmState(v); }),
181  getTrajectory("/api/iv_msgs/planning/scenario_planning/trajectory", rclcpp::QoS(1), *this),
182  getTurnIndicatorsCommandImpl("/control/command/turn_indicators_cmd", rclcpp::QoS(1), *this),
183  requestClearRoute("/api/routing/clear_route", *this),
184  requestCooperateCommands("/api/external/set/rtc_commands", *this),
185  requestEngage("/api/external/set/engage", *this),
186  requestInitialPose("/api/localization/initialize", *this),
187  // NOTE: /api/routing/set_route_points takes a long time to return. But the specified duration is not decided by any technical reasons.
188  requestSetRoutePoints("/api/routing/set_route_points", *this, std::chrono::seconds(10)),
189  requestSetRtcAutoMode("/api/external/set/rtc_auto_mode", *this),
190  requestSetVelocityLimit("/api/autoware/set/velocity_limit", *this),
191  getPathWithLaneId("/planning/scenario_planning/lane_driving/behavior_planning/path_with_lane_id", rclcpp::QoS(1), *this)
192  // clang-format on
193  {
194  }
195 
196  ~FieldOperatorApplicationFor() override;
197 
198  auto engage() -> void override;
199 
200  auto engageable() const -> bool override;
201 
202  auto engaged() const -> bool override;
203 
204  auto getAutowareStateName() const -> std::string override;
205 
206  auto getWaypoints() const -> traffic_simulator_msgs::msg::WaypointsArray override;
207 
208  auto getTurnIndicatorsCommand() const
209  -> autoware_auto_vehicle_msgs::msg::TurnIndicatorsCommand override;
210 
211  auto getEmergencyStateName() const -> std::string override;
212 
213  auto getMinimumRiskManeuverBehaviorName() const -> std::string override;
214 
215  auto getMinimumRiskManeuverStateName() const -> std::string override;
216 
217  auto initialize(const geometry_msgs::msg::Pose &) -> void override;
218 
219  auto plan(const std::vector<geometry_msgs::msg::PoseStamped> &) -> void override;
220 
221  auto clearRoute() -> void override;
222 
223  auto requestAutoModeForCooperation(const std::string &, bool) -> void override;
224 
225  auto restrictTargetSpeed(double) const -> double override;
226 
227  auto sendCooperateCommand(const std::string &, const std::string &) -> void override;
228 
229  auto setVelocityLimit(double) -> void override;
230 };
231 } // namespace concealer
232 
233 #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:146
auto getAutowareStateString(std::uint8_t state) const -> char const *
Definition: field_operator_application_for_autoware_universe.hpp:122
CONCEALER_PUBLIC FieldOperatorApplicationFor(Ts &&... xs)
Definition: field_operator_application_for_autoware_universe.hpp:150
Definition: field_operator_application.hpp:44
Definition: field_operator_application.hpp:60
#define CONCEALER_PUBLIC
Definition: visibility.hpp:49
#define CASE(IDENTIFIER)
#define DEFINE_STATE_PREDICATE(NAME, VALUE)
Definition: field_operator_application_for_autoware_universe.hpp:106
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:27