I’ve been working on using to Romi to detect AprilTags to get experience before kickoff. The issue I am having is that the readings for distance have been extremely erratic, fluctuating based of the yaw of the target and sometimes reaching into the negatives, an impossibility. My original guess for the cause of the problem was the little height delta between the tag and camera, so I mounted the tag significantly above the Romi. This has done nothing to resolve the issue. I also have calibrated the camera. My code to find the distance is as follows:
public double getBestTagDistance(){
if(bestTag != null)
return PhotonUtils.calculateDistanceToTargetMeters(Constants.CAMERA_HEIGHT,
Constants.TARGET_HEIGHT[bestTag.getFiducialId()],
Constants.CAMERA_PITCH,
Units.degreesToRadians(bestTag.getPitch()));
else
return -1;
}
The constants in question are a camera height of 4.5 inches, converted to meters, a target height of 32 13/16 inches converted to meters(I use a list to store the heights if I would work with multiple targets), and a camera pitch of 0. Unfortunately, the Camera I am using has a flexible mount, but the camera looks quite parallel to me.
Any ideas for potential causes for this erratic reading and methods to solve it would be greatly appreciated.