Skip to content

Commit 901525e

Browse files
committed
coverage: improve coverage
1 parent 4f3c487 commit 901525e

File tree

7 files changed

+774
-168
lines changed

7 files changed

+774
-168
lines changed

core/test/core_test.cc

Lines changed: 40 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -223,40 +223,6 @@ TEST_F(C3CartpoleTest, UpdateCostMatrix) {
223223
}
224224
}
225225

226-
// Test if user can update the LCS for the C3 problem
227-
TEST_F(C3CartpoleTest, UpdateLCSTest) {
228-
std::vector<drake::solvers::LinearEqualityConstraint*>
229-
pre_dynamic_constraints = pOpt->GetDynamicConstraints();
230-
vector<MatrixXd> pre_Al(N);
231-
for (int i = 0; i < N; ++i) {
232-
pre_Al[i] = pre_dynamic_constraints[i]->GetDenseA();
233-
}
234-
235-
// Dynamics
236-
vector<MatrixXd> An(N, MatrixXd::Identity(n, n));
237-
vector<MatrixXd> Bn(N, MatrixXd::Identity(n, k));
238-
vector<MatrixXd> Dn(N, MatrixXd::Identity(n, m));
239-
vector<VectorXd> dn(N, VectorXd::Ones(n));
240-
241-
// Complimentary constraints
242-
vector<MatrixXd> En(N, MatrixXd::Identity(m, n));
243-
vector<MatrixXd> Fn(N, MatrixXd::Identity(m, m));
244-
vector<VectorXd> cn(N, VectorXd::Ones(m));
245-
vector<MatrixXd> Hn(N, MatrixXd::Identity(m, k));
246-
247-
LCS TestSystem(An, Bn, Dn, dn, En, Fn, Hn, cn, dt);
248-
249-
pOpt->UpdateLCS(TestSystem);
250-
251-
std::vector<drake::solvers::LinearEqualityConstraint*>
252-
pst_dynamic_constraints = pOpt->GetDynamicConstraints();
253-
for (int i = 0; i < N; ++i) {
254-
// Linear Equality A matrix should be updated
255-
MatrixXd pst_Al = pst_dynamic_constraints[i]->GetDenseA();
256-
EXPECT_EQ(pre_Al[i].isApprox(pst_Al), false);
257-
}
258-
}
259-
260226
class C3CartpoleTestParameterizedScalingLCSTest
261227
: public C3CartpoleTest,
262228
public ::testing::WithParamInterface<std::tuple<bool, bool>> {};
@@ -368,6 +334,46 @@ class C3CartpoleTypedTest : public testing::Test, public C3CartpoleProblem {
368334
using projection_types = ::testing::Types<C3QP, C3MIQP, C3Plus>;
369335
TYPED_TEST_SUITE(C3CartpoleTypedTest, projection_types);
370336

337+
// Test if user can update the LCS for the C3 problem
338+
TYPED_TEST(C3CartpoleTypedTest, UpdateLCSTest) {
339+
c3::C3* pOpt = this->pOpt.get();
340+
auto dt = this->dt;
341+
std::vector<drake::solvers::LinearEqualityConstraint*>
342+
pre_dynamic_constraints = pOpt->GetDynamicConstraints();
343+
auto& N = this->N;
344+
auto n = this->n;
345+
auto k = this->k;
346+
auto m = this->m;
347+
vector<MatrixXd> pre_Al(N);
348+
for (int i = 0; i < N; ++i) {
349+
pre_Al[i] = pre_dynamic_constraints[i]->GetDenseA();
350+
}
351+
352+
// Dynamics
353+
vector<MatrixXd> An(N, MatrixXd::Identity(n, n));
354+
vector<MatrixXd> Bn(N, MatrixXd::Identity(n, k));
355+
vector<MatrixXd> Dn(N, MatrixXd::Identity(n, m));
356+
vector<VectorXd> dn(N, VectorXd::Ones(n));
357+
358+
// Complimentary constraints
359+
vector<MatrixXd> En(N, MatrixXd::Identity(m, n));
360+
vector<MatrixXd> Fn(N, MatrixXd::Identity(m, m));
361+
vector<VectorXd> cn(N, VectorXd::Ones(m));
362+
vector<MatrixXd> Hn(N, MatrixXd::Identity(m, k));
363+
364+
LCS TestSystem(An, Bn, Dn, dn, En, Fn, Hn, cn, dt);
365+
366+
pOpt->UpdateLCS(TestSystem);
367+
368+
std::vector<drake::solvers::LinearEqualityConstraint*>
369+
pst_dynamic_constraints = pOpt->GetDynamicConstraints();
370+
for (int i = 0; i < N; ++i) {
371+
// Linear Equality A matrix should be updated
372+
MatrixXd pst_Al = pst_dynamic_constraints[i]->GetDenseA();
373+
EXPECT_EQ(pre_Al[i].isApprox(pst_Al), false);
374+
}
375+
}
376+
371377
// Test the cartpole example
372378
// This test will take some time to complete ~30s
373379
TYPED_TEST(C3CartpoleTypedTest, End2EndCartpoleTest) {
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
projection_type: "MIQP"
2+
3+
solve_time_filter_alpha: 0.0
4+
#set to 0 to publish as fast as possible
5+
publish_frequency: 100
6+
state_prediction_joints: []
7+
# - name : "CartSlider"
8+
# max_acceleration : 10
9+
10+
lcs_factory_options:
11+
#options are 'stewart_and_trinkle' or 'anitescu'
12+
# contact_model : 'stewart_and_trinkle'
13+
contact_model: "frictionless_spring"
14+
num_friction_directions: 0
15+
num_contacts: 2
16+
spring_stiffness: 100
17+
mu: [0, 0]
18+
N: 5
19+
dt: 0.01
20+
21+
c3_options:
22+
warm_start: false
23+
end_on_qp_step: true
24+
scale_lcs: false
25+
26+
num_threads: 5
27+
delta_option: 0
28+
29+
M: 1000
30+
admm_iter: 10
31+
32+
gamma: 1.0
33+
rho_scale: 2 #matrix scaling
34+
w_Q: 1
35+
w_R: 1 #Penalty on all decision variables, assuming scalar
36+
w_G: 1 #Penalty on all decision variables, assuming scalar
37+
w_U: 1 #State Tracking Error, assuming diagonal
38+
q_vector: [10, 2, 1, 1] #Penalty on efforts, assuming diagonal
39+
r_vector: [1] #Penalty on matching projected variables
40+
g_x: [0, 0, 0, 0]
41+
g_gamma: [1, 1]
42+
g_lambda_n: []
43+
g_lambda_t: []
44+
g_lambda: [1, 1]
45+
g_u: [0] #Penalty on matching the QP variables
46+
u_x: [0, 0, 0, 0]
47+
u_gamma: [10000, 10000]
48+
u_lambda_n: []
49+
u_lambda_t: []
50+
u_lambda: [1, 1]
51+
u_u: [0]

0 commit comments

Comments
 (0)