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_
22 #include <rclcpp/logging.hpp>
28 #include "eigen3/Eigen/Core"
29 #include "eigen3/Eigen/LU"
37 throw std::invalid_argument(
"Points is empty.");
40 for (
size_t i = 0; i < x.size() - 1; ++i) {
41 if (x.at(i) >= x.at(i + 1)) {
52 throw std::invalid_argument(
"Points is empty.");
55 for (
size_t i = 0; i < x.size() - 1; ++i) {
56 if (x.at(i) > x.at(i + 1)) {
65 const std::vector<double> & base_keys,
const std::vector<double> & query_keys)
68 if (base_keys.empty() || query_keys.empty()) {
69 throw std::invalid_argument(
"Points is empty.");
73 if (base_keys.size() < 2) {
74 throw std::invalid_argument(
75 "The size of points is less than 2. base_keys.size() = " +
std::to_string(base_keys.size()));
80 throw std::invalid_argument(
"Either base_keys or query_keys is not sorted.");
84 constexpr
double epsilon = 1e-3;
86 query_keys.front() < base_keys.front() - epsilon ||
87 base_keys.back() + epsilon < query_keys.back()) {
88 throw std::invalid_argument(
"query_keys is out of base_keys");
93 auto validated_query_keys = query_keys;
94 validated_query_keys.front() = std::max(validated_query_keys.front(), base_keys.front());
95 validated_query_keys.back() = std::min(validated_query_keys.back(), base_keys.back());
97 return validated_query_keys;
102 const std::vector<double> & base_keys,
const std::vector<T> & base_values)
105 if (base_keys.empty() || base_values.empty()) {
106 throw std::invalid_argument(
"Points is empty.");
110 if (base_keys.size() < 2 || base_values.size() < 2) {
111 throw std::invalid_argument(
112 "The size of points is less than 2. base_keys.size() = " +
std::to_string(base_keys.size()) +
117 if (base_keys.size() != base_values.size()) {
118 throw std::invalid_argument(
"The size of base_keys and base_values are not the same.");
126 double lerp(
const double src_val,
const double dst_val,
const double ratio);
128 std::vector<double>
lerp(
129 const std::vector<double> & base_keys,
const std::vector<double> & base_values,
130 const std::vector<double> & query_keys);
133 const std::vector<double> & base_keys,
const std::vector<double> & base_values,
134 const double query_key);
138 using Table = std::vector<std::vector<std::string>>;
139 using Map = std::vector<std::vector<double>>;
149 static bool validateMap(
const Map & map,
const bool is_col_decent);
154 const double val,
const std::vector<double> & ranges,
const std::string & name);
166 std::vector<std::vector<std::string>> table;
169 rclcpp::get_logger(
"SimModelDelaySteerMapAccGeared"),
170 "failed to read acceleration map from " << csv_path);
174 vehicle_name_ = table[0][0];
180 rclcpp::get_logger(
"SimModelDelaySteerMapAccGeared"),
181 "success to read acceleration map from " << csv_path);
187 std::vector<double> interpolated_acc_vec;
206 std::vector<double> vel_index_;
207 std::vector<double> acc_index_;
228 double vx_lim,
double steer_lim,
double vx_rate_lim,
double steer_rate_lim,
double wheelbase,
229 double dt,
double acc_delay,
double acc_time_constant,
double steer_delay,
240 const double MIN_TIME_CONSTANT;
256 const double vx_lim_;
257 const double vx_rate_lim_;
258 const double steer_lim_;
259 const double steer_rate_lim_;
260 const double wheelbase_;
262 std::deque<double> acc_input_queue_;
263 std::deque<double> steer_input_queue_;
264 const double acc_delay_;
265 const double acc_time_constant_;
266 const double steer_delay_;
267 const double steer_time_constant_;
274 void initializeInputQueue(
const double & dt);
279 double getX()
override;
284 double getY()
override;
289 double getYaw()
override;
294 double getVx()
override;
299 double getVy()
override;
304 double getAx()
override;
309 double getWz()
override;
314 double getSteer()
override;
320 void update(
const double & dt)
override;
327 Eigen::VectorXd calcModel(
const Eigen::VectorXd & state,
const Eigen::VectorXd & input)
override;
336 void updateStateWithGear(
337 Eigen::VectorXd & state,
const Eigen::VectorXd & prev_state,
const uint8_t gear,
Definition: sim_model_delay_steer_map_acc_geared.hpp:161
bool readAccelerationMapFromCSV(const std::string &csv_path)
Definition: sim_model_delay_steer_map_acc_geared.hpp:163
double getAcceleration(const double acc_des, const double vel) const
Definition: sim_model_delay_steer_map_acc_geared.hpp:185
std::vector< std::vector< double > > acceleration_map_
Definition: sim_model_delay_steer_map_acc_geared.hpp:202
Definition: sim_model_delay_steer_map_acc_geared.hpp:143
static Map getMap(const Table &table)
Definition: sim_model_delay_steer_map_acc_geared.cpp:148
static double clampValue(const double val, const std::vector< double > &ranges, const std::string &name)
Definition: sim_model_delay_steer_map_acc_geared.cpp:179
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:123
static std::vector< double > getRowIndex(const Table &table)
Definition: sim_model_delay_steer_map_acc_geared.cpp:161
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:170
Definition: sim_model_delay_steer_map_acc_geared.hpp:211
AccelerationMap acc_map_
Definition: sim_model_delay_steer_map_acc_geared.hpp:237
~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:194
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:33
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:64
bool isIncreasing(const std::vector< double > &x)
Definition: sim_model_delay_steer_map_acc_geared.hpp:34
bool isNotDecreasing(const std::vector< double > &x)
Definition: sim_model_delay_steer_map_acc_geared.hpp:49
void validateKeysAndValues(const std::vector< double > &base_keys, const std::vector< T > &base_values)
Definition: sim_model_delay_steer_map_acc_geared.hpp:101
Definition: sim_model_delay_steer_map_acc_geared.hpp:125
double lerp(const double src_val, const double dst_val, const double ratio)
Definition: sim_model_delay_steer_map_acc_geared.cpp:22
char const * to_string(const RoutingGraphType &)
Definition: routing_graph_type.cpp:21
std::string string
Definition: junit5.hpp:26
std::vector< std::vector< double > > Map
Definition: sim_model_delay_steer_map_acc_geared.hpp:139
std::vector< std::vector< std::string > > Table
Definition: sim_model_delay_steer_map_acc_geared.hpp:138