Class DriveInputProcessor

java.lang.Object
com.stuypulse.robot.util.swerve.swerveinput.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
  • 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 Command.execute() method of the command.

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

  • Field Details

    • controller

      private final edu.wpi.first.wpilibj2.command.button.CommandXboxController controller
    • deadband

      private final double deadband
    • clamp

      private final double clamp
    • power

      private final double power
    • maxVelocity

      private final double maxVelocity
      The max velocity in meters per second/
    • xRateLimiter

      private final edu.wpi.first.math.filter.SlewRateLimiter xRateLimiter
    • yRateLimiter

      private final edu.wpi.first.math.filter.SlewRateLimiter yRateLimiter
    • xLowPassFilter

      private final edu.wpi.first.math.filter.LinearFilter xLowPassFilter
    • yLowPassFilter

      private final edu.wpi.first.math.filter.LinearFilter yLowPassFilter
    • processedSpeed

      private edu.wpi.first.math.geometry.Translation2d processedSpeed
      The speed vector after the full processing and filtering.
  • Constructor Details

    • DriveInputProcessor

      public DriveInputProcessor(edu.wpi.first.wpilibj2.command.button.CommandXboxController controller, double deadband, double clamp, double power, double maxVelocity, double 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)
      clamp - The maximum magnitude of the input vector (0-1)
      power - The power to apply to the input
      maxVelocity - The maximum velocity to scale the input to (m/s)
      maxAcceleration - The maximum acceleration to apply to the input (m/s^2)
      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
    • applyClamp

      Limits the magnitude of the current processedSpeed vector to a maximum
      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 within the start of the Command.execute() method of the command using DriveInputProcessor.
    • get

      public edu.wpi.first.math.geometry.Translation2d get()
      Get the processed speed.
      Returns:
      A Translation2d representing the processed speed