Vision Distance Estimation issues

Hello, on our team we’re currently trying to use PhotonVision’s calculateDistanceToMeters function, but for some reason we are running into issues with our distances. We are getting a value back from the camera that roughly scales with distance, but for some reason the distance returned isn’t consistent with the distance measured, and doesn’t follow a linier path. I’ll list some distances with the actual distance, along with the measured distance by the camera (both in meters)

Actual distance | Measured distance
0.9 1.29
1.5 2.18
2.1 3.65
2.7 5.08
3.4 10.2

Here is the code that does the actual distance estimation.

public Double returnDistanceToTag(Vision vision) {
    var result = vision.photonCamera.getLatestResult();
    if (result.hasTargets()) {
      double range = PhotonUtils.calculateDistanceToTargetMeters(
        0.3, //camera height 
        0.5, //test target height
        0.0, //camera pitch - we are currently perpendicular to the ground 
        Units.degreesToRadians(result.getBestTarget().getPitch()));
      currentDistance = range;
      return range;
    } else {
      return currentDistance;
    }
  }```

Have you tried to recalibrate your camera (using something like www.calibdb.net) and reupload that to PhotonVision? PhotonVision needs to have an accurate camera calibration to know how big a tag is and estimate distance based on the camera feed.

1 Like

They’re using retro-reflective mode from the looks of it, which doesn’t need calibration.

Are you sure you want to use a retro-reflective pipeline in PhotonVision?

An AprilTag pipeline will give you better results, as you can accurately calculate your robot’s position on the field, and from their, get your distance from your robot to any desired point.

The first thing I’d check is if the pitch and height really is correct.

I currently have the Photonvision pipeline set to the AprilTag mode. I’m not sure where the retro-reflicive pipeline is coming from. Is that method only intended for tape?

I think the camera recalibration actually worked. I’ll have to double check to make sure the distance is accurate. Thank you for the reminder that the camera sometimes basically just needs a power on and off!

So turns out the distance isn’t accurate. I’m luckily having a consistent change in number based on how far away I am, but it isn’t linked to how far it is in meters. I can give some numbers if that would be useful. The number is significantly smaller than what it used to be, so that’s in my mind an improvement

I see, are you using 3D mode? I only speculated that you’re using retro-reflective mode (or colored shape), because of the method you’re using to calculate the distance to the object. That method is designed for the colored shape pipelines. If you have AprilTag 3D mode, you can input those pose estimates into your pose estimator, and calculate distance from your robot to any desired point like I said earlier.

ohh that make a lot more sense. We are currently using 3D mode, so we could get the poses from both and make that work. Are there any good references to make that work code wise?

You can look at our repository, its public.

1 Like