Skip to content

Commit 7aa34ae

Browse files
committed
Added debugging logging
1 parent 5f49d99 commit 7aa34ae

File tree

4 files changed

+27
-4
lines changed

4 files changed

+27
-4
lines changed

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import choreo.trajectory.SwerveSample;
44
import choreo.trajectory.Trajectory;
5+
import edu.wpi.first.math.MathSharedStore;
56
import edu.wpi.first.math.Matrix;
67
import edu.wpi.first.math.controller.HolonomicDriveController;
78
import edu.wpi.first.math.controller.PIDController;
@@ -168,10 +169,21 @@ public Trajectory<SwerveSample> getAutoTrajectory() {
168169
}
169170

170171
public void addVisionMeasurement(Pose2d pose, double timestamp) {
172+
org.littletonrobotics.junction.Logger.recordOutput("DriveSubsystem/Pose from vision", pose);
173+
org.littletonrobotics.junction.Logger.recordOutput(
174+
"DriveSubsystem/Time Since Vision Update", MathSharedStore.getTimestamp() - timestamp);
171175
io.addVisionMeasurement(pose, timestamp);
172176
}
173177

174178
public void addVisionMeasurement(Pose2d pose, double timestamp, Matrix<N3, N1> stdDevvs) {
179+
org.littletonrobotics.junction.Logger.recordOutput("DriveSubsystem/Pose from vision", pose);
180+
org.littletonrobotics.junction.Logger.recordOutput("DriveSubsystem/stdDevvs", stdDevvs);
181+
org.littletonrobotics.junction.Logger.recordOutput(
182+
"DriveSubsystem/Time Since Vision Update", MathSharedStore.getTimestamp() - timestamp);
183+
org.littletonrobotics.junction.Logger.recordOutput(
184+
"DriveSubsystem/Vision Timestamp", timestamp);
185+
org.littletonrobotics.junction.Logger.recordOutput(
186+
"DriveSubsystem/Vision MathShared Time", MathSharedStore.getTimestamp());
175187
io.addVisionMeasurement(pose, timestamp, stdDevvs);
176188
}
177189

@@ -334,6 +346,8 @@ public PIDController getomegaControllerNonProfiled() {
334346
public void periodic() {
335347
io.updateInputs(inputs);
336348
Logger.processInputs(getName(), inputs);
349+
org.littletonrobotics.junction.Logger.recordOutput(
350+
"DriveSubsystem/Swerve Pose", inputs.swervePose);
337351
if (Math.abs(inputs.gyroRotation2d.minus(inputs.navxRotation2d).getDegrees())
338352
> DriveConstants.kGyroDifferentThreshold) {
339353
gyroDifferentCount++;

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,8 @@ public Swerve() {
113113
getSwerveModulePositions());
114114

115115
swerveDrive.setOdometry(odometryStrategy);
116+
org.littletonrobotics.junction.Logger.recordOutput(
117+
"Swerve/OdometryStratgey Pose", odometryStrategy.getPoseMeters());
116118
}
117119

118120
// Getters/Setter
@@ -249,6 +251,7 @@ public void updateInputs(SwerveIOInputs inputs) {
249251

250252
inputs.odometryX = swerveDrive.getPoseMeters().getX();
251253
inputs.odometryY = swerveDrive.getPoseMeters().getY();
254+
inputs.swervePose = odometryStrategy.getPoseMeters();
252255
inputs.odometryRotation2D = swerveDrive.getPoseMeters().getRotation().getDegrees();
253256
inputs.gyroRotation2d = swerveDrive.getHeading();
254257
inputs.navxRotation2d = navx.getRotation2d().rotateBy(navxOffset);

src/main/java/frc/robot/subsystems/drive/SwerveIO.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public interface SwerveIO {
2222
public static class SwerveIOInputs {
2323
public double odometryX = 0.0;
2424
public double odometryY = 0.0;
25+
public Pose2d swervePose;
2526
public double odometryRotation2D = 0.0;
2627
public Rotation2d gyroRotation2d = new Rotation2d();
2728
public Rotation2d navxRotation2d = new Rotation2d();

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import edu.wpi.first.apriltag.AprilTagFields;
88
import edu.wpi.first.math.Matrix;
99
import edu.wpi.first.math.Pair;
10+
import edu.wpi.first.math.VecBuilder;
1011
import edu.wpi.first.math.geometry.Pose2d;
1112
import edu.wpi.first.math.geometry.Pose3d;
1213
import edu.wpi.first.math.geometry.Rotation2d;
@@ -308,12 +309,13 @@ private Pose3d getCorrectPose(Pose3d pose1, Pose3d pose2, double time, int camIn
308309
double dist1 = Math.abs(camHeights[camIndex] - pose1.getZ());
309310
double dist2 = Math.abs(camHeights[camIndex] - pose2.getZ());
310311
// This filters out results by seeing if they are close to the right height
311-
if (dist1 < dist2 && dist1 < 0.5) {
312+
// If you use height ot gyro rotation should be determined experimentally
313+
/*if (dist1 < dist2 && dist1 < 0.5) {
312314
return pose1;
313315
}
314316
if (dist2 < dist1 && dist2 < 0.5) {
315317
return pose2;
316-
}
318+
}*/
317319
// If we don't have enough data in the gyro buffer we default to returning a pose
318320
if (gyroBuffer.size() < VisionConstants.kCircularBufferSize) return pose1;
319321

@@ -369,7 +371,7 @@ public void periodic() {
369371
WallEyePoseResult result = (WallEyePoseResult) res.getFirst();
370372
int idx = res.getSecond();
371373

372-
logger.recordOutput("Vision", result.getTimeStamp());
374+
logger.recordOutput("Vision/resultTime", result.getTimeStamp());
373375
for (int i = 0; i < 2; i++) {
374376
stdMatrix.set(
375377
i,
@@ -421,8 +423,11 @@ public void periodic() {
421423
logger.recordOutput("Vision/Accepted Cam " + camNames[idx], robotPose);
422424
// However we do have to be accepting the poses to use them
423425
if (visionUpdating) {
424-
driveSubsystem.addVisionMeasurement(robotPose, result.getTimeStamp(), stdMatrix);
426+
Matrix<N3, N1> testingMatrix = VecBuilder.fill(0.0001, 0.0001, 0.0001);
427+
driveSubsystem.addVisionMeasurement(
428+
robotPose, result.getTimeStamp() / 1_000_000, testingMatrix);
425429
logger.recordOutput("Vision/Vision Updating", visionUpdating);
430+
logger.recordOutput("Vision/std", stdMatrix.get(0, 0));
426431
}
427432
} else {
428433
logger.recordOutput("Vision/Rejected Cam " + camNames[idx], robotPose);

0 commit comments

Comments
 (0)