Skip to content

Commit 0e0e486

Browse files
Added barge buffer zone, and reservsal mode for loop overruns
1 parent ad2a59b commit 0e0e486

File tree

4 files changed

+34
-10
lines changed

4 files changed

+34
-10
lines changed

src/main/java/frc/robot/constants/BargeAlignConstants.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@ public class BargeAlignConstants {
77

88
public static final double kBlueEjectAlgaeX = 7.67; // 7.72
99
public static final double kRedEjectAlgaeX = 9.86; // 9.81
10-
public static final double kBlueRaiseElevatorX = 7.02; // 7.22
11-
public static final double kRedRaiseElevatorX = 10.51; // 10.31
10+
public static final double kBlueRaiseElevatorX = 7.22; // 7.22
11+
public static final double kRedRaiseElevatorX = 10.71; // 10.31
12+
public static final double kBlueUnsafeX = 7.02;
13+
public static final double kRedUnsafeX = 10.51;
1214

1315
public static final Rotation2d kBlueDesiredYaw = Rotation2d.fromDegrees(0.0);
1416
public static final Rotation2d kRedDesiredYaw = Rotation2d.fromDegrees(180.0);

src/main/java/frc/robot/constants/RobotStateConstants.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ public class RobotStateConstants {
88
public static final double[] kNodeAngles = {0.0, 60.0, 120.0, 180.0, -120.0, -60.0};
99
public static final double kAlgaeRetreatDistance = 0;
1010

11-
public static final double kBlueBargeSafeX = 7; // 7.6
12-
public static final double kRedBargeSafeX = DriveConstants.kFieldMaxX - kBlueBargeSafeX;
11+
// Use Barge align constants
12+
// public static final double kBlueBargeSafeX = 7; // 7.6
13+
// public static final double kRedBargeSafeX = DriveConstants.kFieldMaxX - kBlueBargeSafeX;
1314

1415
public static final double kCoralEjectTimer = 0.25;
1516
public static final double kAlgaeEjectTimer = 0.5;

src/main/java/frc/robot/subsystems/robotState/RobotStateSubsystem.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import edu.wpi.first.units.measure.Angle;
1010
import edu.wpi.first.wpilibj.DriverStation.Alliance;
1111
import edu.wpi.first.wpilibj.Timer;
12+
import frc.robot.constants.BargeAlignConstants;
1213
import frc.robot.constants.DriveConstants;
1314
import frc.robot.constants.ElevatorConstants;
1415
import frc.robot.constants.RobotConstants;
@@ -672,8 +673,8 @@ public void toScoreAlgae() {
672673
}
673674
double poseX = driveSubsystem.getPoseMeters().getX();
674675
isBargeSafe =
675-
poseX > RobotStateConstants.kRedBargeSafeX
676-
|| poseX < RobotStateConstants.kBlueBargeSafeX;
676+
poseX > BargeAlignConstants.kRedRaiseElevatorX
677+
|| poseX < BargeAlignConstants.kBlueRaiseElevatorX;
677678
if (isBargeSafe) {
678679
driveSubsystem.setDriveMultiplier(DriveConstants.kBargeScoreStickMultiplier);
679680
if (isAutoPlacing) {

src/main/java/frc/robot/subsystems/tagAlign/BargeAlignSubsystem.java

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
import edu.wpi.first.wpilibj.DriverStation.Alliance;
66
import frc.robot.constants.BargeAlignConstants;
77
import frc.robot.constants.DriveConstants;
8-
import frc.robot.constants.RobotStateConstants;
98
import frc.robot.controllers.FlyskyJoystick;
109
import frc.robot.subsystems.drive.DriveSubsystem;
1110
import java.util.Set;
1211
import org.littletonrobotics.junction.Logger;
1312
import org.strykeforce.telemetry.measurable.MeasurableSubsystem;
1413
import org.strykeforce.telemetry.measurable.Measure;
14+
// TODO Make final drive faster. Reverse if we are too close to the barge.
1515

1616
public class BargeAlignSubsystem extends MeasurableSubsystem {
1717

@@ -76,15 +76,24 @@ private void setupBargeAlign() {
7676
private boolean isSafe() {
7777
double poseX = driveSubsystem.getPoseMeters().getX();
7878

79-
return poseX > RobotStateConstants.kRedBargeSafeX
80-
|| poseX < RobotStateConstants.kBlueBargeSafeX;
79+
return poseX > BargeAlignConstants.kRedRaiseElevatorX
80+
|| poseX < BargeAlignConstants.kBlueRaiseElevatorX;
8181
}
8282

8383
private boolean shouldRaiseElevator() {
8484
double poseX = driveSubsystem.getPoseMeters().getX();
8585
return isOnBlueSide
8686
? poseX > BargeAlignConstants.kBlueRaiseElevatorX
87-
: poseX < BargeAlignConstants.kRedRaiseElevatorX;
87+
&& poseX <= BargeAlignConstants.kBlueUnsafeX
88+
: poseX < BargeAlignConstants.kRedRaiseElevatorX
89+
&& poseX >= BargeAlignConstants.kRedUnsafeX;
90+
}
91+
92+
private boolean shouldDriveBackwards() {
93+
double poseX = driveSubsystem.getPoseMeters().getX();
94+
return isOnBlueSide
95+
? poseX > BargeAlignConstants.kBlueUnsafeX
96+
: poseX < BargeAlignConstants.kRedUnsafeX;
8897
}
8998

9099
private boolean shouldEjectAlgae() {
@@ -131,6 +140,8 @@ public void periodic() {
131140
Logger.recordOutput("BargeAlign/Vomega", vOmega);
132141
if (shouldRaiseElevator()) {
133142
setState(BargeAlignStates.RAISE_ELEV);
143+
} else if (shouldDriveBackwards()) {
144+
setState(BargeAlignStates.REVERSE);
134145
}
135146
}
136147
case RAISE_ELEV -> {
@@ -145,6 +156,14 @@ public void periodic() {
145156
terminate();
146157
}
147158
}
159+
case REVERSE -> {
160+
if (isOnBlueSide) {
161+
driveSubsystem.move(
162+
-vX, getYStickReading(), BargeAlignConstants.kBlueRaiseElevatorX, true);
163+
} else {
164+
driveSubsystem.move(vX, getYStickReading(), BargeAlignConstants.kRedRaiseElevatorX, true);
165+
}
166+
}
148167
case FINISHED -> {}
149168
}
150169
}
@@ -158,6 +177,7 @@ public enum BargeAlignStates {
158177
// INIT,
159178
DRIVE,
160179
RAISE_ELEV,
180+
REVERSE,
161181
FINISHED
162182
}
163183
}

0 commit comments

Comments
 (0)