Skip to content

Commit 8c544e6

Browse files
temp
Signed-off-by: kyoichi-sugahara <kyoichi.sugahara@tier4.jp>
1 parent 66300f1 commit 8c544e6

File tree

3 files changed

+36
-113
lines changed

3 files changed

+36
-113
lines changed

control/mpc_lateral_controller/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,5 @@ endif()
3838

3939
ament_auto_package(INSTALL_TO_SHARE
4040
param
41+
test
4142
)

control/mpc_lateral_controller/test/test_mpc.cpp

+23-113
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15+
#include "ament_index_cpp/get_package_share_directory.hpp"
1516
#include "gtest/gtest.h"
1617
#include "mpc_lateral_controller/mpc.hpp"
1718
#include "mpc_lateral_controller/qp_solver/qp_solver_osqp.hpp"
@@ -49,6 +50,18 @@ using geometry_msgs::msg::Pose;
4950
using geometry_msgs::msg::PoseStamped;
5051
using tier4_debug_msgs::msg::Float32MultiArrayStamped;
5152

53+
rclcpp::NodeOptions makeNodeOptions()
54+
{
55+
// Pass default parameter file to the node
56+
const auto share_dir = ament_index_cpp::get_package_share_directory("mpc_lateral_controller");
57+
rclcpp::NodeOptions node_options;
58+
node_options.arguments(
59+
{"--ros-args", "--params-file", share_dir + "/param/lateral_controller_defaults.param.yaml",
60+
"--params-file", share_dir + "/test/test_vehicle_info.param.yaml"});
61+
62+
return node_options;
63+
}
64+
5265
TrajectoryPoint makePoint(const double x, const double y, const float vx)
5366
{
5467
TrajectoryPoint p;
@@ -77,69 +90,12 @@ class MPCTest : public ::testing::Test
7790
double default_velocity = 1.0;
7891
rclcpp::Logger logger = rclcpp::get_logger("mpc_test_logger");
7992

80-
// Vehicle model parameters
81-
double wheelbase = 2.7;
82-
double steer_limit = 1.0;
83-
double steer_tau = 0.1;
84-
double mass_fl = 600.0;
85-
double mass_fr = 600.0;
86-
double mass_rl = 600.0;
87-
double mass_rr = 600.0;
88-
double cf = 155494.663;
89-
double cr = 155494.663;
90-
91-
// Filters parameter
92-
double steering_lpf_cutoff_hz = 3.0;
93-
double error_deriv_lpf_cutoff_hz = 5.0;
94-
95-
// Test Parameters
96-
double admissible_position_error = 5.0;
97-
double admissible_yaw_error_rad = M_PI_2;
98-
double steer_lim = 0.610865; // 35 degrees
99-
double steer_rate_lim = 2.61799; // 150 degrees
10093
double ctrl_period = 0.03;
10194

102-
bool use_steer_prediction = true;
103-
10495
TrajectoryFilteringParam trajectory_param;
10596

10697
void initParam()
10798
{
108-
param.prediction_horizon = 50;
109-
param.prediction_dt = 0.1;
110-
param.zero_ff_steer_deg = 0.5;
111-
param.input_delay = 0.0;
112-
param.acceleration_limit = 2.0;
113-
param.velocity_time_constant = 0.3;
114-
param.min_prediction_length = 5.0;
115-
param.steer_tau = 0.1;
116-
param.nominal_weight.lat_error = 1.0;
117-
param.nominal_weight.heading_error = 1.0;
118-
param.nominal_weight.heading_error_squared_vel = 1.0;
119-
param.nominal_weight.terminal_lat_error = 1.0;
120-
param.nominal_weight.terminal_heading_error = 0.1;
121-
param.low_curvature_weight.lat_error = 0.1;
122-
param.low_curvature_weight.heading_error = 0.0;
123-
param.low_curvature_weight.heading_error_squared_vel = 0.3;
124-
param.nominal_weight.steering_input = 1.0;
125-
param.nominal_weight.steering_input_squared_vel = 0.25;
126-
param.nominal_weight.lat_jerk = 0.0;
127-
param.nominal_weight.steer_rate = 0.0;
128-
param.nominal_weight.steer_acc = 0.000001;
129-
param.low_curvature_weight.steering_input = 1.0;
130-
param.low_curvature_weight.steering_input_squared_vel = 0.25;
131-
param.low_curvature_weight.lat_jerk = 0.0;
132-
param.low_curvature_weight.steer_rate = 0.0;
133-
param.low_curvature_weight.steer_acc = 0.000001;
134-
param.low_curvature_thresh_curvature = 0.0;
135-
136-
trajectory_param.traj_resample_dist = 0.1;
137-
trajectory_param.path_filter_moving_ave_num = 35;
138-
trajectory_param.curvature_smoothing_num_traj = 1;
139-
trajectory_param.curvature_smoothing_num_ref_steer = 35;
140-
trajectory_param.enable_path_smoothing = true;
141-
trajectory_param.extend_trajectory_for_end_yaw_control = true;
142-
14399
dummy_straight_trajectory.points.push_back(makePoint(0.0, 0.0, 1.0f));
144100
dummy_straight_trajectory.points.push_back(makePoint(1.0, 0.0, 1.0f));
145101
dummy_straight_trajectory.points.push_back(makePoint(2.0, 0.0, 1.0f));
@@ -158,18 +114,7 @@ class MPCTest : public ::testing::Test
158114

159115
void initializeMPC(mpc_lateral_controller::MPC & mpc)
160116
{
161-
mpc.m_param = param;
162-
mpc.m_admissible_position_error = admissible_position_error;
163-
mpc.m_admissible_yaw_error_rad = admissible_yaw_error_rad;
164-
mpc.m_steer_lim = steer_lim;
165-
mpc.m_steer_rate_lim_map_by_curvature.emplace_back(0.0, steer_rate_lim);
166-
mpc.m_steer_rate_lim_map_by_velocity.emplace_back(0.0, steer_rate_lim);
167117
mpc.m_ctrl_period = ctrl_period;
168-
mpc.m_use_steer_prediction = use_steer_prediction;
169-
170-
mpc.initializeLowPassFilters(steering_lpf_cutoff_hz, error_deriv_lpf_cutoff_hz);
171-
mpc.initializeSteeringPredictor();
172-
173118
// Init trajectory
174119
const auto current_kinematics =
175120
makeOdometry(dummy_straight_trajectory.points.front().pose, 0.0);
@@ -188,14 +133,10 @@ class MPCTest : public ::testing::Test
188133
/* cppcheck-suppress syntaxError */
189134
TEST_F(MPCTest, InitializeAndCalculate)
190135
{
191-
auto node = rclcpp::Node("mpc_test_node", rclcpp::NodeOptions{});
136+
auto node = rclcpp::Node("mpc_test_node", makeNodeOptions());
192137
auto mpc = std::make_unique<MPC>(node);
193138
EXPECT_FALSE(mpc->hasVehicleModel());
194139
EXPECT_FALSE(mpc->hasQPSolver());
195-
196-
std::shared_ptr<VehicleModelInterface> vehicle_model_ptr =
197-
std::make_shared<KinematicsBicycleModel>(wheelbase, steer_limit, steer_tau);
198-
mpc->setVehicleModel(vehicle_model_ptr);
199140
ASSERT_TRUE(mpc->hasVehicleModel());
200141

201142
std::shared_ptr<QPSolverInterface> qpsolver_ptr = std::make_shared<QPSolverEigenLeastSquareLLT>();
@@ -217,14 +158,11 @@ TEST_F(MPCTest, InitializeAndCalculate)
217158

218159
TEST_F(MPCTest, InitializeAndCalculateRightTurn)
219160
{
220-
auto node = rclcpp::Node("mpc_test_node", rclcpp::NodeOptions{});
161+
auto node = rclcpp::Node("mpc_test_node", makeNodeOptions());
221162
auto mpc = std::make_unique<MPC>(node);
222163
EXPECT_FALSE(mpc->hasVehicleModel());
223164
EXPECT_FALSE(mpc->hasQPSolver());
224165

225-
std::shared_ptr<VehicleModelInterface> vehicle_model_ptr =
226-
std::make_shared<KinematicsBicycleModel>(wheelbase, steer_limit, steer_tau);
227-
mpc->setVehicleModel(vehicle_model_ptr);
228166
ASSERT_TRUE(mpc->hasVehicleModel());
229167

230168
std::shared_ptr<QPSolverInterface> qpsolver_ptr = std::make_shared<QPSolverEigenLeastSquareLLT>();
@@ -249,15 +187,12 @@ TEST_F(MPCTest, InitializeAndCalculateRightTurn)
249187

250188
TEST_F(MPCTest, OsqpCalculate)
251189
{
252-
auto node = rclcpp::Node("mpc_test_node", rclcpp::NodeOptions{});
190+
auto node = rclcpp::Node("mpc_test_node", makeNodeOptions());
253191
auto mpc = std::make_unique<MPC>(node);
254192
initializeMPC(*mpc);
255193
const auto current_kinematics = makeOdometry(dummy_straight_trajectory.points.front().pose, 0.0);
256194
mpc->setReferenceTrajectory(dummy_straight_trajectory, trajectory_param, current_kinematics);
257195

258-
std::shared_ptr<VehicleModelInterface> vehicle_model_ptr =
259-
std::make_shared<KinematicsBicycleModel>(wheelbase, steer_limit, steer_tau);
260-
mpc->setVehicleModel(vehicle_model_ptr);
261196
ASSERT_TRUE(mpc->hasVehicleModel());
262197

263198
std::shared_ptr<QPSolverInterface> qpsolver_ptr = std::make_shared<QPSolverOSQP>(logger);
@@ -276,16 +211,12 @@ TEST_F(MPCTest, OsqpCalculate)
276211

277212
TEST_F(MPCTest, OsqpCalculateRightTurn)
278213
{
279-
auto node = rclcpp::Node("mpc_test_node", rclcpp::NodeOptions{});
214+
auto node = rclcpp::Node("mpc_test_node", makeNodeOptions());
280215
auto mpc = std::make_unique<MPC>(node);
281216
initializeMPC(*mpc);
282217
const auto current_kinematics =
283218
makeOdometry(dummy_right_turn_trajectory.points.front().pose, 0.0);
284219
mpc->setReferenceTrajectory(dummy_right_turn_trajectory, trajectory_param, current_kinematics);
285-
286-
std::shared_ptr<VehicleModelInterface> vehicle_model_ptr =
287-
std::make_shared<KinematicsBicycleModel>(wheelbase, steer_limit, steer_tau);
288-
mpc->setVehicleModel(vehicle_model_ptr);
289220
ASSERT_TRUE(mpc->hasVehicleModel());
290221

291222
std::shared_ptr<QPSolverInterface> qpsolver_ptr = std::make_shared<QPSolverOSQP>(logger);
@@ -304,21 +235,15 @@ TEST_F(MPCTest, OsqpCalculateRightTurn)
304235

305236
TEST_F(MPCTest, KinematicsNoDelayCalculate)
306237
{
307-
auto node = rclcpp::Node("mpc_test_node", rclcpp::NodeOptions{});
238+
auto node = rclcpp::Node("mpc_test_node", makeNodeOptions());
308239
auto mpc = std::make_unique<MPC>(node);
309240
initializeMPC(*mpc);
310-
311-
std::shared_ptr<VehicleModelInterface> vehicle_model_ptr =
312-
std::make_shared<KinematicsBicycleModelNoDelay>(wheelbase, steer_limit);
313-
mpc->setVehicleModel(vehicle_model_ptr);
314241
ASSERT_TRUE(mpc->hasVehicleModel());
315242

316243
std::shared_ptr<QPSolverInterface> qpsolver_ptr = std::make_shared<QPSolverEigenLeastSquareLLT>();
317244
mpc->setQPSolver(qpsolver_ptr);
318245
ASSERT_TRUE(mpc->hasQPSolver());
319246

320-
// Init filters
321-
mpc->initializeLowPassFilters(steering_lpf_cutoff_hz, error_deriv_lpf_cutoff_hz);
322247
// Init trajectory
323248
const auto current_kinematics = makeOdometry(dummy_straight_trajectory.points.front().pose, 0.0);
324249
mpc->setReferenceTrajectory(dummy_straight_trajectory, trajectory_param, current_kinematics);
@@ -334,25 +259,18 @@ TEST_F(MPCTest, KinematicsNoDelayCalculate)
334259

335260
TEST_F(MPCTest, KinematicsNoDelayCalculateRightTurn)
336261
{
337-
auto node = rclcpp::Node("mpc_test_node", rclcpp::NodeOptions{});
262+
auto node = rclcpp::Node("mpc_test_node", makeNodeOptions());
338263
auto mpc = std::make_unique<MPC>(node);
339264
initializeMPC(*mpc);
340265
const auto current_kinematics =
341266
makeOdometry(dummy_right_turn_trajectory.points.front().pose, 0.0);
342267
mpc->setReferenceTrajectory(dummy_right_turn_trajectory, trajectory_param, current_kinematics);
343-
344-
std::shared_ptr<VehicleModelInterface> vehicle_model_ptr =
345-
std::make_shared<KinematicsBicycleModelNoDelay>(wheelbase, steer_limit);
346-
mpc->setVehicleModel(vehicle_model_ptr);
347268
ASSERT_TRUE(mpc->hasVehicleModel());
348269

349270
std::shared_ptr<QPSolverInterface> qpsolver_ptr = std::make_shared<QPSolverEigenLeastSquareLLT>();
350271
mpc->setQPSolver(qpsolver_ptr);
351272
ASSERT_TRUE(mpc->hasQPSolver());
352273

353-
// Init filters
354-
mpc->initializeLowPassFilters(steering_lpf_cutoff_hz, error_deriv_lpf_cutoff_hz);
355-
356274
// Calculate MPC
357275
AckermannLateralCommand ctrl_cmd;
358276
Trajectory pred_traj;
@@ -365,13 +283,10 @@ TEST_F(MPCTest, KinematicsNoDelayCalculateRightTurn)
365283

366284
TEST_F(MPCTest, DynamicCalculate)
367285
{
368-
auto node = rclcpp::Node("mpc_test_node", rclcpp::NodeOptions{});
286+
auto node = rclcpp::Node("mpc_test_node", makeNodeOptions());
369287
auto mpc = std::make_unique<MPC>(node);
370288
initializeMPC(*mpc);
371289

372-
std::shared_ptr<VehicleModelInterface> vehicle_model_ptr =
373-
std::make_shared<DynamicsBicycleModel>(wheelbase, mass_fl, mass_fr, mass_rl, mass_rr, cf, cr);
374-
mpc->setVehicleModel(vehicle_model_ptr);
375290
ASSERT_TRUE(mpc->hasVehicleModel());
376291

377292
std::shared_ptr<QPSolverInterface> qpsolver_ptr = std::make_shared<QPSolverEigenLeastSquareLLT>();
@@ -390,11 +305,8 @@ TEST_F(MPCTest, DynamicCalculate)
390305

391306
TEST_F(MPCTest, MultiSolveWithBuffer)
392307
{
393-
auto node = rclcpp::Node("mpc_test_node", rclcpp::NodeOptions{});
308+
auto node = rclcpp::Node("mpc_test_node", makeNodeOptions());
394309
auto mpc = std::make_unique<MPC>(node);
395-
std::shared_ptr<VehicleModelInterface> vehicle_model_ptr =
396-
std::make_shared<KinematicsBicycleModel>(wheelbase, steer_limit, steer_tau);
397-
mpc->setVehicleModel(vehicle_model_ptr);
398310
std::shared_ptr<QPSolverInterface> qpsolver_ptr = std::make_shared<QPSolverEigenLeastSquareLLT>();
399311
mpc->setQPSolver(qpsolver_ptr);
400312

@@ -428,11 +340,8 @@ TEST_F(MPCTest, MultiSolveWithBuffer)
428340

429341
TEST_F(MPCTest, FailureCases)
430342
{
431-
auto node = rclcpp::Node("mpc_test_node", rclcpp::NodeOptions{});
343+
auto node = rclcpp::Node("mpc_test_node", makeNodeOptions());
432344
auto mpc = std::make_unique<MPC>(node);
433-
std::shared_ptr<VehicleModelInterface> vehicle_model_ptr =
434-
std::make_shared<KinematicsBicycleModel>(wheelbase, steer_limit, steer_tau);
435-
mpc->setVehicleModel(vehicle_model_ptr);
436345
std::shared_ptr<QPSolverInterface> qpsolver_ptr = std::make_shared<QPSolverEigenLeastSquareLLT>();
437346
mpc->setQPSolver(qpsolver_ptr);
438347

@@ -441,6 +350,7 @@ TEST_F(MPCTest, FailureCases)
441350

442351
// Calculate MPC with a pose too far from the trajectory
443352
Pose pose_far;
353+
constexpr double admissible_position_error = 5.0;
444354
pose_far.position.x = pose_zero.position.x - admissible_position_error - 1.0;
445355
pose_far.position.y = pose_zero.position.y - admissible_position_error - 1.0;
446356
AckermannLateralCommand ctrl_cmd;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/**:
2+
ros__parameters:
3+
wheel_radius: 0.39
4+
wheel_width: 0.42
5+
wheel_base: 2.74 # between front wheel center and rear wheel center
6+
wheel_tread: 1.63 # between left wheel center and right wheel center
7+
front_overhang: 1.0 # between front wheel center and vehicle front
8+
rear_overhang: 1.03 # between rear wheel center and vehicle rear
9+
left_overhang: 0.1 # between left wheel center and vehicle left
10+
right_overhang: 0.1 # between right wheel center and vehicle right
11+
vehicle_height: 2.5
12+
max_steer_angle: 0.70 # [rad]

0 commit comments

Comments
 (0)