Class DriveTurnInputProcessor
java.lang.Object
com.stuypulse.robot.util.swerve.swerveinput.DriveTurnInputProcessor
DriveTurnInputProcessor
Class for processing driver turn input for the drivetrain. It's intended to replace StuyLib's IStream 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 max angular velocity
- 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 edu.wpi.first.wpilibj2.command.button.CommandXboxControllerprivate final doubleprivate final edu.wpi.first.math.filter.LinearFilterprivate final doubleThe max angular velocity in radians per secondprivate final doubleprivate doubleThe processed angular velocity after the full processing and filtering. -
Constructor Summary
ConstructorsConstructorDescriptionDriveTurnInputProcessor(edu.wpi.first.wpilibj2.command.button.CommandXboxController controller, double deadband, double power, double maxAngularVelocity, double rc) Constructor for the DriveInputProcessor -
Method Summary
Modifier and TypeMethodDescriptionprivate DriveTurnInputProcessorApplies a deadband to the currentprocessedAngularVelocityvalue.private DriveTurnInputProcessorApplies a low pass filter toprocessedAngularVelocityusing aLinearFilter.private DriveTurnInputProcessorApply a power curve to the currentprocessedAngularVelocityvalue.private DriveTurnInputProcessorScale theprocessedAngularVelocityvalue to the robot's maximum velocity.doubleget()Get the processed angular velocityprivate DriveTurnInputProcessorRead the raw joystick axis value for the right X axis and store it inprocessedAngularVelocityvoidupdate()Update method that processes all filters and updates the filtered angular velocity.
-
Field Details
-
controller
-
deadband
-
power
-
maxAngularVelocity
The max angular velocity in radians per second -
lowPassFilter
-
processedAngularVelocity
The processed angular velocity after the full processing and filtering.
-
-
Constructor Details
-
DriveTurnInputProcessor
public DriveTurnInputProcessor(edu.wpi.first.wpilibj2.command.button.CommandXboxController controller, double deadband, double power, double maxAngularVelocity, double rc) Constructor for the DriveInputProcessor
Creates a new DriveInputProcessor with the specified parameters processes the input periodically.
- Parameters:
controller- The CommandXboxController to get driver input fromdeadband- The deadband to apply to the input (0-1)power- The power to apply to the inputmaxAngularVelocity- The maximum angular velocity to scale the input to (radians/s)rc- The time constant for the low pass filter (seconds)
-
-
Method Details
-
getRightX
Read the raw joystick axis value for the right X axis and store it inprocessedAngularVelocity- Returns:
- This instance of the class
-
applyDeadband
Applies a deadband to the currentprocessedAngularVelocityvalue.- Returns:
- This instance of the class
-
applyPowerCurve
Apply a power curve to the currentprocessedAngularVelocityvalue.- Returns:
- This instance of the class
-
applyScalingToMaxAngularVelocity
Scale theprocessedAngularVelocityvalue to the robot's maximum velocity.- Returns:
- This instance of the class
-
applyLowPassFilter
Applies a low pass filter toprocessedAngularVelocityusing aLinearFilter. This smooths out the input and reduces noise.- Returns:
- This instance of the class
-
update
Update method that processes all filters and updates the filtered angular velocity. This should be called within theCommand.execute()method of the command using this DriveTurnInputProcessor. -
get
Get the processed angular velocity- Returns:
- The processed angular velocity
-