Skip to content

Commit f2523ff

Browse files
fix
1 parent e69b61d commit f2523ff

File tree

14 files changed

+383
-149
lines changed

14 files changed

+383
-149
lines changed

control/autoware_mpc_lateral_controller/src/qp_solver/qp_solver_osqp.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,11 @@ bool QPSolverOSQP::solve(
5454
/* execute optimization */
5555
auto result = osqpsolver_.optimize(h_mat, osqpA, f, lower_bound, upper_bound);
5656

57-
std::vector<double> U_osqp = std::get<0>(result);
57+
std::vector<double> U_osqp = result.primal_solution;
5858
u = Eigen::Map<Eigen::Matrix<double, Eigen::Dynamic, 1>>(
5959
&U_osqp[0], static_cast<Eigen::Index>(U_osqp.size()), 1);
6060

61-
const int status_val = std::get<3>(result);
61+
const int status_val = result.solution_status;
6262
if (status_val != 1) {
6363
RCLCPP_WARN(logger_, "optimization failed : %s", osqpsolver_.getStatusMessage().c_str());
6464
return false;
@@ -71,7 +71,7 @@ bool QPSolverOSQP::solve(
7171
}
7272

7373
// polish status: successful (1), unperformed (0), (-1) unsuccessful
74-
int status_polish = std::get<2>(result);
74+
int status_polish = result.polish_status;
7575
if (status_polish == -1 || status_polish == 0) {
7676
const auto s = (status_polish == 0) ? "Polish process is not performed in osqp."
7777
: "Polish process failed in osqp.";

evaluator/autoware_planning_evaluator/include/autoware/planning_evaluator/planning_evaluator_node.hpp

+25-78
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2025 Tier IV, Inc.
1+
// Copyright 2021 Tier IV, Inc.
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.
@@ -16,54 +16,41 @@
1616
#define AUTOWARE__PLANNING_EVALUATOR__PLANNING_EVALUATOR_NODE_HPP_
1717

1818
#include "autoware/planning_evaluator/metrics_calculator.hpp"
19-
#include "autoware_utils/math/accumulator.hpp"
19+
#include "autoware/planning_evaluator/stat.hpp"
2020
#include "rclcpp/rclcpp.hpp"
2121
#include "tf2_ros/buffer.h"
2222
#include "tf2_ros/transform_listener.h"
2323

24-
#include <autoware/route_handler/route_handler.hpp>
25-
#include <autoware_utils/ros/polling_subscriber.hpp>
26-
#include <autoware_utils/system/stop_watch.hpp>
27-
#include <autoware_vehicle_info_utils/vehicle_info_utils.hpp>
28-
2924
#include "autoware_perception_msgs/msg/predicted_objects.hpp"
3025
#include "autoware_planning_msgs/msg/pose_with_uuid_stamped.hpp"
3126
#include "autoware_planning_msgs/msg/trajectory.hpp"
3227
#include "autoware_planning_msgs/msg/trajectory_point.hpp"
33-
#include "geometry_msgs/msg/accel_with_covariance_stamped.hpp"
28+
#include "diagnostic_msgs/msg/diagnostic_array.hpp"
3429
#include "nav_msgs/msg/odometry.hpp"
35-
#include <autoware_internal_debug_msgs/msg/float64_stamped.hpp>
36-
#include <autoware_planning_msgs/msg/lanelet_route.hpp>
37-
#include <tier4_metric_msgs/msg/metric.hpp>
38-
#include <tier4_metric_msgs/msg/metric_array.hpp>
3930

4031
#include <array>
4132
#include <deque>
4233
#include <memory>
4334
#include <string>
4435
#include <vector>
36+
4537
namespace planning_diagnostics
4638
{
47-
using autoware::vehicle_info_utils::VehicleInfo;
4839
using autoware_perception_msgs::msg::PredictedObjects;
4940
using autoware_planning_msgs::msg::PoseWithUuidStamped;
5041
using autoware_planning_msgs::msg::Trajectory;
5142
using autoware_planning_msgs::msg::TrajectoryPoint;
52-
using autoware_utils::Accumulator;
53-
using MetricMsg = tier4_metric_msgs::msg::Metric;
54-
using MetricArrayMsg = tier4_metric_msgs::msg::MetricArray;
43+
using diagnostic_msgs::msg::DiagnosticArray;
44+
using diagnostic_msgs::msg::DiagnosticStatus;
5545
using nav_msgs::msg::Odometry;
56-
using LaneletMapBin = autoware_map_msgs::msg::LaneletMapBin;
57-
using autoware_planning_msgs::msg::LaneletRoute;
58-
using geometry_msgs::msg::AccelWithCovarianceStamped;
5946
/**
6047
* @brief Node for planning evaluation
6148
*/
6249
class PlanningEvaluatorNode : public rclcpp::Node
6350
{
6451
public:
6552
explicit PlanningEvaluatorNode(const rclcpp::NodeOptions & node_options);
66-
~PlanningEvaluatorNode() override;
53+
~PlanningEvaluatorNode();
6754

6855
/**
6956
* @brief callback on receiving an odometry
@@ -75,8 +62,7 @@ class PlanningEvaluatorNode : public rclcpp::Node
7562
* @brief callback on receiving a trajectory
7663
* @param [in] traj_msg received trajectory message
7764
*/
78-
void onTrajectory(
79-
const Trajectory::ConstSharedPtr traj_msg, const Odometry::ConstSharedPtr ego_state_ptr);
65+
void onTrajectory(const Trajectory::ConstSharedPtr traj_msg);
8066

8167
/**
8268
* @brief callback on receiving a reference trajectory
@@ -94,81 +80,42 @@ class PlanningEvaluatorNode : public rclcpp::Node
9480
* @brief callback on receiving a modified goal
9581
* @param [in] modified_goal_msg received modified goal message
9682
*/
97-
void onModifiedGoal(
98-
const PoseWithUuidStamped::ConstSharedPtr modified_goal_msg,
99-
const Odometry::ConstSharedPtr ego_state_ptr);
100-
101-
/**
102-
* @brief add the given metric statistic
103-
*/
104-
void AddMetricMsg(const Metric & metric, const Accumulator<double> & metric_stat);
105-
106-
/**
107-
* @brief add current ego lane info
108-
*/
109-
void AddLaneletMetricMsg(const Odometry::ConstSharedPtr ego_state_ptr);
83+
void onModifiedGoal(const PoseWithUuidStamped::ConstSharedPtr modified_goal_msg);
11084

11185
/**
112-
* @brief add current ego kinematic state
86+
* @brief publish the given metric statistic
11387
*/
114-
void AddKinematicStateMetricMsg(
115-
const AccelWithCovarianceStamped & accel_stamped, const Odometry::ConstSharedPtr ego_state_ptr);
88+
DiagnosticStatus generateDiagnosticStatus(
89+
const Metric & metric, const Stat<double> & metric_stat) const;
11690

11791
private:
11892
static bool isFinite(const TrajectoryPoint & p);
119-
120-
/**
121-
* @brief update route handler data
122-
*/
123-
void getRouteData();
124-
125-
/**
126-
* @brief fetch data and publish diagnostics
127-
*/
128-
void onTimer();
93+
void publishModifiedGoalDeviationMetrics();
12994

13095
// ROS
131-
autoware_utils::InterProcessPollingSubscriber<Trajectory> traj_sub_{this, "~/input/trajectory"};
132-
autoware_utils::InterProcessPollingSubscriber<Trajectory> ref_sub_{
133-
this, "~/input/reference_trajectory"};
134-
autoware_utils::InterProcessPollingSubscriber<PredictedObjects> objects_sub_{
135-
this, "~/input/objects"};
136-
autoware_utils::InterProcessPollingSubscriber<PoseWithUuidStamped> modified_goal_sub_{
137-
this, "~/input/modified_goal"};
138-
autoware_utils::InterProcessPollingSubscriber<Odometry> odometry_sub_{this, "~/input/odometry"};
139-
autoware_utils::InterProcessPollingSubscriber<
140-
LaneletRoute, autoware_utils::polling_policy::Newest>
141-
route_subscriber_{this, "~/input/route", rclcpp::QoS{1}.transient_local()};
142-
autoware_utils::InterProcessPollingSubscriber<
143-
LaneletMapBin, autoware_utils::polling_policy::Newest>
144-
vector_map_subscriber_{this, "~/input/vector_map", rclcpp::QoS{1}.transient_local()};
145-
autoware_utils::InterProcessPollingSubscriber<AccelWithCovarianceStamped> accel_sub_{
146-
this, "~/input/acceleration"};
147-
148-
rclcpp::Publisher<autoware_internal_debug_msgs::msg::Float64Stamped>::SharedPtr
149-
processing_time_pub_;
150-
rclcpp::Publisher<MetricArrayMsg>::SharedPtr metrics_pub_;
96+
rclcpp::Subscription<Trajectory>::SharedPtr traj_sub_;
97+
rclcpp::Subscription<Trajectory>::SharedPtr ref_sub_;
98+
rclcpp::Subscription<PredictedObjects>::SharedPtr objects_sub_;
99+
rclcpp::Subscription<PoseWithUuidStamped>::SharedPtr modified_goal_sub_;
100+
rclcpp::Subscription<Odometry>::SharedPtr odom_sub_;
101+
102+
rclcpp::Publisher<DiagnosticArray>::SharedPtr metrics_pub_;
151103
std::shared_ptr<tf2_ros::TransformListener> transform_listener_{nullptr};
152104
std::unique_ptr<tf2_ros::Buffer> tf_buffer_;
153-
autoware::route_handler::RouteHandler route_handler_;
154-
155-
// Message to publish
156-
MetricArrayMsg metrics_msg_;
157105

158106
// Parameters
159-
bool output_metrics_;
107+
std::string output_file_str_;
160108
std::string ego_frame_str_;
161109

162110
// Calculator
163111
MetricsCalculator metrics_calculator_;
164112
// Metrics
165113
std::vector<Metric> metrics_;
166-
std::array<std::array<Accumulator<double>, 3>, static_cast<size_t>(Metric::SIZE)>
167-
metric_accumulators_; // 3(min, max, mean) * metric_size
114+
std::deque<rclcpp::Time> stamps_;
115+
std::array<std::deque<Stat<double>>, static_cast<size_t>(Metric::SIZE)> metric_stats_;
168116

169-
rclcpp::TimerBase::SharedPtr timer_;
170-
VehicleInfo vehicle_info_;
171-
std::optional<AccelWithCovarianceStamped> prev_acc_stamped_{std::nullopt};
117+
Odometry::ConstSharedPtr ego_state_ptr_;
118+
PoseWithUuidStamped::ConstSharedPtr modified_goal_ptr_;
172119
};
173120
} // namespace planning_diagnostics
174121

planning/autoware_obstacle_cruise_planner/src/optimization_based_planner/velocity_optimizer.cpp

+4-3
Original file line numberDiff line numberDiff line change
@@ -246,10 +246,11 @@ VelocityOptimizer::OptimizationResult VelocityOptimizer::optimize(const Optimiza
246246
}
247247

248248
// execute optimization
249-
const auto result = qp_solver_.optimize(P, A, q, lower_bound, upper_bound);
250-
const std::vector<double> optval = std::get<0>(result);
249+
const autoware::osqp_interface::OSQPResult result =
250+
qp_solver_.optimize(P, A, q, lower_bound, upper_bound);
251+
const std::vector<double> optval = result.primal_solution;
251252

252-
const int status_val = std::get<3>(result);
253+
const int status_val = result.solution_status;
253254
if (status_val != 1)
254255
std::cerr << "optimization failed : " << qp_solver_.getStatusMessage().c_str() << std::endl;
255256

planning/autoware_path_optimizer/include/autoware/path_optimizer/mpt_optimizer.hpp

+99-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "autoware/path_optimizer/common_structs.hpp"
2222
#include "autoware/path_optimizer/state_equation_generator.hpp"
2323
#include "autoware/path_optimizer/type_alias.hpp"
24+
#include "autoware/path_optimizer/utils/conditional_timer.hpp"
2425
#include "autoware_utils/geometry/geometry.hpp"
2526
#include "autoware_utils/system/time_keeper.hpp"
2627
#include "autoware_vehicle_info_utils/vehicle_info_utils.hpp"
@@ -57,6 +58,15 @@ struct Bounds
5758
lower_bound -= offset;
5859
upper_bound -= offset;
5960
}
61+
62+
friend std::ostream & operator<<(std::ostream & os, const Bounds & bounds)
63+
{
64+
os << "Bounds: {\n";
65+
os << "\tlower_bound: " << bounds.lower_bound << ",\n";
66+
os << "\tupper_bound: " << bounds.upper_bound << "\n";
67+
os << "}\n";
68+
return os;
69+
}
6070
};
6171

6272
struct KinematicState
@@ -65,6 +75,15 @@ struct KinematicState
6575
double yaw{0.0};
6676

6777
Eigen::Vector2d toEigenVector() const { return Eigen::Vector2d{lat, yaw}; }
78+
79+
friend std::ostream & operator<<(std::ostream & os, const KinematicState & state)
80+
{
81+
os << "KinematicState: {\n";
82+
os << "\tlat: " << state.lat << ",\n";
83+
os << "\tyaw: " << state.yaw << "\n";
84+
os << "}\n";
85+
return os;
86+
}
6887
};
6988

