Vision Sensor


#1

In the V5 System Architecture, https://www.vexrobotics.com/v5-architecture.html it is stated under the vision sensor tab that “When the camera is tilted down, the Y-value gives you the distance to the object, with a little basic trigonometry” . How would someone be able to calculate the distance of an object when the camera is tilted up? Also, what method is the “result array” under sensor programming for?


#2

You might use other information. For example, if you’re looking at a flag and you know which one, then you know its height. You also know the height of the vision sensor as well as the angle it’s aimed up at. That’s enough to do the trigonometry.

If you want the actual trigonometry, I could sketch it out later and scan it.


#3

That makes sense, thanks @callen


#4

I am making a diagram right now, I will post it when I complete it
Edit: This is almost finished, the math is just grueling…


#5

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.


#6

Can you use two vision sensors and implement stereo for distance?


#7

@Impulse Theory , your math isn’t quite right, and that error is assuming the flat projection (not fish-eye) you’ve drawn. The problem is that it’s not c/400. That 400 isn’t aligned with c. And then there is the whole issue of the curved image (fish-eye) the vision sensor seems to provide. I’ll do the flat projection calculation later and post it.

Do we know the field of view’s angle? That would be nice to have. I don’t see it in the specs, though.


#8

I knew my math would miss something!
Sadly, we do not know the FOV yet. Maybe put a variable in its place, and work it out like that. Tag me if you post your new calculations.


#9

Yes, I figured I would still use your c because it’s something everyone can measure quickly by just putting a tape measure or similar on the floor. It also has the advantage that it can still be used if the camera can zoom.


#10

I’d presume it would be the same FOV as the cmucam5, which the sensor is stated to be closely based on. According to the product page:


#11

I’m assuming a flat projection, though the images make it look as though it may be a fish-eye lens or similar. I’m assuming the target is like a piece of tape on the floor; if it’s elevated significantly, that will change things. I’m also working with the 47 degrees given by @BWorcester ; if the angle is different, just use half that in place of the 23.5 degrees showing up below.

The variables:
S = distance to target
H = the height of the middle of the camera lens
ø = the angle up from straight downward you aim the camera (the center of its view), making horizontal 90 degrees
y = the y value from the camera’s output (assuming 0 to 400)

S = H * tan( ø - atan ( (1-y/200) * tan(23.5 deg) ) )

I haven’t taken the time yet to write up the solution neatly, nor have I taken the time to see if there is a nice expression by expanding the tangents of sums or differences.


#12

@Impulse Theory @caek

I’m attaching the two images showing the derivations and the final results. It looks like I switch what theta is between them, but not really. Theta is the angle up from looking straight at the surface. So if you’re looking toward the floor, horizontal is 90 degrees; if you’re looking toward a wall, horizontal is 0 degrees. You have to figure out the heights based on where you mount the vision sensor (really, its lens) and what you’re looking at. I’ve left the field of view angle general because I wasn’t sure which orientation the vision sensor would have, and I’m not 100% sure on the angles given above. If you don’t know the measure of the field of view angle, you can use the camera, check the endpoints, and measure out the triangle FOV to get it.


#13

Hmm… I’ve found some images of the vision sensor with y labels. I can’t figure out where the origin is. I used it as F receiving the value of 0 and V receiving a value of 400. Also, if you choose to use it sideways, the camera will probably return x values to be used here in place of y values.


#14

So does this equation work? I’m trying to figure out how to calculate the distance to the flag and it doesn’t seem as if there is a set equation yet. Also how would this equation work with a vision sensor angled up as wouldn’t the field of view change? I’m having trouble following this equation so could you explain it better please? Thanks


#15

How are you going to use this? Are you going to adjust the rpm of your shooter or are you going to just move the robot forward and backward until it lines up?

If you are adjusting the rpm to hit the flag, then you will take the y position of the flag and you could just guess and check to see what rpm works. Then move the robot and repeat. You would then fit a line or curve to fill in the values. If your camera is positioned correctly it may be able to identify high and low flags just based on their y values.

If you have a catapult, then you could just not let it shoot unless the y-coordinate is within the target range. You could have the screen flash a color when it likes what it sees.

In other words, be an engineer, not a mathematician. :slight_smile:


#16

The goal is to move the robot to a desired position. However, I still don’t understand how this equation works especially when the vision sensor is aimed upwards so that’s what I’m wondering.


#17

If you want angled up, use the lower diagram. Look at the picture and you’ll see that the camera is angled up. As for the set equation, look at the last line on the right-hand side; it’s an equation for s, the horizontal displacement to the target.

As for changing the field of view, that has nothing to do with angling the camera up or down. That’s a feature of the camera. If you rotate the camera 90 degrees, then you can get something different.

As for using the equation, look at the diagram to see what most the values are, and look at the preceding post for a verbal description of the values and the assumed 400 pixels.

If you don’t know what the trigonometric functions mean, it would probably be a lot easier to go to a math teacher at your school than for me to try to explain it all online. And note the post afterward specifying where the 0 and the 400 are set. I think they set the origin at the top, but I hadn’t known that would be done. Changing y to 400-y switches the origin to the top.


#18

@3034 The equation does work, but the vision sensor reads the values in 320 by 200 not 640 by 400, so replace the 400 with a 200. Also, my team developed an equation for a flywheel that provides the rpm given distance and height. If you do this, you do not even need to move the robot, just adjust rpm of the flywheel. @sankeydd being a mathematician is a part of being an engineer. With a flywheel you can hit the ball anywhere on the field.


#19

My students are finally getting around to trying to use the vision sensors to improve their game. This thread has such great content in that regard. Hopefully, many of you are able to align the array of symbols in the formula and diagram that @callen posted to the real world elements involved. For those of us with less supple minds I would like to offer a natural-ish language version of the final formula (for an upward angled camera) :

distToTarget = TARGET_HEIGHT - LENS_HEIGHT / tan (LENS_ANGLE - atan( (1 - sensed_target_center / LENS_PIXELS) * tan (LENS_DEGREES / 2) ) )

ALL CAPS values are all known/measurable, and the bolded item is the value you are getting from the vision sensor. Most likely just as (or more) cryptic, but to a different set of readers :slight_smile: