# Trouble with Calculating Distance/camera pitch

Hello,

My name is Liran, and I’m representing Team 1943. I’m currently working on a project that involves calculating distance using a Microsoft LifeCam HD-3000 camera and the PhotonUtils.calculateDistanceToTargetMeters() function from the Photon Vision library.

I’m facing an issue with determining the correct pitch of the camera. I attempted to use basic trigonometry by measuring the Δx and Δy values of the camera from the April tag (tried both from the middle and top of the April tag). I then used the atan function to calculate the angle. However, this approach resulted in significantly incorrect distance values.

As an alternative, I also tried aligning the camera as straight as possible and setting the pitch to 0 before calculating the distance. Unfortunately, this method also gave me poor results.

I would greatly appreciate any suggestions or guidance you can provide regarding my situation. Since I’m new to vision-related tasks.

Here are a few additional notes:

• The camera and the April tag are placed at different heights.
• I measured the Δx and Δy values from a horizontal plane accordingly.

For reference, here is the documentation for the PhotonUtils.calculateDistanceToTargetMeters() function:

Thank you for the assistance!

2 Likes

While I’m not familiar with this method, based on the documentation, I would interpret the camera pitch as the rotation of the camera relative to the floor (completely independent of any AprilTag). For example, if the plane of the camera lens is perpendicular to the floor (i.e., the camera isn’t tilted up or down), the pitch would be π/2 radians.

1 Like

You should be able to just call getPitch() on a PhotonTrackedTarget and convert that to radians

It appears you are trying to replicate the geometry shown in the LimeLightVision documents https://docs.limelightvision.io/en/latest/cs_estimating_distance.html#fixed-angle-camera

What part of the drawing is not working for you? Is it the alpha2 angle which comes from your camera processing software such as PhotonVision, LImeLIght, or your home brew? Are you trying to double check the software by measuring it yourself with a protractor (smartphones have that function and my team uses often uses them since it’s easier to find a phone in the shop than the team’s inclinometer

)
I am

AndyMark
concerned with your statement

since the drawing and formula are only for one or the other and not both (I don’t remember which one). You’d have to have 3-D formula to use both x and y, if you don’t align straight on although you did say you tried that, too.

If you still have the question and can provide a drawing or reference the LL

Limelight, an integrated vision coprocessor
drawing of what isn’t working and all the numbers that you plugged into the formula, we can provide better guidance.

Sorry for the great delay in response time.

The documentation that you linked really helped!
Thank you very much.

The problem was, indeed, in how we looked at the pitch calculation.

for any other team: use this formula to calculate the pitch:

d = (h2-h1) / tan(a1+a2)

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.