Class TuningCommands
This class provides reusable command sequences for empirically determining drivetrain parameters such as feedforward gains and effective wheel radius. These commands are intended to be run manually during calibration and development, not during normal match operation.
This class is non-instantiable and only contains static factory methods.
-
Method Summary
Modifier and TypeMethodDescriptionstatic CommandfeedforwardCharacterization(Swerve swerve, DoubleConsumer runCharacterization, DoubleSupplier getFFCharacterizationVelocity) Creates a command to characterize drivetrain feedforward constants.static CommandwheelRadiusCharacterization(Swerve swerve, Consumer<ChassisSpeeds> setModuleStates, Supplier<double[]> getWheelRadiusCharacterizationPositions, Supplier<Rotation2d> gyroYaw) Creates a command to characterize the effective wheel radius of the drivetrain.
-
Method Details
-
feedforwardCharacterization
public static Command feedforwardCharacterization(Swerve swerve, DoubleConsumer runCharacterization, DoubleSupplier getFFCharacterizationVelocity) Creates a command to characterize drivetrain feedforward constants.This routine performs a quasi-static ramp test by slowly increasing applied voltage while measuring the resulting drivetrain velocity. The collected data is fit using linear regression to estimate:
- kS - static friction voltage
- kV - velocity-proportional voltage
The characterization process consists of:
- Orient all modules to face forward
- Holding zero output to allow modules to fully orient
- Linearly ramping voltage at a fixed rate
- Recording velocity and voltage samples each loop
When the command is cancelled, the collected samples are fit and the resulting constants are printed to the console and logged.
This routine should be run on flat carpet with minimal disturbances.
- Parameters:
swerve- the swerve subsystem being characterizedrunCharacterization- consumer that applies a raw voltage command to the drivetraingetFFCharacterizationVelocity- supplier that returns the current drivetrain velocity for sampling- Returns:
- a command that performs feedforward characterization
-
wheelRadiusCharacterization
public static Command wheelRadiusCharacterization(Swerve swerve, Consumer<ChassisSpeeds> setModuleStates, Supplier<double[]> getWheelRadiusCharacterizationPositions, Supplier<Rotation2d> gyroYaw) Creates a command to characterize the effective wheel radius of the drivetrain.This routine estimates wheel radius by rotating the robot in place and comparing the integrated gyro rotation against the average wheel travel. The wheel radius is computed using the relationship:
wheelRadius = (robotRotation * driveBaseRadius) / wheelTravel
The command runs two sequences in parallel:
- A drive sequence that smoothly accelerates rotational speed
- A measurement sequence that integrates gyro rotation and wheel deltas
Intermediate values and the computed wheel radius are logged continuously for validation and offline analysis.
This routine assumes:
- Accurate gyro measurements
- Consistent wheel traction during rotation
- Correct drivetrain geometry constants
- Parameters:
swerve- the swerve subsystem being characterizedsetModuleStates- consumer used to command rotational chassis speedsgetWheelRadiusCharacterizationPositions- supplier of wheel position measurementsgyroYaw- supplier of the current robot yaw angle- Returns:
- a command that performs wheel radius characterization
-