Calculating the angle of servos based on the position of an object

Hello, I am currently creating a model anti-air SAM launcher and using servos instead of CFrames. This brings up the problem of me never using servos in my life and having no idea how to calculate the X and Y positions for the two of them. Let me give some context.


There are three servos two of them having the same angle for the Y-Axis and one for the X-Axis. You can probably picture how this is supposed to work.

Now, all I want to do is change the angle of the X-Axis servo to match that of the yellow part while also changing the Y-Axis servos to match the Y-Axis of the yellow part so, in a whole, the SAM launcher is looking at the part but instead of using CFrames which are gross and choppy, we are using servos.

1 Like

Yeahh Vector mathss

Here is the diagram of information you can get when you obtain the vector of the base of the turret to the target position:

DiagramToYourProblem

Once you found this you can use trigonometry to calculate the angle. Hope my MSPaint skills helped.

Edit: whoops typo for the bottom length its

sqrt(X^2 + Z^2) length of the vector to find that orange length.

7 Likes

angle = tan^-1(dy / dx)
tan^-1 means inverse tangent;

where dy is the the height from some starting position and dx is the length from some starting position.

Remember: SOH CAH TOA.
In this case we have O and A (opposite and adjacent) so we use tangent.

6 Likes

Of course you could weld the LH side of the Launcher to the RH side so you only need one servo for both Y angles.

I ran into the same problem as the original poster, but I don’t know any trig. How would I go about getting those 2 angles? Sorry for the bump.