Skip to content

Commit 179bf1d

Browse files
committed
feat: add clang formatting check
1 parent 9e9d7e5 commit 179bf1d

File tree

16 files changed

+57
-45
lines changed

16 files changed

+57
-45
lines changed

.cirrus.yml

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,24 @@ jammy_task:
2222
--local_resources=cpu=8
2323
--remote_cache=http://$CIRRUS_HTTP_CACHE_HOST
2424
//...
25-
- genhtml --branch-coverage
26-
--output genhtml
27-
"$(bazel info output_path)/_coverage/_coverage_report.dat"
25+
# - genhtml --branch-coverage
26+
# --output genhtml
27+
# "$(bazel info output_path)/_coverage/_coverage_report.dat"
28+
format_script:
29+
- find .
30+
-name "*.cpp" -o -name "*.hpp" -o -name "*.cxx" -o -name "*.hxx" |
31+
xargs clang-format-15 --dry-run --Werror
32+
--output-replacements-xml > replacements.xml 2>&1
2833
always:
2934
jammy_test_artifacts:
3035
path: "bazel-testlogs/**/test.xml"
3136
format: junit
3237
jammy_coverage_artifacts:
3338
path: "genhtml/index.html"
3439
type: text/html
40+
jammy_format_artifacts:
41+
path: "genhtml/index.html"
42+
type: replacements.xml
3543

3644
noble_task:
3745
timeout_in: 120m
@@ -56,14 +64,21 @@ noble_task:
5664
--local_resources=cpu=8
5765
--remote_cache=http://$CIRRUS_HTTP_CACHE_HOST
5866
//...
59-
- ls -aux
60-
- genhtml --branch-coverage
61-
--output genhtml
62-
"bazel-out/_coverage/_coverage_report.dat"
67+
# - genhtml --branch-coverage
68+
# --output genhtml
69+
# "bazel-out/_coverage/_coverage_report.dat"
70+
format_script:
71+
- find .
72+
-name "*.cpp" -o -name "*.hpp" -o -name "*.cxx" -o -name "*.hxx" |
73+
xargs clang-format-15 --dry-run --Werror
74+
--output-replacements-xml > replacements.xml 2>&1
6375
always:
6476
noble_test_artifacts:
6577
path: "bazel-testlogs/**/test.xml"
6678
format: junit
6779
noble_coverage_artifacts:
6880
path: "genhtml/index.html"
6981
type: text/html
82+
noble_format_artifacts:
83+
path: "genhtml/index.html"
84+
type: replacements.xml

bindings/pyc3/c3_multibody_py.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
#include <pybind11/pybind11.h>
33

44
#include "core/lcs.h"
5-
#include "multibody/lcs_factory_options.h"
65
#include "multibody/geom_geom_collider.h"
76
#include "multibody/lcs_factory.h"
7+
#include "multibody/lcs_factory_options.h"
88
#include "multibody/multibody_utils.h"
99

1010
#include "drake/bindings/pydrake/common/sorted_pair_pybind.h"

