机器人包含5个关节,建立以下的DH参数表
matlab代码
%机器人学导论仿真大作业(RTB)
clear
clc
h = figure;
axis tight manual
filename = 'SchunkRobot_Simulation.gif';
%Schunk机械臂参数的输入
L1=0.35;
L2=0.305;
L3=0.3;
%DH参数建立
Joint1 = Link([ 0, 0, 0, 0, 0],'revolute', 'modified');
Joint2 = Link([ 0, L1, 0, -pi/2, 0], 'revolute','modified');
Joint3 = Link([ 0, 0, 0, pi/2, 0], 'revolute','modified');
Joint4 = Link([ 0, L2, 0, -pi/2, 0], 'revolute','modified');
Joint5 = Link([ 0, 0, 0, pi/2, 0],'revolute', 'modified');
Joint6 = Link([ 0, L3, 0, -pi/2, 0],'revolute', 'modified');
Joint7 = Link([ 0, 0, 0, pi/2, 0],'modified');
%机器人模型建立
SchunkRobot = SerialLink([Joint1 Joint2 Joint3 Joint4 Joint5 Joint6 Joint7], 'name', 'Schunk机械臂');
%8个圆上的目标点
R = 0.2;%半径
L = 0.4;%与机械臂的距离
target = [ R,L,0;-R,L,0;0,L,R;0,L,-R;R*cos(pi/4), L, R*sin(pi/4);R*cos(pi/4), L, -R*sin(pi/4);-R*cos(pi/4), L, R*sin(pi/4);-R*cos(pi/4), L, -R*sin(pi/4)];
%绘制目标点
plot3(target(:,1), target(:,2), target(:,3), 'Marker', 'X', 'MarkerFaceColor', 'c', 'MarkerSize', 9, 'LineStyle', 'none');
%控制机械臂抵达目标点
Time=0:0.02:0.8;
angle = zeros(9,7);
for i=1:8
%逆运动学求解关节角
angle(i+1,:) = SchunkRobot.ikine(reshape(transl(target(i,:)),4,4),'q0',angle(i,:));
%轨迹规划并绘图
trajectory=jtraj(angle(i,:),angle(i+1,:),Time);
title('SchunkRobot Simulation')
plot(SchunkRobot,trajectory);
%绘制gif动图
drawnow
frame = getframe(h);
im = frame2im(frame);
[imind,cm] = rgb2ind(im,256);
if i == 1
imwrite(imind,cm,filename,'gif', 'Loopcount',inf);
else
imwrite(imind,cm,filename,'gif','WriteMode','append');
end
end
生成图