Robotics-Documents/matlab/myArm.m

62 lines
1.6 KiB
Mathematica
Raw Normal View History

clear;
clc;
L1=0.151;L3=0.350; L4=0.139;
theta_1=-0.02;
theta_2=-1.473;
theta_3=-0.024;
theta_4=-1.559;
theta_5=-2.98966;
q = [theta_1,theta_2,theta_3,theta_4,theta_5]
%
lim1_min = -pi/2; lim1_max = pi/2; %1(-90,90)
lim2_min = -pi/2; lim2_max = pi/2; %2(090)
lim3_min = -pi; lim3_max = pi; %4(-180180)
lim4_min = -pi; lim4_max = pi; %5(-180180)
lim5_min = -pi/2; lim5_max = pi/2; %6(-9090)
%
lim1 = lim1_max - lim1_min;
lim2 = lim2_max - lim2_min;
lim3 = lim3_max - lim3_min;
lim4 = lim4_max - lim4_min;
lim5 = lim5_max - lim5_min;
%
r(1)=Link([0 L1 0 pi/2]);r(1).qlim=[lim1_min,lim1_max];
r(2)=Link([0 0 L3 pi/2]);r(2).qlim=[lim2_min,lim2_max];
r(3)=Link([0 0 0 -pi/2]);r(3).qlim=[lim3_min,lim3_max];
r(4)=Link([0 0 0 pi/2]);r(4).qlim=[lim4_min,lim4_max];
r(5)=Link([0 L4 0 0]);r(5).qlim=[lim5_min,lim5_max];
%
robot=SerialLink([r(1),r(2),r(3),r(4),r(5)],'name','robot');
robot.fkine(q)
robot.display();
%
%使
N=5000;
theta1 = ( lim1_min + (lim1 * rand(N,1)) );
theta2 = ( lim2_min + (lim2 * rand(N,1)) );
theta3 = ( lim3_min + (lim3 * rand(N,1)) );
theta4 = ( lim4_min + (lim4 * rand(N,1)) );
theta5 = ( lim5_min + (lim5 * rand(N,1)) );
% for n = 1:N
% theta = [theta1(n),theta2(n),theta3(n),theta4(n),theta5(n)];
% workspace = robot.fkine(theta);
% plot3(workspace.t(1),workspace.t(2),workspace.t(3),'b.','markersize',1);
% hold on;
% end
% robot.plot(theta); %
robot.teach;