Update swerve drivetrain position messages & logic
This makes it so that the swerve drivetrain positions are sent in two
separate position messages (for FPGA-based and CAN-based positions),
using message definitions from the frc971/ folder.
Also refactors the SwerveModule class/usage a bit.
Removes the follower wheels from the y2024_swerve code.
Change-Id: I36898c3337b5a1437ce0c2a0189fd317929f1986
Signed-off-by: James Kuszmaul <jabukuszmaul+collab@gmail.com>
diff --git a/frc971/control_loops/swerve/BUILD b/frc971/control_loops/swerve/BUILD
index 4e06932..ea6dd7c 100644
--- a/frc971/control_loops/swerve/BUILD
+++ b/frc971/control_loops/swerve/BUILD
@@ -8,6 +8,13 @@
)
static_flatbuffer(
+ name = "swerve_drivetrain_can_position_fbs",
+ srcs = ["swerve_drivetrain_can_position.fbs"],
+ visibility = ["//visibility:public"],
+ deps = ["//frc971/control_loops:can_talonfx_fbs"],
+)
+
+static_flatbuffer(
name = "swerve_drivetrain_position_fbs",
srcs = ["swerve_drivetrain_position.fbs"],
visibility = ["//visibility:public"],
diff --git a/frc971/control_loops/swerve/swerve_drivetrain_can_position.fbs b/frc971/control_loops/swerve/swerve_drivetrain_can_position.fbs
new file mode 100644
index 0000000..957bce8
--- /dev/null
+++ b/frc971/control_loops/swerve/swerve_drivetrain_can_position.fbs
@@ -0,0 +1,18 @@
+include "frc971/control_loops/can_talonfx.fbs";
+
+namespace frc971.control_loops.swerve;
+
+table SwerveModuleCanPosition {
+ rotation: frc971.control_loops.CANTalonFX (id: 0);
+ translation: frc971.control_loops.CANTalonFX (id: 1);
+}
+
+// CAN Readings from the CAN sensor reader loop for each swerve module
+table CanPosition {
+ front_left: SwerveModuleCanPosition (id: 0);
+ front_right: SwerveModuleCanPosition (id: 1);
+ back_left: SwerveModuleCanPosition (id: 2);
+ back_right: SwerveModuleCanPosition (id: 3);
+}
+
+root_type CanPosition;
diff --git a/frc971/control_loops/swerve/swerve_drivetrain_output.fbs b/frc971/control_loops/swerve/swerve_drivetrain_output.fbs
index 43ba0ed..72517a6 100644
--- a/frc971/control_loops/swerve/swerve_drivetrain_output.fbs
+++ b/frc971/control_loops/swerve/swerve_drivetrain_output.fbs
@@ -1,4 +1,4 @@
-namespace frc971.control_loops.drivetrain.swerve;
+namespace frc971.control_loops.swerve;
table SwerveModuleOutput {
// Current in Amps.
diff --git a/frc971/control_loops/swerve/swerve_drivetrain_position.fbs b/frc971/control_loops/swerve/swerve_drivetrain_position.fbs
index bad8af1..a5c921a 100644
--- a/frc971/control_loops/swerve/swerve_drivetrain_position.fbs
+++ b/frc971/control_loops/swerve/swerve_drivetrain_position.fbs
@@ -1,17 +1,19 @@
-namespace frc971.control_loops.drivetrain.swerve;
+include "frc971/control_loops/control_loops.fbs";
+
+namespace frc971.control_loops.swerve;
table SwerveModulePosition {
- // Rotation in radians
- rotation_encoder:double (id: 0);
- // Translation in meters
- translation_encoder:double (id: 1);
+ // Position of the mag encoder for the rotation of the module.
+ rotation_position: frc971.AbsolutePosition (id: 0);
}
+// Captures all of the roborio-sourced position information for a
+// swerve drivetrain.
table Position {
- front_left_position:SwerveModulePosition (id: 0);
- front_right_position:SwerveModulePosition (id: 1);
- back_left_position:SwerveModulePosition (id: 2);
- back_right_position:SwerveModulePosition (id: 3);
+ front_left:SwerveModulePosition (id: 0);
+ front_right:SwerveModulePosition (id: 1);
+ back_left:SwerveModulePosition (id: 2);
+ back_right:SwerveModulePosition (id: 3);
}
root_type Position;