Using 3D graphics animate the robot in Matlab GUI.
4 次查看(过去 30 天)
显示 更早的评论
Hello,
I have seen this example ( http://in.mathworks.com/matlabcentral/fileexchange/14932-3d-puma-robot-demo/content/puma3d.m) in file exchange and want to same with 4 dof rootic arm. I follow below steps. 1. Create a very simple 4 dof roots links using Solid Works and convert it into .stl file (ASCII) by using cad2matdemo.m file and store all data manually. 2. Alter the code according to my requirements. But I'm unable to create 3d model in Matlab GUI. My code is given below.
function rob3d
loaddata
InitHome
function InitHome
% Use forward kinematics to place the robot in a specified
% configuration.
% Figure setup data, create a new figure for the GUI
set(0,'Units','pixels')
dim = get(0,'ScreenSize');
% fig_1 = figure('doublebuffer','on','Position',[0,35,dim(3)-200,dim(4)-110],...
% 'MenuBar','none','Name',' 3D Puma Robot Graphical Demo',...
% 'NumberTitle','off','CloseRequestFcn',@del_app);
fig_1 = figure('doublebuffer','on','Position',[0,35,dim(3)-200,dim(4)-110],...
'MenuBar','figure','Name',' 3D Puma Robot Graphical Demo',...
'NumberTitle','off');
hold on;
%light('Position',[-1 0 0]);
light % add a default light
daspect([1 1 1]) % Setting the aspect ratio
view(135,25)
xlabel('X'),ylabel('Y'),zlabel('Z');
title('Robot');
axis([-1000 1000 -1000 1000 -1000 1000]);
plot3([-1500,1500],[-1500,-1500],[-1120,-1120],'k')
plot3([-1500,-1500],[-1500,1500],[-1120,-1120],'k')
plot3([-1500,-1500],[-1500,-1500],[-1120,1500],'k')
plot3([-1500,-1500],[1500,1500],[-1120,1500],'k')
plot3([-1500,1500],[-1500,-1500],[1500,1500],'k')
plot3([-1500,-1500],[-1500,1500],[1500,1500],'k')
s1 = getappdata(0,'Link1_data');
s2 = getappdata(0,'Link2_data');
s3 = getappdata(0,'Link3_data');
s4 = getappdata(0,'Link4_data');
s5 = getappdata(0,'Link5_data');
a2 = 300;
a3 = 300;
a4 = 300;
d1 = 300;
d2 = 50;
d3 = 50;
d4 = 50;
%The 'home' position, for init.
t1 = 0;
t2 = 0;
t3 = 0;
t4 = 0;
% Forward Kinematics
% tmat(alpha, a, d, theta)
T_01 = tmat(90, 0, d1, t1);
T_12 = tmat(0, a2, d2, t2);
T_23 = tmat(0, a3, d3, t3);
T_34 = tmat(0, a4, d4, t4);
% Each link fram to base frame transformation
T_02 = T_01*T_12;
T_03 = T_02*T_23;
T_04 = T_03*T_34;
% Actual vertex data of robot links
Link1 = s1.V1;
Link2 = (T_01*s2.V2')';
Link3 = (T_02*s3.V3')';
Link4 = (T_03*s4.V4')';
Link5 = (T_04*s5.V5')';
% points are no fun to watch, make it look 3d.
L1 = patch('faces', s1.F1, 'vertices' ,Link1(:,1:3));
L2 = patch('faces', s2.F2, 'vertices' ,Link2(:,1:3));
L3 = patch('faces', s3.F3, 'vertices' ,Link3(:,1:3));
L4 = patch('faces', s4.F4, 'vertices' ,Link4(:,1:3));
L5 = patch('faces', s5.F5, 'vertices' ,Link5(:,1:3));
Tr = plot3(0,0,0,'b.'); % holder for trail paths
setappdata(0,'patch_h',[L1,L2,L3,L4,L5,Tr]);
%
set(L1, 'facec', [0.717,0.116,0.123]);
set(L1, 'EdgeColor','none');
set(L2, 'facec', [0.216,1,.583]);
set(L2, 'EdgeColor','none');
set(L3, 'facec', [0.306,0.733,1]);
set(L3, 'EdgeColor','none');
set(L4, 'facec', [1,0.542,0.493]);
set(L4, 'EdgeColor','none');
set(L5, 'facec', [0.216,1,.583]);
set(L5, 'EdgeColor','none');
%
setappdata(0,'ThetaOld',[0,0,0,0]);
%
end
function T = tmat(alpha, a, d, theta)
% tmat(alpha, a, d, theta) (T-Matrix used in Robotics)
% The homogeneous transformation called the "T-MATRIX"
% as used in the Kinematic Equations for robotic type
% systems (or equivalent).
%
% This is equation 3.6 in Craig's "Introduction to Robotics."
% alpha, a, d, theta are the Denavit-Hartenberg parameters.
%
% (NOTE: ALL ANGLES MUST BE IN DEGREES.)
%
alpha = alpha*pi/180; %Note: alpha is in radians.
theta = theta*pi/180; %Note: theta is in radians.
c = cos(theta);
s = sin(theta);
ca = cos(alpha);
sa = sin(alpha);
T = [c -s*ca s*sa a*c; s c*ca -c*sa a*s; 0 sa ca d; 0 0 0 1];
end
function del_app(varargin)
delete(fig_1);
end
function loaddata
% Loads all the link data from file linksdata.mat.
% This data comes from a Pro/E 3D CAD model and was made with cad2matdemo.m
% from the file exchange. All link data manually stored in linksdata.mat
[linkdata1]=load('linksdata.mat','s1','s2','s3','s4','s5');
%Place the robot link 'data' in a storage area
setappdata(0,'Link1_data',linkdata1.s1);
setappdata(0,'Link2_data',linkdata1.s2);
setappdata(0,'Link3_data',linkdata1.s3);
setappdata(0,'Link4_data',linkdata1.s4);
setappdata(0,'Link5_data',linkdata1.s5);
end
end
Below figure shows desired and actual comes out model.
All others thing, which may be useful (like linksdata file, sw model etc.) I shared on dropbox. Anybody can accesss from there. Dropox link: https://www.dropbox.com/sh/llwa0chsjuc1iju/AACrOTqCRBmDShGgJKpEVAlOa?dl=0
i want to know to connect two components in 3d model in Matla gui. Any study about this will be very helpful. Thanks.
0 个评论
回答(0 个)
另请参阅
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!