7089
struct ReferencePoint
@@ -92,6 +111,57 @@ struct ReferencePoint
92111

93112
double getYaw() const { return tf2::getYaw(pose.orientation); }
94113

114+
115+
friend std::ostream & operator<<(std::ostream & os, const ReferencePoint & ref_point)
116+
{
117+
os << "ReferencePoint: {\n";
118+
os << "\tpose: " << ref_point.pose.position.x << ", " << ref_point.pose.position.y << ",\n";
119+
os << "\tlongitudinal_velocity_mps: " << ref_point.longitudinal_velocity_mps << ",\n";
120+
os << "\tcurvature: " << ref_point.curvature << ",\n";
121+
os << "\tdelta_arc_length: " << ref_point.delta_arc_length << ",\n";
122+
os << "\talpha: " << ref_point.alpha << ",\n";
123+
os << "\tbounds: " << ref_point.bounds << ",\n";
124+
os << "\tbeta: [";
125+
for (const auto & b : ref_point.beta) {
126+
os << b << ", ";
127+
}
128+
os << "],\n";
129+
os << "\tnormalized_avoidance_cost: " << ref_point.normalized_avoidance_cost << ",\n";
130+
os << "\tbounds_on_constraints: [";
131+
for (const auto & b : ref_point.bounds_on_constraints) {
132+
os << b << ", ";
133+
}
134+
os << "],\n";
135+
os << "\tpose_on_constraints: [";
136+
for (const auto & p : ref_point.pose_on_constraints) {
137+
os << "(" << p.position.x << ", " << p.position.y << ") , ";
138+
}
139+
os << "],\n";
140+
os << "\tfixed_kinematic_state: ";
141+
if (ref_point.fixed_kinematic_state) {
142+
os << *ref_point.fixed_kinematic_state;
143+
} else {
144+
os << "nullopt";
145+
}
146+
os << ",\n";
147+
os << "\toptimized_kinematic_state: " << ref_point.optimized_kinematic_state
148+
<< ",\n";
149+
os << "\toptimized_input: " << ref_point.optimized_input << ",\n";
150+
os << "\tslack_variables: ";
151+
if (ref_point.slack_variables) {
152+
os << "[";
153+
for (const auto & s : *ref_point.slack_variables) {
154+
os << s << ", ";
155+
}
156+
os << "]";
157+
} else {
158+
os << "nullopt";
159+
}
160+
os << "\n";
161+
os << "}\n";
162+
return os;
163+
}
164+
95165
geometry_msgs::msg::Pose offsetDeviation(const double lat_dev, const double yaw_dev) const
96166
{
97167
auto pose_with_deviation = autoware_utils::calc_offset_pose(pose, 0.0, lat_dev, 0.0);
@@ -110,7 +180,7 @@ class MPTOptimizer
110180
const TrajectoryParam & traj_param, const std::shared_ptr<DebugData> debug_data_ptr,
111181
const std::shared_ptr<autoware_utils::TimeKeeper> time_keeper_);
112182

