Skip to content

Commit f3bdb25

Browse files
committed
add auto align offset
1 parent f1f927d commit f3bdb25

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

src/main/java/frc/robot/RobotState.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,9 @@ public static RobotState getInstance() {
4040
@Getter
4141
@AutoLogOutput(key = "RobotState/Elevator Level")
4242
private ElevatorGoal elevatorLevel;
43+
44+
@Setter
45+
@Getter
46+
@AutoLogOutput(key = "RobotState/Is early")
47+
private boolean isEarly;
4348
}

src/main/java/frc/robot/subsystems/swerve/Swerve.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,15 @@
3737
import edu.wpi.first.math.kinematics.SwerveModuleState;
3838
import edu.wpi.first.math.numbers.N1;
3939
import edu.wpi.first.math.numbers.N3;
40+
import edu.wpi.first.math.util.Units;
4041
import edu.wpi.first.wpilibj.Alert;
4142
import edu.wpi.first.wpilibj.Alert.AlertType;
4243
import edu.wpi.first.wpilibj.DriverStation;
4344
import edu.wpi.first.wpilibj.DriverStation.Alliance;
4445
import edu.wpi.first.wpilibj2.command.Command;
4546
import edu.wpi.first.wpilibj2.command.SubsystemBase;
4647
import edu.wpi.first.wpilibj2.command.sysid.SysIdRoutine;
48+
import frc.robot.RobotState;
4749
import frc.robot.constants.FieldConstants;
4850
import frc.robot.constants.GlobalConstants;
4951
import frc.robot.constants.GlobalConstants.Mode;
@@ -386,7 +388,12 @@ public Pose2d getBestReefTagNoOffset() {
386388
}
387389

388390
public Pose2d getBestCoralAutoAlign() {
389-
Translation2d offset = new Translation2d();
391+
Translation2d offset = RobotState.getInstance().isEarly()
392+
? FieldConstants.CoralTags.kCoralAlignOffset.plus(
393+
new Translation2d(-0.025, 0.05 + .0175 + Units.inchesToMeters(1.5)))
394+
: FieldConstants.CoralTags.kCoralAlignOffset
395+
.plus(new Translation2d(0.025, 0.142))
396+
.unaryMinus();
390397
return getBestCoralTag()
391398
.plus(GeomUtil.toTransform2d(offset))
392399
.plus(new Transform2d(new Translation2d(), Rotation2d.fromDegrees(180)));

src/main/java/frc/robot/subsystems/swerve/SwerveConstants.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package frc.robot.subsystems.swerve;
22

33
import static edu.wpi.first.units.Units.MetersPerSecond;
4-
import static frc.robot.subsystems.swerve.SwerveConstants.TunerConstants;
54

65
import com.ctre.phoenix6.CANBus;
76
import com.pathplanner.lib.config.ModuleConfig;
@@ -15,10 +14,9 @@
1514

1615
public class SwerveConstants {
1716

18-
/** <b> !! PLACEHOLDER VALUE !! </b> */
1917
public static final ConstantsWrapper TunerConstants = new ConstantsWrapper(TunerConstantsV3.class);
2018

21-
// TunerConstantsPlaceholder doesn't include these constants, so they are declared locally
19+
// TunerConstants doesn't include these constants, so they are declared locally
2220

2321
public static final double kOdometryFreq =
2422
new CANBus(TunerConstants.getDrivetrainConstants().CANBusName).isNetworkFD() ? 250.0 : 100.0;
@@ -30,6 +28,7 @@ public class SwerveConstants {
3028
Math.hypot(TunerConstants.getBackLeft().LocationX, TunerConstants.getBackLeft().LocationY),
3129
Math.hypot(TunerConstants.getBackRight().LocationX, TunerConstants.getBackRight().LocationY)));
3230

31+
// TODO: set
3332
public static final double kRobotMass = 63.957;
3433
public static final double kRobotMoi = 3.825;
3534
public static final double kWheelCOF = 1.9;
@@ -51,6 +50,8 @@ public class SwerveConstants {
5150
getModuleTranslations());
5251

5352
public static final PPHolonomicDriveController kAutoController =
53+
// translation pids, rotation pids
54+
// TODO: set
5455
new PPHolonomicDriveController(new PIDConstants(2, 0.0, 0), new PIDConstants(2, 0.0, 0.0));
5556

5657
public static Translation2d[] getModuleTranslations() {

0 commit comments

Comments
 (0)