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 do similar thing 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
        function InitHome
            % Use forward kinematics to place the robot in a specified
            % configuration.
            % Figure setup data, create a new figure for the GUI
            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',...
            hold on;
            %light('Position',[-1 0 0]);
            light                               % add a default light
            daspect([1 1 1])                    % Setting the aspect ratio
            axis([-1000 1000 -1000 1000 -1000 1000]);
            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
            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');
        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.
            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];
        function del_app(varargin)
        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
            %Place the robot link 'data' in a storage area

Below figure shows desired and actual comes out model.

enter image description here

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.

  • $\begingroup$ He is just transforming the links using transformation matrices. I think there might be a problem with your transformation matrices. Use D-H to find transformation matrices for each link. $\endgroup$ Mar 29, 2017 at 9:38
  • $\begingroup$ Thanks for reply @the_parzival. I solved inverse kinematics and forward kinematics using same DH parameters as I used in above case. So, I think my DH parameters are correct. Can you please suggest me what should be DH parameters acc. to you. It will help me a lot. By watching above image (desired pose) you can drive DH parameters. All are revolute joints. Thanks. $\endgroup$ Mar 29, 2017 at 10:23

1 Answer 1


STL Files have an internal coordinate system relative to which the vertices of the mesh are expressed. You are transforming these vertices with the transformation matrix that is correct, however only in the case when the origin coordinate system of the STL file (the coordinate system relative to which the vertice coordinates are expressed correspond to the DH coordinate system attached to the linkage.

Make sure to define a coordinate system in SolidWorks which has the same origin point and orientation relative to the linkage as the Dh coordinate system has. In other words, orient the z axis towards the motion axis, etc. After this, when you export the STL file, make sure to select this coordinate system as the origin. Furthermore, make sure not to select the translate all vertices to positive option. (SolidWorks offers both these option and AFAIK the default options are not the required ones.)

  • $\begingroup$ I believe this is the correct answer. Constraining CAD models to the drafting origin is part of "best practices" for general CAD development (in general, your parts should always be fully constrained; assemblies should be fully constrained unless you intend for there to be motion). As 50k4 mentions, you need to be sure that part is oriented in CAD the same as you have it imagined, which may mean that you need separate part files for the column and arms even though they're dimensional equivalents (or you need to pre-transform the column). Be sure also that your units are the same in both. $\endgroup$
    – Chuck
    May 16, 2019 at 13:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.