Skip to content

Commit 4627d92

Browse files
feat: add sim_model_delay_articulate_acc_geared for adt model (#1548)
* add sim_model_delay_articulate_acc_geared for adt model Signed-off-by: Autumn60 <harada.akiro@gmail.com> * style(pre-commit): autofix * enable articulate model VehicleModelType for psim Signed-off-by: Autumn60 <harada.akiro@gmail.com> * style(pre-commit): autofix * parameterize wheelbase ratio Signed-off-by: Autumn60 <harada.akiro@gmail.com> --------- Signed-off-by: Autumn60 <harada.akiro@gmail.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 79dc610 commit 4627d92

File tree

6 files changed

+380
-3
lines changed

6 files changed

+380
-3
lines changed

simulator/simple_planning_simulator/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ ament_auto_add_library(${PROJECT_NAME} SHARED
2121
src/simple_planning_simulator/vehicle_model/sim_model_delay_steer_acc_geared.cpp
2222
src/simple_planning_simulator/vehicle_model/sim_model_delay_steer_acc_geared_wo_fall_guard.cpp
2323
src/simple_planning_simulator/vehicle_model/sim_model_delay_steer_map_acc_geared.cpp
24+
src/simple_planning_simulator/vehicle_model/articulate/sim_model_delay_articulate_acc_geared.cpp
2425
src/simple_planning_simulator/utils/csv_loader.cpp
2526
)
2627
target_include_directories(${PROJECT_NAME} PUBLIC ${Python3_INCLUDE_DIRS} ${learning_based_vehicle_model_INCLUDE_DIRS})

simulator/simple_planning_simulator/include/simple_planning_simulator/simple_planning_simulator_core.hpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,8 @@ class PLANNING_SIMULATOR_PUBLIC SimplePlanningSimulator : public rclcpp::Node
206206
DELAY_STEER_VEL = 5,
207207
DELAY_STEER_MAP_ACC_GEARED = 6,
208208
LEARNED_STEER_VEL = 7,
209-
DELAY_STEER_ACC_GEARED_WO_FALL_GUARD = 8
209+
DELAY_STEER_ACC_GEARED_WO_FALL_GUARD = 8,
210+
DELAY_ARTICULATE_ACC_GEARED = 9
210211
} vehicle_model_type_; //!< @brief vehicle model type to decide the model dynamics
211212
std::shared_ptr<SimModelInterface> vehicle_model_ptr_; //!< @brief vehicle model pointer
212213

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
// Copyright 2024 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+
15+
#ifndef SIMPLE_PLANNING_SIMULATOR__VEHICLE_MODEL__ARTICULATE__SIM_MODEL_DELAY_ARTICULATE_ACC_GEARED_HPP_
16+
#define SIMPLE_PLANNING_SIMULATOR__VEHICLE_MODEL__ARTICULATE__SIM_MODEL_DELAY_ARTICULATE_ACC_GEARED_HPP_
17+
18+
#include "simple_planning_simulator/vehicle_model/sim_model_interface.hpp"
19+
20+
#include <Eigen/Core>
21+
#include <Eigen/LU>
22+
23+
#include <deque>
24+
#include <iostream>
25+
#include <queue>
26+
27+
class SimModelDelayArticulateAccGeared : public SimModelInterface
28+
{
29+
public:
30+
/**
31+
* @brief constructor
32+
* @param [in] vx_lim velocity limit [m/s]
33+
* @param [in] steer_lim steering limit [rad]
34+
* @param [in] vx_rate_lim acceleration limit [m/ss]
35+
* @param [in] steer_rate_lim steering angular velocity limit [rad/ss]
36+
* @param [in] wheelbase vehicle wheelbase length [m]
37+
* @param [in] dt delta time information to set input buffer for delay
38+
* @param [in] acc_delay time delay for accel command [s]
39+
* @param [in] acc_time_constant time constant for 1D model of accel dynamics
40+
* @param [in] steer_delay time delay for steering command [s]
41+
* @param [in] steer_time_constant time constant for 1D model of steering dynamics
42+
* @param [in] steer_dead_band dead band for steering angle [rad]
43+
* @param [in] steer_bias steering bias [rad]
44+
* @param [in] debug_acc_scaling_factor scaling factor for accel command
45+
* @param [in] debug_steer_scaling_factor scaling factor for steering command
46+
*/
47+
SimModelDelayArticulateAccGeared(
48+
double vx_lim, double steer_lim, double vx_rate_lim, double steer_rate_lim,
49+
double front_wheelbase, double rear_wheelbase, double dt, double acc_delay,
50+
double acc_time_constant, double steer_delay, double steer_time_constant,
51+
double steer_dead_band, double steer_bias, double debug_acc_scaling_factor,
52+
double debug_steer_scaling_factor);
53+
54+
/**
55+
* @brief default destructor
56+
*/
57+
~SimModelDelayArticulateAccGeared() = default;
58+
59+
private:
60+
const double MIN_TIME_CONSTANT; //!< @brief minimum time constant
61+
62+
enum IDX {
63+
X = 0,
64+
Y,
65+
YAW,
66+
VX,
67+
STEER,
68+
ACCX,
69+
};
70+
enum IDX_U {
71+
ACCX_DES = 0,
72+
STEER_DES,
73+
DRIVE_SHIFT,
74+
};
75+
76+
const double vx_lim_; //!< @brief velocity limit [m/s]
77+
const double vx_rate_lim_; //!< @brief acceleration limit [m/ss]
78+
const double steer_lim_; //!< @brief steering limit [rad]
79+
const double steer_rate_lim_; //!< @brief steering angular velocity limit [rad/s]
80+
const double front_wheelbase_; //!< @brief front wheelbase length [m]
81+
const double rear_wheelbase_; //!< @brief rear wheelbase length [m]
82+
83+
std::deque<double> acc_input_queue_; //!< @brief buffer for accel command
84+
std::deque<double> steer_input_queue_; //!< @brief buffer for steering command
85+
const double acc_delay_; //!< @brief time delay for accel command [s]
86+
const double acc_time_constant_; //!< @brief time constant for accel dynamics
87+
const double steer_delay_; //!< @brief time delay for steering command [s]
88+
const double steer_time_constant_; //!< @brief time constant for steering dynamics
89+
const double steer_dead_band_; //!< @brief dead band for steering angle [rad]
90+
const double steer_bias_; //!< @brief steering angle bias [rad]
91+
const double debug_acc_scaling_factor_; //!< @brief scaling factor for accel command
92+
const double debug_steer_scaling_factor_; //!< @brief scaling factor for steering command
93+
94+
double state_steer_rate_; //!< @brief steering angular velocity [rad/s]
95+
96+
/**
97+
* @brief set queue buffer for input command
98+
* @param [in] dt delta time
99+
*/
100+
void initializeInputQueue(const double & dt);
101+
102+
/**
103+
* @brief get vehicle position x
104+
*/
105+
double getX() override;
106+
107+
/**
108+
* @brief get vehicle position y
109+
*/
110+
double getY() override;
111+
112+
/**
113+
* @brief get vehicle angle yaw
114+
*/
115+
double getYaw() override;
116+
117+
/**
118+
* @brief get vehicle velocity vx
119+
*/
120+
double getVx() override;
121+
122+
/**
123+
* @brief get vehicle lateral velocity
124+
*/
125+
double getVy() override;
126+
127+
/**
128+
* @brief get vehicle longitudinal acceleration
129+
*/
130+
double getAx() override;
131+
132+
/**
133+
* @brief get vehicle angular-velocity wz
134+
*/
135+
double getWz() override;
136+
137+
/**
138+
* @brief get vehicle steering angle
139+
*/
140+
double getSteer() override;
141+
142+
/**
143+
* @brief update vehicle states
144+
* @param [in] dt delta time [s]
145+
*/
146+
void update(const double & dt) override;
147+
148+
/**
149+
* @brief calculate derivative of states with time delay steering model
150+
* @param [in] state current model state
151+
* @param [in] input input vector to model
152+
*/
153+
Eigen::VectorXd calcModel(const Eigen::VectorXd & state, const Eigen::VectorXd & input) override;
154+
155+
/**
156+
* @brief update state considering current gear
157+
* @param [in] state current state
158+
* @param [in] prev_state previous state
159+
* @param [in] gear current gear (defined in autoware_vehicle_msgs/GearCommand)
160+
* @param [in] dt delta time to update state
161+
*/
162+
void updateStateWithGear(
163+
Eigen::VectorXd & state, const Eigen::VectorXd & prev_state, const uint8_t gear,
164+
const double dt);
165+
};
166+
167+
#endif // SIMPLE_PLANNING_SIMULATOR__VEHICLE_MODEL__ARTICULATE__SIM_MODEL_DELAY_ARTICULATE_ACC_GEARED_HPP_

