15 #ifndef SIMPLE_PLANNING_SIMULATOR__VEHICLE_MODEL__SIM_MODEL_DELAY_STEER_MAP_ACC_GEARED_HPP_
16 #define SIMPLE_PLANNING_SIMULATOR__VEHICLE_MODEL__SIM_MODEL_DELAY_STEER_MAP_ACC_GEARED_HPP_
27 #include "eigen3/Eigen/Core"
28 #include "eigen3/Eigen/LU"
36 throw std::invalid_argument(
"Points is empty.");
39 for (
size_t i = 0; i < x.size() - 1; ++i) {
40 if (x.at(i) >= x.at(i + 1)) {
51 throw std::invalid_argument(
"Points is empty.");
54 for (
size_t i = 0; i < x.size() - 1; ++i) {
55 if (x.at(i) > x.at(i + 1)) {
64 const std::vector<double> & base_keys,
const std::vector<double> & query_keys)
67 if (base_keys.empty() || query_keys.empty()) {
68 throw std::invalid_argument(
"Points is empty.");
72 if (base_keys.size() < 2) {
73 throw std::invalid_argument(
74 "The size of points is less than 2. base_keys.size() = " + std::to_string(base_keys.size()));
79 throw std::invalid_argument(
"Either base_keys or query_keys is not sorted.");
83 constexpr
double epsilon = 1e-3;
85 query_keys.front() < base_keys.front() - epsilon ||
86 base_keys.back() + epsilon < query_keys.back()) {
87 throw std::invalid_argument(
"query_keys is out of base_keys");
92 auto validated_query_keys = query_keys;
93 validated_query_keys.front() = std::max(validated_query_keys.front(), base_keys.front());
94 validated_query_keys.back() = std::min(validated_query_keys.back(), base_keys.back());
96 return validated_query_keys;
101 const std::vector<double> & base_keys,
const std::vector<T> & base_values)
104 if (base_keys.empty() || base_values.empty()) {
105 throw std::invalid_argument(
"Points is empty.");
109 if (base_keys.size() < 2 || base_values.size() < 2) {
110 throw std::invalid_argument(
111 "The size of points is less than 2. base_keys.size() = " + std::to_string(base_keys.size()) +
112 ", base_values.size() = " + std::to_string(base_values.size()));
116 if (base_keys.size() != base_values.size()) {
117 throw std::invalid_argument(
"The size of base_keys and base_values are not the same.");
125 double lerp(
const double src_val,
const double dst_val,
const double ratio);
127 std::vector<double>
lerp(
128 const std::vector<double> & base_keys,
const std::vector<double> & base_values,
129 const std::vector<double> & query_keys);
132 const std::vector<double> & base_keys,
const std::vector<double> & base_values,
133 const double query_key);
137 using Table = std::vector<std::vector<std::string>>;
138 using Map = std::vector<std::vector<double>>;
148 static bool validateMap(
const Map & map,
const bool is_col_decent);
153 const double val,
const std::vector<double> & ranges,
const std::string & name);
165 std::vector<std::vector<std::string>> table;
167 std::cerr <<
"[SimModelDelaySteerMapAccGeared]: failed to read acceleration map from "
168 << csv_path << std::endl;
172 vehicle_name_ = table[0][0];
177 std::cout <<
"[SimModelDelaySteerMapAccGeared]: success to read acceleration map from "
178 << csv_path << std::endl;
184 std::vector<double> interpolated_acc_vec;
203 std::vector<double> vel_index_;
204 std::vector<double> acc_index_;
225 double vx_lim,
double steer_lim,
double vx_rate_lim,
double steer_rate_lim,
double wheelbase,
226 double dt,
double acc_delay,
double acc_time_constant,
double steer_delay,
237 const double MIN_TIME_CONSTANT;
253 const double vx_lim_;
254 const double vx_rate_lim_;
255 const double steer_lim_;
256 const double steer_rate_lim_;
257 const double wheelbase_;
259 std::deque<double> acc_input_queue_;
260 std::deque<double> steer_input_queue_;
261 const double acc_delay_;
262 const double acc_time_constant_;
263 const double steer_delay_;
264 const double steer_time_constant_;
271 void initializeInputQueue(
const double & dt);
276 double getX()
override;
281 double getY()
override;
286 double getYaw()
override;
291 double getVx()
override;
296 double getVy()
override;
301 double getAx()
override;
306 double getWz()
override;
311 double getSteer()
override;
317 void update(
const double & dt)
override;
324 Eigen::VectorXd calcModel(
const Eigen::VectorXd & state,
const Eigen::VectorXd & input)
override;
333 void updateStateWithGear(
334 Eigen::VectorXd & state,
const Eigen::VectorXd & prev_state,
const uint8_t gear,
Definition: sim_model_delay_steer_map_acc_geared.hpp:160
bool readAccelerationMapFromCSV(const std::string &csv_path)
Definition: sim_model_delay_steer_map_acc_geared.hpp:162
double getAcceleration(const double acc_des, const double vel) const
Definition: sim_model_delay_steer_map_acc_geared.hpp:182
std::vector< std::vector< double > > acceleration_map_
Definition: sim_model_delay_steer_map_acc_geared.hpp:199
Definition: sim_model_delay_steer_map_acc_geared.hpp:142
static Map getMap(const Table &table)
Definition: sim_model_delay_steer_map_acc_geared.cpp:144
static double clampValue(const double val, const std::vector< double > &ranges, const std::string &name)
Definition: sim_model_delay_steer_map_acc_geared.cpp:175
bool readCSV(Table &result, const char delim=',')
Definition: sim_model_delay_steer_map_acc_geared.cpp:64
static bool validateMap(const Map &map, const bool is_col_decent)
Definition: sim_model_delay_steer_map_acc_geared.cpp:92
static bool validateData(const Table &table, const std::string &csv_path)
Definition: sim_model_delay_steer_map_acc_geared.cpp:121
static std::vector< double > getRowIndex(const Table &table)
Definition: sim_model_delay_steer_map_acc_geared.cpp:157
CSVLoader(const std::string &csv_path)
Definition: sim_model_delay_steer_map_acc_geared.cpp:62
static std::vector< double > getColumnIndex(const Table &table)
Definition: sim_model_delay_steer_map_acc_geared.cpp:166
Definition: sim_model_delay_steer_map_acc_geared.hpp:208
AccelerationMap acc_map_
Definition: sim_model_delay_steer_map_acc_geared.hpp:234
~SimModelDelaySteerMapAccGeared()=default
default destructor
SimModelDelaySteerMapAccGeared(double vx_lim, double steer_lim, double vx_rate_lim, double steer_rate_lim, double wheelbase, double dt, double acc_delay, double acc_time_constant, double steer_delay, double steer_time_constant, std::string path)
constructor
Definition: sim_model_delay_steer_map_acc_geared.cpp:189
simple_planning_simulator vehicle model class to calculate vehicle dynamics
Definition: sim_model_interface.hpp:26
Definition: sim_model_delay_steer_map_acc_geared.hpp:32
std::vector< double > validateKeys(const std::vector< double > &base_keys, const std::vector< double > &query_keys)
Definition: sim_model_delay_steer_map_acc_geared.hpp:63
bool isIncreasing(const std::vector< double > &x)
Definition: sim_model_delay_steer_map_acc_geared.hpp:33
bool isNotDecreasing(const std::vector< double > &x)
Definition: sim_model_delay_steer_map_acc_geared.hpp:48
void validateKeysAndValues(const std::vector< double > &base_keys, const std::vector< T > &base_values)
Definition: sim_model_delay_steer_map_acc_geared.hpp:100
Definition: sim_model_delay_steer_map_acc_geared.hpp:124
double lerp(const double src_val, const double dst_val, const double ratio)
Definition: sim_model_delay_steer_map_acc_geared.cpp:22
std::string string
Definition: junit5.hpp:26
std::vector< std::vector< double > > Map
Definition: sim_model_delay_steer_map_acc_geared.hpp:138
std::vector< std::vector< std::string > > Table
Definition: sim_model_delay_steer_map_acc_geared.hpp:137