We are trying to use PhotonVision to get a field relative position but we seem to be stuck on loading the apriltags layout. As far as I know we are not doing anything wrong but the code just throws an IOException saying it cannot read the file however it’s a file that comes with WPILib so it’s clearly there. I’ve completely ran out of ideas so I would gladly appreciate any help.
package frc.robot.subsystems;
import java.util.List;
import org.photonvision.PhotonCamera;
import org.photonvision.targeting.PhotonPipelineResult;
import org.photonvision.targeting.PhotonTrackedTarget;
import edu.wpi.first.apriltag.AprilTagFieldLayout;
import edu.wpi.first.apriltag.AprilTagFields;
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.wpilibj2.command.CommandBase;
import edu.wpi.first.wpilibj2.command.SubsystemBase;
public class VisionSubsystem extends SubsystemBase {
//Telemetry
public PhotonCamera lifecam = new PhotonCamera("lifecam");
public PhotonPipelineResult pipelineResult = lifecam.getLatestResult();
public boolean hasTargets = pipelineResult.hasTargets();
public List<PhotonTrackedTarget> targets = pipelineResult.getTargets();
public PhotonTrackedTarget target = pipelineResult.getBestTarget();
// Cam position
public Transform3d robotToCam = new Transform3d(new Translation3d(0.5, 0.0, 0.5), new Rotation3d(0,0,0));
public AprilTagFieldLayout aprilTagFieldLayout = AprilTagFieldLayout.loadFromResource(AprilTagFields.k2023ChargedUp.m_resourceFile);
public VisionSubsystem() {
}
public CommandBase exampleMethodCommand() {
// Inline construction of command goes here.
// Subsystem::RunOnce implicitly requires `this` subsystem.
return runOnce(
() -> {
/* one-time action goes here */
});
}
@Override
public void periodic() {
// This method will be called once per scheduler run
}
@Override
public void simulationPeriodic() {
// This method will be called once per scheduler run during simulation
}
}