blob: 513bf1bf1fdbc6599fce623169cbc605f8d1c782 [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 Schuh6ea789e2024-07-27 13:45:53 -0700230 ":dynamics",
Austin Schuh76534f32024-09-02 13:52:45 -0700231 ":jax_dynamics",
232 ":physics_test_utils",
233 "@pip//casadi",
234 "@pip//numpy",
235 "@pip//scipy",
236 ],
237)
238
239py_test(
240 name = "physics_test_gpu",
241 srcs = [
242 "physics_test.py",
243 ],
James Kuszmaulef14ab42024-09-14 15:05:24 -0700244 data = [":cpp_dynamics.so"],
Austin Schuh76534f32024-09-02 13:52:45 -0700245 env = {
246 "JAX_PLATFORMS": "cuda",
247 },
248 main = "physics_test.py",
249 target_compatible_with = ["@platforms//cpu:x86_64"],
250 deps = [
251 ":dynamics",
252 ":jax_dynamics",
justinT2107d41ed2024-07-31 21:12:31 -0700253 ":physics_test_utils",
Austin Schuh2a1abec2024-07-10 20:31:16 -0700254 "@pip//casadi",
255 "@pip//numpy",
Austin Schuhbd75c482024-08-18 00:03:51 -0700256 "@pip//scipy",
Austin Schuh2a1abec2024-07-10 20:31:16 -0700257 ],
258)
justinT2107d41ed2024-07-31 21:12:31 -0700259
Austin Schuh6ea789e2024-07-27 13:45:53 -0700260py_binary(
261 name = "casadi_velocity_mpc",
justinT2107d41ed2024-07-31 21:12:31 -0700262 srcs = [
Austin Schuh6ea789e2024-07-27 13:45:53 -0700263 "casadi_velocity_mpc.py",
justinT2107d41ed2024-07-31 21:12:31 -0700264 ],
265 deps = [
Austin Schuh6ea789e2024-07-27 13:45:53 -0700266 ":dynamics",
Austin Schuh9289e6e2024-09-02 13:10:12 -0700267 "@pip//absl_py",
justinT2107d41ed2024-07-31 21:12:31 -0700268 "@pip//casadi",
Austin Schuh6ea789e2024-07-27 13:45:53 -0700269 "@pip//matplotlib",
270 "@pip//numpy",
271 "@pip//pygobject",
272 "@pip//scipy",
justinT2107d41ed2024-07-31 21:12:31 -0700273 ],
274)
275
276py_library(
277 name = "physics_test_utils",
278 srcs = [
279 "physics_test_utils.py",
280 ],
281 deps = [
282 ":dynamics",
283 "@pip//casadi",
284 "@pip//numpy",
285 ],
286)
287
288py_binary(
289 name = "physics_debug",
290 srcs = [
291 "physics_debug.py",
292 ],
293 deps = [
294 ":physics_test_utils",
295 "@pip//matplotlib",
296 "@pip//pygobject",
297 "@pip//scipy",
298 ],
299)
Austin Schuh7fa65212024-08-18 17:20:58 -0700300
301py_binary(
302 name = "debug_fatrop",
303 srcs = [
304 "debug_fatrop.py",
305 ],
306 deps = [
307 "@pip//casadi",
308 "@pip//matplotlib",
309 "@pip//numpy",
310 "@pip//pygobject",
311 "@pip//scipy",
312 ],
313)
justinT21cc6eed02024-08-26 00:15:57 -0700314
315py_binary(
316 name = "smooth_function_graph",
317 srcs = [
318 "smooth_function_graph.py",
319 ],
320 deps = [
321 "@pip//matplotlib",
322 "@pip//numpy",
323 "@pip//pygobject",
324 "@pip//scipy",
325 ],
326)
Austin Schuh3aa49ab2024-09-02 13:14:26 -0700327
328py_binary(
329 name = "multi_casadi_velocity_mpc",
330 srcs = ["multi_casadi_velocity_mpc.py"],
331 data = [":casadi_velocity_mpc"],
332 deps = [
333 ":dynamics",
334 "@pip//absl_py",
335 "@pip//matplotlib",
336 "@pip//numpy",
337 "@pip//pygobject",
338 ],
339)
James Kuszmaulef14ab42024-09-14 15:05:24 -0700340
341cc_binary(
342 name = "cpp_dynamics.so",
343 # Just use the python dynamics directly if you want them; this is just for testing.
344 testonly = True,
345 srcs = ["dynamics_python_bindings.cc"],
346 linkshared = True,
347 target_compatible_with = ["@platforms//os:linux"],
348 deps = [
349 ":eigen_dynamics",
350 "//third_party/python",
351 "@com_google_absl//absl/log",
352 "@com_google_absl//absl/log:check",
353 ],
354)