bindings/pyc3/c3_systems_py.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ PYBIND11_MODULE(systems, m) {
157157
drake::pydrake::AddValueInstantiation<c3::LCS>(m);
158158
drake::pydrake::AddValueInstantiation<C3Output::C3Solution>(m);
159159
drake::pydrake::AddValueInstantiation<C3Output::C3Intermediates>(m);
160-
160+
161161
py::class_<C3StatePredictionJoint>(m, "C3StatePredictionJoint")
162162
.def(py::init<>())
163163
.def_readwrite("name", &C3StatePredictionJoint::name)

core/c3.h

Lines changed: 2 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.

core/c3_miqp.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ static const double kVariableBounds = 10000;
1414
class C3MIQP final : public C3 {
1515
public:
1616
/// Default constructor for time-varying LCS
17-
C3MIQP(const LCS& LCS, const CostMatrices& costs, const std::vector<Eigen::VectorXd>& xdesired,
17+
C3MIQP(const LCS& LCS, const CostMatrices& costs,
18+
const std::vector<Eigen::VectorXd>& xdesired,
1819
const C3Options& options);
1920

2021
~C3MIQP() override = default;

core/c3_options.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#include "drake/common/yaml/yaml_io.h"
44
#include "drake/common/yaml/yaml_read_archive.h"
55

6-
namespace c3{
6+
namespace c3 {
77

88
struct C3Options {
99
// Hyperparameters
@@ -18,7 +18,7 @@ struct C3Options {
1818
int delta_option =
1919
1; // 1 initializes the state value of the delta value with x0
2020

21-
double M = 1000; // big M value for MIQP
21+
double M = 1000; // big M value for MIQP
2222

2323
int admm_iter = 3; // total number of ADMM iterations
2424

@@ -144,6 +144,4 @@ inline C3Options LoadC3Options(const std::string& filename) {
144144
return options;
145145
}
146146

147-
148-
149147
} // namespace c3

core/c3_qp.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ namespace c3 {
1818
class C3QP final : public C3 {
1919
public:
2020
/// Default constructor for time-varying LCS
21-
C3QP(const LCS& LCS, const CostMatrices& costs, const std::vector<Eigen::VectorXd>& xdesired,
22-
const C3Options& options);
21+
C3QP(const LCS& LCS, const CostMatrices& costs,
22+
const std::vector<Eigen::VectorXd>& xdesired, const C3Options& options);
2323

2424
~C3QP() override = default;
2525

core/lcs.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ class LCS {
5050
*
5151
* @return The state at the next timestep
5252
*/
53-
const Eigen::VectorXd Simulate(Eigen::VectorXd& x_init, Eigen::VectorXd& u) const;
53+
const Eigen::VectorXd Simulate(Eigen::VectorXd& x_init,
54+
Eigen::VectorXd& u) const;
5455

5556
/*!
5657
* Accessors dynamics terms

core/solver_options_io.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@
22

33
#include "drake/solvers/solver_options.h"
44

5-
65
namespace c3 {
76

8-
using drake::solvers::SolverOptions;
97
using drake::solvers::CommonSolverOption;
8+
using drake::solvers::SolverOptions;
109

1110
/*
1211
* Struct containing solver options loaded from a YAML.
@@ -35,7 +34,7 @@ struct SolverOptionsFromYaml {
3534
std::map<std::string, double> double_options;
3635
std::map<std::string, std::string> string_options;
3736

38-
template<typename Archive>
37+
template <typename Archive>
3938
void Serialize(Archive* a) {
4039
a->Visit(DRAKE_NVP(print_to_console));
4140
a->Visit(DRAKE_NVP(log_file_name));
@@ -61,4 +60,4 @@ struct SolverOptionsFromYaml {
6160
}
6261
};
6362

64-
}
63+
} // namespace c3

examples/c3_example.cc

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include <chrono>
2-
#include <string>
32
#include <iostream>
3+
#include <string>
44

55
#include "core/c3_miqp.h"
66

@@ -130,7 +130,6 @@ int DoMain(int argc, char* argv[]) {
130130
opt.AddLinearConstraint(LinIneq2, lowerbound, upperbound, stateconstraint);
131131
}
132132

133-
134133
/// initialize ADMM variables (delta, w)
135134
std::vector<VectorXd> delta(N, VectorXd::Zero(n + m + k));
136135
std::vector<VectorXd> w(N, VectorXd::Zero(n + m + k));
@@ -163,7 +162,6 @@ int DoMain(int argc, char* argv[]) {
163162
w = w_reset;
164163
}
165164

166-
167165
if (example == 2) {
168166
init_pivoting(x[i], &nd, &md, &kd, &Nd, &Ad, &Bd, &Dd, &dd, &Ed, &Fd, &Hd,
169167
&cd, &Qd, &Rd, &Gd, &Ud, &x0, &xdesired, &options);
@@ -172,14 +170,12 @@ int DoMain(int argc, char* argv[]) {
172170
C3MIQP opt(system, cost, xdesired, options);
173171
}
174172

175-
176173
auto start = std::chrono::high_resolution_clock::now();
177174
/// calculate the input given x[i]
178175
opt.Solve(x[i]);
179176
input[i] = opt.GetInputSolution()[0];
180177

181-
182-
auto finish = std::chrono::high_resolution_clock::now();
178+
auto finish = std::chrono::high_resolution_clock::now();
183179
std::chrono::duration<double> elapsed = finish - start;
184180
std::cout << "Solve time:" << elapsed.count() << std::endl;
185181
total_time = total_time + elapsed.count();
@@ -188,17 +184,15 @@ int DoMain(int argc, char* argv[]) {
188184
x[i + 1] = system.Simulate(x[i], input[i]);
189185

190186
/// print the state
191-
//std::cout << "state: " << x[i + 1] << std::endl;
187+
// std::cout << "state: " << x[i + 1] << std::endl;
192188
}
193189
std::cout << "Average time: " << total_time / (timesteps - 1) << std::endl;
194190
return 0;
195191
}
196192

197193
} // namespace c3
198194

199-
int main(int argc, char* argv[]) {
200-
return c3::DoMain(argc, argv);
201-
}
195+
int main(int argc, char* argv[]) { return c3::DoMain(argc, argv); }
202196

203197
/// initialize LCS parameters for cartpole
204198
void init_cartpole(int* n_, int* m_, int* k_, int* N_, vector<MatrixXd>* A_,

0 commit comments

Comments
 (0)