15 #ifndef CONCEALER__TRANSITION_ASSERTION_HPP_
16 #define CONCEALER__TRANSITION_ASSERTION_HPP_
19 #include <rclcpp/node.hpp>
20 #include <rclcpp/rate.hpp>
25 template <
typename Autoware>
28 const std::chrono::steady_clock::time_point
start;
36 auto node = rclcpp::Node(
"get_parameter",
"simulation");
37 node.declare_parameter(
"initialize_duration", 0);
38 return node.get_parameter(
"initialize_duration").as_int();
43 #define DEFINE_WAIT_FOR_AUTOWARE_STATE_TO_BE(STATE) \
44 template <typename Thunk = void (*)(), typename Interval = std::chrono::seconds> \
45 auto waitForAutowareStateToBe##STATE( \
46 Thunk && thunk = [] {}, Interval interval = std::chrono::seconds(1)) \
48 for (thunk(); not static_cast<const Autoware &>(*this).isStopRequested() and \
49 not static_cast<const Autoware &>(*this).is##STATE(); \
50 rclcpp::GenericRate<std::chrono::steady_clock>(interval).sleep()) { \
52 have_never_been_engaged and \
53 start + initialize_duration <= std::chrono::steady_clock::now()) { \
54 const auto state = static_cast<const Autoware &>(*this).getAutowareStateName(); \
55 throw common::AutowareError( \
56 "Simulator waited for the Autoware state to transition to " #STATE \
57 ", but time is up. The current Autoware state is ", \
58 (state.empty() ? "not published yet" : state)); \
63 if constexpr (std::string_view(#STATE) == std::string_view("Driving")) { \
64 have_never_been_engaged = false; \
77 #undef DEFINE_WAIT_FOR_AUTOWARE_STATE_TO_BE
Definition: autoware.hpp:30
Definition: transition_assertion.hpp:27
DEFINE_WAIT_FOR_AUTOWARE_STATE_TO_BE(Planning)
DEFINE_WAIT_FOR_AUTOWARE_STATE_TO_BE(Finalizing)
DEFINE_WAIT_FOR_AUTOWARE_STATE_TO_BE(ArrivedGoal)
DEFINE_WAIT_FOR_AUTOWARE_STATE_TO_BE(Initializing)
DEFINE_WAIT_FOR_AUTOWARE_STATE_TO_BE(Driving)
TransitionAssertion()
Definition: transition_assertion.hpp:34
DEFINE_WAIT_FOR_AUTOWARE_STATE_TO_BE(WaitingForRoute)
DEFINE_WAIT_FOR_AUTOWARE_STATE_TO_BE(WaitingForEngage)
bool have_never_been_engaged
Definition: transition_assertion.hpp:32
const std::chrono::seconds initialize_duration
Definition: transition_assertion.hpp:30
const std::chrono::steady_clock::time_point start
Definition: transition_assertion.hpp:28