Skip to content

Commit 72d1d66

Browse files
committed
test: add unit tests for lcmt generators
1 parent edbeaf8 commit 72d1d66

File tree

8 files changed

+408
-9
lines changed

8 files changed

+408
-9
lines changed

.bazelrc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,6 @@ build --action_env=LD_LIBRARY_PATH=
5151
# use python3 by default
5252
build --python_path=python3
5353

54-
build --define=WITH_GUROBI=ON
54+
build --define=WITH_GUROBI=ON
55+
56+
build --local_resources=cpu=8

bindings/pyc3/c3_systems_py.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,9 +248,9 @@ PYBIND11_MODULE(systems, m) {
248248
.def("get_input_port_c3_solution",
249249
&lcmt_generators::ContactForceGenerator::get_input_port_c3_solution,
250250
py::return_value_policy::reference)
251-
.def("get_input_port_lcs_contact_info",
251+
.def("get_input_port_lcs_contact_descriptions",
252252
&lcmt_generators::ContactForceGenerator::
253-
get_input_port_lcs_contact_info,
253+
get_input_port_lcs_contact_descriptions,
254254
py::return_value_policy::reference)
255255
.def("get_output_port_contact_force",
256256
&lcmt_generators::ContactForceGenerator::

core/BUILD.bazel

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ cc_library(
8282
hdrs = [
8383
"test/c3_cartpole_problem.hpp",
8484
],
85+
deps = [
86+
":core",
87+
],
8588
data = [
8689
":test_data",
8790
]

core/test/core_test.cc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ using namespace c3;
4040
* | Solve | - |
4141
* | SetOsqpSolverOptions | - |
4242
* | CreatePlaceholderLCS | DONE |
43+
* | WarmStartSmokeTest | DONE |
4344
* | # of regression tests | 2 |
4445
*
4546
* It also has an E2E test for ensuring the "Solve()" function and other
@@ -342,6 +343,16 @@ TEST_F(C3CartpoleTest, CreatePlaceholder) {
342343
ASSERT_TRUE(placeholder.HasSameDimensionsAs(*pSystem));
343344
}
344345

346+
// Test if the solver works with warm start enabled (smoke test)
347+
TEST_F(C3CartpoleTest, WarmStartSmokeTest) {
348+
// Enable warm start option
349+
options.warm_start = true;
350+
C3MIQP optimizer(*pSystem, cost, xdesired, options);
351+
352+
// Solver should not throw when called with warm start
353+
ASSERT_NO_THROW(optimizer.Solve(x0));
354+
}
355+
345356
template <typename T>
346357
class C3CartpoleTypedTest : public testing::Test, public C3CartpoleProblem {
347358
protected:

systems/BUILD.bazel

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,18 @@ cc_test(
153153
],
154154
)
155155

156+
cc_test(
157+
name = "generators_test",
158+
srcs = [
159+
"test/generators_test.cc"
160+
],
161+
deps = [
162+
":lcmt_generators",
163+
"//core:c3_cartpole_problem",
164+
"@gtest//:main",
165+
],
166+
)
167+
156168
filegroup(
157169
name = "headers",
158170
srcs = glob([

systems/lcmt_generators/contact_force_generator.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,15 +87,15 @@ void ContactForceGenerator::DoCalc(const Context<double>& context,
8787
LcmPublisherSystem* ContactForceGenerator::AddLcmPublisherToBuilder(
8888
DiagramBuilder<double>& builder,
8989
const drake::systems::OutputPort<double>& solution_port,
90-
const drake::systems::OutputPort<double>& lcs_contact_info_port,
90+
const drake::systems::OutputPort<double>& lcs_contact_descriptions_port,
9191
const std::string& channel, drake::lcm::DrakeLcmInterface* lcm,
9292
const drake::systems::TriggerTypeSet& publish_triggers,
9393
double publish_period, double publish_offset) {
9494
// Add and connect the ContactForceGenerator system.
9595
auto force_publisher = builder.AddSystem<ContactForceGenerator>();
9696
builder.Connect(solution_port, force_publisher->get_input_port_c3_solution());
97-
builder.Connect(lcs_contact_info_port,
98-
force_publisher->get_input_port_lcs_contact_info());
97+
builder.Connect(lcs_contact_descriptions_port,
98+
force_publisher->get_input_port_lcs_contact_descriptions());
9999

100100
// Add and connect the LCM publisher system.
101101
auto lcm_force_publisher =

systems/lcmt_generators/contact_force_generator.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ class ContactForceGenerator : public drake::systems::LeafSystem<double> {
4848
* @brief Returns the input port for the LCS contact information.
4949
* @return Reference to the input port for LCS contact info.
5050
*/
51-
const drake::systems::InputPort<double>& get_input_port_lcs_contact_info()
52-
const {
51+
const drake::systems::InputPort<double>&
52+
get_input_port_lcs_contact_descriptions() const {
5353
return this->get_input_port(lcs_contact_info_port_);
5454
}
5555

@@ -82,7 +82,7 @@ class ContactForceGenerator : public drake::systems::LeafSystem<double> {
8282
static drake::systems::lcm::LcmPublisherSystem* AddLcmPublisherToBuilder(
8383
drake::systems::DiagramBuilder<double>& builder,
8484
const drake::systems::OutputPort<double>& solution_port,
85-
const drake::systems::OutputPort<double>& lcs_contact_info_port,
85+
const drake::systems::OutputPort<double>& lcs_contact_descriptions_port,
8686
const std::string& channel, drake::lcm::DrakeLcmInterface* lcm,
8787
const drake::systems::TriggerTypeSet& publish_triggers,
8888
double publish_period = 0.0, double publish_offset = 0.0);

0 commit comments

Comments
 (0)