|
35 | 35 | namespace autoware::motion::control::mpc_lateral_controller
|
36 | 36 | {
|
37 | 37 |
|
38 |
| -MpcLateralController::MpcLateralController(rclcpp::Node & node) |
| 38 | +MpcLateralController::MpcLateralController( |
| 39 | + rclcpp::Node & node, std::shared_ptr<diagnostic_updater::Updater> diag_updater) |
39 | 40 | : clock_(node.get_clock()), logger_(node.get_logger().get_child("lateral_controller"))
|
40 | 41 | {
|
41 | 42 | const auto dp_int = [&](const std::string & s) { return node.declare_parameter<int>(s); };
|
42 | 43 | const auto dp_bool = [&](const std::string & s) { return node.declare_parameter<bool>(s); };
|
43 | 44 | const auto dp_double = [&](const std::string & s) { return node.declare_parameter<double>(s); };
|
44 | 45 |
|
| 46 | + diag_updater_ = diag_updater; |
| 47 | + |
45 | 48 | m_mpc = std::make_unique<MPC>(node);
|
46 | 49 |
|
47 | 50 | m_mpc->m_ctrl_period = node.get_parameter("ctrl_period").as_double();
|
@@ -152,6 +155,8 @@ MpcLateralController::MpcLateralController(rclcpp::Node & node)
|
152 | 155 |
|
153 | 156 | m_mpc->setLogger(logger_);
|
154 | 157 | m_mpc->setClock(clock_);
|
| 158 | + |
| 159 | + setupDiag(); |
155 | 160 | }
|
156 | 161 |
|
157 | 162 | MpcLateralController::~MpcLateralController()
|
@@ -227,6 +232,24 @@ std::shared_ptr<SteeringOffsetEstimator> MpcLateralController::createSteerOffset
|
227 | 232 | return steering_offset_;
|
228 | 233 | }
|
229 | 234 |
|
| 235 | +void MpcLateralController::setStatus(diagnostic_updater::DiagnosticStatusWrapper & stat) |
| 236 | +{ |
| 237 | + if (m_is_mpc_solved) { |
| 238 | + stat.summary(diagnostic_msgs::msg::DiagnosticStatus::OK, "MPC succeeded."); |
| 239 | + } else { |
| 240 | + const std::string error_msg = "The MPC solver failed. Call MRM to stop the car."; |
| 241 | + stat.summary(diagnostic_msgs::msg::DiagnosticStatus::ERROR, error_msg); |
| 242 | + } |
| 243 | +} |
| 244 | + |
| 245 | +void MpcLateralController::setupDiag() |
| 246 | +{ |
| 247 | + auto & d = diag_updater_; |
| 248 | + d->setHardwareID("mpc_lateral_controller"); |
| 249 | + |
| 250 | + d->add("MPC_solve_checker", [&](auto & stat) { setStatus(stat); }); |
| 251 | +} |
| 252 | + |
230 | 253 | trajectory_follower::LateralOutput MpcLateralController::run(
|
231 | 254 | trajectory_follower::InputData const & input_data)
|
232 | 255 | {
|
@@ -255,6 +278,10 @@ trajectory_follower::LateralOutput MpcLateralController::run(
|
255 | 278 | const bool is_mpc_solved = m_mpc->calculateMPC(
|
256 | 279 | m_current_steering, m_current_kinematic_state, ctrl_cmd, predicted_traj, debug_values);
|
257 | 280 |
|
| 281 | + m_is_mpc_solved = is_mpc_solved; // for diagnostic updater |
| 282 | + |
| 283 | + diag_updater_->force_update(); |
| 284 | + |
258 | 285 | // reset previous MPC result
|
259 | 286 | // Note: When a large deviation from the trajectory occurs, the optimization stops and
|
260 | 287 | // the vehicle will return to the path by re-planning the trajectory or external operation.
|
|
0 commit comments