Class SwerveChassisTracker

java.lang.Object
me.wobblyyyy.pathfinder.tracking.swerve.SwerveChassisTracker
All Implemented Interfaces:
Odometry, Tracker
Direct Known Subclasses:
GyroSwerveTracker

public class SwerveChassisTracker
extends java.lang.Object
implements Tracker
Track the position of a swerve chassis with four swerve modules.

As with any of the trackers in this library, this is compatible with the Pathfinder system out of the box. In fact, you can even convert your swerve drivetrain into a swerve chassis tracker pretty easily by using the ChassisConverter class.

Much of the tracking math behind the swerve chassis tracker happens elsewhere in the code. A lot of it happens in the SwerveModuleTracker class, which is included as an `@see` tag in this doc.

Since:
0.1.0
Author:
Colin Robertson
See Also:
SwerveModuleTracker
  • Field Details

    • frTurn

      private final Encoder frTurn
      The front-right turn motor's encoder.
    • frDrive

      private final Encoder frDrive
      The front-right drive motor's encoder.
    • flTurn

      private final Encoder flTurn
      The front-left turn motor's encoder.
    • flDrive

      private final Encoder flDrive
      The front-left drive motor's encoder.
    • brTurn

      private final Encoder brTurn
      The back-right turn motor's encoder.
    • brDrive

      private final Encoder brDrive
      The back-right drive motor's encoder.
    • blTurn

      private final Encoder blTurn
      The back-left turn motor's encoder.
    • blDrive

      private final Encoder blDrive
      The back-left dive motor's encoder.
    • wheelDiameter

      public final double wheelDiameter
      The diameter of each of the four drive wheels. As usual, this value is measured in inches.
    • gapX

      public final double gapX
      The X distance, measured in inches, between the FR-FL pair of swerve modules. This distance should be measured from the very center of the swerve module's rotational radius.
    • gapY

      public final double gapY
      The Y distance, measured in inches, between the FR-FL pair of swerve modules. This distance should be measured from the very center of the swerve module's rotational radius.
    • fr

      private final SwerveModuleTracker fr
      Front-right swerve tracker.
    • fl

      private final SwerveModuleTracker fl
      Front-left swerve tracker.
    • br

      private final SwerveModuleTracker br
      Back-right swerve tracker.
    • bl

      private final SwerveModuleTracker bl
      Back-left swerve tracker.
  • Constructor Details

    • SwerveChassisTracker

      public SwerveChassisTracker​(Encoder frTurn, Encoder frDrive, Encoder flTurn, Encoder flDrive, Encoder brTurn, Encoder brDrive, Encoder blTurn, Encoder blDrive, double wheelDiameter, double gapX, double gapY)
      Create a new swerve chassis tracker! Yay!

      Each of these constructor parameters is detailed in their own field JavaDocs in this Java file. If you're confused about what's going on, or what the meaning of a term is, you should go ahead and read those.

      Parameters:
      frTurn - FR turn encoder
      frDrive - FR drive encoder
      flTurn - FL turn encoder
      flDrive - FL drive encoder
      brTurn - BR turn encoder
      brDrive - BR drive encoder
      blTurn - BL turn encoder
      blDrive - BL drive encoder
      wheelDiameter - see: wheelDiameter
      gapX - see: gapX
      gapY - see: gapY
    • SwerveChassisTracker

      public SwerveChassisTracker​(SwerveModuleTracker fr, SwerveModuleTracker fl, SwerveModuleTracker br, SwerveModuleTracker bl)
      Create a new swerve chassis tracker.
      Parameters:
      fr - front-right tracker.
      fl - front-left tracker.
      br - back-right tracker.
      bl - back-left tracker.
  • Method Details

    • getHeadlessPoint

      private HeadingPoint getHeadlessPoint()
      Get the chassis' position WITHOUT HEADING.

      This point is calculated by averaging the position of all four of the swerve modules. In theory, this should give the chassis's center position, as the robot's position is defined as the very center of it.

      Returns:
      the chassis position, without heading.
    • getPos

      public HeadingPoint getPos()
      Get the robot's position and heading.

      THIS CLASS DOES NOT SUPPORT TRACKING THE HEADING OF THE ROBOT. If you'd like to track the heading of the robot, you're going to have to do that some other way. Possibly the SwerveHeadingChassisTracker class that's in the very same package as this one. Just possibly.

      Specified by:
      getPos in interface Odometry
      Returns:
      the robot's position and heading.
      See Also:
      getHeadlessPoint()
    • update

      public void update()
      Update the odometry system.

      As I'm sure you've seen me say a million times already, this NEEDS to be called as frequently as possible. A whole thread can even be dedicated to doing just this.

      Specified by:
      update in interface Odometry
      See Also:
      SwerveModuleTracker.update()
    • getFrPos

      public HeadingPoint getFrPos()
      Get the position of the front right swerve module.
      Specified by:
      getFrPos in interface Tracker
      Returns:
      the front right swerve module's position.
    • getFlPos

      public HeadingPoint getFlPos()
      Get the position of the front left swerve module.
      Specified by:
      getFlPos in interface Tracker
      Returns:
      the front left swerve module's position.
    • getBrPos

      public HeadingPoint getBrPos()
      Get the position of the back right swerve module.
      Specified by:
      getBrPos in interface Tracker
      Returns:
      the back right swerve module's position.
    • getBlPos

      public HeadingPoint getBlPos()
      Get the position of the back left swerve module.
      Specified by:
      getBlPos in interface Tracker
      Returns:
      the back left swerve module's position.