Vision Sensor

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.

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:

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.

1 Like

@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.


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.

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

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:

1 Like

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.

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.

@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.

1 Like

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:


but how would one put this in Vex coding Studio C++ Pro

This should be possible with a little algebra and a caliper (distance from lens, length of field of view at that point. It’d be a little inaccurate, but good enough for testing

After doing some experiments, I think the horizontal FOV should be around 60 degrees(±1º).

Yes, @jpearman just posted 61°, and we had measured something similar. Note you’ll also have to adjust the 400 (which becomes 200 in the y/200 part after a division by 2). That was assuming 400 pixels across, and the wide angle is 316 pixels, making that 200 become 158. Of course, you also have to change y to reflect the orientation of the camera and how y is actually measured on the camera.

Is it possible to use de vision sensor to track a line?

I believe so, but it might be better/easier to use the line sensor or the light sensor. This might be worth making as a new topic, by the way.

hey guys I was wondering if the vision sensor could potentially help me locate exactly where a tower is and have it go and take it for autonomous mode, it would be quite helpful. And when it shows x and y coordinates does that count starting from your start point (0,0)? Or does it have its own start coordinates that it uses?

Please do not revive old threads