Class SpeedConverter

java.lang.Object
me.wobblyyyy.pathfinder.kinematics.SpeedConverter

public class SpeedConverter
extends java.lang.Object
Convert between wheel speed (-1 to 1) and velocity (in inches per second, most often). Mostly used for odometry.
Since:
0.3.0
Author:
Colin Robertson
  • Field Summary

    Fields
    Modifier and Type Field Description
    private GearRatio gearRatio
    The gear ratio between the motor and the wheel.
    private RotationalVelocity velocity
    The wheel's rotational velocity.
    private WheelSize wheelSize
    The wheel's size.
  • Constructor Summary

    Constructors
    Constructor Description
    SpeedConverter​(RotationalVelocity velocity, WheelSize wheelSize)
    Create a new SpeedConverter instance that can be used to convert between speed values (assigned by states) and real velocities that can be used for odometry purposes.
    SpeedConverter​(RotationalVelocity velocity, WheelSize wheelSize, GearRatio gearRatio)
    Create a new SpeedConverter instance that can be used to convert between speed values (assigned by states) and real velocities that can be used for odometry purposes.
  • Method Summary

    Modifier and Type Method Description
    double feetPerMinute()
    Get the speed of the wheel in feet per minute.
    double feetPerSecond()
    Get the speed of the wheel in feet per second.
    static me.wobblyyyy.edt.StaticArray<SwerveState> getSwerveModuleStates​(me.wobblyyyy.edt.StaticArray<SwerveState> originalStates, me.wobblyyyy.edt.StaticArray<SpeedConverter> speedConverters)
    Convert a StaticArray of swerve module states to a more odometrically-usable version of those same states by using another StaticArray of speed converters.
    double inchesPerMinute()
    Get the speed of the wheel in inches per minute.
    double inchesPerSecond()
    Get the speed of the wheel in inches per second.
    double metersPerMinute()
    Get the speed of the wheel in meters per minute.
    double metersPerSecond()
    Get the speed of the wheel in meters per second.
    double milesPerHour()
    This one's just for fun - don't actually use it.

    Methods inherited from class java.lang.Object

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

    • velocity

      private final RotationalVelocity velocity
      The wheel's rotational velocity.
    • wheelSize

      private final WheelSize wheelSize
      The wheel's size.
    • gearRatio

      private final GearRatio gearRatio
      The gear ratio between the motor and the wheel.
  • Constructor Details

    • SpeedConverter

      public SpeedConverter​(RotationalVelocity velocity, WheelSize wheelSize, GearRatio gearRatio)
      Create a new SpeedConverter instance that can be used to convert between speed values (assigned by states) and real velocities that can be used for odometry purposes.
      Parameters:
      velocity - the wheel velocity system.
      wheelSize - the size of the wheel.
      gearRatio - the gear ratio between the motor and the wheel.
    • SpeedConverter

      public SpeedConverter​(RotationalVelocity velocity, WheelSize wheelSize)
      Create a new SpeedConverter instance that can be used to convert between speed values (assigned by states) and real velocities that can be used for odometry purposes. This constructor is an overload for the other constructor. This constructor assumes a gear ratio of 1:1.
      Parameters:
      velocity - the wheel velocity system.
      wheelSize - the size of the wheel.
  • Method Details

    • inchesPerSecond

      public double inchesPerSecond()
      Get the speed of the wheel in inches per second.
      Returns:
      the speed of the wheel in inches per second.
    • inchesPerMinute

      public double inchesPerMinute()
      Get the speed of the wheel in inches per minute.
      Returns:
      the speed of the wheel in inches per minute.
    • feetPerSecond

      public double feetPerSecond()
      Get the speed of the wheel in feet per second.
      Returns:
      the speed of the wheel in feet per second.
    • feetPerMinute

      public double feetPerMinute()
      Get the speed of the wheel in feet per minute.
      Returns:
      the speed of the wheel in feet per minute.
    • metersPerSecond

      public double metersPerSecond()
      Get the speed of the wheel in meters per second.
      Returns:
      the speed of the wheel in meters per second.
    • metersPerMinute

      public double metersPerMinute()
      Get the speed of the wheel in meters per minute.
      Returns:
      the speed of the wheel in meters per second.
    • milesPerHour

      public double milesPerHour()
      This one's just for fun - don't actually use it.
      Returns:
      the robot's speed, in miles per hour.
    • getSwerveModuleStates

      public static me.wobblyyyy.edt.StaticArray<SwerveState> getSwerveModuleStates​(me.wobblyyyy.edt.StaticArray<SwerveState> originalStates, me.wobblyyyy.edt.StaticArray<SpeedConverter> speedConverters)
      Convert a StaticArray of swerve module states to a more odometrically-usable version of those same states by using another StaticArray of speed converters.

      These speed converters work by using the rotational velocity of each of the swerve chassis' wheels to determine the current movement of the robot. Using real velocity is much more useful than using simulated velocity. Although you could technically use the SwerveOdometry class directly, it wouldn't be very accurate - using this method helps to improve the accuracy of exactly that.

      Parameters:
      originalStates - a StaticArray of original states.
      speedConverters - a StaticArray of speed converters. This array must be the same size as the original states array, or an exception will be thrown.
      Returns:
      actually accurate swerve module states. Not based on speed, but based on the velocity of each of the wheels. This is significantly more accurate than the alternatives.