Hi; my first post to CD, hope it helps. We’ve been looking at similar uses for the Limelight, and I think I understand how to solve your issue. Try this:

I assume you have a gyro of some ilk on your robot (without it, accurately turning to a given angle is difficult); and I assume the gyro is calibrated to give you a reasonably accurate value for the robot’s absolute angle *relative* *to* *the* *field* at any given time. (Gyros will drift, but can also be recalibrated on the fly when you know the robot’s orientation). Assume in your image above that the target is perpendicular to the field, so the “approach line” protruding from the target (along which you’d like to approach it) is at 0 degrees field-relative.

Now, call the robot’s current field-relative angle theta. You can see that the field-relative angle of the line between the robot’s camera and the target is just (theta - angle1). But, a line drawn from the robot’s camera at zero degrees will be parallel to the field and hence parallel to the approach line; so by the parallel postulate, angle2 must also equal (theta - angle1). That is: angle2 is the robot’s current field-relative angle minus the angle between the camera centerline and the target, when the target is perpendicular to the field.

If the target isn’t perpendicular to the field, the same reasoning applies, but everything is rotated by the target angle.

Note that from this information you can also determine the distance the robot needs to drive to reach the approach line. The third angle of the triangle (the angle between the robot’s direction and the approach line) is angle3 = (180 deg - angle1 - angle2) . By the Law of Sines,

sin(angle3)/Distance = sin(angle2)/DDrive

where DDrive is the distance you need to drive to reach the approach line; and angle3 is the angle you will need the robot to turn to be aligned with the target.

Note: we haven’t actually tried this yet, and someone definitely should check my math! But, I hope it helps!