Skip to content

Commit 0ff39d9

Browse files
committed
fix: load default solver options
1 parent f0d319f commit 0ff39d9

File tree

5 files changed

+37
-15
lines changed

5 files changed

+37
-15
lines changed

core/BUILD.bazel

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,13 @@ cc_library(
2222
],
2323
)
2424

25+
filegroup(
26+
name = "default_solver_options",
27+
srcs = [
28+
"configs/solver_options_default.yaml",
29+
],
30+
)
31+
2532
cc_library(
2633
name = "c3",
2734
srcs = [
@@ -39,7 +46,9 @@ cc_library(
3946
"c3.h",
4047
"c3_miqp.h",
4148
"c3_qp.h",
42-
"configs/solve_options_default.hpp"
49+
],
50+
data = [
51+
":default_solver_options",
4352
],
4453
copts = ["-fopenmp"],
4554
linkopts = ["-fopenmp"],

core/c3.cc

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
#include <iostream>
55

66
#include <Eigen/Core>
7+
#include <drake/common/find_runfiles.h>
78
#include <omp.h>
89

910
#include "lcs.h"
1011
#include "solver_options_io.h"
11-
#include "configs/solve_options_default.hpp"
1212

1313
#include "drake/common/text_logging.h"
1414
#include "drake/solvers/mathematical_program.h"
@@ -154,8 +154,24 @@ C3::C3(const LCS& lcs, const CostMatrices& costs,
154154
}
155155

156156
// Set default solver options
157+
SetDefaultSolverOptions();
158+
}
159+
160+
void C3::SetDefaultSolverOptions() {
161+
// Set default solver options
162+
auto main_runfile =
163+
drake::FindRunfile("_main/core/configs/solver_options_default.yaml");
164+
auto external_runfile =
165+
drake::FindRunfile("c3/core/configs/solver_options_default.yaml");
166+
if (main_runfile.abspath.empty() && external_runfile.abspath.empty()) {
167+
throw std::runtime_error(fmt::format(
168+
"Could not find the default solver options YAML file. {}, {}",
169+
main_runfile.error, external_runfile.error));
170+
}
157171
drake::solvers::SolverOptions solver_options =
158-
drake::yaml::LoadYamlString<c3::SolverOptionsFromYaml>(default_solver_options)
172+
drake::yaml::LoadYamlFile<c3::SolverOptionsFromYaml>(
173+
main_runfile.abspath.empty() ? external_runfile.abspath
174+
: main_runfile.abspath)
159175
.GetAsSolverOptions(drake::solvers::OsqpSolver::id());
160176
SetSolverOptions(solver_options);
161177
}

core/c3.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,8 @@ class C3 {
164164
* @param options The C3Options object containing configuration values.
165165
* @return CostMatrices The initialized cost matrices.
166166
*/
167-
static CostMatrices CreateCostMatricesFromC3Options(const C3Options& options, int N);
167+
static CostMatrices CreateCostMatricesFromC3Options(const C3Options& options,
168+
int N);
168169

169170
/**
170171
* @brief Get a vector of user defined linear constraints.
@@ -228,6 +229,12 @@ class C3 {
228229
*/
229230
void ScaleLCS();
230231

232+
/*!
233+
* Set the default solver options for the MathematicalProgram
234+
* This is called in the constructor, and can be overridden by the user
235+
*/
236+
void SetDefaultSolverOptions();
237+
231238
/*!
232239
* Solve the projection problem for all time-steps
233240
* @param U Similarity cost weights for the projection optimization

core/configs/solve_options_default.hpp

Lines changed: 0 additions & 11 deletions
This file was deleted.

systems/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ cc_library(
88
visibility = ["//visibility:public"],
99
deps = [
1010
":framework",
11+
":options",
1112
":c3_controller",
1213
":lcs_simulator",
1314
":lcs_factory_system",

0 commit comments

Comments
 (0)