Using an Uncentered Vision Sensor to Align the Bot to the Center of the detected object

Hey. I was wondering if anyone could help me understand how to go about researching the math behind and coding an unaligned vision sensor on our robot. I am pretty sure it is possible but I don’t understand the math to start it yet. Let’s say our robot vision sensor is 6 inches to the left of the center of our robot.


I understand that we have to use an offset and most likely trigonometry, but I don’t know where to find this information. Can anyone offer links or resources to help me?

Are you referring to a GPS Sensor? What are you trying to learn or do?

He was referring to this

It detects blobs of color, and the new one can be used (choppily) to detect field objects for VEX AI

As helpful as a long description is, you’re still missing some details, like do you want the angle to turn the robot to face towards the object? Do you have a holomonic drive that can move anywhere? Regardless, here’s the math

D: Distance from the robot to the object (measured by distance sensor).

L: Lateral offset of the sensor from the robot’s centerline.

θ: Angle between the object and the sensor’s line of sight (I’ll show the math after this section).

X: The lateral shift you need to make to center the robot in front of the object.

Since the sensor is offset by L, you need to calculate the lateral distance from the robot’s centerline to the object using the angle θ provided by the sensor.

The lateral distance X is given by:

(This is the hardest trig part you wanted)
X=D × tan(θ)

Since the sensor is offset by L, you need to add or subtract this value depending on the configuration (whether the sensor is on the left or right of the robot’s centerline). Assuming the sensor is on the left, the required lateral movement C to center the robot is:

C = X − L

Move the robot laterally by C to center it in front of the object.

Example:
If the distance sensor reports a distance D = 2ft and the vision sensor an angle of θ = 30°, and the sensor is offset L = 0.5ft to the left:
Calculate the lateral distance from the robot’s center to the object:

X = 2 × tan(30°) = 2 × 0.577 = 1.154ft
Correct for the offset:

C = 1.154 − 0.5 = 0.654ft
The robot needs to move 0.654 ft to the right to center itself in front of the object.

Here’s how to calculate the angle from the object using the vision sensor.

You need:
FOV = 61°
Width = 316 pixels

The total horizontal field of view is spread across the width of the sensor’s image, so each pixel corresponds to a small angle. The angular resolution per pixel is:

Angular resolution per pixel = FOV / W

If the object is at pixel position P, and the center of the image is at pixel W/2, the offset from the center is:

Pixel offset = P - (W / 2)

Multiply the pixel offset by the angular resolution per pixel to get the angle θ from the centerline of the sensor to the object:

𝜃 = Pixel offset × (FOV / W)

𝜃 is the angle to the object.

6 Likes

Thank you for the response! I’ll have to test and apply this knowledge when I can go to our field. Also is it possible to do it without a distance sensor? We do want the robot to turn and face with the object.

We want to face it to* the object

I don’t think it is possible without a distance sensor. You need the horizontal distance for the calculation. If you know the size of the object, you could do calculations with how big it appears on the vision sensor.

This is how you get the angle to the object
θ = atan2(y, x)
where y is the horizontal distance to the object (how far forward), and x is the lateral distance (how far to the side).

You should get the horizontal distance from the distance sensor, and the lateral distance from the original calculation.

Most programming languages have a atan2 function built in.

Python:

C++:
https://cplusplus.com/reference/cmath/atan2/

1 Like

Ah, I think I understand now, and thank you for your responses. But what if you, instead, just move and face the center of the robot to the object using solely the vision sensor? Is that possible with the unaligned vision sensor? Once we get close enough, to the point where the object is probably out of the vision sensors view) we could just move forward and pick it up- assuming that we have it angled properly.

It would be difficult. You would need more trig to calculate the distance, and even then it would be choppy. Not ideal to use a vision sensor for distance.

Ok, thank you so much.

1 Like