Skip to content

Commit 7de89d4

Browse files
committed
fix: use modified lcs regularized solve
1 parent f7edc74 commit 7de89d4

File tree

2 files changed

+21
-14
lines changed

2 files changed

+21
-14
lines changed

MODULE.bazel

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -90,14 +90,10 @@ archive_override(
9090
)
9191

9292
bazel_dep(name = "c3")
93-
# git_override(
94-
# module_name = "c3",
95-
# remote = "https://github.com/DAIRLab/c3.git",
96-
# commit = "2bd13495c3306cf7d53992e2495774d1ad454cca"
97-
# )
98-
local_path_override(
93+
git_override(
9994
module_name = "c3",
100-
path = "/home/stephen/Workspace/DAIR/c3"
95+
remote = "https://github.com/DAIRLab/c3.git",
96+
commit = "2a68a2fbfbf3dc6b8d5b2b6e3cd09a61e3c0ec1f"
10197
)
10298

10399
INEKF_COMMIT = "297c308e50fa599af92ce3bd5f11d71e2bf8af69"

systems/controllers/sampling_based_c3_controller.cc

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
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

Comments
 (0)