blob: ed2c604c9fdbb2f3157b18acc087c41e3116f99b [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",
120 "@com_github_google_glog//:glog",
121 "@com_google_absl//absl/strings",
122 "@com_google_absl//absl/strings:str_format",
123 "@symengine",
124 ],
125)
126
127run_binary(
128 name = "dynamics_codegen",
129 outs = [
130 "dynamics.cc",
131 "dynamics.h",
justinT21942892b2024-07-02 22:33:50 -0700132 "dynamics.py",
Austin Schuh0f881092024-06-28 15:36:48 -0700133 "numpy_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 "--py_output_path=$(location :numpy_dynamics.py)",
140 "--casadi_py_output_path=$(location :dynamics.py)",
justinT21446e4f62024-06-16 22:36:10 -0700141 ],
142 tool = ":generate_physics",
143)
144
145cc_library(
146 name = "dynamics",
147 srcs = ["dynamics.cc"],
148 hdrs = ["dynamics.h"],
149 deps = [
150 "@org_tuxfamily_eigen//:eigen",
151 ],
152)
justinT21942892b2024-07-02 22:33:50 -0700153
154py_binary(
155 name = "dynamics_sim",
156 srcs = [
justinT21942892b2024-07-02 22:33:50 -0700157 "dynamics_sim.py",
Austin Schuh0f881092024-06-28 15:36:48 -0700158 "numpy_dynamics.py",
justinT21942892b2024-07-02 22:33:50 -0700159 ],
160 deps = [
161 "//frc971/control_loops/python:controls",
162 "@pip//matplotlib",
163 "@pip//numpy",
164 "@pip//pygobject",
165 "@pip//scipy",
166 ],
167)
Austin Schuh2a1abec2024-07-10 20:31:16 -0700168
169py_test(
170 name = "physics_test",
171 srcs = [
172 "dynamics.py",
173 "physics_test.py",
174 ],
175 target_compatible_with = ["@platforms//cpu:x86_64"],
176 deps = [
177 "@pip//casadi",
178 "@pip//numpy",
179 ],
180)