Inverse Kinematics for a 2D Scara Robot

Hello, I am currently working on the inverse kinematics for my scara robot. This is the code and equation I use:

const double L1 = 202.25;
const double L2 = 193.35;

float alpha = 0;
float beta = 0;

void calc_IK(float x, float y){
  beta = acos((pow(x, 2)+pow(y, 2)-pow(L1, 2)-pow(L2, 2))/(2*pow(L1, 2)*pow(L2, 2)));
  alpha = atan((y/x)-atan((L2*sin(beta))/(L1+L2*cos(beta))));
  Serial.print("Beta: ");
  Serial.print(beta);
  Serial.print(" ");
  Serial.print("Alpha: "); 
  Serial.print(alpha);
  Serial.println(" ");
}

void setup() {
  Serial.begin(9600);
}

void loop() {
  calc_IK(3.0, 5.0);
  delay(500);
}


The equation itself works on paper but the code doesn't. I get for beta 1.57 and for alpha 0.73 instead of 89° and -88°. What am I missing?

In most programming languages, trigonometric functions operate on radians, not degrees. In C/C++ you have to perform the conversion in the code.

Instead of atan(), atan2() is usually preferred, as it correctly handles assignment of quadrants.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.