@@ -76,16 +76,10 @@ bool MPC::calculateMPC(
76
76
// get the diagnostic data
77
77
const auto [success_data_for_diagnostic, mpc_data_for_diagnostic] =
78
78
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
- }
82
79
83
80
// get the diagnostic data w.r.t. the original trajectory
84
81
const auto [success_data_traj_raw, mpc_data_traj_raw] =
85
82
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
- }
89
83
90
84
// generate mpc matrix : predict equation Xec = Aex * x0 + Bex * Uex + Wex
91
85
const auto mpc_matrix = generateMPCMatrix (mpc_resampled_ref_trajectory, prediction_dt);
@@ -125,15 +119,15 @@ bool MPC::calculateMPC(
125
119
// prepare diagnostic message
126
120
diagnostic = generateDiagData (
127
121
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 );
129
123
130
124
return true ;
131
125
}
132
126
133
127
Float32MultiArrayStamped MPC::generateDiagData (
134
128
const MPCTrajectory & reference_trajectory, const MPCData & mpc_data_traj_raw,
135
129
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
137
131
{
138
132
Float32MultiArrayStamped diagnostic;
139
133
@@ -156,28 +150,28 @@ Float32MultiArrayStamped MPC::generateDiagData(
156
150
append_diag (ctrl_cmd.steering_tire_angle ); // [0] final steering command (MPC + LPF)
157
151
append_diag (Uex (0 )); // [1] mpc calculation result
158
152
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)
162
156
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
166
160
append_diag (current_velocity); // [10] measured velocity
167
161
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
174
168
append_diag (iteration_num); // [18] iteration number
175
169
append_diag (runtime); // [19] runtime of the latest problem solved
176
170
append_diag (objective_value); // [20] objective value of the latest problem solved
177
171
append_diag (std::clamp (
178
172
Uex (0 ), -m_steer_lim,
179
173
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
181
175
182
176
return diagnostic;
183
177
}
0 commit comments