Skip to content

Commit 25e9168

Browse files
authored
Merge pull request #123 from strykeforce/drivePracticeTweaks
Drive Practice Tweaks
2 parents b92f05e + fd031ba commit 25e9168

File tree

4 files changed

+28
-6
lines changed

4 files changed

+28
-6
lines changed

src/main/java/frc/robot/Constants.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@ public static Translation2d[] getWheelLocationMeters() {
226226
public static final double kAutoBalanceStableCount = 10;
227227
public static final double kAutoBalanceStartTimerThresholdDeg = 5;
228228
public static final double kAutoBalanceEnableGyroThresholdDegrees = 8;
229+
public static final int kMaxAutoBalanceRetries = 3;
229230

230231
public static final double kAutoBalanceSlowDriveVel = 0.35; // 0.6
231232
public static final double kAutoBalanceRecoveryDriveVel = 0.25;

src/main/java/frc/robot/RobotContainer.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@
7373
import frc.robot.subsystems.ArmSubsystem;
7474
import frc.robot.subsystems.AutoSwitch;
7575
import frc.robot.subsystems.DriveSubsystem;
76+
import frc.robot.subsystems.DriveSubsystem.DriveStates;
7677
import frc.robot.subsystems.ElbowSubsystem;
7778
import frc.robot.subsystems.ElevatorSubsystem;
7879
import frc.robot.subsystems.HandSubsystem;
@@ -203,6 +204,10 @@ public void autoStowTele() {
203204
}
204205
}
205206

207+
public void driveSubsystemTele() {
208+
driveSubsystem.setDriveState(DriveStates.IDLE);
209+
}
210+
206211
public void setDisabled(boolean isDisabled) {
207212
robotStateSubsystem.setDisabled(isDisabled);
208213
}

src/main/java/frc/robot/subsystems/DriveSubsystem.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ public class DriveSubsystem extends MeasurableSubsystem {
7373
private double yCalc;
7474
private double omegaCalc;
7575
private RobotStateSubsystem robotStateSubsystem;
76+
private int numAutoBalanceRetries = 0;
7677

7778
// HEALTHCHECK FIX
7879
@HealthCheck
@@ -498,6 +499,7 @@ public void setAutoDriving(boolean autoDrive) {
498499

499500
public void autoBalance(boolean isOnAllianceSide) {
500501
// On alliance side of charge station, drive Positive X
502+
numAutoBalanceRetries = 0;
501503
autoBalanceAvgCount = 0;
502504
sumRoll = 0;
503505
avgStartingRoll = 0;
@@ -702,6 +704,8 @@ public void periodic() {
702704
if (!recoveryStartingPitchSet) {
703705
recoveryStartingPitch = getGyroPitch();
704706
recoveryStartingPitchSet = true;
707+
logger.info("Recovery Start Pitch: {}", recoveryStartingPitch);
708+
numAutoBalanceRetries++;
705709
}
706710
// if (isOnAllianceSide)
707711
if ((Math.abs(tempRoll - getGyroPitch()) > 2)
@@ -741,8 +745,13 @@ public void periodic() {
741745
"AutoBalance Stop: Gyro Roll: {}, trigger Difference: {}",
742746
getGyroPitch(),
743747
Math.abs(avgStartingRoll) - Math.abs(getGyroPitch()));
744-
logger.info("{} -> AUTO_BALANCE_RECOVERY", currDriveState);
745-
currDriveState = DriveStates.AUTO_BALANCE_RECOVERY;
748+
if (numAutoBalanceRetries < DriveConstants.kMaxAutoBalanceRetries) {
749+
logger.info("{} -> AUTO_BALANCE_RECOVERY", currDriveState);
750+
currDriveState = DriveStates.AUTO_BALANCE_RECOVERY;
751+
} else {
752+
logger.info("{} -> AUTO_BALANCE_FINISHED", currDriveState);
753+
currDriveState = DriveStates.AUTO_BALANCE_FINISHED;
754+
}
746755

747756
autoBalanceRecoveryTimer.reset();
748757
autoBalanceRecoveryTimer.start();

src/main/java/frc/robot/subsystems/VisionSubsystem.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ public class VisionSubsystem extends MeasurableSubsystem {
4747
private DigitalInput[][] dios = {diosHigh, diosLow};
4848
private WallEyeResult[][] results = {{}, {}};
4949
private Pose2d[] camPoses = {new Pose2d(), new Pose2d()};
50+
private Pose2d[] currCamPoses = {new Pose2d(), new Pose2d()};
5051
private int[] updates = {0, 0};
5152
private int[] numTags = {0, 0};
5253
private double[] camDelay = {0, 0};
@@ -128,7 +129,8 @@ public void periodic() {
128129
for (int j = 0; j < numCams[i]; ++j) {
129130
numTags[i] = results[i][j].getNumTags();
130131

131-
camPoses[i] =
132+
// Save current camera pose to temp variable until check that it's valid
133+
currCamPoses[i] =
132134
new Pose2d(
133135
new Translation2d(
134136
results[i][j].getCameraPose().getX(),
@@ -176,7 +178,9 @@ private void handleCameraFilter(
176178
for (WallEyeResult res : results) {
177179

178180
if (res.getCameraPose().getX() > 1000.0) continue;
179-
181+
camPoses =
182+
currCamPoses; // If current camera pose = valid then overwrite last valid cam pose with
183+
// it
180184
Pose2d camPose =
181185
new Pose2d(
182186
new Translation2d(res.getCameraPose().getX(), res.getCameraPose().getY())
@@ -242,7 +246,7 @@ private void handleCameraFilter(
242246
public void handleVision(WallEyeResult res, int camNum, Pose2d camPose) {
243247
numUpdateForReset++;
244248
suppliedCamPose[camNum] = camPose;
245-
System.out.println(suppliedCamPose[camNum]);
249+
// System.out.println(suppliedCamPose[camNum]);
246250

247251
driveSubsystem.updateOdometryWithVision(camPose, res.getTimeStamp() / 1000000);
248252
}
@@ -318,7 +322,8 @@ public void resetOdometry(Pose2d errorCheckPose, boolean isBlueAlliance) {
318322
new Pose2d(
319323
new Translation2d(camPoses[0].getX(), camPoses[0].getY()),
320324
driveSubsystem.getGyroRotation2d()));
321-
} else {
325+
} else if (!((camPoses[0].getX() == 0 && camPoses[0].getY() == 0)
326+
|| (camPoses[0].getX() == 2767 && camPoses[0].getY() == 2767))) {
322327
// double tempX = (driveSubsystem.getPoseMeters().getX() + cameraPose.getX()) / 2;
323328
double tempY = (driveSubsystem.getPoseMeters().getY() + camPoses[0].getY()) / 2;
324329
// logger.info("TempX: {}, TempY: {}", tempX, tempY);
@@ -335,6 +340,8 @@ public void resetOdometry(Pose2d errorCheckPose, boolean isBlueAlliance) {
335340
tempPose,
336341
driveSubsystem.getPoseMeters());
337342
driveSubsystem.resetOdometry(tempPose);
343+
} else {
344+
logger.info("Not resetting odometry, last cam pose: {}", camPoses[0]);
338345
}
339346
}
340347

0 commit comments

Comments
 (0)