Robotics StackExchange | Archived questions

KDL Inverse Kinematics for a Hexapod

Dear Community,

lately I have been working on a Hexapod robot and I have got to the point of having the urdf defined and the forward kinematics solved by it. At this point I have realized that solving the inverse kinematics for this class of robots is not a straightforward task.

By reading online I have found the KDL package which could be a solution to my problem, but I am having some difficulties in understanding how to properly use it (I am not really good in this things).

I would like to ask if you know any tutorial I could follow or any reference which might be useful in order to solve the IK of my Hexapod robot (even suggesting alternative methods).

I would really appreciate any answer or suggestion. Thanks for your time.

Best Regards,

Alessandro

Asked by cr055 on 2019-02-28 07:49:46 UTC

Comments

Answers

Try this:

    
/* Adapted from pypose:
 * Simple 3dof leg solver. X,Y,Z are the length from the Coxa rotate to the endpoint. 
 */

ikSolution_t calcLegIK(s32 X, s32 Y, s32 Z) 
{

    ikSolution_t ans;
    s32 trueX;
    s32 im;
    float q1, q2;
    s32 d1, d2;

    // first, make this a 2DOF problem... by solving coxa
    ans.coxa = radToServo(atan2(X,Y));
    trueX = sqrt(X*X + Y*Y) - COXA_LENGTH;
    im = sqrt(trueX*trueX + Z*Z);    // length of imaginary leg

    // get femur angle above horizon...
    q1 = atan2(Z, trueX);
    d1 = (FEMUR_LENGTH*FEMUR_LENGTH) - (TIBIA_LENGTH*TIBIA_LENGTH) + (im*im);
    d2 = 2 * FEMUR_LENGTH * im;
    q2 = acos((float)d1/(float)d2);
    ans.femur = radToServo(q1 + q2);

    // and tibia angle from femur...
    d1 = (FEMUR_LENGTH*FEMUR_LENGTH) - (im*im) + (TIBIA_LENGTH*TIBIA_LENGTH);
    d2 = 2* TIBIA_LENGTH * FEMUR_LENGTH;
    ans.tibia = radToServo(acos((float)d1/(float)d2)-1.57);

    return ans;
}

HTH

Asked by tfurgerson on 2019-03-04 11:25:57 UTC

Comments