介绍了python库的安装及其链接
https://blog.csdn.net/weixin_41826637/article/details/80966836
不懂的matlab函数
函数 | 用法 |
---|---|
inv | 矩阵求逆---------inv(A)*b=A\b |
pause | pause(n)----暂停n秒 pause;-----暂停等待按键触发 |
使用matlab基本函数进行机器人建模仿真
Build_6DOF_Robot_DH.m
// A highlighted block
%% 建立机器人DH参数表
UX = [1 0 0]';
UY = [0 1 0]';
UZ = [0 0 1]';
Link=struct('name','Body','theta',0,'di',0,'ai',0,'alpha',0,'az',UZ);
Link(1)=struct('name','Base','theta',0,'di',0,'ai',0,'alpha',0,'az',UZ);
Link(2)=struct('name','J1','theta',pi/2,'di',100,'ai',0,'alpha',-pi/2,'az',UZ);
Link(3)=struct('name','J2','theta',-pi/2,'di',0,'ai',0,'alpha',-pi/2,'az',UZ);
Link(4)=struct('name','J3','theta',0,'di',80,'ai',0,'alpha',0,'az',UZ);
Link(5)=struct('name','J4','theta',0,'di',80,'ai',0,'alpha',pi/2,'az',UZ);
Link(6)=struct('name','J5','theta',0,'di',0,'ai',0,'alpha',-pi/2,'az',UZ);
Link(7)=struct('name','J6','theta',pi/2,'di',80,'ai',0,'alpha',pi/2,'az',UZ);
Link(8)=struct('name','J7','theta',0,'di',50,'ai',0,'alpha',0,'az',UZ);
Link(9)=struct('name','J8','theta',0,'di',-100,'ai',0,'alpha',0,'az',UZ);
Build_DH_Matrix.m
function Build_DH_Matrix(JointNum)
%% 输入关节数量,生成齐次变换矩阵A、旋转矩阵R
global Link
for i=1:JointNum+3
%获取关节参数
Cth=cos(Link(i).theta);
Sth=sin(Link(i).theta);
Ca=cos(Link(i).alpha);
Sa=sin(Link(i).alpha);
ai=Link(i).ai;
di=Link(i).di;
%添加关节变换信息
Link(i).x=[Cth Sth 0 0]';
Link(i).y=[-Sth*Ca Cth*Ca Sa 0]';
Link(i).z=[Sth*Sa -Cth*Sa Ca 0]';
Link(i).p=[ai*Cth ai*Sth di 1]';
Link(i).R=[Link(i).x(1:3),Link(i).y(1:3),Link(i).z(1:3)];
Link(i).A=[Link(i).x,Link(i).y, Link(i).z, Link(i).p];
end
Connect3D.m
function Connect3D(p1,p2,option,pt)
h = plot3([p1(1) p2(1)],[p1(2) p2(2)],[p1(3) p2(3)],option);
set(h,'LineWidth',pt)
DH_FK_6DOF.m
function pic=DH_FK_6DOF(th1,th2,dz3,th4,th5,th6,th7,th8,fcla)
global Link
ToDeg = 180/pi;
ToRad = pi/180;
Build_6DOF_Robot_DH; %构建DH表
% 获取关节变量
Link(2).theta=th1*ToRad;
Link(3).theta=th2*ToRad;
Link(4).di=80+dz3;
Link(5).theta=th4*ToRad;
Link(6).theta=th5*ToRad;
Link(7).theta=th6*ToRad;
Link(8).theta=th7*ToRad;
Link(9).theta=th8*ToRad;
Build_DH_Matrix(6); %计算齐次变换矩阵
radius = 10; %初始化
len = 30;
joint_col = 0;
plot3(0,0,0,'ro');
% 绘制连杆及其关节
for i=2:9
Link(i).A =Link(i-1).A*Link(i).A;
Link(i).x= Link(i).A(1:3,1);
Link(i).y= Link(i).A(1:3,2);
Link(i).z= Link(i).A(1:3,3);
Link(i).p= Link(i).A(1:3,4);
Link(i).R=[Link(i).x,Link(i).y,Link(i).z];
Connect3D(Link(i-1).p,Link(i).p,'b',3);
plot3(Link(i).p(1),Link(i).p(2),Link(i).p(3),'rx');
hold on;
if i<=7
DrawCylinder(Link(i-1).p, Link(i-1).R * Link(i).az, radius,len, joint_col); hold on;
end
end
% 设置坐标系信息
grid on;
%view(129,28);
axis([-400,400,-400,400,-400,400]);
xlabel('x');
ylabel('y');
zlabel('z');
%生成动画帧
drawnow;
pic=getframe;
% 判断是否清空坐标系
if(fcla)
cla;
end
DH_