# Inverse kinematics robotic arm 6dof

Hello
I am trying to control a 6dof robotic arm with an old controller and would need to calculate the 6 joint rotation after inputting a target x,y,z position and rotation.
So far from my research the inverse kinematics topic looks wide and complex . I am looking for some recommendation and place to start or maybe some existing example in OF
Thanks!

I started a simulation to control the arm rotations (I started with trigonometry and then realized using quaternions was much simpler) this is what I have so far

based on this robot arm
this is the code for the simulation so far

bone1Width = 300;
boneA3Height = 155;

boneLenght = 675;
boneLenght = 650;
boneLenght = 0;
boneLenght = 600;
boneLenght = 125;
boneLenght = 0;

ofVec3f anchor;
ofVec3f newPt;
ofVec3f dir(0, 0, 0);

jointQuat.makeRotate(jointRot, 0, 1, 0);

anchor = ofVec3f(0, boneLenght, bone1Width);
jointPos = anchor * jointQuat;

jointQuat.makeRotate(jointRot, 1, 0, 0);
jointPos = ofVec3f(0, 0, boneLenght) + jointPos;
anchor = jointPos;
dir = jointPos - anchor;
dir = dir * jointQuat * jointQuat;
jointPos = dir + anchor;

jointQuat.makeRotate(jointRot, 1, 0, 0);
jointPos = ofVec3f(0, 0, boneLenght) + jointPos;
anchor = jointPos;
dir = jointPos - anchor;
dir = dir * jointQuat * jointQuat * jointQuat;
jointPos = dir + anchor;

uppoint = ofVec3f(0, boneA3Height, 0) + jointPos;
anchor = jointPos;
dir = uppoint - anchor;
dir = dir * jointQuat * jointQuat * jointQuat;
uppoint = dir + anchor;

jointQuat.makeRotate(jointRot, 0, 0, 1);
jointPos = ofVec3f(0, 0, boneLenght) + uppoint;
anchor = uppoint;
dir = jointPos - anchor;
dir = dir * jointQuat * jointQuat * jointQuat * jointQuat;
jointPos = dir + anchor;

jointQuat.makeRotate(jointRot, 1, 0, 0);
jointPos = ofVec3f(0, 0, boneLenght) + jointPos;
anchor = jointPos;
dir = jointPos - anchor;
dir = dir * jointQuat * jointQuat * jointQuat * jointQuat * jointQuat;
jointPos = dir + anchor;

jointQuat.makeRotate(jointRot, 0, 0, 1);
jointPos = ofVec3f(0, 0, boneLenght) + jointPos;
anchor = jointPos;
dir = jointPos - anchor;
dir = dir * jointQuat * jointQuat * jointQuat * jointQuat * jointQuat * jointQuat;
jointPos = dir + anchor;

posFinal = ofVec3f(70, 100, 150) + jointPos;
anchor = jointPos;
dir = posFinal - anchor;
dir = dir * jointQuat * jointQuat * jointQuat * jointQuat * jointQuat * jointQuat;// *;//
posFinal = dir + anchor;

i would try using ofNode for each joint, that way you can chain all the local transformations without having to do all the calculations manually. The rotations are internally expressed in quaternions in ofNode so it’s really the same but you can parent one node to another instead of having to do all the multiplications manually