Skip to content

Commit d0cfc56

Browse files
committed
set the default error output and update the readme
Signed-off-by: Zhe Shen <lucidshenzhe@gmail.com>
1 parent b9b3e1b commit d0cfc56

File tree

3 files changed

+19
-22
lines changed

3 files changed

+19
-22
lines changed

control/mpc_lateral_controller/README.md

+2
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,8 @@ Some commonly used signals are listed below:
226226
| lateral error w.r.t the modified reference, feeding MPC module | [5] |
227227
| lateral error w.r.t the original reference, feeding mpc.cpp | [22] |
228228

229+
Note: The default error output for each signal is -1.
230+
229231
### How to tune MPC parameters
230232

231233
#### Set kinematics information

control/mpc_lateral_controller/include/mpc_lateral_controller/mpc.hpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,8 @@ class MPC
380380
const MPCTrajectory & reference_trajectory, const MPCData & mpc_data_traj_raw,
381381
const MPCData & mpc_data, const MPCMatrix & mpc_matrix,
382382
const AckermannLateralCommand & ctrl_cmd, const VectorXd & Uex,
383-
const Odometry & current_kinematics) const;
383+
const Odometry & current_kinematics,
384+
bool success_data_for_diagnostic , bool success_data_traj_raw) const;
384385

385386
/**
386387
* @brief calculate steering rate limit along with the target trajectory

control/mpc_lateral_controller/src/mpc.cpp

+15-21
Original file line numberDiff line numberDiff line change
@@ -76,16 +76,10 @@ bool MPC::calculateMPC(
7676
// get the diagnostic data
7777
const auto [success_data_for_diagnostic, mpc_data_for_diagnostic] =
7878
getData(mpc_resampled_ref_trajectory, current_steer, current_kinematics);
79-
if (!success_data_for_diagnostic) {
80-
return fail_warn_throttle("fail to get MPC Data for the diagnostic. Stop MPC.");
81-
}
8279

8380
// get the diagnostic data w.r.t. the original trajectory
8481
const auto [success_data_traj_raw, mpc_data_traj_raw] =
8582
getData(m_mpc_traj_raw, current_steer, current_kinematics);
86-
if (!success_data_traj_raw) {
87-
return fail_warn_throttle("fail to get MPC Data for the raw trajectory. Stop MPC.");
88-
}
8983

9084
// generate mpc matrix : predict equation Xec = Aex * x0 + Bex * Uex + Wex
9185
const auto mpc_matrix = generateMPCMatrix(mpc_resampled_ref_trajectory, prediction_dt);
@@ -125,15 +119,15 @@ bool MPC::calculateMPC(
125119
// prepare diagnostic message
126120
diagnostic = generateDiagData(
127121
mpc_resampled_ref_trajectory, mpc_data_traj_raw, mpc_data_for_diagnostic, mpc_matrix, ctrl_cmd,
128-
Uex, current_kinematics);
122+
Uex, current_kinematics, success_data_for_diagnostic, success_data_traj_raw);
129123

130124
return true;
131125
}
132126

133127
Float32MultiArrayStamped MPC::generateDiagData(
134128
const MPCTrajectory & reference_trajectory, const MPCData & mpc_data_traj_raw,
135129
const MPCData & mpc_data, const MPCMatrix & mpc_matrix, const AckermannLateralCommand & ctrl_cmd,
136-
const VectorXd & Uex, const Odometry & current_kinematics) const
130+
const VectorXd & Uex, const Odometry & current_kinematics, bool success_data_for_diagnostic , bool success_data_traj_raw) const
137131
{
138132
Float32MultiArrayStamped diagnostic;
139133

@@ -156,28 +150,28 @@ Float32MultiArrayStamped MPC::generateDiagData(
156150
append_diag(ctrl_cmd.steering_tire_angle); // [0] final steering command (MPC + LPF)
157151
append_diag(Uex(0)); // [1] mpc calculation result
158152
append_diag(mpc_matrix.Uref_ex(0)); // [2] feed-forward steering value
159-
append_diag(std::atan(nearest_smooth_k * wb)); // [3] feed-forward steering value raw
160-
append_diag(mpc_data.steer); // [4] current steering angle
161-
append_diag(mpc_data.lateral_err); // [5] lateral error
153+
append_diag(success_data_for_diagnostic ? std::atan(nearest_smooth_k * wb) : -1.0); // [3] feed-forward steering value raw
154+
append_diag(success_data_for_diagnostic ? mpc_data.steer : -1.0); // [4] current steering angle
155+
append_diag(success_data_for_diagnostic ? mpc_data.lateral_err : -1.0); // [5] lateral error (the actual error used for MPC)
162156
append_diag(tf2::getYaw(current_kinematics.pose.pose.orientation)); // [6] current_pose yaw
163-
append_diag(tf2::getYaw(mpc_data.nearest_pose.orientation)); // [7] nearest_pose yaw
164-
append_diag(mpc_data.yaw_err); // [8] yaw error
165-
append_diag(reference_trajectory.vx.at(mpc_data.nearest_idx)); // [9] reference velocity
157+
append_diag(success_data_for_diagnostic ? tf2::getYaw(mpc_data.nearest_pose.orientation) : -1.0); // [7] nearest_pose yaw
158+
append_diag(success_data_for_diagnostic ? mpc_data.yaw_err : -1.0); // [8] yaw error
159+
append_diag(success_data_for_diagnostic ? reference_trajectory.vx.at(mpc_data.nearest_idx) : -1.0); // [9] reference velocity
166160
append_diag(current_velocity); // [10] measured velocity
167161
append_diag(wz_command); // [11] angular velocity from steer command
168-
append_diag(wz_measured); // [12] angular velocity from measured steer
169-
append_diag(current_velocity * nearest_smooth_k); // [13] angular velocity from path curvature
170-
append_diag(nearest_smooth_k); // [14] nearest path curvature (used for feed-forward)
171-
append_diag(nearest_k); // [15] nearest path curvature (not smoothed)
172-
append_diag(mpc_data.predicted_steer); // [16] predicted steer
173-
append_diag(wz_predicted); // [17] angular velocity from predicted steer
162+
append_diag(success_data_for_diagnostic ? wz_measured : -1.0); // [12] angular velocity from measured steer
163+
append_diag(success_data_for_diagnostic ? current_velocity * nearest_smooth_k : -1.0); // [13] angular velocity from path curvature
164+
append_diag(success_data_for_diagnostic ? nearest_smooth_k : -1.0); // [14] nearest path curvature (used for feed-forward)
165+
append_diag(success_data_for_diagnostic ? nearest_k : -1.0); // [15] nearest path curvature (not smoothed)
166+
append_diag(success_data_for_diagnostic ? mpc_data.predicted_steer : -1.0); // [16] predicted steer
167+
append_diag(success_data_for_diagnostic ? wz_predicted : -1.0); // [17] angular velocity from predicted steer
174168
append_diag(iteration_num); // [18] iteration number
175169
append_diag(runtime); // [19] runtime of the latest problem solved
176170
append_diag(objective_value); // [20] objective value of the latest problem solved
177171
append_diag(std::clamp(
178172
Uex(0), -m_steer_lim,
179173
m_steer_lim)); // [21] control signal after the saturation constraint (clamp)
180-
append_diag(mpc_data_traj_raw.lateral_err); // [22] lateral error from raw trajectory
174+
append_diag(success_data_traj_raw ? mpc_data_traj_raw.lateral_err : -1.0); // [22] lateral error from raw trajectory
181175

182176
return diagnostic;
183177
}

0 commit comments

Comments
 (0)