inverse kinematic in matlab

Inverse kinematics is the process of determining the joint configurations for a desired end-effector position and orientation. The following steps can be used to perform inverse kinematics in MATLAB:

  1. Define the robot model using the Robotics System Toolbox™. This can be done by defining the robot's kinematic structure using the Robotics System Toolbox™ robot models or by creating a custom model.
main.m
robot = rigidBodyTree;
body = rigidBody('link1');
joint = rigidBodyJoint('joint1', 'revolute');
setFixedTransform(joint,trvec2tform([0 0 0]));
joint.JointAxis = [0 0 1];
body.Joint = joint;
addBody(robot, body, 'base');
220 chars
8 lines
  1. Specify the desired end-effector pose using a transformation matrix.
main.m
T = trvec2tform([0.1 0.1 0.1]) * eul2tform([0 pi/2 0]);
56 chars
2 lines
  1. Define the inverse kinematics solver. The Robotics System Toolbox™ provides a number of inverse kinematics solvers, including the ikunc function for numerical solutions and inverseKinematics for analytical solutions.
main.m
ik = inverseKinematics('RigidBodyTree', robot);
ik.SolverParameters.MaxIterations = 10000;
ik.SolverParameters.SolutionTolerance = 1e-12;
138 chars
4 lines
  1. Call the inverse kinematics solver to solve for the joint angles that achieve the desired end-effector pose.
main.m
q0 = homeConfiguration(robot);
[q, solInfo] = ik('endeffector', T, [1 1 1 1 1 1], q0);
87 chars
3 lines
  1. Set the joint angles of the robot to the calculated solution.
main.m
show(robot,q);
15 chars
2 lines

gistlibby LogSnag