Skip to content

Commit 6988233

Browse files
authored
feat(simple_planning_simulator): add VGR sim model (#8415)
* feat(simple_planning_simulator): add VGR sim model Signed-off-by: kosuke55 <kosuke.tnp@gmail.com> * Update simulator/simple_planning_simulator/test/test_simple_planning_simulator.cpp * move to interface Signed-off-by: kosuke55 <kosuke.tnp@gmail.com> * add const Signed-off-by: kosuke55 <kosuke.tnp@gmail.com> --------- Signed-off-by: kosuke55 <kosuke.tnp@gmail.com>
1 parent d95cfae commit 6988233

File tree

9 files changed

+1127
-39
lines changed

9 files changed

+1127
-39
lines changed

simulator/simple_planning_simulator/README.md

+22-9
Original file line numberDiff line numberDiff line change
@@ -127,17 +127,30 @@ default, 0.00, 1.39, 2.78, 4.17, 5.56, 6.94, 8.33, 9.72, 11.11, 12.50, 1
127127

128128
The simple_planning_simulator usually operates by receiving Control commands, but when the `ACTUATION_CMD` model is selected, it receives Actuation commands instead of Control commands. This model can simulate the motion using the vehicle command that is actually sent to the real vehicle. Therefore, when this model is selected, the `raw_vehicle_cmd_converter` is also launched.
129129

130+
`convert_steer_cmd_method` has two options: "vgr" and "steer_map". If you choose "vgr" (variable gear ratio), it is assumed that the steering wheel angle is sent as the actuation command, and the value is converted to the steering tire angle to move the model. If you choose "steer_map", it is assumed that an arbitrary value is sent as the actuation command, and the value is converted to the steering tire rate to move the model. An arbitrary value is like EPS (Electric Power Steering) Voltage . `enable_pub_steer` determines whether to publish the steering tire angle. If false, it is expected to be converted and published from actuation_status in other nodes (e.g. raw_vehicle_cmd_converter).
131+
132+
![vgr_sim](./media/vgr_sim.drawio.svg)
133+
134+
```yaml
135+
136+
```
137+
130138
The parameters used in the ACTUATION_CMD are as follows.
131139

132-
| Name | Type | Description | unit |
133-
| :------------------ | :----- | :-------------------------------------------------------------------------------------------------------------------------------------------------------------- | :--- |
134-
| accel_time_delay | double | dead time for the acceleration input | [s] |
135-
| accel_time_constant | double | time constant of the 1st-order acceleration dynamics | [s] |
136-
| brake_time_delay | double | dead time for the brake input | [s] |
137-
| brake_time_constant | double | time constant of the 1st-order brake dynamics | [s] |
138-
| convert_accel_cmd | bool | If true, it is assumed that the command is received converted to an accel actuation value, and it is converted back to acceleration value inside the simulator. | [-] |
139-
| convert_brake_cmd | bool | If true, it is assumed that the command is received converted to a brake actuation value, and it is converted back to acceleration value inside the simulator. | [-] |
140-
| convert_steer_cmd | bool | If true, it is assumed that the command is received converted to a steer actuation value, and it is converted back to steer rate value inside the simulator. | [-] |
140+
| Name | Type | Description | unit |
141+
| :----------------------- | :----- | :----------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :--- |
142+
| accel_time_delay | double | dead time for the acceleration input | [s] |
143+
| accel_time_constant | double | time constant of the 1st-order acceleration dynamics | [s] |
144+
| brake_time_delay | double | dead time for the brake input | [s] |
145+
| brake_time_constant | double | time constant of the 1st-order brake dynamics | [s] |
146+
| convert_accel_cmd | bool | If true, it is assumed that the command is received converted to an accel actuation value, and it is converted back to acceleration value inside the simulator. | [-] |
147+
| convert_brake_cmd | bool | If true, it is assumed that the command is received converted to a brake actuation value, and it is converted back to acceleration value inside the simulator. | [-] |
148+
| convert_steer_cmd | bool | If true, it is assumed that the command is received converted to a steer actuation value, and it is converted back to steer rate value inside the simulator. | [-] |
149+
| convert_steer_cmd_method | bool | method to convert steer command. You can choose from "vgr" and "steer_map". | [-] |
150+
| vgr_coef_a | double | the value of the coefficient a of the variable gear ratio | [-] |
151+
| vgr_coef_b | double | the value of the coefficient b of the variable gear ratio | [-] |
152+
| vgr_coef_c | double | the value of the coefficient c of the variable gear ratio | [-] |
153+
| enable_pub_steer | bool | whether to publish the steering tire angle. if false, it is expected to be converted and published from actuation_status in other nodes (e.g. raw_vehicle_cmd_converter) | [-] |
141154

142155
<!-- deadzone_delta_steer | double | dead zone for the steering dynamics | x | x | x | o | o | 0.0 | [rad] | | -->
143156

simulator/simple_planning_simulator/include/simple_planning_simulator/simple_planning_simulator_core.hpp

+9
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
#include "sensor_msgs/msg/imu.hpp"
4646
#include "tier4_external_api_msgs/srv/initialize_pose.hpp"
4747
#include "tier4_vehicle_msgs/msg/actuation_command_stamped.hpp"
48+
#include "tier4_vehicle_msgs/msg/actuation_status_stamped.hpp"
4849

4950
#include <lanelet2_core/geometry/Lanelet.h>
5051
#include <tf2_ros/buffer.h>
@@ -86,6 +87,7 @@ using nav_msgs::msg::Odometry;
8687
using sensor_msgs::msg::Imu;
8788
using tier4_external_api_msgs::srv::InitializePose;
8889
using tier4_vehicle_msgs::msg::ActuationCommandStamped;
90+
using tier4_vehicle_msgs::msg::ActuationStatusStamped;
8991

9092
class DeltaTime
9193
{
@@ -138,6 +140,7 @@ class PLANNING_SIMULATOR_PUBLIC SimplePlanningSimulator : public rclcpp::Node
138140
rclcpp::Publisher<HazardLightsReport>::SharedPtr pub_hazard_lights_report_;
139141
rclcpp::Publisher<tf2_msgs::msg::TFMessage>::SharedPtr pub_tf_;
140142
rclcpp::Publisher<PoseWithCovarianceStamped>::SharedPtr pub_current_pose_;
143+
rclcpp::Publisher<ActuationStatusStamped>::SharedPtr pub_actuation_status_;
141144

142145
rclcpp::Subscription<GearCommand>::SharedPtr sub_gear_cmd_;
143146
rclcpp::Subscription<GearCommand>::SharedPtr sub_manual_gear_cmd_;
@@ -189,6 +192,10 @@ class PLANNING_SIMULATOR_PUBLIC SimplePlanningSimulator : public rclcpp::Node
189192
ControlModeReport current_control_mode_{};
190193
bool enable_road_slope_simulation_ = true;
191194

195+
// if false, it is expected to be converted and published from actuation_status in other nodes
196+
// (e.g. raw_vehicle_cmd_converter)
197+
bool enable_pub_steer_ = true; //!< @brief flag to publish steering report.
198+
192199
/* frame_id */
193200
std::string simulated_frame_id_ = ""; //!< @brief simulated vehicle frame id
194201
std::string origin_frame_id_ = ""; //!< @brief map frame_id
@@ -388,6 +395,8 @@ class PLANNING_SIMULATOR_PUBLIC SimplePlanningSimulator : public rclcpp::Node
388395
*/
389396
void publish_hazard_lights_report();
390397

398+
void publish_actuation_status();
399+
391400
/**
392401
* @brief publish tf
393402
* @param [in] state The kinematic state to publish as a TF

simulator/simple_planning_simulator/include/simple_planning_simulator/vehicle_model/sim_model_actuation_cmd.hpp

+127-10
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,22 @@
2323

2424
#include <deque>
2525
#include <iostream>
26+
#include <optional>
2627
#include <queue>
2728
#include <string>
2829
#include <vector>
2930

3031
/**
3132
* @class ActuationMap
32-
* @brief class to convert actuation command
33+
* @brief class to convert from actuation command to control command
34+
*
35+
* ------- state ------->
36+
* |
37+
* |
38+
* actuation control
39+
* |
40+
* |
41+
* V
3342
*/
3443
class ActuationMap
3544
{
@@ -43,21 +52,91 @@ class ActuationMap
4352
bool readActuationMapFromCSV(const std::string & csv_path, const bool validation = false);
4453
double getControlCommand(const double actuation, const double state) const;
4554

46-
private:
55+
protected:
4756
std::vector<double> state_index_; // e.g. velocity, steering
4857
std::vector<double> actuation_index_;
4958
std::vector<std::vector<double>> actuation_map_;
5059
};
5160

61+
/**
62+
* @class AccelMap
63+
* @brief class to get throttle from acceleration
64+
*
65+
* ------- vel ------>
66+
* |
67+
* |
68+
* throttle acc
69+
* |
70+
* |
71+
* V
72+
*/
73+
class AccelMap : public ActuationMap
74+
{
75+
public:
76+
std::optional<double> getThrottle(const double acc, const double vel) const;
77+
};
78+
79+
/**
80+
* @class BrakeMap
81+
* @brief class to get brake from acceleration
82+
*
83+
* ------- vel ------>
84+
* |
85+
* |
86+
* brake acc
87+
* |
88+
* |
89+
* V
90+
*/
91+
class BrakeMap : public ActuationMap
92+
{
93+
public:
94+
double getBrake(const double acc, const double vel) const;
95+
};
96+
5297
/**
5398
* @class SimModelActuationCmd
5499
* @brief class to handle vehicle model with actuation command
55100
*/
56101
class SimModelActuationCmd : public SimModelInterface
57102
{
58103
public:
104+
enum class ActuationSimType { VGR, STEER_MAP };
105+
59106
/**
60-
* @brief constructor
107+
* @brief constructor (adaptive gear ratio conversion model)
108+
* @param [in] vx_lim velocity limit [m/s]
109+
* @param [in] steer_lim steering limit [rad]
110+
* @param [in] vx_rate_lim acceleration limit [m/ss]
111+
* @param [in] steer_rate_lim steering angular velocity limit [rad/ss]
112+
* @param [in] wheelbase vehicle wheelbase length [m]
113+
* @param [in] dt delta time information to set input buffer for delay
114+
* @param [in] accel_delay time delay for accel command [s]
115+
* @param [in] acc_time_constant time constant for 1D model of accel dynamics
116+
* @param [in] brake_delay time delay for brake command [s]
117+
* @param [in] brake_time_constant time constant for 1D model of brake dynamics
118+
* @param [in] steer_delay time delay for steering command [s]
119+
* @param [in] steer_time_constant time constant for 1D model of steering dynamics
120+
* @param [in] steer_bias steering bias [rad]
121+
* @param [in] convert_accel_cmd flag to convert accel command
122+
* @param [in] convert_brake_cmd flag to convert brake command
123+
* @param [in] convert_steer_cmd flag to convert steer command
124+
* @param [in] accel_map_path path to csv file for accel conversion map
125+
* @param [in] brake_map_path path to csv file for brake conversion map
126+
* @param [in] vgr_coef_a coefficient for variable gear ratio
127+
* @param [in] vgr_coef_b coefficient for variable gear ratio
128+
* @param [in] vgr_coef_c coefficient for variable gear ratio
129+
*/
130+
SimModelActuationCmd(
131+
double vx_lim, double steer_lim, double vx_rate_lim, double steer_rate_lim, double wheelbase,
132+
double dt, double accel_delay, double accel_time_constant, double brake_delay,
133+
double brake_time_constant, double steer_delay, double steer_time_constant, double steer_bias,
134+
bool convert_accel_cmd, bool convert_brake_cmd, bool convert_steer_cmd,
135+
std::string accel_map_path, std::string brake_map_path, double vgr_coef_a, double vgr_coef_b,
136+
double vgr_coef_c);
137+
138+
/**
139+
* @brief constructor (steer map conversion model)
61140
* @param [in] vx_lim velocity limit [m/s]
62141
* @param [in] steer_lim steering limit [rad]
63142
* @param [in] vx_rate_lim acceleration limit [m/ss]
@@ -90,13 +169,15 @@ class SimModelActuationCmd : public SimModelInterface
90169
*/
91170
~SimModelActuationCmd() = default;
92171

93-
ActuationMap accel_map_;
94-
ActuationMap brake_map_;
95-
ActuationMap steer_map_;
172+
/*
173+
* @brief get actuation status
174+
*/
175+
std::optional<ActuationStatusStamped> getActuationStatus() const override;
96176

97-
bool convert_accel_cmd_;
98-
bool convert_brake_cmd_;
99-
bool convert_steer_cmd_;
177+
/**
178+
* @brief is publish actuation status enabled
179+
*/
180+
bool shouldPublishActuationStatus() const override { return true; }
100181

101182
private:
102183
const double MIN_TIME_CONSTANT; //!< @brief minimum time constant
@@ -133,7 +214,23 @@ class SimModelActuationCmd : public SimModelInterface
133214
const double steer_delay_; //!< @brief time delay for steering command [s]
134215
const double steer_time_constant_; //!< @brief time constant for steering dynamics
135216
const double steer_bias_; //!< @brief steering angle bias [rad]
136-
const std::string path_; //!< @brief conversion map path
217+
218+
bool convert_accel_cmd_;
219+
bool convert_brake_cmd_;
220+
bool convert_steer_cmd_;
221+
222+
AccelMap accel_map_;
223+
BrakeMap brake_map_;
224+
ActuationMap steer_map_;
225+
226+
// steer map conversion model
227+
228+
// adaptive gear ratio conversion model
229+
double vgr_coef_a_;
230+
double vgr_coef_b_;
231+
double vgr_coef_c_;
232+
233+
ActuationSimType actuation_sim_type_{ActuationSimType::VGR};
137234

138235
/**
139236
* @brief set queue buffer for input command
@@ -204,6 +301,26 @@ class SimModelActuationCmd : public SimModelInterface
204301
void updateStateWithGear(
205302
Eigen::VectorXd & state, const Eigen::VectorXd & prev_state, const uint8_t gear,
206303
const double dt);
304+
305+
/**
306+
* @brief calculate steering tire command
307+
* @param [in] vel current velocity [m/s]
308+
* @param [in] steer current steering angle [rad]
309+
* @param [in] steer_wheel_des desired steering wheel angle [rad]
310+
* @return steering tire command
311+
*/
312+
double calculateSteeringTireCommand(
313+
const double vel, const double steer, const double steer_wheel_des) const;
314+
315+
double calculateSteeringWheelState(const double target_tire_angle, const double vel) const;
316+
317+
/**
318+
* @brief calculate variable gear ratio
319+
* @param [in] vel current velocity [m/s]
320+
* @param [in] steer_wheel current steering wheel angle [rad]
321+
* @return variable gear ratio
322+
*/
323+
double calculateVariableGearRatio(const double vel, const double steer_wheel) const;
207324
};
208325

209326
#endif // SIMPLE_PLANNING_SIMULATOR__VEHICLE_MODEL__SIM_MODEL_ACTUATION_CMD_HPP_

simulator/simple_planning_simulator/include/simple_planning_simulator/vehicle_model/sim_model_interface.hpp

+15
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
#include <Eigen/Core>
1919

2020
#include "autoware_vehicle_msgs/msg/gear_command.hpp"
21+
#include "tier4_vehicle_msgs/msg/actuation_status_stamped.hpp"
22+
23+
#include <optional>
2124

2225
/**
2326
* @class SimModelInterface
@@ -26,6 +29,8 @@
2629
class SimModelInterface
2730
{
2831
protected:
32+
using ActuationStatusStamped = tier4_vehicle_msgs::msg::ActuationStatusStamped;
33+
2934
const int dim_x_; //!< @brief dimension of state x
3035
const int dim_u_; //!< @brief dimension of input u
3136
Eigen::VectorXd state_; //!< @brief vehicle state vector
@@ -152,6 +157,16 @@ class SimModelInterface
152157
*/
153158
inline int getDimU() { return dim_u_; }
154159

160+
/**
161+
* @brief is publish actuation status enabled
162+
*/
163+
virtual bool shouldPublishActuationStatus() const { return false; }
164+
165+
/*
166+
* @brief get actuation status
167+
*/
168+
virtual std::optional<ActuationStatusStamped> getActuationStatus() const { return std::nullopt; }
169+
155170
/**
156171
* @brief calculate derivative of states with vehicle model
157172
* @param [in] state current model state

simulator/simple_planning_simulator/launch/simple_planning_simulator.launch.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ def launch_setup(context, *args, **kwargs):
6262
("output/turn_indicators_report", "/vehicle/status/turn_indicators_status"),
6363
("output/hazard_lights_report", "/vehicle/status/hazard_lights_status"),
6464
("output/control_mode_report", "/vehicle/status/control_mode"),
65+
("output/actuation_status", "/vehicle/status/actuation_status"),
6566
]
6667

6768
# Additional remappings
@@ -110,8 +111,6 @@ def launch_setup(context, *args, **kwargs):
110111
== "ACTUATION_CMD"
111112
)
112113

113-
# launch_vehicle_cmd_converter = False # tmp
114-
115114
# 1) Launch only simple_planning_simulator_node
116115
if not launch_vehicle_cmd_converter:
117116
return [simple_planning_simulator_node]

0 commit comments

Comments
 (0)