simulator/simple_planning_simulator/include/simple_planning_simulator/vehicle_model/sim_model.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#ifndef SIMPLE_PLANNING_SIMULATOR__VEHICLE_MODEL__SIM_MODEL_HPP_
1616
#define SIMPLE_PLANNING_SIMULATOR__VEHICLE_MODEL__SIM_MODEL_HPP_
1717

18+
#include "simple_planning_simulator/vehicle_model/articulate/sim_model_delay_articulate_acc_geared.hpp"
1819
#include "simple_planning_simulator/vehicle_model/sim_model_delay_steer_acc.hpp"
1920
#include "simple_planning_simulator/vehicle_model/sim_model_delay_steer_acc_geared.hpp"
2021
#include "simple_planning_simulator/vehicle_model/sim_model_delay_steer_acc_geared_wo_fall_guard.hpp"

simulator/simple_planning_simulator/src/simple_planning_simulator/simple_planning_simulator_core.cpp

+15-2
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ void SimplePlanningSimulator::initialize_vehicle_model()
234234
const double debug_steer_scaling_factor = declare_parameter("debug_steer_scaling_factor", 1.0);
235235
const auto vehicle_info = autoware::vehicle_info_utils::VehicleInfoUtils(*this).getVehicleInfo();
236236
const double wheelbase = vehicle_info.wheel_base_m;
237+
const double rear_wheelbase_ratio = declare_parameter("rear_wheelbase_ratio", 1.0);
237238

