Class DriveInputProcessor
java.lang.Object
com.stuypulse.robot.util.swerve.swerveinput.DriveInputProcessor
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 Summary
FieldsModifier and TypeFieldDescriptionprivate final doubleprivate final edu.wpi.first.wpilibj2.command.button.CommandXboxControllerprivate final doubleprivate final doubleThe max velocity in meters per second/private final doubleprivate edu.wpi.first.math.geometry.Translation2dThe speed vector after the full processing and filtering.private final edu.wpi.first.math.filter.LinearFilterprivate final edu.wpi.first.math.filter.SlewRateLimiterprivate final edu.wpi.first.math.filter.LinearFilterprivate final edu.wpi.first.math.filter.SlewRateLimiter -
Constructor Summary
ConstructorsConstructorDescriptionDriveInputProcessor(edu.wpi.first.wpilibj2.command.button.CommandXboxController controller, double deadband, double clamp, double power, double maxVelocity, double maxAcceleration, double rc) Constructor for the DriveInputProcessor -
Method Summary
Modifier and TypeMethodDescriptionprivate DriveInputProcessorLimits the magnitude of the currentprocessedSpeedvector to a maximumprivate DriveInputProcessorApply a deadband on the X and Y axes to the currentprocessedSpeedvector usingMathUtil.applyDeadband(double, double, double)private DriveInputProcessorApplies a low pass filter toprocessedSpeedusing aLinearFilterfor each axis.private DriveInputProcessorApply a power curve to the currentprocessedSpeedvector.private DriveInputProcessorApplies a rate limit toprocessedSpeedusing aSlewRateLimiterfor each axis.private DriveInputProcessorScale theprocessedSpeedvector to the robot's maximum velocity.edu.wpi.first.math.geometry.Translation2dget()Get the processed speed.private DriveInputProcessorRead the raw joystick axes and store them as a velocity vector inprocessedSpeedvoidupdate()Update method that processes all filters and updates the filtered speed.
-
Field Details
-
controller
-
deadband
-
clamp
-
power
-
maxVelocity
The max velocity in meters per second/ -
xRateLimiter
-
yRateLimiter
-
xLowPassFilter
-
yLowPassFilter
-
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 fromdeadband- 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 inputmaxVelocity- 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 inprocessedSpeed- Returns:
- This instance of the class
-
applyDeadband
Apply a deadband on the X and Y axes to the currentprocessedSpeedvector usingMathUtil.applyDeadband(double, double, double)- Returns:
- This instance of the class
-
applyClamp
Limits the magnitude of the currentprocessedSpeedvector to a maximum- Returns:
- This instance of the class
-
applyPowerCurve
Apply a power curve to the currentprocessedSpeedvector. The vector's magnitude is raised according to the configured power while preserving direction.- Returns:
- This instance of the class
-
applyScalingToMaxVelocity
Scale theprocessedSpeedvector 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 toprocessedSpeedusing aSlewRateLimiterfor 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 toprocessedSpeedusing aLinearFilterfor each axis. This smooths out the velocity vector and reduces noise.- Returns:
- This instance of the class
-
update
Update method that processes all filters and updates the filtered speed. This should be called within the start of theCommand.execute()method of the command using DriveInputProcessor. -
get
Get the processed speed.- Returns:
- A Translation2d representing the processed speed
-