www.gusucode.com > robotics 案例源码程序 matlab代码 > robotics/AchieveEndEffectorPositionUsingInverseKinematicsExample.m

    %% Achieve EndiEffector Position Using Inverse Kinematics
% Generate joint positions for a robot model to
% achieve a desired end-effector position. The |InverseKinematics|
% class uses inverse kinematic algorithms to solve for valid joint
% positions.

%%
% Load example robots. The |puma1| robot is a |RigidBodyTree| model of a
% six-axis robot arm with six revolute joints.
load exampleRobots.mat
showdetails(puma1)

%%
% Generate a random configuration. Get the tranformation from the end
% effector (L6) to the base for that random configuration. Use this transform as 
% a goal pose of the end effector. Show this configuration.
randConfig = puma1.randomConfiguration;
tform = getTransform(puma1,randConfig,'base','L6');

show(puma1,randConfig);


%%
% Create an |InverseKinematics| object for the |puma1| model. Use this 
% object to calculate a solution for the given goal. Specify weights for the
% different components of the pose. Use the home configuration of the robot as an
% initial guess.
ik = robotics.InverseKinematics('RigidBodyTree',puma1);
weights = ones(6,1);
initialguess = puma1.homeConfiguration;

%%
% Calculate the joint positions using the |ik| object.
[configSoln, solnInfo] = ik('L6',tform,weights,initialguess);

%%
% Show the newly generated solution configuration. The solution is a
% slightly different joint configuration that achieves the same end-effector
% position. Multiple calls to the |ik| object can give similar or very different joint
% configurations.
show(puma1,configSoln);