Class DriveInputProcessor

java.lang.Object
com.stuypulse.robot.util.swerve.DriveInputProcessor

public class DriveInputProcessor extends Object

DriveInputProcessor

Class for processing driver input for the drivetrain. It's intended to replace StuyLib's VStream and Filters and use pure WPILib and Java.

This will be used to be as close as the original StuyLib implementation as possible It will be used for

  • Applying deadbands
  • Applying power curves
  • Limiting magnitude to 1
  • Scaling to max velocity
  • Applying rate limits
  • Applying a low pass filter

To use within a command, create an instance of this class and call the update() method in the start of the Command.

To get the processed speed, call the get() method.

  • Field Details

    • controller

      private final org.wpilib.command3.button.CommandGamepad controller
    • deadband

      private final double deadband
    • power

      private final double power
    • maxVelocity

      private final org.wpilib.units.measure.LinearVelocity maxVelocity
      The max velocity in meters per second/
    • xRateLimiter

      private final org.wpilib.math.filter.SlewRateLimiter xRateLimiter
    • yRateLimiter

      private final org.wpilib.math.filter.SlewRateLimiter yRateLimiter
    • xLowPassFilter

      private final org.wpilib.math.filter.LinearFilter xLowPassFilter
    • yLowPassFilter

      private final org.wpilib.math.filter.LinearFilter yLowPassFilter
    • processedSpeed

      private org.wpilib.math.geometry.Translation2d processedSpeed
      The speed vector after the full processing and filtering.
  • Constructor Details

    • DriveInputProcessor

      public DriveInputProcessor(org.wpilib.command3.button.CommandGamepad controller, double deadband, double power, org.wpilib.units.measure.LinearVelocity maxVelocity, org.wpilib.units.measure.LinearAcceleration maxAcceleration, double rc)

      Constructor for the DriveInputProcessor

      Creates a new DriveInputProcessor with the specified parameters and processes the input periodically.

      Parameters:
      controller - The CommandXboxController to get driver input from
      deadband - The deadband to apply to the input (0-1)
      power - The power to apply to the input
      maxVelocity - The maximum velocity to scale the input to
      maxAcceleration - The maximum acceleration to apply to the input
      rc - The time constant for the low pass filter (seconds)
  • Method Details

    • getDriverInputAsVelocity

      Read the raw joystick axes and store them as a velocity vector in processedSpeed
      Returns:
      This instance of the class
    • applyDeadband

      Apply a deadband on the X and Y axes to the current processedSpeed vector using MathUtil.applyDeadband(double, double, double)
      Returns:
      This instance of the class
    • applyLimitMagnitudeToOne

      Limits the magnitude of the current processedSpeed vector to 1
      Returns:
      This instance of the class
    • applyPowerCurve

      Apply a power curve to the current processedSpeed vector. The vector's magnitude is raised according to the configured power while preserving direction.
      Returns:
      This instance of the class
    • applyScalingToMaxVelocity

      Scale the processedSpeed vector to the robot's maximum velocity. Multiplies the current vector by maxVelocity (m/s).
      Returns:
      This instance of the class
    • applyRateLimit

      Applies a rate limit to processedSpeed using a SlewRateLimiter for each axis. This limits the rate of change of the velocity vector to the max acceleration (m/s^2).
      Returns:
      This instance of the class
    • applyLowPassFilter

      Applies a low pass filter to processedSpeed using a LinearFilter for each axis. This smooths out the velocity vector and reduces noise.
      Returns:
      This instance of the class
    • update

      public void update()
      Update method that processes all filters and updates the filtered speed. This should be called once per cycle in the Command using this processor, before retrieving the processed velocity vector via get().
    • get

      public org.wpilib.math.geometry.Translation2d get()
      Get the processed speed.
      Returns:
      A Translation2d representing the processed speed