https://www.jianshu.com/p/a31ae1d2c1a2
这个机械臂即V-rep中的example的第一个,注意使用时要先将IK group删除,删掉dummy之间的link.
建立DH矩阵:
clear
deg = pi/180;
L(1) = Revolute('d', 0.1392, 'a', 0, 'alpha', -pi/2,'offset',pi);%关节运行范围
L(2) = Revolute('d',0, 'a', 0, 'alpha',-pi/2,'offset',pi);
L(3) = Revolute('d', 0.2913, 'a', 0, 'alpha',-pi/2,'offset',pi);
L(4) = Revolute('d', 0, 'a', 0, 'alpha', -pi/2,'offset',pi/2);
L(5) = Revolute('d', 0.3236, 'a', 0, 'alpha',-pi/2,'offset',pi);
% L(6) = Revolute('d', 0, 'a', 0, 'alpha', 0,'offset',0);
L(6) = Revolute('d', 0, 'a', 0, 'alpha', -pi/2,'offset',-pi/2);
L(7) = Revolute('d', 0.1, 'a', 0, 'alpha', 0);
% 'qlim', [-45 225]*deg );
T=[1 0 0 0;0 1 0 0;0 0 1 0.0641 ;0 0 0 1];
p560 = SerialLink(L, 'name', 'Puma 560', ...
'manufacturer', 'UnimaLtion', 'base',T,'ikine', 'puma', 'comment', 'viscous friction; params of 8/95');
close all
p560.plot(zeros(1,length(L)))
逆运动解的部分
clear
clc
sss;
vrep=remApi('remoteApi'); % using the prototype file (remoteApiProto.m)
vrep.simxFinish(-1); % just in case, close all opened connections
clientID=vrep.simxStart('127.0.0.1',19997,true,true,5000,5);
JointHandle=zeros(1,7);
for i=1:6
[res,JointHandle(i)] = vrep.simxGetObjectHandle(clientID,['redundantRob_joint' num2str(i)],vrep.simx_opmode_blocking);
end
[res,tar_handle] = vrep.simxGetObjectHandle(clientID,'redundantRob_target',vrep.simx_opmode_blocking);
vrep.simxSynchronous(clientID,true);
vrep.simxStartSimulation(clientID,vrep.simx_opmode_oneshot);
%%
qz = [0 0 0 0 0 0];
qn=[0 pi/4 -pi 0 pi/4 0];
tic;
count=0;
while toc<40
[res,quat]=vrep.simxGetObjectQuaternion(clientID,tar_handle,JointHandle(1),vrep.simx_opmode_blocking );
quater = [quat(4),quat(1:3)];
T = quat2tform(quater);
[res,pos]=vrep.simxGetObjectPosition(clientID,tar_handle,JointHandle(1),vrep.simx_opmode_blocking );
T(1:3,4) = pos';
qi = p560.ikine(T);
JointAng = qi;
for i=1:7
vrep.simxSetJointTargetPosition(clientID,JointHandle(i),JointAng(i),vrep.simx_opmode_blocking );
end
vrep.simxSynchronousTrigger(clientID);
count=count+1;
end
vrep.simxStopSimulation(clientID,vrep.simx_opmode_oneshot_wait);
vrep.simxFinish(clientID);
vrep.delete(); % call the destructor!
完整工程下载链接:https://download.csdn.net/download/qq_33243369/11244067