Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(mpc_lateral_controller): precise backward driving #6578

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion control/mpc_lateral_controller/src/mpc.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2018-2021 The Autoware Foundation

Check notice on line 1 in control/mpc_lateral_controller/src/mpc.cpp

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

ℹ Getting worse: Overall Code Complexity

The mean cyclomatic complexity increases from 4.79 to 4.84, threshold = 4. This file has many conditional statements (e.g. if, for, while) across its implementation, leading to lower code health. Avoid adding more conditionals.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -355,12 +355,15 @@
MatrixXd Wd(DIM_X, 1);
MatrixXd Cd(DIM_Y, DIM_X);

const double sign_vx = m_is_forward_shift ? 1 : -1;

MatrixXd x_curr = x0_orig;
double mpc_curr_time = start_time;
for (size_t i = 0; i < m_input_buffer.size(); ++i) {
double k, v = 0.0;
try {
k = interpolation::lerp(traj.relative_time, traj.k, mpc_curr_time);
// NOTE: When driving backward, the curvature's sign should be reversed.
k = interpolation::lerp(traj.relative_time, traj.k, mpc_curr_time) * sign_vx;
v = interpolation::lerp(traj.relative_time, traj.vx, mpc_curr_time);
} catch (const std::exception & e) {
RCLCPP_ERROR(m_logger, "mpc resample failed at delay compensation, stop mpc: %s", e.what());
Expand Down Expand Up @@ -446,6 +449,7 @@
const double ref_vx = reference_trajectory.vx.at(i);
const double ref_vx_squared = ref_vx * ref_vx;

// NOTE: When driving backward, the curvature's sign should be reversed.
const double ref_k = reference_trajectory.k.at(i) * sign_vx;
const double ref_smooth_k = reference_trajectory.smooth_k.at(i) * sign_vx;

Expand Down
Loading