Skip to content

Commit b9e9659

Browse files
Logic fixes + cleaning for sim cams
1 parent 7a52176 commit b9e9659

File tree

5 files changed

+15
-13
lines changed

5 files changed

+15
-13
lines changed

src/main/java/frc/trigon/robot/commands/LEDAutoSetupCommand.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public class LEDAutoSetupCommand extends SequentialCommandGroup {
2323
TOLERANCE_METERS = 0.1,
2424
TOLERANCE_DEGREES = 2;
2525
private static final int AMOUNT_OF_SECTIONS = 3;
26-
private final Supplier<Color>[] LEDColors = new Supplier[] {
26+
private final Supplier<Color>[] LEDColors = new Supplier[]{
2727
() -> getDesiredLEDColorFromRobotPose(this.autoStartPose.getRotation().getDegrees() - getCurrentRobotPose().getRotation().getDegrees(), TOLERANCE_DEGREES),
2828
() -> getDesiredLEDColorFromRobotPose(this.autoStartPose.getX() - getCurrentRobotPose().getX(), TOLERANCE_METERS),
2929
() -> getDesiredLEDColorFromRobotPose(this.autoStartPose.getY() - getCurrentRobotPose().getY(), TOLERANCE_METERS)

src/main/java/frc/trigon/robot/poseestimation/apriltagcamera/AprilTagCamera.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,11 @@ public void update() {
5757
aprilTagCameraIO.updateInputs(inputs);
5858

5959
robotPose = calculateBestRobotPose();
60-
6160
logCameraInfo();
62-
if (RobotHardwareStats.isSimulation())
63-
AprilTagCameraConstants.VISION_SIMULATION.update(RobotContainer.POSE_ESTIMATOR.getCurrentOdometryPose());
6461
}
6562

6663
public boolean hasNewResult() {
67-
return (inputs.hasResult && inputs.distanceFromBestTag != 0) && isNewTimestamp();
64+
return (inputs.hasResult && inputs.distanceFromBestTag != Double.POSITIVE_INFINITY) && isNewTimestamp();
6865
}
6966

7067
public Pose2d getEstimatedRobotPose() {
@@ -109,7 +106,7 @@ public double getDistanceToBestTagMeters() {
109106
* @return the robot's pose
110107
*/
111108
private Pose2d calculateBestRobotPose() {
112-
final Rotation2d gyroHeadingAtTimestamp = RobotHardwareStats.isSimulation() ? RobotContainer.SWERVE.getHeading() : PoseEstimator6328.getInstance().samplePose(inputs.latestResultTimestampSeconds).getRotation();
109+
final Rotation2d gyroHeadingAtTimestamp = RobotHardwareStats.isSimulation() ? RobotContainer.POSE_ESTIMATOR.getCurrentOdometryPose().getRotation() : PoseEstimator6328.getInstance().samplePose(inputs.latestResultTimestampSeconds).getRotation();
113110
return calculateAssumedRobotHeadingPose(gyroHeadingAtTimestamp);
114111
}
115112

@@ -134,7 +131,7 @@ private Translation2d getFieldRelativeRobotTranslation(Rotation2d currentHeading
134131
if (bestTagPose == null)
135132
return null;
136133

137-
setProperCameraRotation();
134+
correctTargetRelativeRotation();
138135

139136
final Translation2d tagRelativeCameraTranslation = calculateTagRelativeCameraTranslation(currentHeading, bestTagPose);
140137
final Translation2d fieldRelativeRobotPose = getFieldRelativeRobotPose(tagRelativeCameraTranslation, bestTagPose);
@@ -146,7 +143,7 @@ private Translation2d getFieldRelativeRobotTranslation(Rotation2d currentHeading
146143
* When the roll of the camera changes, the target pitch and yaw are also affected.
147144
* This method corrects the yaw and pitch based on the camera's mount position roll.
148145
*/
149-
private void setProperCameraRotation() {
146+
private void correctTargetRelativeRotation() {
150147
final Translation2d targetRotation = new Translation2d(inputs.bestTargetRelativePitchRadians, inputs.bestTargetRelativeYawRadians);
151148
targetRotation.rotateBy(Rotation2d.fromRadians(robotCenterToCamera.getRotation().getX()));
152149
inputs.bestTargetRelativePitchRadians = targetRotation.getX();
@@ -214,7 +211,7 @@ private void logCameraInfo() {
214211
Logger.processInputs("Cameras/" + name, inputs);
215212
if (!FieldConstants.TAG_ID_TO_POSE.isEmpty())
216213
logUsedTags();
217-
if (!inputs.hasResult || inputs.distanceFromBestTag == 0 || robotPose == null) {
214+
if (!inputs.hasResult || inputs.distanceFromBestTag == Double.POSITIVE_INFINITY || robotPose == null) {
218215
logEstimatedRobotPose();
219216
logSolvePNPPose();
220217
} else {

src/main/java/frc/trigon/robot/poseestimation/apriltagcamera/AprilTagCameraConstants.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public class AprilTagCameraConstants {
1717
static final int CALCULATE_YAW_ITERATIONS = 3;
1818
static final Pose2d[] EMPTY_POSE_LIST = new Pose2d[0];
1919

20-
public static final double MAXIMUM_AMBIGUITY = 0.5;
20+
public static final double MAXIMUM_AMBIGUITY = 0.4;
2121

2222
public static final VisionSystemSim VISION_SIMULATION = new VisionSystemSim("VisionSimulation");
2323
private static final int

src/main/java/frc/trigon/robot/poseestimation/poseestimator/PoseEstimator.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
import frc.trigon.robot.RobotContainer;
1111
import frc.trigon.robot.constants.FieldConstants;
1212
import frc.trigon.robot.poseestimation.apriltagcamera.AprilTagCamera;
13+
import frc.trigon.robot.poseestimation.apriltagcamera.AprilTagCameraConstants;
1314
import org.littletonrobotics.junction.Logger;
15+
import org.trigon.hardware.RobotHardwareStats;
1416

1517
import java.util.ArrayList;
1618
import java.util.Comparator;
@@ -108,6 +110,8 @@ private void updateFromVision() {
108110
getViableVisionObservations().stream()
109111
.sorted(Comparator.comparingDouble(PoseEstimator6328.VisionObservation::timestamp))
110112
.forEach(poseEstimator6328::addVisionObservation);
113+
if (RobotHardwareStats.isSimulation())
114+
AprilTagCameraConstants.VISION_SIMULATION.update(RobotContainer.POSE_ESTIMATOR.getCurrentOdometryPose());
111115
}
112116

113117
private List<PoseEstimator6328.VisionObservation> getViableVisionObservations() {

src/main/java/frc/trigon/robot/subsystems/swerve/SwerveModule.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,13 +178,14 @@ private void configureSignals() {
178178
driveMotor.registerSignal(TalonFXSignal.TORQUE_CURRENT, 100);
179179
driveMotor.registerSignal(TalonFXSignal.MOTOR_VOLTAGE, 100);
180180

181+
driveMotor.registerThreadedSignal(TalonFXSignal.POSITION, PoseEstimatorConstants.ODOMETRY_FREQUENCY_HERTZ);
182+
181183
steerMotor.registerSignal(TalonFXSignal.VELOCITY, 100);
182184
steerMotor.registerSignal(TalonFXSignal.MOTOR_VOLTAGE, 100);
183185

186+
steerMotor.registerThreadedSignal(TalonFXSignal.POSITION, PoseEstimatorConstants.ODOMETRY_FREQUENCY_HERTZ);
187+
184188
steerEncoder.registerSignal(CANcoderSignal.POSITION, 100);
185189
steerEncoder.registerSignal(CANcoderSignal.VELOCITY, 100);
186-
187-
driveMotor.registerThreadedSignal(TalonFXSignal.POSITION, PoseEstimatorConstants.ODOMETRY_FREQUENCY_HERTZ);
188-
steerMotor.registerThreadedSignal(TalonFXSignal.POSITION, PoseEstimatorConstants.ODOMETRY_FREQUENCY_HERTZ);
189190
}
190191
}

0 commit comments

Comments
 (0)