blob: 50130e8c88788f64b9705a590314f13198d14a8b [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",
Austin Schuha9550c02024-10-19 13:48:10 -0700147 "dynamics_constants.py",
justinT21446e4f62024-06-16 22:36:10 -0700148 ],
149 args = [
150 "--output_base=$(BINDIR)/",
151 "--cc_output_path=$(location :dynamics.cc)",
152 "--h_output_path=$(location :dynamics.h)",
Austin Schuh0f881092024-06-28 15:36:48 -0700153 "--casadi_py_output_path=$(location :dynamics.py)",
Austin Schuha9550c02024-10-19 13:48:10 -0700154 "--constants_output_path=$(location :dynamics_constants.py)",
justinT21446e4f62024-06-16 22:36:10 -0700155 ],
156 tool = ":generate_physics",
157)
158
Austin Schuh27694fa2024-07-20 16:29:49 -0700159run_binary(
160 name = "dynamics_codegen_nocaster",
161 outs = [
162 "nocaster_dynamics.py",
163 ],
164 args = [
165 "--caster=0.0",
166 "--output_base=$(BINDIR)/",
167 "--casadi_py_output_path=$(location :nocaster_dynamics.py)",
168 ],
169 tool = ":generate_physics",
170)
171
172run_binary(
173 name = "dynamics_codegen_bigcaster",
174 outs = [
175 "bigcaster_dynamics.py",
176 ],
177 args = [
178 "--caster=0.05",
179 "--output_base=$(BINDIR)/",
180 "--casadi_py_output_path=$(location :bigcaster_dynamics.py)",
181 ],
182 tool = ":generate_physics",
183)
184
justinT21446e4f62024-06-16 22:36:10 -0700185cc_library(
justinT2107d41ed2024-07-31 21:12:31 -0700186 name = "eigen_dynamics",
justinT21446e4f62024-06-16 22:36:10 -0700187 srcs = ["dynamics.cc"],
188 hdrs = ["dynamics.h"],
189 deps = [
190 "@org_tuxfamily_eigen//:eigen",
191 ],
192)
justinT21942892b2024-07-02 22:33:50 -0700193
Austin Schuh6ea789e2024-07-27 13:45:53 -0700194py_library(
195 name = "dynamics",
justinT21942892b2024-07-02 22:33:50 -0700196 srcs = [
Austin Schuh6ea789e2024-07-27 13:45:53 -0700197 "bigcaster_dynamics.py",
198 "dynamics.py",
199 "nocaster_dynamics.py",
justinT21942892b2024-07-02 22:33:50 -0700200 ],
201 deps = [
Austin Schuh6ea789e2024-07-27 13:45:53 -0700202 "@pip//casadi",
justinT21942892b2024-07-02 22:33:50 -0700203 ],
204)
Austin Schuh2a1abec2024-07-10 20:31:16 -0700205
Austin Schuh76534f32024-09-02 13:52:45 -0700206py_library(
207 name = "jax_dynamics",
208 srcs = [
Austin Schuha9550c02024-10-19 13:48:10 -0700209 "dynamics_constants.py",
Austin Schuh76534f32024-09-02 13:52:45 -0700210 "jax_dynamics.py",
211 ],
212 deps = [
Austin Schuh76534f32024-09-02 13:52:45 -0700213 "//frc971/control_loops/python:controls",
214 "@pip//jax",
215 ],
216)
217
Austin Schuh2a1abec2024-07-10 20:31:16 -0700218py_test(
Austin Schuh76534f32024-09-02 13:52:45 -0700219 name = "physics_test_cpu",
Austin Schuh2a1abec2024-07-10 20:31:16 -0700220 srcs = [
Austin Schuh2a1abec2024-07-10 20:31:16 -0700221 "physics_test.py",
222 ],
James Kuszmaulef14ab42024-09-14 15:05:24 -0700223 data = [":cpp_dynamics.so"],
Austin Schuh76534f32024-09-02 13:52:45 -0700224 env = {
225 "JAX_PLATFORMS": "cpu",
226 },
227 main = "physics_test.py",
Austin Schuh2a1abec2024-07-10 20:31:16 -0700228 target_compatible_with = ["@platforms//cpu:x86_64"],
229 deps = [
Austin Schuh5dac2292024-10-19 13:56:58 -0700230 ":casadi_velocity_mpc_lib",
Austin Schuh6ea789e2024-07-27 13:45:53 -0700231 ":dynamics",
Austin Schuh76534f32024-09-02 13:52:45 -0700232 ":jax_dynamics",
233 ":physics_test_utils",
Austin Schuh5dac2292024-10-19 13:56:58 -0700234 "@pip//absl_py",
Austin Schuh76534f32024-09-02 13:52:45 -0700235 "@pip//casadi",
Austin Schuh5dac2292024-10-19 13:56:58 -0700236 "@pip//matplotlib",
Austin Schuh76534f32024-09-02 13:52:45 -0700237 "@pip//numpy",
Austin Schuh5dac2292024-10-19 13:56:58 -0700238 "@pip//pygobject",
Austin Schuh76534f32024-09-02 13:52:45 -0700239 "@pip//scipy",
240 ],
241)
242
243py_test(
244 name = "physics_test_gpu",
245 srcs = [
246 "physics_test.py",
247 ],
James Kuszmaulef14ab42024-09-14 15:05:24 -0700248 data = [":cpp_dynamics.so"],
Austin Schuh76534f32024-09-02 13:52:45 -0700249 env = {
250 "JAX_PLATFORMS": "cuda",
251 },
252 main = "physics_test.py",
253 target_compatible_with = ["@platforms//cpu:x86_64"],
254 deps = [
Austin Schuh5dac2292024-10-19 13:56:58 -0700255 ":casadi_velocity_mpc_lib",
Austin Schuh76534f32024-09-02 13:52:45 -0700256 ":dynamics",
257 ":jax_dynamics",
justinT2107d41ed2024-07-31 21:12:31 -0700258 ":physics_test_utils",
Austin Schuh5dac2292024-10-19 13:56:58 -0700259 "@pip//absl_py",
260 "@pip//casadi",
261 "@pip//matplotlib",
262 "@pip//numpy",
263 "@pip//pygobject",
264 "@pip//scipy",
265 ],
266)
267
268py_binary(
269 name = "casadi_velocity_mpc_lib",
270 srcs = [
271 "casadi_velocity_mpc_lib.py",
272 ],
273 deps = [
274 ":dynamics",
Austin Schuh2a1abec2024-07-10 20:31:16 -0700275 "@pip//casadi",
276 "@pip//numpy",
277 ],
278)
justinT2107d41ed2024-07-31 21:12:31 -0700279
Austin Schuh6ea789e2024-07-27 13:45:53 -0700280py_binary(
281 name = "casadi_velocity_mpc",
justinT2107d41ed2024-07-31 21:12:31 -0700282 srcs = [
Austin Schuh6ea789e2024-07-27 13:45:53 -0700283 "casadi_velocity_mpc.py",
justinT2107d41ed2024-07-31 21:12:31 -0700284 ],
285 deps = [
Austin Schuh5dac2292024-10-19 13:56:58 -0700286 ":casadi_velocity_mpc_lib",
Austin Schuh9289e6e2024-09-02 13:10:12 -0700287 "@pip//absl_py",
Austin Schuh6ea789e2024-07-27 13:45:53 -0700288 "@pip//matplotlib",
289 "@pip//numpy",
290 "@pip//pygobject",
291 "@pip//scipy",
justinT2107d41ed2024-07-31 21:12:31 -0700292 ],
293)
294
Austin Schuh9f57e5b2024-10-26 17:27:36 -0700295py_binary(
296 name = "experience_collector",
297 srcs = [
298 "experience_collector.py",
299 ],
300 deps = [
301 ":casadi_velocity_mpc_lib",
302 ":jax_dynamics",
303 "//frc971/control_loops/swerve/velocity_controller:physics",
304 "@pip//absl_py",
305 "@pip//matplotlib",
306 "@pip//numpy",
307 "@pip//pygobject",
308 "@pip//scipy",
309 "@pip//tensorflow",
310 ],
311)
312
313py_binary(
314 name = "multi_experience_collector",
315 srcs = ["multi_experience_collector.py"],
316 data = [":experience_collector"],
317 deps = [
318 "@pip//absl_py",
319 ],
320)
321
justinT2107d41ed2024-07-31 21:12:31 -0700322py_library(
323 name = "physics_test_utils",
324 srcs = [
325 "physics_test_utils.py",
326 ],
327 deps = [
328 ":dynamics",
329 "@pip//casadi",
330 "@pip//numpy",
331 ],
332)
333
334py_binary(
335 name = "physics_debug",
336 srcs = [
337 "physics_debug.py",
338 ],
339 deps = [
340 ":physics_test_utils",
341 "@pip//matplotlib",
342 "@pip//pygobject",
343 "@pip//scipy",
344 ],
345)
Austin Schuh7fa65212024-08-18 17:20:58 -0700346
347py_binary(
348 name = "debug_fatrop",
349 srcs = [
350 "debug_fatrop.py",
351 ],
352 deps = [
353 "@pip//casadi",
354 "@pip//matplotlib",
355 "@pip//numpy",
356 "@pip//pygobject",
357 "@pip//scipy",
358 ],
359)
justinT21cc6eed02024-08-26 00:15:57 -0700360
361py_binary(
362 name = "smooth_function_graph",
363 srcs = [
364 "smooth_function_graph.py",
365 ],
366 deps = [
367 "@pip//matplotlib",
368 "@pip//numpy",
369 "@pip//pygobject",
370 "@pip//scipy",
371 ],
372)
Austin Schuh3aa49ab2024-09-02 13:14:26 -0700373
374py_binary(
375 name = "multi_casadi_velocity_mpc",
376 srcs = ["multi_casadi_velocity_mpc.py"],
377 data = [":casadi_velocity_mpc"],
378 deps = [
379 ":dynamics",
380 "@pip//absl_py",
381 "@pip//matplotlib",
382 "@pip//numpy",
383 "@pip//pygobject",
384 ],
385)
James Kuszmaulef14ab42024-09-14 15:05:24 -0700386
387cc_binary(
388 name = "cpp_dynamics.so",
389 # Just use the python dynamics directly if you want them; this is just for testing.
390 testonly = True,
391 srcs = ["dynamics_python_bindings.cc"],
392 linkshared = True,
393 target_compatible_with = ["@platforms//os:linux"],
394 deps = [
395 ":eigen_dynamics",
396 "//third_party/python",
397 "@com_google_absl//absl/log",
398 "@com_google_absl//absl/log:check",
399 ],
400)
James Kuszmaul43504bf2024-10-08 23:28:11 -0700401
402cc_library(
James Kuszmaul886675c2024-10-09 20:32:00 -0700403 name = "linearization_utils",
404 hdrs = ["linearization_utils.h"],
405)
406
407cc_library(
408 name = "linearized_controller",
409 hdrs = ["linearized_controller.h"],
410 deps = [
411 ":eigen_dynamics",
412 ":linearization_utils",
413 "//frc971/control_loops:c2d",
414 "//frc971/control_loops:dlqr",
415 "//frc971/control_loops:jacobian",
416 "@com_google_absl//absl/log",
417 "@com_google_absl//absl/log:check",
418 ],
419)
420
421cc_test(
422 name = "linearized_controller_test",
423 srcs = ["linearized_controller_test.cc"],
424 deps = [
425 ":linearized_controller",
426 "//aos/testing:googletest",
427 ],
428)
429
430cc_library(
James Kuszmaul43504bf2024-10-08 23:28:11 -0700431 name = "auto_diff_jacobian",
432 hdrs = ["auto_diff_jacobian.h"],
433 target_compatible_with = ["@platforms//os:linux"],
434 deps = [
435 "@com_google_ceres_solver//:ceres",
436 ],
437)
438
439cc_test(
440 name = "auto_diff_jacobian_test",
441 srcs = ["auto_diff_jacobian_test.cc"],
442 deps = [
443 ":auto_diff_jacobian",
444 "//aos/testing:googletest",
445 ],
446)
James Kuszmaulde44eb52024-10-08 23:39:24 -0700447
448cc_library(
449 name = "simplified_dynamics",
450 hdrs = ["simplified_dynamics.h"],
451 deps = [
452 ":auto_diff_jacobian",
453 ":eigen_dynamics",
454 ":motors",
455 "//aos/util:math",
456 "@com_google_absl//absl/log",
457 "@com_google_absl//absl/log:check",
458 ],
459)
460
461cc_test(
462 name = "simplified_dynamics_test",
463 srcs = ["simplified_dynamics_test.cc"],
464 deps = [
465 ":simplified_dynamics",
466 "//aos/testing:googletest",
467 "//aos/time",
468 "//frc971/control_loops:jacobian",
469 "@com_google_absl//absl/log",
470 ],
471)
James Kuszmaulc68b3502024-10-09 07:56:18 -0700472
473cc_library(
474 name = "inverse_kinematics",
475 hdrs = ["inverse_kinematics.h"],
476 deps = [
477 ":simplified_dynamics",
478 "//aos/util:math",
479 ],
480)
481
482cc_test(
483 name = "inverse_kinematics_test",
484 srcs = ["inverse_kinematics_test.cc"],
485 deps = [
486 ":inverse_kinematics",
487 "//aos/testing:googletest",
488 ],
489)