Analytical Inverse Kinematics driven VEX arm with servo calibration. Built to test workspace theories.
Create a robot arm with 2 degrees of freedom that can reliably reach any coordinate within two popsicle-stick lengths of the base.
A horizontal two-link arm uses gear and chain to drive the elbow and a standard servo on the shoulder.
I modeled the links with equal length (L₁ = L₂ = 1) so the analytical IK routine stays
compact, then ported that solver into RobotC.
q1 = angle 1, q2 = angle 2
x = cos(q1) + cos(q1 + q2)
y = sin(q1) + sin(q1 + q2)
r = x² + y²
q1 = acos(r/2 - 1)
// IK Controller for 2-DOF Arm
#pragma config (Motor, port2, shoulder)
#pragma config (Motor, port3, elbow)
const float PI = 3.14159265;
const float gorp = 180.0/PI;
int toCmd(float deg) {
if(deg < 0) deg = 0;
if(deg > 120) deg = 120;
return (int)(-127 + (deg * (254.0/120.0)));
}
float elbo(float x, float y) {
float r = pow(x,2) + pow(y,2);
float q1 = acos(r/2 - 1);
return q1;
}
float sholder(float x, float y) {
float b = elbo(x, y);
float q2 = atan2(y, x) - b/2;
return q2;
}
task main() {
float k = 1, l = 1;
motor[shoulder] = toCmd(sholder(k,l)*gorp);
motor[elbow] = toCmd(elbo(k,l)*gorp);
while(true) wait1Msec(20);
}