blob: 2c3ad5056f5d9151e37aa4b8790611903050950a [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
295py_library(
296 name = "physics_test_utils",
297 srcs = [
298 "physics_test_utils.py",
299 ],
300 deps = [
301 ":dynamics",
302 "@pip//casadi",
303 "@pip//numpy",
304 ],
305)
306
307py_binary(
308 name = "physics_debug",
309 srcs = [
310 "physics_debug.py",
311 ],
312 deps = [
313 ":physics_test_utils",
314 "@pip//matplotlib",
315 "@pip//pygobject",
316 "@pip//scipy",
317 ],
318)
Austin Schuh7fa65212024-08-18 17:20:58 -0700319
320py_binary(
321 name = "debug_fatrop",
322 srcs = [
323 "debug_fatrop.py",
324 ],
325 deps = [
326 "@pip//casadi",
327 "@pip//matplotlib",
328 "@pip//numpy",
329 "@pip//pygobject",
330 "@pip//scipy",
331 ],
332)
justinT21cc6eed02024-08-26 00:15:57 -0700333
334py_binary(
335 name = "smooth_function_graph",
336 srcs = [
337 "smooth_function_graph.py",
338 ],
339 deps = [
340 "@pip//matplotlib",
341 "@pip//numpy",
342 "@pip//pygobject",
343 "@pip//scipy",
344 ],
345)
Austin Schuh3aa49ab2024-09-02 13:14:26 -0700346
347py_binary(
348 name = "multi_casadi_velocity_mpc",
349 srcs = ["multi_casadi_velocity_mpc.py"],
350 data = [":casadi_velocity_mpc"],
351 deps = [
352 ":dynamics",
353 "@pip//absl_py",
354 "@pip//matplotlib",
355 "@pip//numpy",
356 "@pip//pygobject",
357 ],
358)
James Kuszmaulef14ab42024-09-14 15:05:24 -0700359
360cc_binary(
361 name = "cpp_dynamics.so",
362 # Just use the python dynamics directly if you want them; this is just for testing.
363 testonly = True,
364 srcs = ["dynamics_python_bindings.cc"],
365 linkshared = True,
366 target_compatible_with = ["@platforms//os:linux"],
367 deps = [
368 ":eigen_dynamics",
369 "//third_party/python",
370 "@com_google_absl//absl/log",
371 "@com_google_absl//absl/log:check",
372 ],
373)