blob: 1b8dcc369bacece095e89619f289a24d2bcea073 [file] [log] [blame]
justinT21446e4f62024-06-16 22:36:10 -07001load("@aspect_bazel_lib//lib:run_binary.bzl", "run_binary")
Nikolai Sohmers8412fe52024-06-09 18:01:18 -07002load("//aos:config.bzl", "aos_config")
James Kuszmauld938d332024-05-15 20:47:19 -07003load("//aos/flatbuffers:generate.bzl", "static_flatbuffer")
4
Nikolai Sohmers69ecb912024-06-08 14:06:22 -07005package(default_visibility = ["//visibility:public"])
6
7static_flatbuffer(
James Kuszmauldf6b1682024-07-06 13:53:10 -07008 name = "swerve_zeroing_fbs",
9 srcs = ["swerve_zeroing.fbs"],
10 visibility = ["//visibility:public"],
11 deps = [
12 "//frc971/zeroing:constants_fbs",
13 ],
14)
15
16static_flatbuffer(
Nikolai Sohmers69ecb912024-06-08 14:06:22 -070017 name = "swerve_drivetrain_goal_fbs",
18 srcs = ["swerve_drivetrain_goal.fbs"],
19)
20
21static_flatbuffer(
22 name = "swerve_drivetrain_status_fbs",
23 srcs = ["swerve_drivetrain_status.fbs"],
24 deps = ["//frc971/control_loops:profiled_subsystem_fbs"],
25)
26
James Kuszmauld938d332024-05-15 20:47:19 -070027static_flatbuffer(
28 name = "swerve_drivetrain_output_fbs",
29 srcs = ["swerve_drivetrain_output.fbs"],
James Kuszmauld938d332024-05-15 20:47:19 -070030 deps = ["//frc971/control_loops:can_talonfx_fbs"],
31)
32
33static_flatbuffer(
Nikolai Sohmers3f2a5072024-06-08 14:05:59 -070034 name = "swerve_drivetrain_can_position_fbs",
35 srcs = ["swerve_drivetrain_can_position.fbs"],
Nikolai Sohmers3f2a5072024-06-08 14:05:59 -070036 deps = ["//frc971/control_loops:can_talonfx_fbs"],
37)
38
39static_flatbuffer(
James Kuszmauld938d332024-05-15 20:47:19 -070040 name = "swerve_drivetrain_position_fbs",
41 srcs = ["swerve_drivetrain_position.fbs"],
James Kuszmauld938d332024-05-15 20:47:19 -070042 deps = ["//frc971/control_loops:control_loops_fbs"],
43)
44
Austin Schuh999a19e2024-05-04 14:52:39 -070045py_binary(
46 name = "simulation",
47 srcs = [
48 "simulation.py",
49 ],
50 deps = [
51 "//frc971/control_loops/python:controls",
52 "@pip//matplotlib",
53 "@pip//numpy",
54 "@pip//pygobject",
55 "@pip//sympy",
56 ],
57)
Nikolai Sohmers8412fe52024-06-09 18:01:18 -070058
59cc_library(
60 name = "swerve_control_loops",
61 srcs = ["swerve_control_loops.cc"],
62 hdrs = ["swerve_control_loops.h"],
63 target_compatible_with = ["@platforms//os:linux"],
64 deps = [
65 ":swerve_drivetrain_can_position_fbs",
66 ":swerve_drivetrain_goal_fbs",
67 ":swerve_drivetrain_output_fbs",
68 ":swerve_drivetrain_position_fbs",
69 ":swerve_drivetrain_status_fbs",
Nikolai Sohmers308c8992024-06-22 15:11:05 -070070 ":swerve_zeroing_fbs",
Nikolai Sohmers8412fe52024-06-09 18:01:18 -070071 "//frc971/control_loops:control_loop",
Nikolai Sohmers308c8992024-06-22 15:11:05 -070072 "//frc971/control_loops:static_zeroing_single_dof_profiled_subsystem",
73 "//frc971/zeroing:continuous_absolute_encoder",
Nikolai Sohmers8412fe52024-06-09 18:01:18 -070074 ],
75)
76
77cc_test(
78 name = "swerve_control_test",
79 srcs = ["swerve_control_test.cc"],
80 data = [
81 ":aos_config",
Nikolai Sohmers308c8992024-06-22 15:11:05 -070082 "//frc971/control_loops/swerve/test_module:rotation_json",
Nikolai Sohmers8412fe52024-06-09 18:01:18 -070083 ],
84 target_compatible_with = ["@platforms//os:linux"],
85 deps = [
86 ":swerve_control_loops",
87 ":swerve_drivetrain_can_position_fbs",
88 ":swerve_drivetrain_goal_fbs",
89 ":swerve_drivetrain_output_fbs",
90 ":swerve_drivetrain_position_fbs",
91 ":swerve_drivetrain_status_fbs",
92 "//aos/events:shm_event_loop",
93 "//aos/testing:googletest",
94 "//frc971/control_loops:control_loop_test",
95 "//frc971/control_loops:state_feedback_loop",
96 "//frc971/control_loops:team_number_test_environment",
97 ],
98)
99
100aos_config(
101 name = "aos_config",
102 src = "swerve.json",
103 flatbuffers = [
104 ":swerve_drivetrain_goal_fbs",
105 ":swerve_drivetrain_output_fbs",
106 ":swerve_drivetrain_position_fbs",
107 ":swerve_drivetrain_can_position_fbs",
108 ":swerve_drivetrain_status_fbs",
109 ],
110 target_compatible_with = ["@platforms//os:linux"],
111 deps = ["//frc971/input:aos_config"],
112)
justinT21446e4f62024-06-16 22:36:10 -0700113
114cc_library(
115 name = "motors",
116 hdrs = [
117 "motors.h",
118 ],
119 deps = [
120 "@symengine",
121 ],
122)
123
124cc_binary(
125 name = "generate_physics",
126 srcs = [
127 "generate_physics.cc",
128 ],
129 deps = [
130 ":motors",
131 "//aos:init",
132 "//aos/util:file",
Austin Schuh99f7c6a2024-06-25 22:07:44 -0700133 "@com_google_absl//absl/log",
134 "@com_google_absl//absl/log:check",
justinT21446e4f62024-06-16 22:36:10 -0700135 "@com_google_absl//absl/strings",
136 "@com_google_absl//absl/strings:str_format",
137 "@symengine",
138 ],
139)
140
141run_binary(
Austin Schuh27694fa2024-07-20 16:29:49 -0700142 name = "dynamics_codegen_cc",
justinT21446e4f62024-06-16 22:36:10 -0700143 outs = [
144 "dynamics.cc",
145 "dynamics.h",
justinT21942892b2024-07-02 22:33:50 -0700146 "dynamics.py",
justinT21446e4f62024-06-16 22:36:10 -0700147 ],
148 args = [
149 "--output_base=$(BINDIR)/",
150 "--cc_output_path=$(location :dynamics.cc)",
151 "--h_output_path=$(location :dynamics.h)",
Austin Schuh0f881092024-06-28 15:36:48 -0700152 "--casadi_py_output_path=$(location :dynamics.py)",
justinT21446e4f62024-06-16 22:36:10 -0700153 ],
154 tool = ":generate_physics",
155)
156
Austin Schuh27694fa2024-07-20 16:29:49 -0700157run_binary(
158 name = "dynamics_codegen_nocaster",
159 outs = [
160 "nocaster_dynamics.py",
161 ],
162 args = [
163 "--caster=0.0",
164 "--output_base=$(BINDIR)/",
165 "--casadi_py_output_path=$(location :nocaster_dynamics.py)",
166 ],
167 tool = ":generate_physics",
168)
169
170run_binary(
171 name = "dynamics_codegen_bigcaster",
172 outs = [
173 "bigcaster_dynamics.py",
174 ],
175 args = [
176 "--caster=0.05",
177 "--output_base=$(BINDIR)/",
178 "--casadi_py_output_path=$(location :bigcaster_dynamics.py)",
179 ],
180 tool = ":generate_physics",
181)
182
justinT21446e4f62024-06-16 22:36:10 -0700183cc_library(
justinT2107d41ed2024-07-31 21:12:31 -0700184 name = "eigen_dynamics",
justinT21446e4f62024-06-16 22:36:10 -0700185 srcs = ["dynamics.cc"],
186 hdrs = ["dynamics.h"],
187 deps = [
188 "@org_tuxfamily_eigen//:eigen",
189 ],
190)
justinT21942892b2024-07-02 22:33:50 -0700191
Austin Schuh6ea789e2024-07-27 13:45:53 -0700192py_library(
193 name = "dynamics",
justinT21942892b2024-07-02 22:33:50 -0700194 srcs = [
Austin Schuh6ea789e2024-07-27 13:45:53 -0700195 "bigcaster_dynamics.py",
196 "dynamics.py",
197 "nocaster_dynamics.py",
justinT21942892b2024-07-02 22:33:50 -0700198 ],
199 deps = [
Austin Schuh6ea789e2024-07-27 13:45:53 -0700200 "@pip//casadi",
justinT21942892b2024-07-02 22:33:50 -0700201 ],
202)
Austin Schuh2a1abec2024-07-10 20:31:16 -0700203
Austin Schuh76534f32024-09-02 13:52:45 -0700204py_library(
205 name = "jax_dynamics",
206 srcs = [
207 "jax_dynamics.py",
208 ],
209 deps = [
210 ":dynamics",
211 "//frc971/control_loops/python:controls",
212 "@pip//jax",
213 ],
214)
215
Austin Schuh2a1abec2024-07-10 20:31:16 -0700216py_test(
Austin Schuh76534f32024-09-02 13:52:45 -0700217 name = "physics_test_cpu",
Austin Schuh2a1abec2024-07-10 20:31:16 -0700218 srcs = [
Austin Schuh2a1abec2024-07-10 20:31:16 -0700219 "physics_test.py",
220 ],
James Kuszmaulef14ab42024-09-14 15:05:24 -0700221 data = [":cpp_dynamics.so"],
Austin Schuh76534f32024-09-02 13:52:45 -0700222 env = {
223 "JAX_PLATFORMS": "cpu",
224 },
225 main = "physics_test.py",
Austin Schuh2a1abec2024-07-10 20:31:16 -0700226 target_compatible_with = ["@platforms//cpu:x86_64"],
227 deps = [
Austin Schuh6ea789e2024-07-27 13:45:53 -0700228 ":dynamics",
Austin Schuh76534f32024-09-02 13:52:45 -0700229 ":jax_dynamics",
230 ":physics_test_utils",
231 "@pip//casadi",
232 "@pip//numpy",
233 "@pip//scipy",
234 ],
235)
236
237py_test(
238 name = "physics_test_gpu",
239 srcs = [
240 "physics_test.py",
241 ],
James Kuszmaulef14ab42024-09-14 15:05:24 -0700242 data = [":cpp_dynamics.so"],
Austin Schuh76534f32024-09-02 13:52:45 -0700243 env = {
244 "JAX_PLATFORMS": "cuda",
245 },
246 main = "physics_test.py",
247 target_compatible_with = ["@platforms//cpu:x86_64"],
248 deps = [
249 ":dynamics",
250 ":jax_dynamics",
justinT2107d41ed2024-07-31 21:12:31 -0700251 ":physics_test_utils",
Austin Schuh2a1abec2024-07-10 20:31:16 -0700252 "@pip//casadi",
253 "@pip//numpy",
Austin Schuhbd75c482024-08-18 00:03:51 -0700254 "@pip//scipy",
Austin Schuh2a1abec2024-07-10 20:31:16 -0700255 ],
256)
justinT2107d41ed2024-07-31 21:12:31 -0700257
Austin Schuh6ea789e2024-07-27 13:45:53 -0700258py_binary(
259 name = "casadi_velocity_mpc",
justinT2107d41ed2024-07-31 21:12:31 -0700260 srcs = [
Austin Schuh6ea789e2024-07-27 13:45:53 -0700261 "casadi_velocity_mpc.py",
justinT2107d41ed2024-07-31 21:12:31 -0700262 ],
263 deps = [
Austin Schuh6ea789e2024-07-27 13:45:53 -0700264 ":dynamics",
Austin Schuh9289e6e2024-09-02 13:10:12 -0700265 "@pip//absl_py",
justinT2107d41ed2024-07-31 21:12:31 -0700266 "@pip//casadi",
Austin Schuh6ea789e2024-07-27 13:45:53 -0700267 "@pip//matplotlib",
268 "@pip//numpy",
269 "@pip//pygobject",
270 "@pip//scipy",
justinT2107d41ed2024-07-31 21:12:31 -0700271 ],
272)
273
274py_library(
275 name = "physics_test_utils",
276 srcs = [
277 "physics_test_utils.py",
278 ],
279 deps = [
280 ":dynamics",
281 "@pip//casadi",
282 "@pip//numpy",
283 ],
284)
285
286py_binary(
287 name = "physics_debug",
288 srcs = [
289 "physics_debug.py",
290 ],
291 deps = [
292 ":physics_test_utils",
293 "@pip//matplotlib",
294 "@pip//pygobject",
295 "@pip//scipy",
296 ],
297)
Austin Schuh7fa65212024-08-18 17:20:58 -0700298
299py_binary(
300 name = "debug_fatrop",
301 srcs = [
302 "debug_fatrop.py",
303 ],
304 deps = [
305 "@pip//casadi",
306 "@pip//matplotlib",
307 "@pip//numpy",
308 "@pip//pygobject",
309 "@pip//scipy",
310 ],
311)
justinT21cc6eed02024-08-26 00:15:57 -0700312
313py_binary(
314 name = "smooth_function_graph",
315 srcs = [
316 "smooth_function_graph.py",
317 ],
318 deps = [
319 "@pip//matplotlib",
320 "@pip//numpy",
321 "@pip//pygobject",
322 "@pip//scipy",
323 ],
324)
Austin Schuh3aa49ab2024-09-02 13:14:26 -0700325
326py_binary(
327 name = "multi_casadi_velocity_mpc",
328 srcs = ["multi_casadi_velocity_mpc.py"],
329 data = [":casadi_velocity_mpc"],
330 deps = [
331 ":dynamics",
332 "@pip//absl_py",
333 "@pip//matplotlib",
334 "@pip//numpy",
335 "@pip//pygobject",
336 ],
337)
James Kuszmaulef14ab42024-09-14 15:05:24 -0700338
339cc_binary(
340 name = "cpp_dynamics.so",
341 # Just use the python dynamics directly if you want them; this is just for testing.
342 testonly = True,
343 srcs = ["dynamics_python_bindings.cc"],
344 linkshared = True,
345 target_compatible_with = ["@platforms//os:linux"],
346 deps = [
347 ":eigen_dynamics",
348 "//third_party/python",
349 "@com_google_absl//absl/log",
350 "@com_google_absl//absl/log:check",
351 ],
352)