Skip to content

Commit

Permalink
modify PoseObservation logging, error logging struct
Browse files Browse the repository at this point in the history
  • Loading branch information
JayK445 committed Jan 5, 2025
1 parent c494dfc commit 796f642
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 17 deletions.
2 changes: 0 additions & 2 deletions src/main/java/frc/robot/subsystems/vision/Vision.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ public void periodic() {
for (var observation : observations) {
if (observation.ambiguity() > AMBIGUITY_CUTOFF || observation.ambiguity() == -1) continue;
}


}
}
}
15 changes: 6 additions & 9 deletions src/main/java/frc/robot/subsystems/vision/VisionIO.java
Original file line number Diff line number Diff line change
@@ -1,25 +1,22 @@
package frc.robot.subsystems.vision;

import edu.wpi.first.math.geometry.Pose3d;
import java.util.LinkedList;
import java.util.List;
import org.littletonrobotics.junction.AutoLog;

public interface VisionIO {
@AutoLog
class VisionIOInputs {
public class VisionIOInputs {
public boolean connected = false;
public List<PoseObservation> observations = new LinkedList<PoseObservation>();
public PoseObservation[] observations = new PoseObservation[0];
}

default void updateInputs(VisionIOInputs inputs) {}

// from EstimatedRobotPose
public record PoseObservation(
public static record PoseObservation(
double timestamp,
Pose3d estimatedPose,
double ambiguity,
int tagCount,
double averageDistance,
int[] tagIDs) {}
double averageDistance) {}

default void updateInputs(VisionIOInputs inputs) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import edu.wpi.first.apriltag.AprilTagFieldLayout;
import edu.wpi.first.math.geometry.Transform3d;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import org.photonvision.EstimatedRobotPose;
Expand All @@ -28,9 +27,10 @@ public VisionIOPhotonvision(AprilTagFieldLayout fieldLayout, int index) {
public void updateInputs(VisionIOInputs inputs) {
inputs.connected = camera.isConnected();
List<PhotonPipelineResult> results = camera.getAllUnreadResults();
List<PoseObservation> observations = new ArrayList<PoseObservation>();
PoseObservation[] observations = new PoseObservation[results.size()];

for (PhotonPipelineResult frame : results) {
for (int frameIndex = 0; frameIndex < results.size(); ++frameIndex) {
var frame = results.get(frameIndex);
if (!frame.hasTargets()) return;

Optional<EstimatedRobotPose> optEstimation = estimator.update(frame);
Expand All @@ -56,9 +56,8 @@ public void updateInputs(VisionIOInputs inputs) {
estimation.estimatedPose,
frame.getMultiTagResult().get().estimatedPose.ambiguity,
tagIDs.length,
totalDistance / tagIDs.length, // FIXME check if valid
tagIDs);
observations.add(observation);
totalDistance / tagIDs.length);
observations[frameIndex] = observation;
}

inputs.observations = observations;
Expand Down

0 comments on commit 796f642

Please sign in to comment.