15 #ifndef CONCEALER__TRANSITION_ASSERTION_HPP_
16 #define CONCEALER__TRANSITION_ASSERTION_HPP_
18 #include <autoware_auto_system_msgs/msg/autoware_state.hpp>
20 #include <rclcpp/node.hpp>
21 #include <rclcpp/rate.hpp>
29 rclcpp::Node node{
"get_parameter",
"simulation"};
31 node.declare_parameter<T>(name, value);
32 node.get_parameter<T>(name, value);
37 template <
typename Autoware>
43 const clock_type::time_point
start;
54 const auto current_state =
asAutoware().getAutowareStateName();
55 using namespace std::chrono;
57 "Simulator waited for the Autoware state to transition to ", expected,
58 ", but time is up. The current Autoware state is ",
59 (current_state.empty() ?
"NOT PUBLISHED YET" : current_state),
".");
65 #define DEFINE_WAIT_FOR_AUTOWARE_STATE_TO_BE_WITH_INITIALIZE_TIME_LIMIT(STATE) \
66 template <typename Thunk = void (*)()> \
67 void waitForAutowareStateToBe##STATE( \
68 Thunk && thunk = [] {}, std::chrono::seconds interval = std::chrono::seconds(1)) \
70 using std::chrono::duration_cast; \
71 using std::chrono::seconds; \
72 rate_type rate(interval); \
73 for (thunk(); not asAutoware().isStopRequested() and not asAutoware().is##STATE(); \
75 auto now = clock_type::now(); \
76 if (start + initialize_duration <= now) { \
77 throw makeTransitionError(#STATE); \
80 asAutoware().get_logger(), \
81 "Simulator waiting for Autoware state to be " #STATE " (remain: " \
82 << duration_cast<seconds>(start + initialize_duration - now).count() << ")."); \
87 asAutoware().get_logger(), \
88 "Autoware is " << asAutoware().getAutowareStateName() << " now."); \
90 static_assert(true, "")
92 #define DEFINE_WAIT_FOR_AUTOWARE_STATE_TO_BE(STATE) \
93 template <typename Thunk = void (*)()> \
94 void waitForAutowareStateToBe##STATE( \
95 Thunk && thunk = [] {}, std::chrono::seconds interval = std::chrono::seconds(1)) \
97 using std::chrono::duration_cast; \
98 using std::chrono::seconds; \
99 rate_type rate(interval); \
100 for (thunk(); not asAutoware().isStopRequested() and not asAutoware().is##STATE(); \
102 auto now = clock_type::now(); \
103 RCLCPP_INFO_STREAM( \
104 asAutoware().get_logger(), \
105 "Simulator waiting for Autoware state to be " #STATE " (remain: " \
106 << duration_cast<seconds>(start + initialize_duration - now).count() << ")."); \
109 RCLCPP_INFO_STREAM( \
110 asAutoware().get_logger(), \
111 "Autoware is " << asAutoware().getAutowareStateName() << " now."); \
113 static_assert(true, "")
127 #undef DEFINE_WAIT_FOR_AUTOWARE_STATE_TO_BE
Definition: autoware.hpp:38
Definition: autoware.hpp:30
auto getParameter(const std::string &name, T value={})
Definition: transition_assertion.hpp:27
std::string string
Definition: junit5.hpp:26
Autoware encountered some problem that led to a simulation failure.
Definition: exception.hpp:41
Definition: transition_assertion.hpp:39
auto asAutoware() const -> const Autoware &
Definition: transition_assertion.hpp:63
DEFINE_WAIT_FOR_AUTOWARE_STATE_TO_BE(Finalizing)
rclcpp::GenericRate< clock_type > rate_type
Definition: transition_assertion.hpp:41
const clock_type::time_point start
Definition: transition_assertion.hpp:43
DEFINE_WAIT_FOR_AUTOWARE_STATE_TO_BE(ArrivedGoal)
DEFINE_WAIT_FOR_AUTOWARE_STATE_TO_BE(Driving)
DEFINE_WAIT_FOR_AUTOWARE_STATE_TO_BE_WITH_INITIALIZE_TIME_LIMIT(WaitingForRoute)
DEFINE_WAIT_FOR_AUTOWARE_STATE_TO_BE_WITH_INITIALIZE_TIME_LIMIT(WaitingForEngage)
TransitionAssertion()
Definition: transition_assertion.hpp:46
std::chrono::steady_clock clock_type
Definition: transition_assertion.hpp:40
auto asAutoware() -> Autoware &
Definition: transition_assertion.hpp:62
DEFINE_WAIT_FOR_AUTOWARE_STATE_TO_BE_WITH_INITIALIZE_TIME_LIMIT(Planning)
const std::chrono::seconds initialize_duration
Definition: transition_assertion.hpp:44
auto makeTransitionError(const std::string &expected) const
Definition: transition_assertion.hpp:52
DEFINE_WAIT_FOR_AUTOWARE_STATE_TO_BE_WITH_INITIALIZE_TIME_LIMIT(Initializing)