Skip to content

Commit cfb594a

Browse files
style(pre-commit): autofix
1 parent 188b6c7 commit cfb594a

File tree

10 files changed

+100
-91
lines changed

10 files changed

+100
-91
lines changed

common/osqp_interface/include/osqp_interface/csc_matrix_conv.hpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,9 @@ struct OSQP_INTERFACE_PUBLIC CSC_Matrix
3737
std::vector<c_int> m_row_idxs;
3838
/// Vector of 'val' indices where each column starts. Ex: [0, 2, 4] (Eigen: 'outer')
3939
std::vector<c_int> m_col_idxs;
40-
41-
friend std::ostream& operator<<(std::ostream& os, const CSC_Matrix& matrix) {
40+
41+
friend std::ostream & operator<<(std::ostream & os, const CSC_Matrix & matrix)
42+
{
4243
os << "CSC_Matrix: {\n";
4344
os << "\tm_vals: [";
4445
for (size_t i = 0; i < matrix.m_vals.size(); ++i) {

common/osqp_interface/include/osqp_interface/osqp_interface.hpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ namespace osqp
3636
{
3737
constexpr c_float INF = 1e30;
3838

39-
struct OSQPResult {
39+
struct OSQPResult
40+
{
4041
std::vector<double> primal_solution;
4142
std::vector<double> lagrange_multipliers;
4243
int polish_status;

common/osqp_interface/src/osqp_interface.cpp

+3-6
Original file line numberDiff line numberDiff line change
@@ -363,8 +363,7 @@ int64_t OSQPInterface::initializeProblem(
363363
return m_exitflag;
364364
}
365365

366-
OSQPResult
367-
OSQPInterface::solve()
366+
OSQPResult OSQPInterface::solve()
368367
{
369368
// Solve Problem
370369
int32_t exit_flag = osqp_solve(m_work.get());
@@ -396,16 +395,14 @@ OSQPInterface::solve()
396395
return result;
397396
}
398397

399-
OSQPResult
400-
OSQPInterface::optimize()
398+
OSQPResult OSQPInterface::optimize()
401399
{
402400
// Run the solver on the stored problem representation.
403401
OSQPResult result = solve();
404402
return result;
405403
}
406404

407-
OSQPResult
408-
OSQPInterface::optimize(
405+
OSQPResult OSQPInterface::optimize(
409406
const Eigen::MatrixXd & P, const Eigen::MatrixXd & A, const std::vector<double> & q,
410407
const std::vector<double> & l, const std::vector<double> & u)
411408
{

common/osqp_interface/test/test_osqp_interface.cpp

+18-19
Original file line numberDiff line numberDiff line change
@@ -44,25 +44,24 @@ TEST(TestOsqpInterface, BasicQp)
4444
using autoware::common::osqp::calCSCMatrixTrapezoidal;
4545
using autoware::common::osqp::CSC_Matrix;
4646

47-
auto check_result =
48-
[](const autoware::common::osqp::OSQPResult & result) {
49-
EXPECT_EQ(result.polish_status, 1); // polish succeeded
50-
EXPECT_EQ(result.solution_status, 1); // solution succeeded
51-
52-
static const auto ep = 1.0e-8;
53-
54-
const auto prime_val = result.primal_solution;
55-
ASSERT_EQ(prime_val.size(), size_t(2));
56-
EXPECT_NEAR(prime_val[0], 0.3, ep);
57-
EXPECT_NEAR(prime_val[1], 0.7, ep);
58-
59-
const auto dual_val = result.lagrange_multipliers;
60-
ASSERT_EQ(dual_val.size(), size_t(4));
61-
EXPECT_NEAR(dual_val[0], -2.9, ep);
62-
EXPECT_NEAR(dual_val[1], 0.0, ep);
63-
EXPECT_NEAR(dual_val[2], 0.2, ep);
64-
EXPECT_NEAR(dual_val[3], 0.0, ep);
65-
};
47+
auto check_result = [](const autoware::common::osqp::OSQPResult & result) {
48+
EXPECT_EQ(result.polish_status, 1); // polish succeeded
49+
EXPECT_EQ(result.solution_status, 1); // solution succeeded
50+
51+
static const auto ep = 1.0e-8;
52+
53+
const auto prime_val = result.primal_solution;
54+
ASSERT_EQ(prime_val.size(), size_t(2));
55+
EXPECT_NEAR(prime_val[0], 0.3, ep);
56+
EXPECT_NEAR(prime_val[1], 0.7, ep);
57+
58+
const auto dual_val = result.lagrange_multipliers;
59+
ASSERT_EQ(dual_val.size(), size_t(4));
60+
EXPECT_NEAR(dual_val[0], -2.9, ep);
61+
EXPECT_NEAR(dual_val[1], 0.0, ep);
62+
EXPECT_NEAR(dual_val[2], 0.2, ep);
63+
EXPECT_NEAR(dual_val[3], 0.0, ep);
64+
};
6665

6766
const Eigen::MatrixXd P = (Eigen::MatrixXd(2, 2) << 4, 1, 1, 2).finished();
6867
const Eigen::MatrixXd A = (Eigen::MatrixXd(4, 2) << 1, 1, 1, 0, 0, 1, 0, 1).finished();

planning/obstacle_avoidance_planner/include/obstacle_avoidance_planner/mpt_optimizer.hpp

+25-18
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ struct Bounds
5757
upper_bound -= offset;
5858
}
5959

60-
friend std::ostream& operator<<(std::ostream& os, const Bounds& bounds) {
60+
friend std::ostream & operator<<(std::ostream & os, const Bounds & bounds)
61+
{
6162
os << "Bounds: {\n";
6263
os << "\tlower_bound: " << bounds.lower_bound << ",\n";
6364
os << "\tupper_bound: " << bounds.upper_bound << "\n";
@@ -73,7 +74,8 @@ struct KinematicState
7374

7475
Eigen::Vector2d toEigenVector() const { return Eigen::Vector2d{lat, yaw}; }
7576

76-
friend std::ostream& operator<<(std::ostream& os, const KinematicState& state) {
77+
friend std::ostream & operator<<(std::ostream & os, const KinematicState & state)
78+
{
7779
os << "KinematicState: {\n";
7880
os << "\tlat: " << state.lat << ",\n";
7981
os << "\tyaw: " << state.yaw << "\n";
@@ -107,16 +109,17 @@ struct ReferencePoint
107109

108110
double getYaw() const { return tf2::getYaw(pose.orientation); }
109111

110-
friend std::ostream& operator<<(std::ostream& os, const ReferencePoint& ref_point) {
112+
friend std::ostream & operator<<(std::ostream & os, const ReferencePoint & ref_point)
113+
{
111114
os << "ReferencePoint: {\n";
112115
os << "\tpose: " << ref_point.pose.position.x << ", " << ref_point.pose.position.y << ",\n";
113116
os << "\tlongitudinal_velocity_mps: " << ref_point.longitudinal_velocity_mps << ",\n";
114117
os << "\tcurvature: " << ref_point.curvature << ",\n";
115118
os << "\tdelta_arc_length: " << ref_point.delta_arc_length << ",\n";
116119
os << "\talpha: " << ref_point.alpha << ",\n";
117-
os << "\tbounds: " << ref_point.bounds << ",\n"; // Assuming Bounds is printable
120+
os << "\tbounds: " << ref_point.bounds << ",\n"; // Assuming Bounds is printable
118121
os << "\tbeta: [";
119-
for (const auto& b : ref_point.beta) {
122+
for (const auto & b : ref_point.beta) {
120123
if (b) {
121124
os << *b << ", ";
122125
} else {
@@ -126,28 +129,29 @@ struct ReferencePoint
126129
os << "],\n";
127130
os << "\tnormalized_avoidance_cost: " << ref_point.normalized_avoidance_cost << ",\n";
128131
os << "\tbounds_on_constraints: [";
129-
for (const auto& b : ref_point.bounds_on_constraints) {
130-
os << b << ", "; // Assuming Bounds is printable
132+
for (const auto & b : ref_point.bounds_on_constraints) {
133+
os << b << ", "; // Assuming Bounds is printable
131134
}
132135
os << "],\n";
133136
os << "\tpose_on_constraints: [";
134-
for (const auto& p : ref_point.pose_on_constraints) {
137+
for (const auto & p : ref_point.pose_on_constraints) {
135138
os << "(" << p.position.x << ", " << p.position.y << ") , ";
136139
}
137140
os << "],\n";
138141
os << "\tfixed_kinematic_state: ";
139142
if (ref_point.fixed_kinematic_state) {
140-
os << *ref_point.fixed_kinematic_state; // Assuming KinematicState is printable
143+
os << *ref_point.fixed_kinematic_state; // Assuming KinematicState is printable
141144
} else {
142145
os << "nullopt";
143146
}
144147
os << ",\n";
145-
os << "\toptimized_kinematic_state: " << ref_point.optimized_kinematic_state << ",\n"; // Assuming KinematicState is printable
148+
os << "\toptimized_kinematic_state: " << ref_point.optimized_kinematic_state
149+
<< ",\n"; // Assuming KinematicState is printable
146150
os << "\toptimized_input: " << ref_point.optimized_input << ",\n";
147151
os << "\tslack_variables: ";
148152
if (ref_point.slack_variables) {
149153
os << "[";
150-
for (const auto& s : *ref_point.slack_variables) {
154+
for (const auto & s : *ref_point.slack_variables) {
151155
os << s << ", ";
152156
}
153157
os << "]";
@@ -194,8 +198,9 @@ class MPTOptimizer
194198
{
195199
Eigen::SparseMatrix<double> Q;
196200
Eigen::SparseMatrix<double> R;
197-
198-
friend std::ostream& operator<<(std::ostream& os, const ValueMatrix& matrix) {
201+
202+
friend std::ostream & operator<<(std::ostream & os, const ValueMatrix & matrix)
203+
{
199204
os << "ValueMatrix: {\n";
200205
os << "\tQ: (Sparse Matrix):" << matrix.Q;
201206
os << "\tR: (Sparse Matrix):" << matrix.R;
@@ -208,23 +213,25 @@ class MPTOptimizer
208213
{
209214
Eigen::MatrixXd hessian;
210215
Eigen::VectorXd gradient;
211-
212-
friend std::ostream& operator<<(std::ostream& os, const ObjectiveMatrix& matrix) {
216+
217+
friend std::ostream & operator<<(std::ostream & os, const ObjectiveMatrix & matrix)
218+
{
213219
os << "ObjectiveMatrix: {\n";
214220
os << "\thessian:\n" << matrix.hessian << "\n";
215221
os << "\tgradient:\n" << matrix.gradient << "\n";
216222
os << "}\n";
217223
return os;
218224
}
219225
};
220-
226+
221227
struct ConstraintMatrix
222228
{
223229
Eigen::MatrixXd linear;
224230
Eigen::VectorXd lower_bound;
225231
Eigen::VectorXd upper_bound;
226-
227-
friend std::ostream& operator<<(std::ostream& os, const ConstraintMatrix& matrix) {
232+
233+
friend std::ostream & operator<<(std::ostream & os, const ConstraintMatrix & matrix)
234+
{
228235
os << "ConstraintMatrix: {\n";
229236
os << "\tlinear:\n" << matrix.linear << "\n";
230237
os << "\tlower_bound:\n" << matrix.lower_bound << "\n";

planning/obstacle_avoidance_planner/include/obstacle_avoidance_planner/state_equation_generator.hpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ class StateEquationGenerator
3535
Eigen::MatrixXd B;
3636
Eigen::VectorXd W;
3737

38-
friend std::ostream& operator<<(std::ostream& os, const Matrix& matrix) {
38+
friend std::ostream & operator<<(std::ostream & os, const Matrix & matrix)
39+
{
3940
os << "Matrix: {\n";
4041
os << "\tA:\n" << matrix.A << "\n";
4142
os << "\tB:\n" << matrix.B << "\n";

planning/obstacle_avoidance_planner/include/obstacle_avoidance_planner/utils/conditional_timer.hpp

+23-18
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,32 @@
33
#include <chrono>
44
#include <optional>
55

6-
class ConditionalTimer {
6+
class ConditionalTimer
7+
{
78
public:
8-
void update(bool condition) {
9-
if (condition && !start_time_.has_value()) {
10-
// Condition met, start the timer
11-
start_time_ = std::chrono::high_resolution_clock::now();
12-
} else if (!condition && start_time_.has_value()) {
13-
// Condition no longer met, stop the timer
14-
start_time_ = std::nullopt;
15-
}
9+
void update(bool condition)
10+
{
11+
if (condition && !start_time_.has_value()) {
12+
// Condition met, start the timer
13+
start_time_ = std::chrono::high_resolution_clock::now();
14+
} else if (!condition && start_time_.has_value()) {
15+
// Condition no longer met, stop the timer
16+
start_time_ = std::nullopt;
1617
}
18+
}
1719

18-
std::chrono::duration<double> getElapsedTime() const {
19-
if (start_time_.has_value()) {
20-
auto current_time = std::chrono::high_resolution_clock::now();
21-
return current_time - *start_time_;
22-
} else {
23-
return std::chrono::duration<double>(0.0);;
24-
}
20+
std::chrono::duration<double> getElapsedTime() const
21+
{
22+
if (start_time_.has_value()) {
23+
auto current_time = std::chrono::high_resolution_clock::now();
24+
return current_time - *start_time_;
25+
} else {
26+
return std::chrono::duration<double>(0.0);
27+
;
2528
}
29+
}
2630

2731
private:
28-
std::optional<std::chrono::time_point<std::chrono::high_resolution_clock>> start_time_{std::nullopt};
29-
};
32+
std::optional<std::chrono::time_point<std::chrono::high_resolution_clock>> start_time_{
33+
std::nullopt};
34+
};

planning/obstacle_avoidance_planner/src/mpt_optimizer.cpp

+20-24
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "obstacle_avoidance_planner/utils/trajectory_utils.hpp"
2121
#include "tf2/utils.h"
2222
#include "tier4_autoware_utils/tier4_autoware_utils.hpp"
23+
2324
#include <rclcpp/logging.hpp>
2425

2526
#include <algorithm>
@@ -116,13 +117,14 @@ std::vector<double> toStdVector(const Eigen::VectorXd & eigen_vec)
116117
return {eigen_vec.data(), eigen_vec.data() + eigen_vec.rows()};
117118
}
118119

119-
std::string vectorToString(const std::vector<double>& vec) {
120+
std::string vectorToString(const std::vector<double> & vec)
121+
{
120122
std::ostringstream oss;
121123
if (!vec.empty()) {
122-
oss << vec.front(); // Add the first element
123-
for (size_t i = 1; i < vec.size(); ++i) {
124-
oss << "," << vec[i]; // Add the rest with commas
125-
}
124+
oss << vec.front(); // Add the first element
125+
for (size_t i = 1; i < vec.size(); ++i) {
126+
oss << "," << vec[i]; // Add the rest with commas
127+
}
126128
}
127129
return oss.str();
128130
}
@@ -513,21 +515,19 @@ std::pair<std::vector<TrajectoryPoint>, int> MPTOptimizer::optimizeTrajectory(
513515
if (!optimized_variables) {
514516
RCLCPP_INFO_EXPRESSION(
515517
logger_, enable_debug_info_, "return std::nullopt since could not solve qp");
516-
517-
RCLCPP_INFO(
518-
logger_, "Inputs causing failure:"
519-
);
518+
519+
RCLCPP_INFO(logger_, "Inputs causing failure:");
520520
RCLCPP_INFO_STREAM(logger_, "ref_points: ");
521-
522-
for (const auto& ref_point : ref_points) {
521+
522+
for (const auto & ref_point : ref_points) {
523523
std::cout << "\t" << ref_point << "\n";
524524
}
525525

526526
RCLCPP_INFO_STREAM(logger_, "mpt_mat: " << mpt_mat);
527527
RCLCPP_INFO_STREAM(logger_, "val_mat: " << val_mat);
528528
RCLCPP_INFO_STREAM(logger_, "obj_mat: " << obj_mat);
529529
RCLCPP_INFO_STREAM(logger_, "const_mat: " << const_mat);
530-
530+
531531
return std::make_pair<std::vector<TrajectoryPoint>, int>(get_prev_optimized_traj_points(), -1);
532532
}
533533

@@ -1535,10 +1535,8 @@ std::optional<Eigen::VectorXd> MPTOptimizer::calcOptimizedSteerAngles(
15351535
autoware::common::osqp::calCSCMatrixTrapezoidal(H);
15361536
const autoware::common::osqp::CSC_Matrix A_csc = autoware::common::osqp::calCSCMatrix(A);
15371537
if (
1538-
prev_solution_status_ == 1 &&
1539-
mpt_param_.enable_warm_start && prev_mat_n_ == H.rows() &&
1540-
prev_mat_m_ == A.rows()
1541-
) {
1538+
prev_solution_status_ == 1 && mpt_param_.enable_warm_start && prev_mat_n_ == H.rows() &&
1539+
prev_mat_m_ == A.rows()) {
15421540
RCLCPP_INFO_EXPRESSION(logger_, enable_debug_info_, "warm start");
15431541
osqp_solver_ptr_->updateCscP(P_csc);
15441542
osqp_solver_ptr_->updateQ(f);
@@ -1563,24 +1561,23 @@ std::optional<Eigen::VectorXd> MPTOptimizer::calcOptimizedSteerAngles(
15631561
const int solution_status = osqp_result.solution_status;
15641562
prev_solution_status_ = solution_status;
15651563
if (solution_status != 1) {
1566-
15671564
const std::vector<double> lagrange_multiplier = osqp_result.lagrange_multipliers;
15681565
const int status_polish = osqp_result.polish_status;
15691566
const int exit_flag = osqp_result.exit_flag;
1570-
1567+
15711568
RCLCPP_INFO(logger_, "optimization failed: result contains NaN values");
15721569
RCLCPP_INFO(logger_, "Problem details:");
15731570
RCLCPP_INFO_STREAM(logger_, "P_csc: " << P_csc);
15741571
RCLCPP_INFO_STREAM(logger_, "f: " << vectorToString(f));
15751572
RCLCPP_INFO_STREAM(logger_, "A_csc: " << A_csc);
1576-
RCLCPP_INFO_STREAM(logger_, "lower_bound: " << vectorToString(lower_bound));
1573+
RCLCPP_INFO_STREAM(logger_, "lower_bound: " << vectorToString(lower_bound));
15771574
RCLCPP_INFO_STREAM(logger_, "upper_bound: " << vectorToString(upper_bound));
15781575
RCLCPP_INFO(logger_, "Solver details:");
15791576
RCLCPP_INFO_STREAM(logger_, "lagrange_multiplier: " << vectorToString(lagrange_multiplier));
15801577
RCLCPP_INFO_STREAM(logger_, "status_polish: " << status_polish);
15811578
RCLCPP_INFO_STREAM(logger_, "solution_status: " << solution_status);
15821579
RCLCPP_INFO_STREAM(logger_, "exit_flag: " << exit_flag);
1583-
1580+
15841581
osqp_solver_ptr_->logUnsolvedStatus("[MPT]");
15851582
return std::nullopt;
15861583
}
@@ -1595,20 +1592,19 @@ std::optional<Eigen::VectorXd> MPTOptimizer::calcOptimizedSteerAngles(
15951592

15961593
const auto has_nan = std::any_of(
15971594
optimization_result.begin(), optimization_result.end(),
1598-
[](const auto v) { return std::isnan(v); }
1599-
);
1595+
[](const auto v) { return std::isnan(v); });
16001596

16011597
if (has_nan) {
16021598
const std::vector<double> lagrange_multiplier = osqp_result.lagrange_multipliers;
16031599
const int status_polish = osqp_result.polish_status;
16041600
const int exit_flag = osqp_result.exit_flag;
1605-
1601+
16061602
RCLCPP_INFO(logger_, "optimization failed: result contains NaN values");
16071603
RCLCPP_INFO(logger_, "Problem details:");
16081604
RCLCPP_INFO_STREAM(logger_, "P_csc: " << P_csc);
16091605
RCLCPP_INFO_STREAM(logger_, "f: " << vectorToString(f));
16101606
RCLCPP_INFO_STREAM(logger_, "A_csc: " << A_csc);
1611-
RCLCPP_INFO_STREAM(logger_, "lower_bound: " << vectorToString(lower_bound));
1607+
RCLCPP_INFO_STREAM(logger_, "lower_bound: " << vectorToString(lower_bound));
16121608
RCLCPP_INFO_STREAM(logger_, "upper_bound: " << vectorToString(upper_bound));
16131609
RCLCPP_INFO(logger_, "Solver details:");
16141610
RCLCPP_INFO_STREAM(logger_, "optimization_result: " << vectorToString(optimization_result));

0 commit comments

Comments
 (0)