blob: e6a3798b625c84c68dd8e0d672a8ea1a21bce6b2 [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(
8 name = "swerve_drivetrain_goal_fbs",
9 srcs = ["swerve_drivetrain_goal.fbs"],
10)
11
12static_flatbuffer(
13 name = "swerve_drivetrain_status_fbs",
14 srcs = ["swerve_drivetrain_status.fbs"],
15 deps = ["//frc971/control_loops:profiled_subsystem_fbs"],
16)
17
James Kuszmauld938d332024-05-15 20:47:19 -070018static_flatbuffer(
19 name = "swerve_drivetrain_output_fbs",
20 srcs = ["swerve_drivetrain_output.fbs"],
James Kuszmauld938d332024-05-15 20:47:19 -070021 deps = ["//frc971/control_loops:can_talonfx_fbs"],
22)
23
24static_flatbuffer(
Nikolai Sohmers3f2a5072024-06-08 14:05:59 -070025 name = "swerve_drivetrain_can_position_fbs",
26 srcs = ["swerve_drivetrain_can_position.fbs"],
Nikolai Sohmers3f2a5072024-06-08 14:05:59 -070027 deps = ["//frc971/control_loops:can_talonfx_fbs"],
28)
29
30static_flatbuffer(
James Kuszmauld938d332024-05-15 20:47:19 -070031 name = "swerve_drivetrain_position_fbs",
32 srcs = ["swerve_drivetrain_position.fbs"],
James Kuszmauld938d332024-05-15 20:47:19 -070033 deps = ["//frc971/control_loops:control_loops_fbs"],
34)
35
Austin Schuh999a19e2024-05-04 14:52:39 -070036py_binary(
37 name = "simulation",
38 srcs = [
39 "simulation.py",
40 ],
41 deps = [
42 "//frc971/control_loops/python:controls",
43 "@pip//matplotlib",
44 "@pip//numpy",
45 "@pip//pygobject",
46 "@pip//sympy",
47 ],
48)
Nikolai Sohmers8412fe52024-06-09 18:01:18 -070049
50cc_library(
51 name = "swerve_control_loops",
52 srcs = ["swerve_control_loops.cc"],
53 hdrs = ["swerve_control_loops.h"],
54 target_compatible_with = ["@platforms//os:linux"],
55 deps = [
56 ":swerve_drivetrain_can_position_fbs",
57 ":swerve_drivetrain_goal_fbs",
58 ":swerve_drivetrain_output_fbs",
59 ":swerve_drivetrain_position_fbs",
60 ":swerve_drivetrain_status_fbs",
61 "//frc971/control_loops:control_loop",
62 ],
63)
64
65cc_test(
66 name = "swerve_control_test",
67 srcs = ["swerve_control_test.cc"],
68 data = [
69 ":aos_config",
70 ],
71 target_compatible_with = ["@platforms//os:linux"],
72 deps = [
73 ":swerve_control_loops",
74 ":swerve_drivetrain_can_position_fbs",
75 ":swerve_drivetrain_goal_fbs",
76 ":swerve_drivetrain_output_fbs",
77 ":swerve_drivetrain_position_fbs",
78 ":swerve_drivetrain_status_fbs",
79 "//aos/events:shm_event_loop",
80 "//aos/testing:googletest",
81 "//frc971/control_loops:control_loop_test",
82 "//frc971/control_loops:state_feedback_loop",
83 "//frc971/control_loops:team_number_test_environment",
84 ],
85)
86
87aos_config(
88 name = "aos_config",
89 src = "swerve.json",
90 flatbuffers = [
91 ":swerve_drivetrain_goal_fbs",
92 ":swerve_drivetrain_output_fbs",
93 ":swerve_drivetrain_position_fbs",
94 ":swerve_drivetrain_can_position_fbs",
95 ":swerve_drivetrain_status_fbs",
96 ],
97 target_compatible_with = ["@platforms//os:linux"],
98 deps = ["//frc971/input:aos_config"],
99)
justinT21446e4f62024-06-16 22:36:10 -0700100
101cc_library(
102 name = "motors",
103 hdrs = [
104 "motors.h",
105 ],
106 deps = [
107 "@symengine",
108 ],
109)
110
111cc_binary(
112 name = "generate_physics",
113 srcs = [
114 "generate_physics.cc",
115 ],
116 deps = [
117 ":motors",
118 "//aos:init",
119 "//aos/util:file",
Austin Schuh99f7c6a2024-06-25 22:07:44 -0700120 "@com_google_absl//absl/log",
121 "@com_google_absl//absl/log:check",
justinT21446e4f62024-06-16 22:36:10 -0700122 "@com_google_absl//absl/strings",
123 "@com_google_absl//absl/strings:str_format",
124 "@symengine",
125 ],
126)
127
128run_binary(
Austin Schuh27694fa2024-07-20 16:29:49 -0700129 name = "dynamics_codegen_cc",
justinT21446e4f62024-06-16 22:36:10 -0700130 outs = [
131 "dynamics.cc",
132 "dynamics.h",
justinT21942892b2024-07-02 22:33:50 -0700133 "dynamics.py",
justinT21446e4f62024-06-16 22:36:10 -0700134 ],
135 args = [
136 "--output_base=$(BINDIR)/",
137 "--cc_output_path=$(location :dynamics.cc)",
138 "--h_output_path=$(location :dynamics.h)",
Austin Schuh0f881092024-06-28 15:36:48 -0700139 "--casadi_py_output_path=$(location :dynamics.py)",
justinT21446e4f62024-06-16 22:36:10 -0700140 ],
141 tool = ":generate_physics",
142)
143
Austin Schuh27694fa2024-07-20 16:29:49 -0700144run_binary(
145 name = "dynamics_codegen_nocaster",
146 outs = [
147 "nocaster_dynamics.py",
148 ],
149 args = [
150 "--caster=0.0",
151 "--output_base=$(BINDIR)/",
152 "--casadi_py_output_path=$(location :nocaster_dynamics.py)",
153 ],
154 tool = ":generate_physics",
155)
156
157run_binary(
158 name = "dynamics_codegen_bigcaster",
159 outs = [
160 "bigcaster_dynamics.py",
161 ],
162 args = [
163 "--caster=0.05",
164 "--output_base=$(BINDIR)/",
165 "--casadi_py_output_path=$(location :bigcaster_dynamics.py)",
166 ],
167 tool = ":generate_physics",
168)
169
justinT21446e4f62024-06-16 22:36:10 -0700170cc_library(
justinT2107d41ed2024-07-31 21:12:31 -0700171 name = "eigen_dynamics",
justinT21446e4f62024-06-16 22:36:10 -0700172 srcs = ["dynamics.cc"],
173 hdrs = ["dynamics.h"],
174 deps = [
175 "@org_tuxfamily_eigen//:eigen",
176 ],
177)
justinT21942892b2024-07-02 22:33:50 -0700178
Austin Schuh6ea789e2024-07-27 13:45:53 -0700179py_library(
180 name = "dynamics",
justinT21942892b2024-07-02 22:33:50 -0700181 srcs = [
Austin Schuh6ea789e2024-07-27 13:45:53 -0700182 "bigcaster_dynamics.py",
183 "dynamics.py",
184 "nocaster_dynamics.py",
justinT21942892b2024-07-02 22:33:50 -0700185 ],
186 deps = [
Austin Schuh6ea789e2024-07-27 13:45:53 -0700187 "@pip//casadi",
justinT21942892b2024-07-02 22:33:50 -0700188 ],
189)
Austin Schuh2a1abec2024-07-10 20:31:16 -0700190
191py_test(
192 name = "physics_test",
193 srcs = [
Austin Schuh2a1abec2024-07-10 20:31:16 -0700194 "physics_test.py",
195 ],
196 target_compatible_with = ["@platforms//cpu:x86_64"],
197 deps = [
Austin Schuh6ea789e2024-07-27 13:45:53 -0700198 ":dynamics",
justinT2107d41ed2024-07-31 21:12:31 -0700199 ":physics_test_utils",
Austin Schuh2a1abec2024-07-10 20:31:16 -0700200 "@pip//casadi",
201 "@pip//numpy",
202 ],
203)
justinT2107d41ed2024-07-31 21:12:31 -0700204
Austin Schuh6ea789e2024-07-27 13:45:53 -0700205py_binary(
206 name = "casadi_velocity_mpc",
justinT2107d41ed2024-07-31 21:12:31 -0700207 srcs = [
Austin Schuh6ea789e2024-07-27 13:45:53 -0700208 "casadi_velocity_mpc.py",
justinT2107d41ed2024-07-31 21:12:31 -0700209 ],
210 deps = [
Austin Schuh6ea789e2024-07-27 13:45:53 -0700211 ":dynamics",
justinT2107d41ed2024-07-31 21:12:31 -0700212 "@pip//casadi",
Austin Schuh6ea789e2024-07-27 13:45:53 -0700213 "@pip//matplotlib",
214 "@pip//numpy",
215 "@pip//pygobject",
216 "@pip//scipy",
justinT2107d41ed2024-07-31 21:12:31 -0700217 ],
218)
219
220py_library(
221 name = "physics_test_utils",
222 srcs = [
223 "physics_test_utils.py",
224 ],
225 deps = [
226 ":dynamics",
227 "@pip//casadi",
228 "@pip//numpy",
229 ],
230)
231
232py_binary(
233 name = "physics_debug",
234 srcs = [
235 "physics_debug.py",
236 ],
237 deps = [
238 ":physics_test_utils",
239 "@pip//matplotlib",
240 "@pip//pygobject",
241 "@pip//scipy",
242 ],
243)