Class SwerveModuleTracker

java.lang.Object
me.wobblyyyy.pathfinder.tracking.swerve.SwerveModuleTracker

public class SwerveModuleTracker
extends java.lang.Object
Track the position of a swerve module.

In essence, this is a wrapper of a combination of AngleTracker and PointTracker - that's all that a swerve module needs, in reality.

Since:
0.1.0
Author:
Colin Robertson
See Also:
AngleTracker, PointTracker
  • Field Summary

    Fields
    Modifier and Type Field Description
    private Point offset
    The module's offset.
    private PointTracker tDrive
    The point tracker - used for tracking the position of the point.
    private AngleTracker tTurn
    The angle tracker - used for tracking the angle of the drive wheel.
  • Constructor Summary

    Constructors
    Constructor Description
    SwerveModuleTracker​(Encoder turnEncoder, Encoder driveEncoder, double driveWheelDiameter, Point offset)
    Create a new swerve module tracker! Woot-woot!
  • Method Summary

    Modifier and Type Method Description
    protected Encoder gd()
    Get the drive encoder.
    HeadingPoint getPosition()
    Get the position of the module tracker.
    protected Encoder gt()
    Get the turn encoder.
    protected double gwd()
    Get the drive wheel's diameter.
    protected double gxo()
    Get the swerve module's X offset.
    protected double gyo()
    Get the swerve module's Y offset.
    void update()
    Update the turn tracker and the drive tracker.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • tTurn

      private final AngleTracker tTurn
      The angle tracker - used for tracking the angle of the drive wheel.
    • tDrive

      private final PointTracker tDrive
      The point tracker - used for tracking the position of the point.
    • offset

      private final Point offset
      The module's offset.
  • Constructor Details

    • SwerveModuleTracker

      public SwerveModuleTracker​(Encoder turnEncoder, Encoder driveEncoder, double driveWheelDiameter, Point offset)
      Create a new swerve module tracker! Woot-woot!
      Parameters:
      turnEncoder - the encoder that tracks the angle of the drive wheel. In most swerve modules, a non-motor encoder tracks this for you - you just need to find its CPR and get everything set up, and this should handle the rest for you.
      driveEncoder - the encoder that tracks the movement of the drive wheel. Because encoders are unidirectional, the turnEncoder is needed to accurately keep track of the position of the point.
      driveWheelDiameter - the diameter of the drive wheel, preferably measured in inches.
      offset - the swerve module's offset from the center of the robot. This value is INCREDIBLY important to accurately tracking the position of the robot - if this value is off, the chassis position will be as well.
  • Method Details

    • update

      public void update()
      Update the turn tracker and the drive tracker.

      As stressed in the PointTracker class, this needs to be updated as frequently as possible.

      The more frequently this method is called, the more accurate the robot's position will be. X and Y values don't suffer all that much, but the angle they're adjusted at will.

      Generally, it's a wise idea to have a thread dedicated to updating the odometric position of the robot.

      None of the math that's responsible for tracking the chassis' position is stored in this class. Rather, it's available in the point and angle tracker classes, both of which have an `@see` tag.

      See Also:
      AngleTracker.update(), PointTracker.update(double)
    • getPosition

      public HeadingPoint getPosition()
      Get the position of the module tracker.

      In order to make the heading more accurate, we opt to use the turn's position rather than the drive's position. They should be the same anyways, but... y'know. Just in case.

      Returns:
      the module's position.
    • gt

      protected Encoder gt()
      Get the turn encoder.
      Returns:
      the turn encoder.
    • gd

      protected Encoder gd()
      Get the drive encoder.
      Returns:
      the drive encoder.
    • gwd

      protected double gwd()
      Get the drive wheel's diameter.
      Returns:
      the drive wheel's diameter.
    • gxo

      protected double gxo()
      Get the swerve module's X offset.
      Returns:
      the swerve module's X offset.
    • gyo

      protected double gyo()
      Get the swerve module's Y offset.
      Returns:
      the swerve module's Y offset.