Skip to content

Commit 6f23d49

Browse files
fix
Signed-off-by: Arjun Jagdish Ram <arjun.ram@tier4.jp>
1 parent 8fccb2f commit 6f23d49

File tree

2 files changed

+38
-6
lines changed

2 files changed

+38
-6
lines changed

planning/autoware_path_optimizer/config/path_optimizer.param.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535

3636
# mpt param
3737
mpt:
38-
use_acados: false
38+
use_acados: true
3939
option:
4040
# TODO(murooka) enable the following. Currently enabling the flag makes QP so heavy
4141
steer_limit_constraint: false

planning/autoware_path_optimizer/src/mpt_optimizer.cpp

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -763,8 +763,8 @@ std::array<double, NP> MPTOptimizer::buildParameters(
763763
}
764764
}
765765

766-
double last_k = 0;
767-
for (size_t j = 0; j < n_missing-1; ++j) {
766+
double last_k = 0.0;
767+
for (size_t j = 0; j < n_missing; ++j) {
768768
curvatures.push_back(last_k);
769769
}
770770

@@ -780,7 +780,17 @@ std::array<double, NP> MPTOptimizer::buildParameters(
780780
knots.resize(target_n_knots);
781781
x_coeffs_flat.resize(4 * target_segments);
782782
y_coeffs_flat.resize(4 * target_segments);
783-
curvatures.resize(target_segments);
783+
curvatures.resize(target_n_knots);
784+
}
785+
786+
// Ensure curvatures has same size as knots for cubic spline interpolation
787+
if (curvatures.size() < knots.size()) {
788+
double last_k = 0.0;
789+
while (curvatures.size() < knots.size()) {
790+
curvatures.push_back(last_k);
791+
}
792+
} else if (curvatures.size() > knots.size()) {
793+
curvatures.resize(knots.size());
784794
}
785795

786796
RCLCPP_ERROR(logger_, "sizes: knots=%zu x_coeffs=%zu y_coeffs=%zu curvatures=%zu body_points=%zu",
@@ -838,7 +848,23 @@ std::array<double, NP> MPTOptimizer::buildParameters(
838848
// 7. Compute cubic spline coefficients from curvatures
839849
// Python uses: ClothoidSpline -> CubicSpline(knots, curvatures) -> coeffs (4×(N-1))
840850
// We need to fit a cubic spline to (knots, curvatures) and extract the 4×(N-1) coefficients
851+
852+
// Debug: Check curvature values
853+
std::cerr << "Curvatures size: " << curvatures.size() << ", first 10: ";
854+
for (size_t i = 0; i < std::min(size_t(10), curvatures.size()); ++i) {
855+
std::cerr << curvatures[i] << " ";
856+
}
857+
std::cerr << std::endl;
858+
std::cerr << "Knots size: " << knots.size() << std::endl;
859+
841860
const std::vector<double> clothoid_coeffs_flat = computeCubicSplineCoeffs(knots, curvatures);
861+
std::cerr << "Clothoid coeffs size: " << clothoid_coeffs_flat.size() << std::endl;
862+
std::cerr << "Clothoid coeffs (first 20): ";
863+
for (size_t i = 0; i < std::min(size_t(20), clothoid_coeffs_flat.size()); ++i) {
864+
std::cerr << clothoid_coeffs_flat[i] << " ";
865+
}
866+
std::cerr << std::endl;
867+
842868
for (double v : clothoid_coeffs_flat) {
843869
parameters[idx++] = v;
844870
}
@@ -857,11 +883,17 @@ std::array<double, NP> MPTOptimizer::buildParameters(
857883

858884
// set x0: initial state vector
859885
idx = 0;
860-
x0[idx++] = 0.0; // s_interp
861-
x0[idx++] = 0.0;
886+
x0[idx++] = 0.0; // eY (lateral error)
887+
x0[idx++] = 0.0; // eψ (yaw error)
862888
for (const auto& body_point_curvilinear : body_points_curvilinear) {
863889
x0[idx++] = body_point_curvilinear;
864890
}
891+
892+
std::cerr << "Initial state x0: ";
893+
for (size_t i = 0; i < NX; ++i) {
894+
std::cerr << x0[i] << " ";
895+
}
896+
std::cerr << std::endl;
865897

866898
// store reference path length for per-stage s_interp construction
867899
if (!knots.empty()) sref_ = knots.back();

0 commit comments

Comments
 (0)