113-
std::vector<TrajectoryPoint> optimizeTrajectory(const PlannerData & planner_data);
183+
std::pair<std::vector<TrajectoryPoint>, int> optimizeTrajectory(const PlannerData & planner_data);
114184
std::optional<std::vector<TrajectoryPoint>> getPrevOptimizedTrajectoryPoints() const;
115185

116186
void initialize(const bool enable_debug_info, const TrajectoryParam & traj_param);
@@ -126,19 +196,47 @@ class MPTOptimizer
126196
{
127197
Eigen::SparseMatrix<double> Q;
128198
Eigen::SparseMatrix<double> R;
199+
200+
friend std::ostream & operator<<(std::ostream & os, const ValueMatrix & matrix)
201+
{
202+
os << "ValueMatrix: {\n";
203+
os << "\tQ: (Sparse Matrix):" << matrix.Q;
204+
os << "\tR: (Sparse Matrix):" << matrix.R;
205+
os << "}\n";
206+
return os;
207+
}
129208
};
130209

131210
struct ObjectiveMatrix
132211
{
133212
Eigen::MatrixXd hessian;
134213
Eigen::VectorXd gradient;
214+
215+
friend std::ostream & operator<<(std::ostream & os, const ObjectiveMatrix & matrix)
216+
{
217+
os << "ObjectiveMatrix: {\n";
218+
os << "\thessian:\n" << matrix.hessian << "\n";
219+
os << "\tgradient:\n" << matrix.gradient << "\n";
220+
os << "}\n";
221+
return os;
222+
}
135223
};
136224

137225
struct ConstraintMatrix
138226
{
139227
Eigen::MatrixXd linear;
140228
Eigen::VectorXd lower_bound;
141229
Eigen::VectorXd upper_bound;
230+
231+
friend std::ostream & operator<<(std::ostream & os, const ConstraintMatrix & matrix)
232+
{
233+
os << "ConstraintMatrix: {\n";
234+
os << "\tlinear:\n" << matrix.linear << "\n";
235+
os << "\tlower_bound:\n" << matrix.lower_bound << "\n";
236+
os << "\tupper_bound:\n" << matrix.upper_bound << "\n";
237+
os << "}\n";
238+
return os;
239+
}
142240
};
143241

144242
struct MPTParam

0 commit comments

Comments
 (0)