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
@@ -89,7 +90,6 @@ C3::C3(const LCS& lcs, const CostMatrices& costs,
8990 w_sol_ = std::make_unique<std::vector<VectorXd>>();
9091 delta_sol_ = std::make_unique<std::vector<VectorXd>>();
9192 for (int i = 0 ; i < N_; ++i) {
92- z_sol_->push_back (Eigen::VectorXd::Zero (n_z_));
9393 x_sol_->push_back (Eigen::VectorXd::Zero (n_x_));
9494 lambda_sol_->push_back (Eigen::VectorXd::Zero (n_lambda_));
9595 u_sol_->push_back (Eigen::VectorXd::Zero (n_u_));
@@ -267,6 +267,7 @@ const std::vector<drake::solvers::QuadraticCost*>& C3::GetTargetCost() {
267267}
268268
269269void C3::Solve (const VectorXd& x0) {
270+ drake::log ()->debug (" C3::Solve called" );
270271 auto start = std::chrono::high_resolution_clock::now ();
271272 // Set the initial state constraint
272273 if (initial_state_constraint_) {
@@ -317,6 +318,8 @@ void C3::Solve(const VectorXd& x0) {
317318 std::vector<VectorXd> w (N_, VectorXd::Zero (n_z_));
318319 vector<MatrixXd> G = cost_matrices_.G ;
319320
321+ drake::log ()->debug (" C3::Solve starting ADMM iterations." );
322+
320323 for (int iter = 0 ; iter < options_.admm_iter ; iter++) {
321324 ADMMStep (x0, &delta, &w, &G, iter);
322325 }
@@ -332,6 +335,7 @@ void C3::Solve(const VectorXd& x0) {
332335 *delta_sol_ = delta;
333336
334337 if (!options_.end_on_qp_step ) {
338+ drake::log ()->debug (" C3::Solve compute a half step." );
335339 *z_sol_ = delta;
336340 z_sol_->at (0 ).segment (0 , n_x_) = x0;
337341 x_sol_->at (0 ) = x0;
@@ -355,6 +359,7 @@ void C3::Solve(const VectorXd& x0) {
355359 solve_time_ =
356360 std::chrono::duration_cast<std::chrono::microseconds>(elapsed).count () /
357361 1e6 ;
362+ drake::log ()->debug (" C3::Solve completed in {} seconds." , solve_time_);
358363}
359364
360365void C3::ADMMStep (const VectorXd& x0, vector<VectorXd>* delta,
@@ -373,6 +378,7 @@ void C3::ADMMStep(const VectorXd& x0, vector<VectorXd>* delta,
373378 ZW[i] = w->at (i) + z[i];
374379 }
375380
381+ drake::log ()->debug (" C3::ADMMStep SolveProjection step." );
376382 if (cost_matrices_.U [0 ].isZero (0 )) {
377383 *delta = SolveProjection (*G, ZW, admm_iteration);
378384 } else {
@@ -417,10 +423,17 @@ void C3::StoreQPResults(const MathematicalProgramResult& result,
417423 z_sol_->at (i).segment (0 , n_x_) = result.GetSolution (x_[i]);
418424 z_sol_->at (i).segment (n_x_, n_lambda_) = result.GetSolution (lambda_[i]);
419425 z_sol_->at (i).segment (n_x_ + n_lambda_, n_u_) = result.GetSolution (u_[i]);
426+
427+ drake::log ()->trace (
428+ " C3::StoreQPResults storing solution for time step {}: "
429+ " lambda = {}" ,
430+ i, EigenToString (lambda_sol_->at (i).transpose ()));
420431 }
421432
422433 if (!warm_start_)
423434 return ; // No warm start, so no need to update warm start parameters
435+
436+ drake::log ()->trace (" C3::StoreQPResults storing warm start values." );
424437 for (int i = 0 ; i < N_ + 1 ; ++i) {
425438 if (i < N_) {
426439 warm_start_x_[admm_iteration][i] = result.GetSolution (x_[i]);
@@ -438,16 +451,17 @@ vector<VectorXd> C3::SolveQP(const VectorXd& x0, const vector<MatrixXd>& G,
438451 AddAugmentedCost (G, WD, delta, is_final_solve);
439452 SetInitialGuessQP (x0, admm_iteration);
440453
454+ drake::log ()->trace (" C3::SolveQP calling solver." );
441455 try {
442456 MathematicalProgramResult result = osqp_.Solve (prog_);
457+ if (!result.is_success ()) {
458+ drake::log ()->warn (" C3::SolveQP failed to solve the QP with status: {}" ,
459+ result.get_solution_result ());
460+ }
461+ StoreQPResults (result, admm_iteration, is_final_solve);
443462 } catch (const std::exception& e) {
444463 drake::log ()->error (" C3::SolveQP failed with exception: {}" , e.what ());
445464 }
446- if (!result.is_success ()) {
447- drake::log ()->warn (" C3::SolveQP failed to solve the QP with status: {}" ,
448- result.get_solution_result ());
449- }
450- StoreQPResults (result, admm_iteration, is_final_solve);
451465
452466 return *z_sol_;
453467}
0 commit comments