Skip to content

Commit 65a36d4

Browse files
authored
fix(simple_planning_simulator, raw_vehicle_cmd_converter): swap row index and column index for csv loader (#8963)
swap row and column Signed-off-by: Go Sakayori <gsakayori@gmail.com>
1 parent 653ce0e commit 65a36d4

File tree

7 files changed

+25
-23
lines changed

7 files changed

+25
-23
lines changed

simulator/simple_planning_simulator/include/simple_planning_simulator/vehicle_model/sim_model_delay_steer_map_acc_geared.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ class AccelerationMap
4141
}
4242

4343
vehicle_name_ = table[0][0];
44-
vel_index_ = CSVLoader::getRowIndex(table);
45-
acc_index_ = CSVLoader::getColumnIndex(table);
44+
vel_index_ = CSVLoader::getColumnIndex(table);
45+
acc_index_ = CSVLoader::getRowIndex(table);
4646
acceleration_map_ = CSVLoader::getMap(table);
4747

4848
std::cout << "[SimModelDelaySteerMapAccGeared]: success to read acceleration map from "

simulator/simple_planning_simulator/src/simple_planning_simulator/utils/csv_loader.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ Map CSVLoader::getMap(const Table & table)
119119
return map;
120120
}
121121

122-
std::vector<double> CSVLoader::getRowIndex(const Table & table)
122+
std::vector<double> CSVLoader::getColumnIndex(const Table & table)
123123
{
124124
// NOTE: table[0][i] represents the element in the 0-th row and i-th column
125125
// This means that we are getting the index of each column in the 0-th row
@@ -130,7 +130,7 @@ std::vector<double> CSVLoader::getRowIndex(const Table & table)
130130
return index;
131131
}
132132

133-
std::vector<double> CSVLoader::getColumnIndex(const Table & table)
133+
std::vector<double> CSVLoader::getRowIndex(const Table & table)
134134
{
135135
// NOTE: table[i][0] represents the element in the i-th row and 0-th column
136136
// This means that we are getting the index of each row in the 0-th column

simulator/simple_planning_simulator/src/simple_planning_simulator/vehicle_model/sim_model_actuation_cmd.cpp

+13-11
Original file line numberDiff line numberDiff line change
@@ -27,21 +27,19 @@ bool ActuationMap::readActuationMapFromCSV(const std::string & csv_path, const b
2727
return false;
2828
}
2929

30-
state_index_ = CSVLoader::getRowIndex(table);
31-
actuation_index_ = CSVLoader::getColumnIndex(table);
30+
state_index_ = CSVLoader::getColumnIndex(table);
31+
actuation_index_ = CSVLoader::getRowIndex(table);
3232
actuation_map_ = CSVLoader::getMap(table);
33-
if (validation && !CSVLoader::validateMap(actuation_map_, true)) {
34-
return false;
35-
}
36-
return true;
33+
return !validation || CSVLoader::validateMap(actuation_map_, true);
3734
}
3835

