1111#include " c3/core/c3_miqp.h"
1212#include " c3/core/c3_plus.h"
1313#include " c3/core/c3_qp.h"
14+ #include " c3/core/lcs.h"
1415#include " c3/multibody/lcs_factory.h"
1516#include " common/quaternion_error_hessian.h"
1617#include " dairlib/lcmt_radio_out.hpp"
@@ -544,12 +545,16 @@ std::pair<double, std::vector<Eigen::VectorXd>> SamplingC3Controller::CalcCost(
544545
545546 const int ee_vel_index = 7 * num_objects + 3 ;
546547
548+ auto simulate_config = c3::LCSSimulateConfig ();
549+ simulate_config.regularized = true ;
550+ simulate_config.min_exp = -8 ;
551+
547552 // Simulate the dynamics from the planned inputs.
548553 if (cost_type == C3CostComputationType::kSimLCS ) {
549554 XX[0 ] = z_fin[0 ].segment (0 , n_x_);
550555 for (int i = 0 ; i < N_ * resolution; i++) {
551556 UU[i] = z_fin[i / resolution].segment (n_x_ + n_lambda_, n_u_);
552- XX[i + 1 ] = lcs_for_cost.Simulate (XX[i], UU[i]);
557+ XX[i + 1 ] = lcs_for_cost.Simulate (XX[i], UU[i], simulate_config );
553558 }
554559 }
555560
@@ -559,7 +564,7 @@ std::pair<double, std::vector<Eigen::VectorXd>> SamplingC3Controller::CalcCost(
559564 UU[i] = z_fin[i / resolution].segment (n_x_ + n_lambda_, n_u_);
560565 XX[i] = z_fin[i / resolution].segment (0 , n_x_);
561566 if (i == N_ - 1 ) {
562- XX[i + 1 ] = lcs_for_cost.Simulate (XX[i], UU[i]);
567+ XX[i + 1 ] = lcs_for_cost.Simulate (XX[i], UU[i], simulate_config );
563568 }
564569 }
565570 }
@@ -571,14 +576,14 @@ std::pair<double, std::vector<Eigen::VectorXd>> SamplingC3Controller::CalcCost(
571576 XX[0 ] = z_fin[0 ].segment (0 , n_x_);
572577 for (int i = 0 ; i < N_ * resolution; i++) {
573578 UU[i] = z_fin[i / resolution].segment (n_x_ + n_lambda_, n_u_);
574- XX[i + 1 ] = lcs_for_cost.Simulate (XX[i], UU[i]);
579+ XX[i + 1 ] = lcs_for_cost.Simulate (XX[i], UU[i], simulate_config );
575580 }
576581 // Replace ee traj with those from z_fin.
577582 for (int i = 0 ; i < N_; i++) {
578583 XX[i].segment (0 , 3 ) = z_fin[i / resolution].segment (0 , 3 );
579584 if (i == N_ - 1 ) {
580585 XX[i + 1 ].segment (0 , 3 ) =
581- lcs_for_cost.Simulate (XX[i], UU[i]).segment (0 , 3 );
586+ lcs_for_cost.Simulate (XX[i], UU[i], simulate_config ).segment (0 , 3 );
582587 }
583588 }
584589 }
@@ -913,14 +918,18 @@ SamplingC3Controller::SimulatePDControl(
913918 const int ee_vel_index = 7 * num_objects + 3 ;
914919 int resolution = sampling_c3_options_.lcs_dt_resolution ;
915920
921+ auto simulate_config = c3::LCSSimulateConfig ();
922+ simulate_config.regularized = true ;
923+ simulate_config.min_exp = -8 ;
924+
916925 // Obtain the solutions from C3.
917926 vector<VectorXd> UU (N_ * resolution, VectorXd::Zero (n_u_));
918927 std::vector<Eigen::VectorXd> XX (N_ * resolution + 1 , VectorXd::Zero (n_x_));
919928 for (int i = 0 ; i < N_ * resolution; i++) {
920929 UU[i] = z_fin[i / resolution].segment (n_x_ + n_lambda_, n_u_);
921930 XX[i] = z_fin[i / resolution].segment (0 , n_x_);
922931 if (i == N_ * resolution - 1 ) {
923- XX[i + 1 ] = lcs_for_cost.Simulate (XX[i], UU[i]);
932+ XX[i + 1 ] = lcs_for_cost.Simulate (XX[i], UU[i], simulate_config );
924933 }
925934 }
926935
@@ -937,7 +946,8 @@ SamplingC3Controller::SimulatePDControl(
937946
938947 // Obtain modified solutions for the PD controller.
939948 std::vector<Eigen::VectorXd> UU_new (N_ * resolution, VectorXd::Zero (n_u_));
940- std::vector<Eigen::VectorXd> XX_new (N_ * resolution + 1 , VectorXd::Zero (n_x_));
949+ std::vector<Eigen::VectorXd> XX_new (N_ * resolution + 1 ,
950+ VectorXd::Zero (n_x_));
941951
942952 XX_new[0 ] = z_fin[0 ].segment (0 , n_x_);
943953 // This will just be the original u from z_fin[0] for the first time step.
@@ -956,7 +966,8 @@ SamplingC3Controller::SimulatePDControl(
956966 if (verbose) {
957967 std::cout << " simulated step " << i + 1 << std::endl;
958968 }
959- XX_new[i + 1 ] = lcs_for_cost.Simulate (XX_new[i], UU_new[i]);
969+ XX_new[i + 1 ] =
970+ lcs_for_cost.Simulate (XX_new[i], UU_new[i], simulate_config);
960971 }
961972 return {XX_new, UU_new};
962973}
0 commit comments