Autoware.Auto
ssc_interface.hpp
Go to the documentation of this file.
1 // Copyright 2020 The Autoware Foundation
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 
18 
19 #ifndef SSC_INTERFACE__SSC_INTERFACE_HPP_
20 #define SSC_INTERFACE__SSC_INTERFACE_HPP_
21 
23 
24 #include <common/types.hpp>
26 
27 #include <automotive_platform_msgs/msg/gear_command.hpp>
28 #include <automotive_platform_msgs/msg/gear_feedback.hpp>
29 #include <automotive_platform_msgs/msg/speed_mode.hpp>
30 #include <automotive_platform_msgs/msg/steering_feedback.hpp>
31 #include <automotive_platform_msgs/msg/steer_mode.hpp>
32 #include <automotive_platform_msgs/msg/turn_signal_command.hpp>
33 #include <automotive_platform_msgs/msg/velocity_accel_cov.hpp>
34 #include <autoware_auto_msgs/msg/high_level_control_command.hpp>
35 #include <autoware_auto_msgs/msg/raw_control_command.hpp>
36 #include <autoware_auto_msgs/msg/trajectory_point.hpp>
37 #include <autoware_auto_msgs/msg/vehicle_control_command.hpp>
38 #include <autoware_auto_msgs/msg/vehicle_kinematic_state.hpp>
39 #include <autoware_auto_msgs/msg/vehicle_state_command.hpp>
40 #include <autoware_auto_msgs/msg/vehicle_state_report.hpp>
41 #include <autoware_auto_msgs/srv/autonomy_mode_change.hpp>
42 #include <std_msgs/msg/bool.hpp>
43 
44 #include <rclcpp/rclcpp.hpp>
45 
46 #include <chrono>
47 #include <iostream>
48 #include <memory>
49 #include <mutex>
50 
54 
55 using automotive_platform_msgs::msg::GearCommand;
56 using automotive_platform_msgs::msg::GearFeedback;
57 using automotive_platform_msgs::msg::SpeedMode;
58 using automotive_platform_msgs::msg::SteeringFeedback;
59 using automotive_platform_msgs::msg::SteerMode;
60 using automotive_platform_msgs::msg::TurnSignalCommand;
61 using automotive_platform_msgs::msg::VelocityAccelCov;
62 using autoware_auto_msgs::msg::HighLevelControlCommand;
63 using autoware_auto_msgs::msg::RawControlCommand;
67 using autoware_auto_msgs::msg::VehicleStateCommand;
68 using autoware_auto_msgs::srv::AutonomyModeChange;
69 using ModeChangeRequest = autoware_auto_msgs::srv::AutonomyModeChange_Request;
70 
71 namespace ssc_interface
72 {
73 
74 static constexpr float32_t STEERING_TO_TIRE_RATIO = 0.533F / 8.6F;
75 
76 enum class DbwState
77 {
78  DISABLED = 0,
79  ENABLE_REQUESTED = 1,
80  ENABLE_SENT = 2,
81  ENABLED = 3
82 };
83 
85 class SSC_INTERFACE_PUBLIC DbwStateMachine
86 {
87 public:
90  explicit DbwStateMachine(uint16_t dbw_disabled_debounce);
91 
93  bool8_t enabled() const;
94 
97  DbwState get_state() const;
98 
101  void dbw_feedback(bool8_t enabled);
102 
104  void control_cmd_sent();
105 
107  void state_cmd_sent();
108 
111  void user_request(bool8_t enable);
112 
113 private:
114  bool8_t m_first_control_cmd_sent;
115  bool8_t m_first_state_cmd_sent;
116  uint16_t m_disabled_feedback_count;
117  const uint16_t DISABLED_FEEDBACK_THRESH;
118  DbwState m_state;
119 
120  void disable_and_reset();
121 };
122 
124 class SSC_INTERFACE_PUBLIC SscInterface
126 {
127 public:
135  explicit SscInterface(
136  rclcpp::Node & node,
137  float32_t front_axle_to_cog,
138  float32_t rear_axle_to_cog,
139  float32_t max_accel_mps2,
140  float32_t max_decel_mps2,
141  float32_t max_yaw_rate_rad
142  );
144  ~SscInterface() noexcept override = default;
145 
150  bool8_t update(std::chrono::nanoseconds timeout) override;
155  bool8_t send_state_command(const VehicleStateCommand & msg) override;
160  bool8_t send_control_command(const HighLevelControlCommand & msg);
165  bool8_t send_control_command(const RawControlCommand & msg) override;
170  bool8_t send_control_command(const VehicleControlCommand & msg) override;
175  bool8_t handle_mode_change_request(ModeChangeRequest::SharedPtr request) override;
176 
177  static void kinematic_bicycle_model(
178  float32_t dt, float32_t l_r, float32_t l_f, VehicleKinematicState * vks);
179 
180 private:
181  // Publishers (to SSC)
182  rclcpp::Publisher<GearCommand>::SharedPtr m_gear_cmd_pub;
183  rclcpp::Publisher<SpeedMode>::SharedPtr m_speed_cmd_pub;
184  rclcpp::Publisher<SteerMode>::SharedPtr m_steer_cmd_pub;
185  rclcpp::Publisher<TurnSignalCommand>::SharedPtr m_turn_signal_cmd_pub;
186 
187  // Publishers (to Autoware)
188  rclcpp::Publisher<VehicleKinematicState>::SharedPtr m_kinematic_state_pub;
189 
190  // Subscribers (from SSC)
191  rclcpp::SubscriptionBase::SharedPtr m_dbw_state_sub, m_gear_feedback_sub, m_vel_accel_sub,
192  m_steer_sub;
193 
194  rclcpp::Logger m_logger;
195  float32_t m_front_axle_to_cog;
196  float32_t m_rear_axle_to_cog;
197  float32_t m_accel_limit;
198  float32_t m_decel_limit;
199  float32_t m_max_yaw_rate;
200  std::unique_ptr<DbwStateMachine> m_dbw_state_machine;
201 
202  // The vehicle kinematic state is stored because it needs information from
203  // both on_steer_report() and on_vel_accel_report().
204  VehicleKinematicState m_vehicle_kinematic_state;
205  bool m_seen_steer{false};
206  bool m_seen_vel_accel{false};
207  // In case both arrive at the same time
208  std::mutex m_vehicle_kinematic_state_mutex;
209 
210  void on_dbw_state_report(const std_msgs::msg::Bool::SharedPtr & msg);
211  void on_gear_report(const GearFeedback::SharedPtr & msg);
212  void on_steer_report(const SteeringFeedback::SharedPtr & msg);
213  void on_vel_accel_report(const VelocityAccelCov::SharedPtr & msg);
214 };
215 
216 } // namespace ssc_interface
217 
218 #endif // SSC_INTERFACE__SSC_INTERFACE_HPP_
autoware::motion::control::pure_pursuit::VehicleControlCommand
autoware_auto_msgs::msg::VehicleControlCommand VehicleControlCommand
Definition: pure_pursuit.hpp:41
ssc_interface::DbwState::ENABLED
@ ENABLED
ssc_interface
Definition: ssc_interface.hpp:71
motion::motion_testing_nodes::TrajectoryPoint
autoware_auto_msgs::msg::TrajectoryPoint TrajectoryPoint
Definition: motion_testing_publisher.hpp:36
autoware::trajectory_spoofer::VehicleKinematicState
autoware_auto_msgs::msg::VehicleKinematicState VehicleKinematicState
Definition: trajectory_spoofer.hpp:44
autoware::common::types::TAU
constexpr float32_t TAU
tau = 2 pi
Definition: types.hpp:44
types.hpp
This file includes common type definition.
ssc_interface::DbwStateMachine
Class for maintaining the DBW state.
Definition: ssc_interface.hpp:85
ModeChangeRequest
autoware_auto_msgs::srv::AutonomyModeChange_Request ModeChangeRequest
Definition: ssc_interface.hpp:69
ssc_interface::DbwState::ENABLE_SENT
@ ENABLE_SENT
autoware::drivers::vehicle_interface::PlatformInterface
Definition: platform_interface.hpp:52
autoware::common::types::bool8_t
bool bool8_t
Definition: types.hpp:33
ssc_interface::DbwState::ENABLE_REQUESTED
@ ENABLE_REQUESTED
platform_interface.hpp
Base class for vehicle "translator".
ssc_interface::DbwState
DbwState
Definition: ssc_interface.hpp:76
ssc_interface::DbwState::DISABLED
@ DISABLED
autoware::common::types::float32_t
float float32_t
Definition: types.hpp:36
ssc_interface::SscInterface
Class for interfacing with AS SSC.
Definition: ssc_interface.hpp:124
ssc_interface::STEERING_TO_TIRE_RATIO
static constexpr float32_t STEERING_TO_TIRE_RATIO
Definition: ssc_interface.hpp:74
visibility_control.hpp