Skip to content

Commit fbd61e2

Browse files
feat(mpc_lateral_controller): signal a MRM when MPC fails. (#7016)
* mpc fail checker diagnostic added Signed-off-by: Zhe Shen <lucidshenzhe@gmail.com> * fix some scope issues Signed-off-by: Zhe Shen <lucidshenzhe@gmail.com> * member attribute added. Signed-off-by: Zhe Shen <lucidshenzhe@gmail.com> * shared pointer added. Signed-off-by: Zhe Shen <lucidshenzhe@gmail.com> * member attribute (diag_updater_) added Signed-off-by: Zhe Shen <lucidshenzhe@gmail.com> * dependency added. Signed-off-by: Zhe Shen <lucidshenzhe@gmail.com> * implementation of the MpcLateralController corrected! Signed-off-by: Zhe Shen <lucidshenzhe@gmail.com> * typo in comment corrected! Signed-off-by: Zhe Shen <lucidshenzhe@gmail.com> * member method argument corrected Signed-off-by: Zhe Shen <lucidshenzhe@gmail.com> * delete unnecessary reference mark Co-authored-by: Takamasa Horibe <horibe.takamasa@gmail.com> * rebase Signed-off-by: Zhe Shen <lucidshenzhe@gmail.com> * correct the include Signed-off-by: Zhe Shen <lucidshenzhe@gmail.com> * pre-commit Signed-off-by: Zhe Shen <lucidshenzhe@gmail.com> --------- Signed-off-by: Zhe Shen <lucidshenzhe@gmail.com> Co-authored-by: Takamasa Horibe <horibe.takamasa@gmail.com>
1 parent a443210 commit fbd61e2

File tree

4 files changed

+49
-3
lines changed

4 files changed

+49
-3
lines changed

control/autoware_mpc_lateral_controller/include/autoware/mpc_lateral_controller/mpc_lateral_controller.hpp

+14-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
#include "autoware/trajectory_follower_base/lateral_controller_base.hpp"
2323
#include "rclcpp/rclcpp.hpp"
2424

25+
#include <diagnostic_updater/diagnostic_updater.hpp>
26+
2527
#include "autoware_control_msgs/msg/lateral.hpp"
2628
#include "autoware_planning_msgs/msg/trajectory.hpp"
2729
#include "autoware_vehicle_msgs/msg/steering_report.hpp"
@@ -52,7 +54,8 @@ class MpcLateralController : public trajectory_follower::LateralControllerBase
5254
{
5355
public:
5456
/// \param node Reference to the node used only for the component and parameter initialization.
55-
explicit MpcLateralController(rclcpp::Node & node);
57+
explicit MpcLateralController(
58+
rclcpp::Node & node, std::shared_ptr<diagnostic_updater::Updater> diag_updater);
5659
virtual ~MpcLateralController();
5760

5861
private:
@@ -63,6 +66,9 @@ class MpcLateralController : public trajectory_follower::LateralControllerBase
6366
rclcpp::Publisher<Float32MultiArrayStamped>::SharedPtr m_pub_debug_values;
6467
rclcpp::Publisher<Float32Stamped>::SharedPtr m_pub_steer_offset;
6568

69+
std::shared_ptr<diagnostic_updater::Updater>
70+
diag_updater_{}; // Diagnostic updater for publishing diagnostic data.
71+
6672
//!< @brief parameters for path smoothing
6773
TrajectoryFilteringParam m_trajectory_filtering_param;
6874

@@ -87,9 +93,16 @@ class MpcLateralController : public trajectory_follower::LateralControllerBase
8793
// Flag indicating whether to keep the steering control until it converges.
8894
bool m_keep_steer_control_until_converged;
8995

96+
// MPC solver checker.
97+
bool m_is_mpc_solved{true};
98+
9099
// trajectory buffer for detecting new trajectory
91100
std::deque<Trajectory> m_trajectory_buffer;
92101

102+
void setStatus(diagnostic_updater::DiagnosticStatusWrapper & stat);
103+
104+
void setupDiag();
105+
93106
std::unique_ptr<MPC> m_mpc; // MPC object for trajectory following.
94107

95108
// Check is mpc output converged

control/autoware_mpc_lateral_controller/src/mpc_lateral_controller.cpp

+28-1
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,16 @@
3535
namespace autoware::motion::control::mpc_lateral_controller
3636
{
3737

38-
MpcLateralController::MpcLateralController(rclcpp::Node & node)
38+
MpcLateralController::MpcLateralController(
39+
rclcpp::Node & node, std::shared_ptr<diagnostic_updater::Updater> diag_updater)
3940
: clock_(node.get_clock()), logger_(node.get_logger().get_child("lateral_controller"))
4041
{
4142
const auto dp_int = [&](const std::string & s) { return node.declare_parameter<int>(s); };
4243
const auto dp_bool = [&](const std::string & s) { return node.declare_parameter<bool>(s); };
4344
const auto dp_double = [&](const std::string & s) { return node.declare_parameter<double>(s); };
4445

46+
diag_updater_ = diag_updater;
47+
4548
m_mpc = std::make_unique<MPC>(node);
4649

4750
m_mpc->m_ctrl_period = node.get_parameter("ctrl_period").as_double();
@@ -152,6 +155,8 @@ MpcLateralController::MpcLateralController(rclcpp::Node & node)
152155

153156
m_mpc->setLogger(logger_);
154157
m_mpc->setClock(clock_);
158+
159+
setupDiag();
155160
}
156161

157162
MpcLateralController::~MpcLateralController()
@@ -227,6 +232,24 @@ std::shared_ptr<SteeringOffsetEstimator> MpcLateralController::createSteerOffset
227232
return steering_offset_;
228233
}
229234

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+
230253
trajectory_follower::LateralOutput MpcLateralController::run(
231254
trajectory_follower::InputData const & input_data)
232255
{
@@ -255,6 +278,10 @@ trajectory_follower::LateralOutput MpcLateralController::run(
255278
const bool is_mpc_solved = m_mpc->calculateMPC(
256279
m_current_steering, m_current_kinematic_state, ctrl_cmd, predicted_traj, debug_values);
257280

281+
m_is_mpc_solved = is_mpc_solved; // for diagnostic updater
282+
283+
diag_updater_->force_update();
284+
258285
// reset previous MPC result
259286
// Note: When a large deviation from the trajectory occurs, the optimization stops and
260287
// the vehicle will return to the path by re-planning the trajectory or external operation.

control/autoware_trajectory_follower_node/include/autoware/trajectory_follower_node/controller_node.hpp

+5
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include <Eigen/Core>
3131
#include <Eigen/Geometry>
3232
#include <autoware/universe_utils/ros/published_time_publisher.hpp>
33+
#include <diagnostic_updater/diagnostic_updater.hpp>
3334

3435
#include "autoware_control_msgs/msg/control.hpp"
3536
#include "autoware_control_msgs/msg/longitudinal.hpp"
@@ -73,6 +74,10 @@ class TRAJECTORY_FOLLOWER_PUBLIC Controller : public rclcpp::Node
7374
double timeout_thr_sec_;
7475
boost::optional<LongitudinalOutput> longitudinal_output_{boost::none};
7576

77+
std::shared_ptr<diagnostic_updater::Updater> diag_updater_ =
78+
std::make_shared<diagnostic_updater::Updater>(
79+
this); // Diagnostic updater for publishing diagnostic data.
80+
7681
std::shared_ptr<trajectory_follower::LongitudinalControllerBase> longitudinal_controller_;
7782
std::shared_ptr<trajectory_follower::LateralControllerBase> lateral_controller_;
7883

control/autoware_trajectory_follower_node/src/controller_node.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ Controller::Controller(const rclcpp::NodeOptions & node_options) : Node("control
3939
getLateralControllerMode(declare_parameter<std::string>("lateral_controller_mode"));
4040
switch (lateral_controller_mode) {
4141
case LateralControllerMode::MPC: {
42-
lateral_controller_ = std::make_shared<mpc_lateral_controller::MpcLateralController>(*this);
42+
lateral_controller_ =
43+
std::make_shared<mpc_lateral_controller::MpcLateralController>(*this, diag_updater_);
4344
break;
4445
}
4546
case LateralControllerMode::PURE_PURSUIT: {

0 commit comments

Comments
 (0)