Vision Processing Calculation Consistency

Hi everyone. I am having some problems with the consistency of the camera (using an AXIS cam) where it will only calculate the correct distance/angle values when the camera is perfectly perpendicular to the robot. Sadly, this is not always not the case and the camera often gets tilted.

Is this normal or should I be able to calculate the correct distance/angle no matter how my camera is oriented?

There will always be some distortion in cameras, so if you’re not accounting for that you’re likely not going to get a perfectly accurate position or angle, but you should be able to get your numbers close enough for almost all FRC use cases. Do you have a repository with your vision code you can share with us to help debug your issues?

Sure here it is! All the distance/angle calculation code is in the ‘Target’ class.

I don’t see anything obviously wrong with the code in that file. Do you have any recorded data points of your issue? What is the actual angle/distance and what does your code report the angle/distance as? Being able to spot a pattern there between several points will help diagnose the issue in your code.

If you’re not already doing so, using OpenCV to draw a dot where you think the center of the target is can also be helpful to further narrow down where the issue might be hiding.

I believe the problem here is that their camera is being physically tilted, therefore throwing off their calculations due to target angles being skewed by the camera not being in a vertical orientation.

If this isn’t the issue, disregard, but I suggest you look into having a more sturdy mount for your camera rather than trying to mitigate this issue by dynamically adjusting your code due to the camera being tilted off axis physically.

Yes. I know the code is fine but it only works with the camera being perfectly perpendicular to the robot.

I will look into having a sturdier camera mount if I can’t solve it within the code… Thanks!