Weird Output Values when Trying to Find Target Distance

Hello everyone,

This season, my team has started using a Limelight 2+ for our robot build, and they’ve assigned me to figure out how to program it.

What a fun ride that’s been. :roll_eyes:

Anyway, I managed to program it to automatically adjust to a target (which still has its issues), but the team asked if I could program it to calculate distance. I looked at the Limelight documentation, which was helpful, but I’m here today to share some weird issue I’m having.

I created a Blank VI to simulate the offset values changing, but every time I run it and change the offset, the values jump around a lot, and even occasionally jumping down to the negatives.

Code below

Not sure what you are trying to do here.
I doubt camera height (35) is in radians (the input required by the tangent function)?

Nope. It’s in inches. I’ll look into converting it to radians. In the code, I’m trying to find the distance of the target (in inches) using the equation
d = (h2-h1) / tan(a1+a2)
where d is distance, h1 is the height of the robot, h2 is the height of the target, a1 is the angle in which the Limelight on our robot is tilted at (35 deg) —

Whoops. The label next to the 35 is actually supposed to say Camera Angle.

– And finally, a2 is the offset (/limelight/ty) given by the Limelight.

Yea, so 35 degrees should be .61 radians
For readability you might want to do the conversion in code so you can keep thinking in degrees.
Make sure the Ty values you choose are also in radians.

1 Like

Thank you, I will try this now

Ok, so I tried converting everything to radians, which eliminated the issue of the Distance output jumping around.

The thing is, when I increase the Offset, the Distance decreases when it’s supposed to decrease. Also, is there any way to take the radians after the tangent calculation and somehow make the Distance output in inches?

Screenshot 2021-03-04 105544 Screenshot 2021-03-04 105812

The output is in whatever units you use for height, I presume that’s in inches.
Tangent is just a ratio. It has no units associated with it.

I’d expect the distance to decrease as the total angle increases.
You’re looking up at a steeper angle as you get closer to the wall. Craning your neck so to speak.

As the angle decreases the distance gets farther.

My assumptions are:

  • the 35 degrees is your camera tilted up.
  • The Limelight Ty is an additional tilt up when positive and down when negative.

You can simplify/clarify the code by adding the camera angle to ty, then converting to radians and sending that to the Tan function. That way all your inputs are in degrees making it easier to think of 35+7=42 total degrees.

1 Like

Thank you, I’ll try this out after school

Update – the distance works. All we had to do was multiply the output by 4 and then divide that by 12. Thank y’all so much!

Here’s the code in case anybody needs it…

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