Skip to content

Commit

Permalink
remove unused code which breaks build
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelLesirge committed Oct 29, 2024
1 parent 5c29f7b commit 1a30b7a
Showing 1 changed file with 35 additions and 42 deletions.
77 changes: 35 additions & 42 deletions src/main/java/frc/robot/subsystems/Vision.java
Original file line number Diff line number Diff line change
@@ -1,25 +1,17 @@
package frc.robot.subsystems;

import java.util.ArrayList;

import org.photonvision.PhotonCamera;
import org.photonvision.targeting.PhotonPipelineResult;
import org.photonvision.targeting.PhotonTrackedTarget;

import edu.wpi.first.math.geometry.Rotation3d;
import edu.wpi.first.math.geometry.Transform3d;
import edu.wpi.first.math.geometry.Translation3d;
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
import edu.wpi.first.wpilibj2.command.SubsystemBase;

/** Vision subsystem */
public class Vision extends SubsystemBase {

private final static boolean DEBUG_INFO = false;
// private final static boolean DEBUG_INFO = false;

private boolean visionEnabled = false;

final PhotonCamera camera;
// final PhotonCamera camera;
final Transform3d robotToCamera;
final Transform3d cameraToRobot;

Expand All @@ -30,7 +22,7 @@ public class Vision extends SubsystemBase {
* @param robotToCamera distance from the camera to the center of the robot
*/
public Vision(String cameraName, Transform3d robotToCamera) {
camera = new PhotonCamera(cameraName);
// camera = new PhotonCamera(cameraName);
this.robotToCamera = robotToCamera;
cameraToRobot = robotToCamera.inverse();

Expand Down Expand Up @@ -62,11 +54,12 @@ public void toggleUsing() {
*
*/
public Transform3d getTransformToTag() {
PhotonTrackedTarget target = camera.getLatestResult().getBestTarget();
if (target == null) {
return null;
}
return target.getBestCameraToTarget().plus(cameraToRobot);
// PhotonTrackedTarget target = camera.getLatestResult().getBestTarget();
// if (target == null) {
// return null;
// }
// return target.getBestCameraToTarget().plus(cameraToRobot);
return null;
}

/**
Expand All @@ -80,12 +73,12 @@ public Transform3d getTransformToTag(int tagID) {
if (tagID == -1)
return getTransformToTag();

var results = camera.getLatestResult();
// var results = camera.getLatestResult();

for (PhotonTrackedTarget target : results.getTargets()) {
if (target.getFiducialId() == tagID)
return target.getBestCameraToTarget().plus(cameraToRobot);
}
// for (PhotonTrackedTarget target : results.getTargets()) {
// if (target.getFiducialId() == tagID)
// return target.getBestCameraToTarget().plus(cameraToRobot);
// }
return null;
}

Expand All @@ -95,32 +88,32 @@ public void periodic() {

SmartDashboard.putBoolean("Use Vision", visionEnabled);

if (visionEnabled && DEBUG_INFO) {
PhotonPipelineResult result = camera.getLatestResult();
PhotonTrackedTarget bestTag = result.getBestTarget();
// if (visionEnabled && DEBUG_INFO) {
// PhotonPipelineResult result = camera.getLatestResult();
// PhotonTrackedTarget bestTag = result.getBestTarget();

if (bestTag == null) {
bestTag = new PhotonTrackedTarget(-1, -1, -1, -1, -1,
new Transform3d(new Translation3d(-1, -1, -1), new Rotation3d(-1, -1, -1)), null, 0,
new ArrayList<>(), new ArrayList<>());
}
// if (bestTag == null) {
// bestTag = new PhotonTrackedTarget(-1, -1, -1, -1, -1,
// new Transform3d(new Translation3d(-1, -1, -1), new Rotation3d(-1, -1, -1)), null, 0,
// new ArrayList<>(), new ArrayList<>());
// }

SmartDashboard.putNumber("Tag ID", bestTag.getFiducialId());
SmartDashboard.putNumber("Tag Yaw", bestTag.getYaw());
SmartDashboard.putNumber("Tag Pitch", bestTag.getPitch());
SmartDashboard.putNumber("Tag Skew", bestTag.getSkew());
// SmartDashboard.putNumber("Tag ID", bestTag.getFiducialId());
// SmartDashboard.putNumber("Tag Yaw", bestTag.getYaw());
// SmartDashboard.putNumber("Tag Pitch", bestTag.getPitch());
// SmartDashboard.putNumber("Tag Skew", bestTag.getSkew());

Transform3d tagPose = bestTag.getBestCameraToTarget();
// Transform3d tagPose = bestTag.getBestCameraToTarget();

SmartDashboard.putNumber("Tag Pose X", tagPose.getX());
SmartDashboard.putNumber("Tag Pose Y", tagPose.getY());
SmartDashboard.putNumber("Tag Pose Z", tagPose.getZ());
// SmartDashboard.putNumber("Tag Pose X", tagPose.getX());
// SmartDashboard.putNumber("Tag Pose Y", tagPose.getY());
// SmartDashboard.putNumber("Tag Pose Z", tagPose.getZ());

Rotation3d tagPoseRotation = tagPose.getRotation();
// Rotation3d tagPoseRotation = tagPose.getRotation();

SmartDashboard.putNumber("Tag Pose Yaw", tagPoseRotation.getZ());
SmartDashboard.putNumber("Tag Pose Pitch", tagPoseRotation.getY());
SmartDashboard.putNumber("Tag Pose Roll", tagPoseRotation.getX());
}
// SmartDashboard.putNumber("Tag Pose Yaw", tagPoseRotation.getZ());
// SmartDashboard.putNumber("Tag Pose Pitch", tagPoseRotation.getY());
// SmartDashboard.putNumber("Tag Pose Roll", tagPoseRotation.getX());
// }
}
}

0 comments on commit 1a30b7a

Please sign in to comment.