Skip to content

Commit

Permalink
Added comments and remove useless code
Browse files Browse the repository at this point in the history
  • Loading branch information
JacksonElia committed Jan 5, 2025
1 parent bc353ad commit df753f2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 13 deletions.
7 changes: 4 additions & 3 deletions src/main/java/frc/robot/commands/drive/DriveCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
import java.util.function.BooleanSupplier;
import java.util.function.DoubleSupplier;

// import frc.robot.subsystems.vision.VisionSubsystem;

public class DriveCommand extends DriveCommandBase {

private final SwerveDrive driveSubsystem;
Expand Down Expand Up @@ -38,6 +36,7 @@ public DriveCommand(
super(driveSubsystem, visionSubsystem);
this.driveSubsystem = driveSubsystem;
addRequirements(driveSubsystem, visionSubsystem);

this.leftJoystickY = leftJoystickY;
this.leftJoystickX = leftJoystickX;
this.rightJoystickX = rightJoystickX;
Expand All @@ -50,13 +49,15 @@ public void initialize() {}

@Override
public void execute() {
// Drives the robot
// Most of the time the driver prefers that the robot rotates slowly, as it gives them more control
// but sometimes (e.g. when fighting defense bots) being able to rotate quickly is necessary
if (isHighRotation.getAsBoolean()) {
angularSpeed = DriveConstants.MAX_ANGULAR_SPEED_RADIANS_PER_SECOND;
} else {
angularSpeed = DriveConstants.LOW_ANGULAR_SPEED_RADIANS_PER_SECOND;
}

// Drives the robot by scaling the joystick inputs
driveSubsystem.drive(
leftJoystickY.getAsDouble() * DriveConstants.MAX_SPEED_METERS_PER_SECOND,
leftJoystickX.getAsDouble() * DriveConstants.MAX_SPEED_METERS_PER_SECOND,
Expand Down
14 changes: 4 additions & 10 deletions src/main/java/frc/robot/commands/drive/DriveCommandBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,21 +47,16 @@ public void execute() {
}

public void calculatePoseFromLimelight(Limelight limelightNumber) {
double currentTimeStampSeconds = lastTimeStampSeconds;

// Updates the robot's odometry with april tags
if (vision.canSeeAprilTags(limelightNumber)) {
currentTimeStampSeconds = vision.getTimeStampSeconds(limelightNumber);

double distanceFromClosestAprilTag = vision.getLimelightAprilTagDistance(limelightNumber);

// Depending on how many april tags we see, we change our confidence as more april tags
// results in a much more accurate pose estimate
// TODO: check if this is necessary anymore with MT2, also we might want to set the limelight
// so it only uses 1 april tag, if they set up the field wrong (they can set april tags +-1
// inch I believe)
// using multiple *could* really mess things up.
// So if we only see 1 april tag, we have *high* standard deviations -> lower confidence
if (vision.getNumberOfAprilTags(limelightNumber) == 1) {
// But then we use the lookup table here to account for how far away the robot is from the april tag
// because if we are closer to the april tag, we are more confident in our position -> lower standard deviation
double[] standardDeviations =
oneAprilTagLookupTable.getLookupValue(distanceFromClosestAprilTag);
swerveDrive.setPoseEstimatorVisionConfidence(
Expand All @@ -73,11 +68,10 @@ public void calculatePoseFromLimelight(Limelight limelightNumber) {
standardDeviations[0], standardDeviations[1], standardDeviations[2]);
}

// Adds the timestamped pose gotten from the limelights to our pose estimation
swerveDrive.addPoseEstimatorVisionMeasurement(
vision.getPoseFromAprilTags(limelightNumber),
Timer.getFPGATimestamp() - vision.getLatencySeconds(limelightNumber));
}

lastTimeStampSeconds = currentTimeStampSeconds;
}
}

0 comments on commit df753f2

Please sign in to comment.