3936
double ActuationMap::getControlCommand(const double actuation, const double state) const
4037
{
4138
std::vector<double> interpolated_control_vec{};
4239
const double clamped_state = CSVLoader::clampValue(state, state_index_);
4340

44-
for (std::vector<double> control_command_values : actuation_map_) {
41+
interpolated_control_vec.reserve(actuation_map_.size());
42+
for (const std::vector<double> & control_command_values : actuation_map_) {
4543
interpolated_control_vec.push_back(
4644
autoware::interpolation::lerp(state_index_, control_command_values, clamped_state));
4745
}
@@ -61,7 +59,8 @@ std::optional<double> AccelMap::getThrottle(const double acc, double vel) const
6159
const double clamped_vel = CSVLoader::clampValue(vel, vel_indices);
6260

6361
// (throttle, vel, acc) map => (throttle, acc) map by fixing vel
64-
for (std::vector<double> accelerations : accel_map) {
62+
interpolated_acc_vec.reserve(accel_map.size());
63+
for (const std::vector<double> & accelerations : accel_map) {
6564
interpolated_acc_vec.push_back(
6665
autoware::interpolation::lerp(vel_indices, accelerations, clamped_vel));
6766
}
@@ -71,7 +70,8 @@ std::optional<double> AccelMap::getThrottle(const double acc, double vel) const
7170
// When the desired acceleration is greater than the throttle area, return max throttle
7271
if (acc < interpolated_acc_vec.front()) {
7372
return std::nullopt;
74-
} else if (interpolated_acc_vec.back() < acc) {
73+
}
74+
if (interpolated_acc_vec.back() < acc) {
7575
return throttle_indices.back();
7676
}
7777

@@ -88,7 +88,8 @@ double BrakeMap::getBrake(const double acc, double vel) const
8888
const double clamped_vel = CSVLoader::clampValue(vel, vel_indices);
8989

9090
// (brake, vel, acc) map => (brake, acc) map by fixing vel
91-
for (std::vector<double> accelerations : brake_map) {
91+
interpolated_acc_vec.reserve(brake_map.size());
92+
for (const std::vector<double> & accelerations : brake_map) {
9293
interpolated_acc_vec.push_back(
9394
autoware::interpolation::lerp(vel_indices, accelerations, clamped_vel));
9495
}
@@ -98,7 +99,8 @@ double BrakeMap::getBrake(const double acc, double vel) const
9899
// When the desired acceleration is greater than the brake area, return min brake on the map
99100
if (acc < interpolated_acc_vec.back()) {
100101
return brake_indices.back();
101-
} else if (interpolated_acc_vec.front() < acc) {
102+
}
103+
if (interpolated_acc_vec.front() < acc) {
102104
return brake_indices.front();
103105
}
104106

vehicle/autoware_raw_vehicle_cmd_converter/src/accel_map.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ bool AccelMap::readAccelMapFromCSV(const std::string & csv_path, const bool vali
3131
}
3232

3333
vehicle_name_ = table[0][0];
34-
vel_index_ = CSVLoader::getRowIndex(table);
35-
throttle_index_ = CSVLoader::getColumnIndex(table);
34+
vel_index_ = CSVLoader::getColumnIndex(table);
35+
throttle_index_ = CSVLoader::getRowIndex(table);
3636
accel_map_ = CSVLoader::getMap(table);
3737
return !validation || CSVLoader::validateMap(accel_map_, true);
3838
}

vehicle/autoware_raw_vehicle_cmd_converter/src/brake_map.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ bool BrakeMap::readBrakeMapFromCSV(const std::string & csv_path, const bool vali
3232
}
3333

3434
vehicle_name_ = table[0][0];
35-
vel_index_ = CSVLoader::getRowIndex(table);
36-
brake_index_ = CSVLoader::getColumnIndex(table);
35+
vel_index_ = CSVLoader::getColumnIndex(table);
36+
brake_index_ = CSVLoader::getRowIndex(table);
3737
brake_map_ = CSVLoader::getMap(table);
3838
brake_index_rev_ = brake_index_;
3939
if (validation && !CSVLoader::validateMap(brake_map_, false)) {

vehicle/autoware_raw_vehicle_cmd_converter/src/csv_loader.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ Map CSVLoader::getMap(const Table & table)
115115
return map;
116116
}
117117

118-
std::vector<double> CSVLoader::getRowIndex(const Table & table)
118+
std::vector<double> CSVLoader::getColumnIndex(const Table & table)
119119
{
120120
std::vector<double> index = {};
121121
for (size_t i = 1; i < table[0].size(); i++) {
@@ -124,7 +124,7 @@ std::vector<double> CSVLoader::getRowIndex(const Table & table)
124124
return index;
125125
}
126126

127-
std::vector<double> CSVLoader::getColumnIndex(const Table & table)
127+
std::vector<double> CSVLoader::getRowIndex(const Table & table)
128128
{
129129
std::vector<double> index = {};
130130
for (size_t i = 1; i < table.size(); i++) {

vehicle/autoware_raw_vehicle_cmd_converter/src/steer_map.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ bool SteerMap::readSteerMapFromCSV(const std::string & csv_path, const bool vali
3232
}
3333

3434
vehicle_name_ = table[0][0];
35-
steer_index_ = CSVLoader::getRowIndex(table);
36-
output_index_ = CSVLoader::getColumnIndex(table);
35+
steer_index_ = CSVLoader::getColumnIndex(table);
36+
output_index_ = CSVLoader::getRowIndex(table);
3737
steer_map_ = CSVLoader::getMap(table);
3838
return !validation || CSVLoader::validateMap(steer_map_, true);
3939
}

0 commit comments

Comments
 (0)