clc; clear all; close all; %------------------------------------------------------------------------- % Loading file from urdf % ------------------------------------------------------------------------ plnr = xml2struct('planar_manip.urdf'); % ------------------------------------------------------------------------ % Extracting parameters of the robot % ------------------------------------------------------------------------ for i = 1:2 % axis of rotation of a joint i in coordinate system of joint i axis_of_rot = str2num(plnr.robot.joint{i}.axis.Attributes.xyz)'; % mass of link (i+1) because joint i rotates link (i+1) as the numbering of % links starts from base link that it not moving link_mass = str2double(plnr.robot.link{i+1}.inertial.mass.Attributes.value); % poistion of the com in frame attached to link com_pos = str2num(plnr.robot.link{i+1}.inertial.origin.Attributes.xyz)'; com_vec2mat = vec2skewSymMat(com_pos); % inertial parameters of the link expressed in coordinate system attached % the center of mass. ixx = str2double(plnr.robot.link{i+1}.inertial.inertia.Attributes.ixx); ixy = str2double(plnr.robot.link{i+1}.inertial.inertia.Attributes.ixy); ixz = str2double(plnr.robot.link{i+1}.inertial.inertia.Attributes.ixz); iyy = str2double(plnr.robot.link{i+1}.inertial.inertia.Attributes.iyy); iyz = str2double(plnr.robot.link{i+1}.inertial.inertia.Attributes.iyz); izz = str2double(plnr.robot.link{i+1}.inertial.inertia.Attributes.izz); % the inertia tensor wrt the frame oriented as the body frame and with the % origin in the COM link_inertia = [ixx, ixy, ixz; ixy, iyy iyz; ixz, iyz, izz]; % manipulator regressor plnr.m(i) = link_mass; plnr.k(:,i) = axis_of_rot; plnr.r_com(:,i) = com_pos; plnr.I(:,:,i) = link_inertia; plnr.h(:,i) = link_mass*com_pos; plnr.I_vec(:,i) = inertiaMatrix2Vector(link_inertia-... link_mass*com_vec2mat*com_vec2mat); plnr.pi(:,i) = [plnr.I_vec(:,i);plnr.h(:,i);plnr.m(i)]; end % ------------------------------------------------------------------------ % Defining parameters symbolically % ------------------------------------------------------------------------ m = sym('m%d',[2,1],'real'); hx = sym('h%d_x',[2,1],'real'); hy = sym('h%d_y',[2,1],'real'); hz = sym('h%d_z',[2,1],'real'); ixx = sym('i%d_xx',[2,1],'real'); ixy = sym('i%d_xy',[2,1],'real'); ixz = sym('i%d_xz',[2,1],'real'); iyy = sym('i%d_yy',[2,1],'real'); iyz = sym('i%d_yz',[2,1],'real'); izz = sym('i%d_zz',[2,1],'real'); % Vector of symbolic parameters for i = 1:2 pi_plnr_sym(:,i) = [ixx(i),ixy(i),ixz(i),iyy(i),iyz(i),izz(i),... hx(i),hy(i),hz(i),m(i)]'; end % ------------------------------------------------------------------------ % Symbolic generilized coordiates, their first and second deriatives % ------------------------------------------------------------------------ q_sym = sym('q%d',[2,1],'real'); qd_sym = sym('qd%d',[2,1],'real'); q2d_sym = sym('q2d%d',[2,1],'real'); % ------------------------------------------------------------------------ % Getting energy functions, to derive dynamics % ------------------------------------------------------------------------ T_pk = sym(zeros(4,4,2)); % transformation between links w_kk(:,1) = sym(zeros(3,1)); % angular velocity k in frame k v_kk(:,1) = sym(zeros(3,1)); % linear velocity of the origin of frame k in frame k g_kk(:,1) = sym([0,0,9.81])'; % vector of graviatational accelerations in frame k p_kk(:,1) = sym(zeros(3,1)); % origin of frame k in frame k DK(:,1) = sym(zeros(10,1)); % gradient of kinetic energy DP(:,1) = sym([zeros(1,6),[0,0,9.81],0]'); % gradient of gravitational energy for i = 1:2 jnt_axs_k = str2num(plnr.robot.joint{i}.axis.Attributes.xyz)'; % Transformation from parent link frame p to current joint frame rpy_k = sym(str2num(plnr.robot.joint{i}.origin.Attributes.rpy)); R_pj = RPY(rpy_k); % R_pj(abs(R_pj)