blob: c7355b5e26b5affe1935c86d465d99b6c7273737 [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
200py_test(
201 name = "physics_test",
202 srcs = [
Austin Schuh2a1abec2024-07-10 20:31:16 -0700203 "physics_test.py",
204 ],
205 target_compatible_with = ["@platforms//cpu:x86_64"],
206 deps = [
Austin Schuh6ea789e2024-07-27 13:45:53 -0700207 ":dynamics",
justinT2107d41ed2024-07-31 21:12:31 -0700208 ":physics_test_utils",
Austin Schuh2a1abec2024-07-10 20:31:16 -0700209 "@pip//casadi",
210 "@pip//numpy",
Austin Schuhbd75c482024-08-18 00:03:51 -0700211 "@pip//scipy",
Austin Schuh2a1abec2024-07-10 20:31:16 -0700212 ],
213)
justinT2107d41ed2024-07-31 21:12:31 -0700214
Austin Schuh6ea789e2024-07-27 13:45:53 -0700215py_binary(
216 name = "casadi_velocity_mpc",
justinT2107d41ed2024-07-31 21:12:31 -0700217 srcs = [
Austin Schuh6ea789e2024-07-27 13:45:53 -0700218 "casadi_velocity_mpc.py",
justinT2107d41ed2024-07-31 21:12:31 -0700219 ],
220 deps = [
Austin Schuh6ea789e2024-07-27 13:45:53 -0700221 ":dynamics",
Austin Schuh9289e6e2024-09-02 13:10:12 -0700222 "@pip//absl_py",
justinT2107d41ed2024-07-31 21:12:31 -0700223 "@pip//casadi",
Austin Schuh6ea789e2024-07-27 13:45:53 -0700224 "@pip//matplotlib",
225 "@pip//numpy",
226 "@pip//pygobject",
227 "@pip//scipy",
justinT2107d41ed2024-07-31 21:12:31 -0700228 ],
229)
230
231py_library(
232 name = "physics_test_utils",
233 srcs = [
234 "physics_test_utils.py",
235 ],
236 deps = [
237 ":dynamics",
238 "@pip//casadi",
239 "@pip//numpy",
240 ],
241)
242
243py_binary(
244 name = "physics_debug",
245 srcs = [
246 "physics_debug.py",
247 ],
248 deps = [
249 ":physics_test_utils",
250 "@pip//matplotlib",
251 "@pip//pygobject",
252 "@pip//scipy",
253 ],
254)
Austin Schuh7fa65212024-08-18 17:20:58 -0700255
256py_binary(
257 name = "debug_fatrop",
258 srcs = [
259 "debug_fatrop.py",
260 ],
261 deps = [
262 "@pip//casadi",
263 "@pip//matplotlib",
264 "@pip//numpy",
265 "@pip//pygobject",
266 "@pip//scipy",
267 ],
268)
justinT21cc6eed02024-08-26 00:15:57 -0700269
270py_binary(
271 name = "smooth_function_graph",
272 srcs = [
273 "smooth_function_graph.py",
274 ],
275 deps = [
276 "@pip//matplotlib",
277 "@pip//numpy",
278 "@pip//pygobject",
279 "@pip//scipy",
280 ],
281)
Austin Schuh3aa49ab2024-09-02 13:14:26 -0700282
283py_binary(
284 name = "multi_casadi_velocity_mpc",
285 srcs = ["multi_casadi_velocity_mpc.py"],
286 data = [":casadi_velocity_mpc"],
287 deps = [
288 ":dynamics",
289 "@pip//absl_py",
290 "@pip//matplotlib",
291 "@pip//numpy",
292 "@pip//pygobject",
293 ],
294)