Home > @robot > robot.m

robot

PURPOSE ^

ROBOT Robot object constructor

SYNOPSIS ^

function r = robot(L, a1, a2, a3)

DESCRIPTION ^

ROBOT Robot object constructor

    ROBOT            create a ROBOT object with no links
    ROBOT(robot)        create a copy of an existing ROBOT object
    ROBOT(robot, LINK)    replaces links for robot object
    ROBOT(LINK, ...)    create from a cell array of LINK objects
    ROBOT(DH, ...)        create from legacy DH matrix
    ROBOT(DYN, ...)        create from legacy DYN matrix

 Optional trailing arguments are:
     Name            robot type or name
     Manufacturer        who built it
     Comment            general comment

 If the legacy matrix forms are used the default name is the workspace
 matrix that held the data.

 See also: ROBOT/SUBSREF, ROBOT/SUBSASGN, LINK.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 %ROBOT Robot object constructor
0002 %
0003 %    ROBOT            create a ROBOT object with no links
0004 %    ROBOT(robot)        create a copy of an existing ROBOT object
0005 %    ROBOT(robot, LINK)    replaces links for robot object
0006 %    ROBOT(LINK, ...)    create from a cell array of LINK objects
0007 %    ROBOT(DH, ...)        create from legacy DH matrix
0008 %    ROBOT(DYN, ...)        create from legacy DYN matrix
0009 %
0010 % Optional trailing arguments are:
0011 %     Name            robot type or name
0012 %     Manufacturer        who built it
0013 %     Comment            general comment
0014 %
0015 % If the legacy matrix forms are used the default name is the workspace
0016 % matrix that held the data.
0017 %
0018 % See also: ROBOT/SUBSREF, ROBOT/SUBSASGN, LINK.
0019 
0020 % Copyright (C) 1999-2008, by Peter I. Corke
0021 %
0022 % This file is part of The Robotics Toolbox for Matlab (RTB).
0023 %
0024 % RTB is free software: you can redistribute it and/or modify
0025 % it under the terms of the GNU Lesser General Public License as published by
0026 % the Free Software Foundation, either version 3 of the License, or
0027 % (at your option) any later version.
0028 %
0029 % RTB is distributed in the hope that it will be useful,
0030 % but WITHOUT ANY WARRANTY; without even the implied warranty of
0031 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0032 % GNU Lesser General Public License for more details.
0033 %
0034 % You should have received a copy of the GNU Leser General Public License
0035 % along with RTB.  If not, see <http://www.gnu.org/licenses/>.
0036 
0037 function r = robot(L, a1, a2, a3)
0038 
0039     if nargin == 0
0040         r.name = 'noname';
0041         r.manuf = '';
0042         r.comment = '';
0043         r.link = {};
0044         r.n = 0;
0045         r.mdh = 0;
0046         r.gravity = [0; 0; 9.81];
0047         r.base = eye(4,4);
0048         r.tool = eye(4,4);
0049         r.handle = [];    % graphics handles
0050         r.q = [];    % current joint angles
0051         r.plotopt = {};
0052         r.lineopt = {'Color', 'black', 'Linewidth', 4};
0053         r.shadowopt = {'Color', 'black', 'Linewidth', 1};
0054         r = class(r, 'robot');
0055     elseif isa(L, 'robot')
0056         r = L;
0057         if nargin == 2,
0058             r.link = a1;
0059         end
0060     else
0061         % assume arguments are: name, manuf, comment
0062         if nargin > 1,
0063             r.name = a1;
0064         else
0065             r.name = 'noname';
0066         end
0067         if nargin > 2,
0068             r.manuf = a2;
0069         else
0070             r.manuf = '';
0071         end
0072         if nargin > 3,
0073             r.comment = a3;
0074         else
0075             r.comment = '';
0076         end
0077 
0078         if isa(L, 'double')
0079             % legacy matrix
0080             dh_dyn = L;
0081             clear L
0082             for j=1:numrows(dh_dyn)
0083                 L{j} = link(dh_dyn(j,:));
0084             end
0085             % get name of variable
0086             r.name = inputname(1);
0087             r.link = L;
0088         elseif iscell(L) & isa(L{1}, 'link')
0089 
0090             r.link = L;
0091         else
0092             error('unknown type passed to robot');
0093         end
0094         r.n = length(L);
0095 
0096         % set the robot object mdh status flag
0097         mdh = [];
0098         for j = 1:length(L)
0099             mdh = [mdh L{j}.mdh];
0100         end
0101         if all(mdh == 0)
0102             r.mdh = mdh(1);
0103         elseif all (mdh == 1)
0104             r.mdh = mdh(1);
0105         else
0106             error('robot has mixed D&H link conventions');
0107         end
0108 
0109         % fill in default base and gravity direction
0110         r.gravity = [0; 0; 9.81];
0111         r.base = eye(4,4);
0112         r.tool = eye(4,4);
0113         r.handle = [];
0114         r.q = [];
0115         r.plotopt = {};
0116         r.lineopt = {'Color', 'black', 'Linewidth', 4};
0117         r.shadowopt = {'Color', 'black', 'Linewidth', 1};
0118 
0119         r = class(r, 'robot');
0120     end

Generated on Sun 15-Feb-2009 18:09:29 by m2html © 2003