Trigonometry

I need some help!

I am building a robot arm and im trying to get the claw-end of it to move linearly. So both horizontally and vertically. the arm consists of two joints, like a shoulder and elbow. I'm trying to use trigonometry to do the calculations for this, but i have no idea how to approach this in Arduino code, is it even possible for an Uno?
Is there some library or something that could help with the trigonometry?

Thanks!

math.h

Remember to use radians.

Hi,
Good question. IsThere some notation for multiple axes that defines the relative angles and motion? Some algorithm to derive a third motion? Some serious robot guys must have done this...

Check this library SpeedTrig

SpeedTrig

Simple Arduino library that speeds up trigonometry functions, based on work by Oscar Liang.

Simply drag the main folder into the libraries subdirectory of your Arduino IDE sketch folder.

This is a simple output (via serial) to show accuracy of library compared to the Arduino functions:

Sin 15:

  • Standard [RAD]: 0.6503
  • Fast [DEG]: 0.2588
    Cos 15:
  • Standard [RAD]: -0.7597
  • Fast [DEG]: 0.9659
    Acos .15:
  • Standard [RAD]: 1.4202
  • Fast [RAD]: 1.4230
    Atan2 5, 5:
  • Standard [RAD]: 0.7854
  • Fast [RAD]: 0.7823
    Also useful if you need degrees for sin/cos.

The two parts of the arm are fixed in length. You know how far the desired position is from the shoulder by the Pythagorean Theorem: Distance = sqrt(xDistancexDistance+yDistanceyDistance). That gives you the third side of the triangle from which you can calculate the elbow angle.

You can get the shoulder angle from trig because the xDistance and yDistance are two sides of a right triangle. The Distance calculated above is the Hypotenuse. Sine is Opposite/Hypotenuse so the Shoulder angle is arcsin(yDistance/Distance).

You now have the two angles to feed to your servos.