@@ -152,6 +152,8 @@ MpcLateralController::MpcLateralController(rclcpp::Node & node)
152
152
153
153
m_mpc->setLogger (logger_);
154
154
m_mpc->setClock (clock_);
155
+
156
+ setupDiag ();
155
157
}
156
158
157
159
MpcLateralController::~MpcLateralController ()
@@ -227,6 +229,28 @@ std::shared_ptr<SteeringOffsetEstimator> MpcLateralController::createSteerOffset
227
229
return steering_offset_;
228
230
}
229
231
232
+ void MpcLateralController::setStatus (
233
+ DiagnosticStatusWrapper & stat, const bool & is_mpc_solved)
234
+ {
235
+ if (is_mpc_solved) {
236
+ stat.summary (DiagnosticStatus::OK, " MPC succeeded." );
237
+ } else {
238
+ const std::string & error_msg = " The MPC solver failed. Call MRM to stop the car." ;
239
+ stat.summary (DiagnosticStatus::ERROR, error_msg);
240
+ }
241
+ }
242
+
243
+ void MpcLateralController::setupDiag ()
244
+ {
245
+ auto & d = diag_updater_;
246
+ d.setHardwareID (" mpc_lateral_controller" );
247
+
248
+ d.add (" MPC_solve_checker" , [&](auto & stat) {
249
+ setStatus (
250
+ stat, is_mpc_solved);
251
+ });
252
+ }
253
+
230
254
trajectory_follower::LateralOutput MpcLateralController::run (
231
255
trajectory_follower::InputData const & input_data)
232
256
{
@@ -255,6 +279,8 @@ trajectory_follower::LateralOutput MpcLateralController::run(
255
279
const bool is_mpc_solved = m_mpc->calculateMPC (
256
280
m_current_steering, m_current_kinematic_state, ctrl_cmd, predicted_traj, debug_values);
257
281
282
+ diag_updater_.force_update ();
283
+
258
284
// reset previous MPC result
259
285
// Note: When a large deviation from the trajectory occurs, the optimization stops and
260
286
// the vehicle will return to the path by re-planning the trajectory or external operation.
0 commit comments