-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
copy paste copy schmaste sys id routines
- Loading branch information
Showing
7 changed files
with
177 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
95 changes: 95 additions & 0 deletions
95
src/main/java/frc/robot/commands/DriveCommands/WheelBaseCharacterizationRoutineCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
package frc.robot.commands.DriveCommands; | ||
|
||
import edu.wpi.first.math.filter.SlewRateLimiter; | ||
import edu.wpi.first.math.geometry.Rotation2d; | ||
import edu.wpi.first.math.kinematics.ChassisSpeeds; | ||
import edu.wpi.first.math.util.Units; | ||
import edu.wpi.first.wpilibj2.command.Command; | ||
import edu.wpi.first.wpilibj2.command.Commands; | ||
import edu.wpi.first.wpilibj2.command.ParallelCommandGroup; | ||
import frc.robot.constants.DriveConstants; | ||
import frc.robot.subsystems.DriveSubsystem.DriveSubsystem; | ||
|
||
import java.text.DecimalFormat; | ||
import java.text.NumberFormat; | ||
|
||
|
||
/** Measures the robot's wheel radius by spinning in a circle. */ | ||
public class WheelBaseCharacterizationRoutineCommand extends ParallelCommandGroup { | ||
private static final double WHEEL_RADIUS_MAX_VELOCITY = 0.25; // Rad/Sec | ||
private static final double WHEEL_RADIUS_RAMP_RATE = 0.05; // Rad/Sec^2 | ||
static SlewRateLimiter limiter = new SlewRateLimiter(WHEEL_RADIUS_RAMP_RATE); | ||
static WheelRadiusCharacterizationState state = new WheelRadiusCharacterizationState(); | ||
|
||
public WheelBaseCharacterizationRoutineCommand(DriveSubsystem drive) { | ||
super(Commands.parallel( | ||
// Drive control sequence | ||
Commands.sequence( | ||
// Reset acceleration limiter | ||
Commands.runOnce( | ||
() -> { | ||
limiter.reset(0.0); | ||
}), | ||
|
||
// Turn in place, accelerating up to full speed | ||
Commands.run( | ||
() -> { | ||
double speed = limiter.calculate(WHEEL_RADIUS_MAX_VELOCITY); | ||
drive.runVelocity(new ChassisSpeeds(0.0, 0.0, speed)); | ||
}, | ||
drive)), | ||
|
||
// Measurement sequence | ||
Commands.sequence( | ||
// Wait for modules to fully orient before starting measurement | ||
Commands.waitSeconds(1.0), | ||
|
||
// Record starting measurement | ||
Commands.runOnce( | ||
() -> { | ||
state.positions = drive.getWheelRadiusCharacterizationPositions(); | ||
state.lastAngle = drive.getRotation(); | ||
state.gyroDelta = 0.0; | ||
}), | ||
|
||
// Update gyro delta | ||
Commands.run( | ||
() -> { | ||
var rotation = drive.getRotation(); | ||
state.gyroDelta += Math.abs(rotation.minus(state.lastAngle).getRadians()); | ||
state.lastAngle = rotation; | ||
}) | ||
|
||
// When cancelled, calculate and print results | ||
.finallyDo( | ||
() -> { | ||
double[] positions = drive.getWheelRadiusCharacterizationPositions(); | ||
double wheelDelta = 0.0; | ||
for (int i = 0; i < 4; i++) { | ||
wheelDelta += Math.abs(positions[i] - state.positions[i]) / 4.0; | ||
} | ||
double wheelRadius = (state.gyroDelta * DriveConstants.driveBaseRadius) / wheelDelta; | ||
|
||
NumberFormat formatter = new DecimalFormat("#0.000"); | ||
System.out.println( | ||
"********** Wheel Radius Characterization Results **********"); | ||
System.out.println( | ||
"\tWheel Delta: " + formatter.format(wheelDelta) + " radians"); | ||
System.out.println( | ||
"\tGyro Delta: " + formatter.format(state.gyroDelta) + " radians"); | ||
System.out.println( | ||
"\tWheel Radius: " | ||
+ formatter.format(wheelRadius) | ||
+ " meters, " | ||
+ formatter.format(Units.metersToInches(wheelRadius)) | ||
+ " inches"); | ||
})))); | ||
} | ||
|
||
private static class WheelRadiusCharacterizationState { | ||
double[] positions = new double[4]; | ||
Rotation2d lastAngle = new Rotation2d(); | ||
double gyroDelta = 0.0; | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters