blob: 2d0683722aa2bbc2f0a106c7c0724027d4e65777 [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",
70 "//frc971/control_loops:control_loop",
71 ],
72)
73
74cc_test(
75 name = "swerve_control_test",
76 srcs = ["swerve_control_test.cc"],
77 data = [
78 ":aos_config",
79 ],
80 target_compatible_with = ["@platforms//os:linux"],
81 deps = [
82 ":swerve_control_loops",
83 ":swerve_drivetrain_can_position_fbs",
84 ":swerve_drivetrain_goal_fbs",
85 ":swerve_drivetrain_output_fbs",
86 ":swerve_drivetrain_position_fbs",
87 ":swerve_drivetrain_status_fbs",
88 "//aos/events:shm_event_loop",
89 "//aos/testing:googletest",
90 "//frc971/control_loops:control_loop_test",
91 "//frc971/control_loops:state_feedback_loop",
92 "//frc971/control_loops:team_number_test_environment",
93 ],
94)
95
96aos_config(
97 name = "aos_config",
98 src = "swerve.json",
99 flatbuffers = [
100 ":swerve_drivetrain_goal_fbs",
101 ":swerve_drivetrain_output_fbs",
102 ":swerve_drivetrain_position_fbs",
103 ":swerve_drivetrain_can_position_fbs",
104 ":swerve_drivetrain_status_fbs",
105 ],
106 target_compatible_with = ["@platforms//os:linux"],
107 deps = ["//frc971/input:aos_config"],
108)
justinT21446e4f62024-06-16 22:36:10 -0700109
110cc_library(
111 name = "motors",
112 hdrs = [
113 "motors.h",
114 ],
115 deps = [
116 "@symengine",
117 ],
118)
119
120cc_binary(
121 name = "generate_physics",
122 srcs = [
123 "generate_physics.cc",
124 ],
125 deps = [
126 ":motors",
127 "//aos:init",
128 "//aos/util:file",
Austin Schuh99f7c6a2024-06-25 22:07:44 -0700129 "@com_google_absl//absl/log",
130 "@com_google_absl//absl/log:check",
justinT21446e4f62024-06-16 22:36:10 -0700131 "@com_google_absl//absl/strings",
132 "@com_google_absl//absl/strings:str_format",
133 "@symengine",
134 ],
135)
136
137run_binary(
Austin Schuh27694fa2024-07-20 16:29:49 -0700138 name = "dynamics_codegen_cc",
justinT21446e4f62024-06-16 22:36:10 -0700139 outs = [
140 "dynamics.cc",
141 "dynamics.h",
justinT21942892b2024-07-02 22:33:50 -0700142 "dynamics.py",
justinT21446e4f62024-06-16 22:36:10 -0700143 ],
144 args = [
145 "--output_base=$(BINDIR)/",
146 "--cc_output_path=$(location :dynamics.cc)",
147 "--h_output_path=$(location :dynamics.h)",
Austin Schuh0f881092024-06-28 15:36:48 -0700148 "--casadi_py_output_path=$(location :dynamics.py)",
justinT21446e4f62024-06-16 22:36:10 -0700149 ],
150 tool = ":generate_physics",
151)
152
Austin Schuh27694fa2024-07-20 16:29:49 -0700153run_binary(
154 name = "dynamics_codegen_nocaster",
155 outs = [
156 "nocaster_dynamics.py",
157 ],
158 args = [
159 "--caster=0.0",
160 "--output_base=$(BINDIR)/",
161 "--casadi_py_output_path=$(location :nocaster_dynamics.py)",
162 ],
163 tool = ":generate_physics",
164)
165
166run_binary(
167 name = "dynamics_codegen_bigcaster",
168 outs = [
169 "bigcaster_dynamics.py",
170 ],
171 args = [
172 "--caster=0.05",
173 "--output_base=$(BINDIR)/",
174 "--casadi_py_output_path=$(location :bigcaster_dynamics.py)",
175 ],
176 tool = ":generate_physics",
177)
178
justinT21446e4f62024-06-16 22:36:10 -0700179cc_library(
justinT2107d41ed2024-07-31 21:12:31 -0700180 name = "eigen_dynamics",
justinT21446e4f62024-06-16 22:36:10 -0700181 srcs = ["dynamics.cc"],
182 hdrs = ["dynamics.h"],
183 deps = [
184 "@org_tuxfamily_eigen//:eigen",
185 ],
186)
justinT21942892b2024-07-02 22:33:50 -0700187
Austin Schuh6ea789e2024-07-27 13:45:53 -0700188py_library(
189 name = "dynamics",
justinT21942892b2024-07-02 22:33:50 -0700190 srcs = [
Austin Schuh6ea789e2024-07-27 13:45:53 -0700191 "bigcaster_dynamics.py",
192 "dynamics.py",
193 "nocaster_dynamics.py",
justinT21942892b2024-07-02 22:33:50 -0700194 ],
195 deps = [
Austin Schuh6ea789e2024-07-27 13:45:53 -0700196 "@pip//casadi",
justinT21942892b2024-07-02 22:33:50 -0700197 ],
198)
Austin Schuh2a1abec2024-07-10 20:31:16 -0700199
Austin Schuh76534f32024-09-02 13:52:45 -0700200py_library(
201 name = "jax_dynamics",
202 srcs = [
203 "jax_dynamics.py",
204 ],
205 deps = [
206 ":dynamics",
207 "//frc971/control_loops/python:controls",
208 "@pip//jax",
209 ],
210)
211
Austin Schuh2a1abec2024-07-10 20:31:16 -0700212py_test(
Austin Schuh76534f32024-09-02 13:52:45 -0700213 name = "physics_test_cpu",
Austin Schuh2a1abec2024-07-10 20:31:16 -0700214 srcs = [
Austin Schuh2a1abec2024-07-10 20:31:16 -0700215 "physics_test.py",
216 ],
James Kuszmaulef14ab42024-09-14 15:05:24 -0700217 data = [":cpp_dynamics.so"],
Austin Schuh76534f32024-09-02 13:52:45 -0700218 env = {
219 "JAX_PLATFORMS": "cpu",
220 },
221 main = "physics_test.py",
Austin Schuh2a1abec2024-07-10 20:31:16 -0700222 target_compatible_with = ["@platforms//cpu:x86_64"],
223 deps = [
Austin Schuh6ea789e2024-07-27 13:45:53 -0700224 ":dynamics",
Austin Schuh76534f32024-09-02 13:52:45 -0700225 ":jax_dynamics",
226 ":physics_test_utils",
227 "@pip//casadi",
228 "@pip//numpy",
229 "@pip//scipy",
230 ],
231)
232
233py_test(
234 name = "physics_test_gpu",
235 srcs = [
236 "physics_test.py",
237 ],
James Kuszmaulef14ab42024-09-14 15:05:24 -0700238 data = [":cpp_dynamics.so"],
Austin Schuh76534f32024-09-02 13:52:45 -0700239 env = {
240 "JAX_PLATFORMS": "cuda",
241 },
242 main = "physics_test.py",
243 target_compatible_with = ["@platforms//cpu:x86_64"],
244 deps = [
245 ":dynamics",
246 ":jax_dynamics",
justinT2107d41ed2024-07-31 21:12:31 -0700247 ":physics_test_utils",
Austin Schuh2a1abec2024-07-10 20:31:16 -0700248 "@pip//casadi",
249 "@pip//numpy",
Austin Schuhbd75c482024-08-18 00:03:51 -0700250 "@pip//scipy",
Austin Schuh2a1abec2024-07-10 20:31:16 -0700251 ],
252)
justinT2107d41ed2024-07-31 21:12:31 -0700253
Austin Schuh6ea789e2024-07-27 13:45:53 -0700254py_binary(
255 name = "casadi_velocity_mpc",
justinT2107d41ed2024-07-31 21:12:31 -0700256 srcs = [
Austin Schuh6ea789e2024-07-27 13:45:53 -0700257 "casadi_velocity_mpc.py",
justinT2107d41ed2024-07-31 21:12:31 -0700258 ],
259 deps = [
Austin Schuh6ea789e2024-07-27 13:45:53 -0700260 ":dynamics",
Austin Schuh9289e6e2024-09-02 13:10:12 -0700261 "@pip//absl_py",
justinT2107d41ed2024-07-31 21:12:31 -0700262 "@pip//casadi",
Austin Schuh6ea789e2024-07-27 13:45:53 -0700263 "@pip//matplotlib",
264 "@pip//numpy",
265 "@pip//pygobject",
266 "@pip//scipy",
justinT2107d41ed2024-07-31 21:12:31 -0700267 ],
268)
269
270py_library(
271 name = "physics_test_utils",
272 srcs = [
273 "physics_test_utils.py",
274 ],
275 deps = [
276 ":dynamics",
277 "@pip//casadi",
278 "@pip//numpy",
279 ],
280)
281
282py_binary(
283 name = "physics_debug",
284 srcs = [
285 "physics_debug.py",
286 ],
287 deps = [
288 ":physics_test_utils",
289 "@pip//matplotlib",
290 "@pip//pygobject",
291 "@pip//scipy",
292 ],
293)
Austin Schuh7fa65212024-08-18 17:20:58 -0700294
295py_binary(
296 name = "debug_fatrop",
297 srcs = [
298 "debug_fatrop.py",
299 ],
300 deps = [
301 "@pip//casadi",
302 "@pip//matplotlib",
303 "@pip//numpy",
304 "@pip//pygobject",
305 "@pip//scipy",
306 ],
307)
justinT21cc6eed02024-08-26 00:15:57 -0700308
309py_binary(
310 name = "smooth_function_graph",
311 srcs = [
312 "smooth_function_graph.py",
313 ],
314 deps = [
315 "@pip//matplotlib",
316 "@pip//numpy",
317 "@pip//pygobject",
318 "@pip//scipy",
319 ],
320)
Austin Schuh3aa49ab2024-09-02 13:14:26 -0700321
322py_binary(
323 name = "multi_casadi_velocity_mpc",
324 srcs = ["multi_casadi_velocity_mpc.py"],
325 data = [":casadi_velocity_mpc"],
326 deps = [
327 ":dynamics",
328 "@pip//absl_py",
329 "@pip//matplotlib",
330 "@pip//numpy",
331 "@pip//pygobject",
332 ],
333)
James Kuszmaulef14ab42024-09-14 15:05:24 -0700334
335cc_binary(
336 name = "cpp_dynamics.so",
337 # Just use the python dynamics directly if you want them; this is just for testing.
338 testonly = True,
339 srcs = ["dynamics_python_bindings.cc"],
340 linkshared = True,
341 target_compatible_with = ["@platforms//os:linux"],
342 deps = [
343 ":eigen_dynamics",
344 "//third_party/python",
345 "@com_google_absl//absl/log",
346 "@com_google_absl//absl/log:check",
347 ],
348)