Robot Exit Angle Between Two Objects

imk

New member
Joined
Apr 7, 2023
Messages
7
Hello,

I am building (3D Printing / Writing C/CPP Software for ) an autonomous wheeled robot which at this time is going pretty well. However I have got myself stuck on a bit of math (function) that will return the (Robot Exit Angle) In- Between two vectors/points. I have been at this for couple of days and now figure it is time I turned to better mathematical minds than mine.

I have done a little sketch of the problem for clarity just in case my description is not clear.
So the robot has identified two objects and my goal is that it will drive in-between these two objects in a straight line (Exit Angle) passing each object by the same lateral distance.

The objects are defined in my system by their x,y coordinates and a vector of angle and length.
Thus:
Object A is 25 Units Length by 45 Degrees
Object B is 50 Units Length by 90 Degrees
I have an approximation in my sketch of an Exit Angle of ~ 70 Degrees which gives about 14/15 Units Length on each side assuming Zero Robot Width. I figure the problem is basically Two Right Angled Triangles that share a common Hypotenuse, and then compute their Opposite Sides to get the lateral passing distance.

Problem I am having is finding the Exit Angle, can someone help please?
BTW I am not very good at reading math formula in terms of |x|.|y| etc. so a solution that I can enter into a calculator would really help me best.

Many thanks in advance IMK


IMG_5986.JPG
 
passing each object by the same lateral distance.
I am not sure I understand your problem 100%, but: the red segments in your drawing do not represent the shortest distances between the robot and the objects.
 
Hello Blamocur and many thanks for the post.
The Robot is in the middle at 0,0 and must pass in-between the two objects at vector 25 by 45 and vector 50 by 90 vectors, The Black Dots.
Hence I need to find the Green Exit Vector that it must travel along, so the length of the two Opposite Sides (Red Lines) are the same.

Maybe I have the Triangles wrong and the Opposite Sides should in fact be the Adjacent Sides and meet the Exit Vector (Green Line) at 90 degrees. I have added amended sketch with Dotted Red Adjacent which maybe the correct way to solve this?

Many thanks IMK

IMG_5987.JPG
 
Last edited:
math (function) that will return the (Robot Exit Angle) In- Between two vectors/points.
Hi IMK. Please confirm whether or not each vector angle may range from 0º to 360º. Also, might the two vector lengths ever be equal? :)
[imath]\;[/imath]
 
Hello Otis and many thanks for your post.
To answer your question; YES the vector angle can be in the range of 0 360 and YES two vectors lengths can be equal.
For clarity the two sketches above are really an over simplifications of what is going on.
The Robot (ERIN) lives in the middle of a 201x201 matrix of 1cm cells.
The cells are populated by what the Robot's sensors detect on it travels.
As the Robot moves forward, the 201x201 matrix scrolls backwards and is also rotated in sympathy with the Robot turns.
The real world situation I am trying to resolve can be found in the image below.
Where the Robot has detected a multiple Exit Opportunity situation and needs to figure out which are Go or No Go.
I am retired and doing this project to keep my brain going, however my brain seems to have gimble locked on this one.
I could solve it by successive approximations by I believe there is a more elegant solution.
Many thanks for looking IMK




ERIN-Capture1.png
 
Last edited:
...which maybe the correct way to solve this?
To figure out the correct way we need to clearly define what "this" is in your case. In particular, what is "lateral passing distance"? If it is the shortest distance between the robot and the object then your dashed red lines (i.e., the lines orthogonal to the robots' path) are the correct approach, and the solution would be for the robots path to go through the midpoint between the two objects.
 
For two objects: given angles [imath]\theta_1, \theta_2[/imath] and the corresponding distances [imath]d_1, d_2[/imath] the cartesian coordinates [imath](x_m, y_m)[/imath] of the midpoint between them are defined as [math]x_m = \frac{1}{2}\left(d_1\cos\theta_1 + d_2\cos\theta_2\right)[/math][math]y_m = \frac{1}{2}\left(d_1\sin\theta_1 + d_2\sin\theta_2\right)[/math]and the corresponding angle for the robot sitting at the coordinate origin (0,0) is [math]\theta_m = \arctan\left(\frac{y_m}{x_m}\right)[/math]The last formula is not very practical because a) it does not work when [imath]x_m = 0[/imath], and b) the answer is defined modulo 180 degrees. In most programming languages (in their libraries to be precise) there is a more practical function arctan2 which solves the above problems.
Good luck with the project!
 
  • Like
Reactions: imk
Hello Blamocur and many thanks for the solution, I have left a LIKE :) for you.
I have coded up your solution and tested with a few test vectors and it returns expected results which I guess is proof I have coded it correctly.
ERIN can not thank you enough as now she won't be running into thing as often :)
I tried to post youtube video of ERIN but the forum removed it, she can however be found on my youtube page @ianknight4013
I have I guess another year or three work to do on a flock of autonomous Robots, ERIN is really the proving ground for the software.
Code is below also image of ERIN from 3D CAD in Alibre Design again many many thanks IMK

int FindAngleInBetweenTwoVectors( int Angle_A , double Dist_A , int Angle_B , double Dist_B )
{
double M_X, M_Y;
int Angle;

M_X = ( ( Dist_A * cos( (double)Angle_A * DEG_TO_RAD ) ) + ( Dist_B * cos( (double)Angle_B * DEG_TO_RAD ) ) ) * 0.5;
M_Y = ( ( Dist_A * sin( (double)Angle_A * DEG_TO_RAD ) ) + ( Dist_B * sin( (double)Angle_B * DEG_TO_RAD ) ) ) * 0.5;

Angle = (int)round( atan2( M_Y , M_X ) * RAD_TO_DEG );

if( Angle < 0.0 )
Angle += 360;

return( Angle );
}
 

Attachments

  • ERIN-1.JPG
    ERIN-1.JPG
    95.7 KB · Views: 2
Top