Code check

Hi. Can somebody see what is wrong here: package frc.robot.subsystems;
import edu.wpi.first.wpilibj;
import edu.wpi.first.wpilibj2.command.SubsystemBase;
import com.photonvision.PhotonCamera;
import com.photonvision.targeting.PhotonTrackedTarget;
import edu.wpi.first.util.net.PortForwarder;

public class PhotonVision extends SubsystemBase {

private final PhotonCamera camera;
private PhotonTrackedTarget trackedTarget;

public double yaw;
public double pitch;
public double roll;
public double latency;
public double skew;
public boolean hasTarget;

public PhotonVision() {
    camera = new PhotonCamera("Microsoft LifeCam HD-3000");
    PortForwarder.add(5800, "photonvision", 5800);
    camera.setPipelineIndex(0);
}

public boolean hasTarget() {
    return hasTarget;
}

public double getSkew() {
    return skew;
}

public double getYaw() {
    return yaw;
}

public double getPitch() {
    return pitch;
}

public double getRoll() {
    return roll;
}

public double getLatency() {
    return latency;
}

public void periodic() {
    var result = camera.getLatestResult();
    hasTarget = result.hasTargets();

    if (hasTarget) {
        trackedTarget = result.getBestTarget();
        yaw = trackedTarget.getYaw();
        roll = trackedTarget.getRoll();
        pitch = trackedTarget.getPitch();
        skew = trackedTarget.getSkew();
    }
}

}

1 Like

I do not have the answer you seek, but I will point you to the next step.

Remember none of us are in the room with you. While telling all details isn’t possible, there will need to be a bit more detail before help can be given.

Formulate your world like a scientist. Apply the scientific method.

What experiment did you run?
What did you expect to see happen?
What did you observe actually happen?

Breaking down the problem you face will both be helpful for yourself, as well as help others direct you better.

6 Likes

Also, this thread in the same vein as the first answer. There are a few older similar threads, too.