238239
std::vector<std::string> model_module_paths = declare_parameter<std::vector<std::string>>(
239240
"model_module_paths", std::vector<std::string>({""}));
@@ -297,6 +298,16 @@ void SimplePlanningSimulator::initialize_vehicle_model()
297298
vehicle_model_ptr_ = std::make_shared<SimModelLearnedSteerVel>(
298299
timer_sampling_time_ms_ / 1000.0, model_module_paths, model_param_paths, model_class_names);
299300

301+
} else if (vehicle_model_type_str == "DELAY_ARTICULATE_ACC_GEARED") {
302+
const double front_wheelbase = wheelbase * (1.0 - rear_wheelbase_ratio);
303+
const double rear_wheelbase = wheelbase * rear_wheelbase_ratio;
304+
305+
vehicle_model_type_ = VehicleModelType::DELAY_ARTICULATE_ACC_GEARED;
306+
vehicle_model_ptr_ = std::make_shared<SimModelDelayArticulateAccGeared>(
307+
vel_lim, steer_lim, vel_rate_lim, steer_rate_lim, front_wheelbase, rear_wheelbase,
308+
timer_sampling_time_ms_ / 1000.0, acc_time_delay, acc_time_constant, steer_time_delay,
309+
steer_time_constant, steer_dead_band, steer_bias, debug_acc_scaling_factor,
310+
debug_steer_scaling_factor);
300311
} else {
301312
throw std::invalid_argument("Invalid vehicle_model_type: " + vehicle_model_type_str);
302313
}
@@ -507,7 +518,8 @@ void SimplePlanningSimulator::set_input(const Control & cmd, const double acc_by
507518
} else if ( // NOLINT
508519
vehicle_model_type_ == VehicleModelType::IDEAL_STEER_ACC_GEARED ||
509520
vehicle_model_type_ == VehicleModelType::DELAY_STEER_ACC_GEARED ||
510-
vehicle_model_type_ == VehicleModelType::DELAY_STEER_MAP_ACC_GEARED) {
521+
vehicle_model_type_ == VehicleModelType::DELAY_STEER_MAP_ACC_GEARED ||
522+
vehicle_model_type_ == VehicleModelType::DELAY_ARTICULATE_ACC_GEARED) {
511523
input << combined_acc, steer;
512524
} else if ( // NOLINT
513525
vehicle_model_type_ == VehicleModelType::DELAY_STEER_ACC_GEARED_WO_FALL_GUARD) {
@@ -612,7 +624,8 @@ void SimplePlanningSimulator::set_initial_state(const Pose & pose, const Twist &
612624
vehicle_model_type_ == VehicleModelType::DELAY_STEER_ACC ||
613625
vehicle_model_type_ == VehicleModelType::DELAY_STEER_ACC_GEARED ||
614626
vehicle_model_type_ == VehicleModelType::DELAY_STEER_ACC_GEARED_WO_FALL_GUARD ||
615-
vehicle_model_type_ == VehicleModelType::DELAY_STEER_MAP_ACC_GEARED) {
627+
vehicle_model_type_ == VehicleModelType::DELAY_STEER_MAP_ACC_GEARED ||
628+
vehicle_model_type_ == VehicleModelType::DELAY_ARTICULATE_ACC_GEARED) {
616629
state << x, y, yaw, vx, steer, accx;
617630
}
618631
vehicle_model_ptr_->setState(state);

0 commit comments

Comments
 (0)