Skip to content

Commit 893f5af

Browse files
committed
align the MPC steering angle when the car is controlled manually.
Signed-off-by: Zhe Shen <lucidshenzhe@gmail.com>
1 parent 0de4a0a commit 893f5af

File tree

3 files changed

+7
-3
lines changed

3 files changed

+7
-3
lines changed

control/mpc_lateral_controller/include/mpc_lateral_controller/mpc.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ class MPC
443443
bool calculateMPC(
444444
const SteeringReport & current_steer, const Odometry & current_kinematics,
445445
AckermannLateralCommand & ctrl_cmd, Trajectory & predicted_trajectory,
446-
Float32MultiArrayStamped & diagnostic);
446+
Float32MultiArrayStamped & diagnostic, const bool is_under_control = true);
447447

448448
/**
449449
* @brief Set the reference trajectory to be followed.

control/mpc_lateral_controller/src/mpc.cpp

+5-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ MPC::MPC(rclcpp::Node & node)
3838
bool MPC::calculateMPC(
3939
const SteeringReport & current_steer, const Odometry & current_kinematics,
4040
AckermannLateralCommand & ctrl_cmd, Trajectory & predicted_trajectory,
41-
Float32MultiArrayStamped & diagnostic)
41+
Float32MultiArrayStamped & diagnostic, const bool is_under_control)
4242
{
4343
// since the reference trajectory does not take into account the current velocity of the ego
4444
// vehicle, it needs to calculate the trajectory velocity considering the longitudinal dynamics.
@@ -103,6 +103,10 @@ bool MPC::calculateMPC(
103103
// save previous input for the mpc rate limit
104104
m_raw_steer_cmd_pprev = m_raw_steer_cmd_prev;
105105
m_raw_steer_cmd_prev = Uex(0);
106+
if (!is_under_control) {
107+
m_raw_steer_cmd_pprev = m_raw_steer_cmd_prev;
108+
m_raw_steer_cmd_prev = mpc_data.steer;
109+
}
106110

107111
/* calculate predicted trajectory */
108112
predicted_trajectory =

control/mpc_lateral_controller/src/mpc_lateral_controller.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ trajectory_follower::LateralOutput MpcLateralController::run(
253253
}
254254

255255
const bool is_mpc_solved = m_mpc->calculateMPC(
256-
m_current_steering, m_current_kinematic_state, ctrl_cmd, predicted_traj, debug_values);
256+
m_current_steering, m_current_kinematic_state, ctrl_cmd, predicted_traj, debug_values, is_under_control);
257257

258258
// reset previous MPC result
259259
// Note: When a large deviation from the trajectory occurs, the optimization stops and

0 commit comments

Comments
 (0)