77#include < drake/common/find_runfiles.h>
88#include < omp.h>
99
10+ #include " common/logging_utils.hpp"
1011#include " lcs.h"
1112#include " solver_options_io.h"
1213
@@ -90,7 +91,6 @@ C3::C3(const LCS& lcs, const CostMatrices& costs,
9091 w_sol_ = std::make_unique<std::vector<VectorXd>>();
9192 delta_sol_ = std::make_unique<std::vector<VectorXd>>();
9293 for (int i = 0 ; i < N_; ++i) {
93- z_sol_->push_back (Eigen::VectorXd::Zero (n_z_));
9494 x_sol_->push_back (Eigen::VectorXd::Zero (n_x_));
9595 lambda_sol_->push_back (Eigen::VectorXd::Zero (n_lambda_));
9696 u_sol_->push_back (Eigen::VectorXd::Zero (n_u_));
@@ -269,6 +269,7 @@ const std::vector<drake::solvers::QuadraticCost*>& C3::GetTargetCost() {
269269}
270270
271271void C3::Solve (const VectorXd& x0) {
272+ drake::log ()->debug (" C3::Solve called" );
272273 auto start = std::chrono::high_resolution_clock::now ();
273274 // Set the initial state constraint
274275 if (initial_state_constraint_) {
@@ -319,6 +320,8 @@ void C3::Solve(const VectorXd& x0) {
319320 std::vector<VectorXd> w (N_, VectorXd::Zero (n_z_));
320321 vector<MatrixXd> G = cost_matrices_.G ;
321322
323+ drake::log ()->debug (" C3::Solve starting ADMM iterations." );
324+
322325 for (int iter = 0 ; iter < options_.admm_iter ; iter++) {
323326 ADMMStep (x0, &delta, &w, &G, iter);
324327 }
@@ -328,12 +331,14 @@ void C3::Solve(const VectorXd& x0) {
328331 WD.at (i) = delta.at (i) - w.at (i);
329332 }
330333
334+ drake::log ()->debug (" C3::Solve final SolveQP step." );
331335 *z_fin_ = SolveQP (x0, G, WD, options_.admm_iter , true );
332336
333337 *w_sol_ = w;
334338 *delta_sol_ = delta;
335339
336340 if (!options_.end_on_qp_step ) {
341+ drake::log ()->debug (" C3::Solve compute a half step." );
337342 *z_sol_ = delta;
338343 z_sol_->at (0 ).segment (0 , n_x_) = x0;
339344 x_sol_->at (0 ) = x0;
@@ -357,6 +362,7 @@ void C3::Solve(const VectorXd& x0) {
357362 solve_time_ =
358363 std::chrono::duration_cast<std::chrono::microseconds>(elapsed).count () /
359364 1e6 ;
365+ drake::log ()->debug (" C3::Solve completed in {} seconds." , solve_time_);
360366}
361367
362368void C3::ADMMStep (const VectorXd& x0, vector<VectorXd>* delta,
@@ -368,13 +374,15 @@ void C3::ADMMStep(const VectorXd& x0, vector<VectorXd>* delta,
368374 WD.at (i) = delta->at (i) - w->at (i);
369375 }
370376
377+ drake::log ()->debug (" C3::ADMMStep SolveQP step." );
371378 vector<VectorXd> z = SolveQP (x0, *G, WD, admm_iteration, false );
372379
373380 vector<VectorXd> ZW (N_, VectorXd::Zero (n_z_));
374381 for (int i = 0 ; i < N_; ++i) {
375382 ZW[i] = w->at (i) + z[i];
376383 }
377384
385+ drake::log ()->debug (" C3::ADMMStep SolveProjection step." );
378386 if (cost_matrices_.U [0 ].isZero (0 )) {
379387 *delta = SolveProjection (*G, ZW, admm_iteration);
380388 } else {
@@ -419,10 +427,17 @@ void C3::StoreQPResults(const MathematicalProgramResult& result,
419427 z_sol_->at (i).segment (0 , n_x_) = result.GetSolution (x_[i]);
420428 z_sol_->at (i).segment (n_x_, n_lambda_) = result.GetSolution (lambda_[i]);
421429 z_sol_->at (i).segment (n_x_ + n_lambda_, n_u_) = result.GetSolution (u_[i]);
430+
431+ drake::log ()->trace (
432+ " C3::StoreQPResults storing solution for time step {}: "
433+ " lambda = {}" ,
434+ i, EigenToString (lambda_sol_->at (i).transpose ()));
422435 }
423436
424437 if (!warm_start_)
425438 return ; // No warm start, so no need to update warm start parameters
439+
440+ drake::log ()->trace (" C3::StoreQPResults storing warm start values." );
426441 for (int i = 0 ; i < N_ + 1 ; ++i) {
427442 if (i < N_) {
428443 warm_start_x_[admm_iteration][i] = result.GetSolution (x_[i]);
@@ -436,6 +451,7 @@ void C3::StoreQPResults(const MathematicalProgramResult& result,
436451vector<VectorXd> C3::SolveQP (const VectorXd& x0, const vector<MatrixXd>& G,
437452 const vector<VectorXd>& WD, int admm_iteration,
438453 bool is_final_solve) {
454+ drake::log ()->trace (" C3::SolveQP Adding augmented costs(G)." );
439455 // Add or update augmented costs
440456 if (augmented_costs_.size () == 0 ) {
441457 for (int i = 0 ; i < N_; ++i)
@@ -452,16 +468,17 @@ vector<VectorXd> C3::SolveQP(const VectorXd& x0, const vector<MatrixXd>& G,
452468
453469 SetInitialGuessQP (x0, admm_iteration);
454470
471+ drake::log ()->trace (" C3::SolveQP calling solver." );
455472 try {
456473 MathematicalProgramResult result = osqp_.Solve (prog_);
474+ if (!result.is_success ()) {
475+ drake::log ()->warn (" C3::SolveQP failed to solve the QP with status: {}" ,
476+ result.get_solution_result ());
477+ }
478+ StoreQPResults (result, admm_iteration, is_final_solve);
457479 } catch (const std::exception& e) {
458480 drake::log ()->error (" C3::SolveQP failed with exception: {}" , e.what ());
459481 }
460- if (!result.is_success ()) {
461- drake::log ()->warn (" C3::SolveQP failed to solve the QP with status: {}" ,
462- result.get_solution_result ());
463- }
464- StoreQPResults (result, admm_iteration, is_final_solve);
465482
466483 return *z_sol_;
467484}
@@ -477,8 +494,11 @@ vector<VectorXd> C3::SolveProjection(const vector<MatrixXd>& U,
477494 omp_set_schedule (omp_sched_static, 0 );
478495 }
479496
497+ // clang-format off
480498#pragma omp parallel for num_threads( \
481499 options_.num_threads ) if (use_parallelization_in_projection_)
500+ // clang-format on
501+
482502 for (int i = 0 ; i < N_; ++i) {
483503 if (warm_start_) {
484504 if (i == N_ - 1 ) {
0 commit comments