Vision Sensor

EDIT: DODGY AND/OR INCORRECT MATH

CASE WITH GROUND OBJECT
I am not that confident in my math, but here is what I came up with.
SETUP

Your sensor is mounted on a tower. Your sensor is always a certain distance from the ground, if your robot stays level.

The sensor can see objects, and it gives them X and Y coordinates. (x is between 0 and 640, y is between 0 and 400.) I am not sure if the coordinates will work exactly as shown, but it will be close enough.

I did lots of math, and for this case, you do not need trigonometry, because it all cancels out.
(Specifically, when I solved this right triangle, I ran into the law of sines setup, which eventually collapsed into a tangent, which canceled out the arctangent which converts the Y Value into the object’s angle from the camera.)

So in this case, you just need to use a linear equation to solve for distance:

I wrote this distance equation in the format of y = mx+b, since the relationship between distance and Y Value is linear. M, or slope, is the parenthesis part that converts the Y value in pixels into distance. You’ll need to measure c yourself, but I hope the diagram makes it clear enough what c is (It is the length in inches of the size of your field view at your sensor’s give height). B is just the distance from the foot of your robot (under the vision sensor) to the lower bound of your sensor’s field of view. You will need to measure this manually too.

This is just one way to calculate it. If you instead wanted to use the camera’s height from the ground and the camera’s angle (Which is arguably easier to measure once your camera is on a robot, ESPECIALLY if the camera has a built in angle measure), you would have to use trigonometry then to calculate a new value for the slope/m value, but the whole relationship between the Y Value and the resulting distance remains linear.

Furthermore, you can modify a custom equation with any amount of extra goodies, like calculating distance from a certain seperate point on your robot, or account for horizontal distance/angle, but that is beyond the scope of this basic demonstration.

3 Likes