Go to the documentation of this file.
18 #ifndef VEHICLE_INTERFACE__SAFETY_STATE_MACHINE_HPP_
19 #define VEHICLE_INTERFACE__SAFETY_STATE_MACHINE_HPP_
22 #include <autoware_auto_msgs/msg/vehicle_control_command.hpp>
23 #include <autoware_auto_msgs/msg/vehicle_odometry.hpp>
24 #include <autoware_auto_msgs/msg/vehicle_state_command.hpp>
25 #include <autoware_auto_msgs/msg/vehicle_state_report.hpp>
26 #include <vehicle_interface/visibility_control.hpp>
28 #include <experimental/optional>
39 namespace vehicle_interface
41 using MaybeStateCommand = std::experimental::optional<autoware_auto_msgs::msg::VehicleStateCommand>;
43 using Odometry = autoware_auto_msgs::msg::VehicleOdometry;
44 using StateReport = autoware_auto_msgs::msg::VehicleStateReport;
53 : m_control{control}, m_state{state} {}
90 : m_min{min}, m_max{max}, m_threshold{threshold}
93 throw std::domain_error{
"min >= max"};
97 T min() const noexcept {
return m_min;}
98 T max() const noexcept {
return m_max;}
103 const auto value_raw = value;
104 value = std::min(std::max(m_min, value_raw), m_max);
105 return std::abs(value - value_raw) >= m_threshold;
119 using AccelT = decltype(BasicControlCommand::long_accel_mps2);
143 const VelocityT gear_shift_velocity_threshold,
146 const std::chrono::nanoseconds time_step,
147 const AccelT timeout_accel_mps2,
148 const std::chrono::nanoseconds state_transition_timeout,
149 const AccelT auto_gear_shift_accel_deadzone_mps2
152 VelocityT gear_shift_velocity_threshold() const noexcept;
155 std::chrono::nanoseconds time_step() const noexcept;
156 AccelT timeout_acceleration() const noexcept;
157 std::chrono::nanoseconds state_transition_timeout() const noexcept;
158 AccelT auto_gear_shift_accel_deadzone() const noexcept;
161 VelocityT m_gear_shift_velocity_threshold;
164 std::chrono::nanoseconds m_time_step;
165 AccelT m_timeout_acceleration;
166 std::chrono::nanoseconds m_state_transition_timeout;
167 AccelT m_auto_gear_shift_accel_deadzone;
176 using Reports = std::vector<StateMachineReport>;
190 Command timeout_commands() const noexcept;
192 const
Reports & reports() const noexcept;
198 using MaybeEnum = std::experimental::optional<decltype(VSC::blinker)>;
204 std::chrono::system_clock::time_point stamp{std::chrono::system_clock::time_point::min()};
206 struct StateChangeRequests
208 ValueStamp<decltype(VSC::gear)> gear;
209 ValueStamp<decltype(VSC::blinker)> blinker;
210 ValueStamp<decltype(VSC::wiper)> wiper;
211 ValueStamp<decltype(VSC::headlight)> headlight;
212 ValueStamp<decltype(VSC::mode)> mode;
213 ValueStamp<decltype(VSC::hand_brake)> hand_brake;
214 ValueStamp<decltype(VSC::horn)> horn;
224 const VSC & state)
const;
234 StateMachineConfig m_config;
237 StateChangeRequests m_requests{};
238 mutable Reports m_reports{};
244 #endif // VEHICLE_INTERFACE__SAFETY_STATE_MACHINE_HPP_
autoware_auto_msgs::msg::VehicleControlCommand VehicleControlCommand
Definition: pure_pursuit.hpp:41
@ STATE_TRANSITION_TIMEOUT
Commanded state transition didn't happen.
T
Definition: catr_diff.py:22
T threshold() const noexcept
Definition: safety_state_machine.hpp:99
This file includes common type definition.
StateMachineReport
Definition: safety_state_machine.hpp:67
T clamp(T val, T min, T max)
Standard clamp implementation.
Definition: motion_common.hpp:142
autoware_auto_msgs::msg::VehicleStateReport StateReport
Definition: safety_state_machine.hpp:44
Command(const BasicControlCommand &control=BasicControlCommand{}, const MaybeStateCommand &state=MaybeStateCommand{})
Constructor.
Definition: safety_state_machine.hpp:50
T min() const noexcept
Definition: safety_state_machine.hpp:97
Configuration class for SafetyStateMachine.
Definition: safety_state_machine.hpp:115
@ BAD_STATE
A state command was not one of the specified constants.
@ CLAMP_PAST_THRESHOLD
Clamped a command that was way out of bounds.
std::experimental::optional< autoware_auto_msgs::msg::VehicleStateCommand > MaybeStateCommand
Definition: safety_state_machine.hpp:41
const BasicControlCommand & control() const noexcept
Getter.
Definition: safety_state_machine.hpp:56
Definition: motion_common.hpp:259
bool bool8_t
Definition: types.hpp:33
Definition: safety_state_machine.hpp:173
bool8_t clamp_warn(T &value) const noexcept
Clamps value to max/min range; return true if value is threshold past limits.
Definition: safety_state_machine.hpp:101
autoware_auto_msgs::msg::VehicleOdometry Odometry
Definition: safety_state_machine.hpp:43
This file defines the lanelet2_map_provider_node class.
Definition: quick_sort.hpp:24
#define VEHICLE_INTERFACE_LOCAL
Definition: drivers/vehicle_interface/include/vehicle_interface/visibility_control.hpp:45
Definition: safety_state_machine.hpp:84
Limits(T min, T max, T threshold)
Definition: safety_state_machine.hpp:89
const MaybeStateCommand & state() const noexcept
Getter.
Definition: safety_state_machine.hpp:58
@ WIPERS_ON_HEADLIGHTS_ON
Turn on headlights because you turned on wipers.
@ HIGH_FREQUENCY_STEER_REPORT
Reported steering has high frequency components.
@ HIGH_FREQUENCY_VELOCITY_REPORT
Reported velocity has high frequency components.
@ REMOVE_GEAR_COMMAND
Converted gear command to GEAR_NO_COMMAND because you're going too fast.
decltype(BasicControlCommand::long_accel_mps2) AccelT
Definition: safety_state_machine.hpp:119
autoware_auto_msgs::msg::VehicleControlCommand BasicControlCommand
Definition: safety_state_machine.hpp:42
@ HIGH_FREQUENCY_ACCELERATION_COMMAND
Acceleration has high frequency components.
@ HIGH_FREQUENCY_STEER_COMMAND
Steering has high frequency components.
decltype(Odometry::velocity_mps) VelocityT
Definition: safety_state_machine.hpp:118
std::vector< StateMachineReport > Reports
Definition: safety_state_machine.hpp:176
Simple wrapper for control command and state command together.
Definition: safety_state_machine.hpp:46
autoware_auto_msgs::msg::VehicleStateCommand VSC
Definition: lgsvl_interface.hpp:78
T max() const noexcept
Definition: safety_state_machine.hpp:98
#define VEHICLE_INTERFACE_PUBLIC
Definition: drivers/vehicle_interface/include/vehicle_interface/visibility_control.hpp:44