0001 function dataset = ccl_data_genlwr (settings)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035 settings.dim_hand = 6 ;
0036 settings.dim_joint = 7 ;
0037 settings.joint.free = setdiff(1:settings.dim_joint, settings.joint.fixed);
0038 settings.joint.target = pi/180 * zeros(7,1) ;
0039 settings.joint.limit = pi/180 * [170, 120, 170, 120, 170, 120, 170]';
0040
0041 settings.end.free = setdiff(1:settings.dim_hand, settings.end.fixed) ;
0042
0043 settings.dim_u = size(settings.joint.free,2) ;
0044 settings.dim_x = size(settings.joint.free,2) ;
0045 settings.dim_r = size(settings.end.free,2) ;
0046
0047
0048 switch (settings.null.type)
0049 case 'linear'
0050 settings.null.alpha = 1 ;
0051 settings.null.target = settings.joint.target(settings.joint.free) ;
0052 policy_ns = @(x) policy_linear(x, settings.null) ;
0053 case 'avoidance'
0054 settings.null.alpha = 1 ;
0055 settings.null.target = settings.joint.target(settings.joint.free) ;
0056 policy_ns = @(x) policy_avoidance ( x, settings.null ) ;
0057 case 'learnt'
0058 policy_ns = settings.null.func ;
0059 otherwise
0060 fprintf('Unkown null-space policy\n') ;
0061 end
0062
0063
0064 Lambda = settings.Lambda ;
0065
0066 rob = dlr_7dof ;
0067
0068 J = @(q) jacob0(rob,q) ;
0069 Jx = @(x) get_jacobian (x, rob, settings) ;
0070 dt = settings.dt;
0071 Iu = eye(settings.dim_u) ;
0072
0073 X = cell(settings.dim_traj,1) ;
0074 Pi= cell(settings.dim_traj,1) ;
0075 U = cell(settings.dim_traj,1) ;
0076 R = cell(settings.dim_traj,1) ;
0077 V = cell(settings.dim_traj,1) ;
0078
0079 for k=1: settings.dim_traj
0080
0081
0082 q = settings.joint.target ;
0083 q(settings.joint.free) = settings.joint.limit(settings.joint.free).*rand(settings.dim_u,1)- (settings.joint.limit(settings.joint.free)/2) ;
0084 x = q(settings.joint.free);
0085
0086 X{k} = zeros(settings.dim_u, settings.dim_step);
0087 U{k} = zeros(settings.dim_u, settings.dim_step);
0088 Pi{k} = zeros(settings.dim_u, settings.dim_step);
0089
0090 for n = 1 : settings.dim_step+1
0091 q(settings.joint.free) = x ;
0092 Jn = J(q) ;
0093 A = Lambda * Jn(settings.end.free,settings.joint.free) ;
0094 invA= pinv(A) ;
0095
0096 P = Iu - invA*A ;
0097 f = policy_ns(x) ;
0098 u = P * f ;
0099
0100 r = fkine(rob,q) ;
0101
0102 r = r(settings.end.free) ;
0103
0104 X{k}(:,n) = x ;
0105 U{k}(:,n) = u ;
0106 R{k}(:,n) = r ;
0107 Pi{k}(:,n) = f ;
0108 x = x + dt*u;
0109
0110 if norm(u) < 1e-3
0111 break ;
0112 end
0113 end
0114 V{k} = diff(R{k}')' ;
0115 V{k} = V{k}(:,1:n-1) ;
0116 X{k} = X{k}(:,1:n-1);
0117 R{k} = R{k}(:,1:n-1);
0118 U{k} = U{k}(:,1:n-1);
0119 Pi{k}= Pi{k}(:,1:n-1);
0120 end
0121
0122 dataset.X = [X{:}] ;
0123 dataset.U = [U{:}] ;
0124 dataset.Pi= [Pi{:}];
0125 dataset.R = [R{:}] ;
0126 dataset.V = [V{:}] ;
0127 dataset.rob=rob ;
0128 dataset.J = Jx ;
0129 dataset.Lambda= Lambda ;
0130 dataset.settings = settings ;
0131 dataset.settings.dim_n = size(X,2) ;
0132 end
0133
0134 function Jxn = get_jacobian (x, rob, settings)
0135
0136
0137
0138
0139
0140
0141
0142
0143
0144
0145
0146
0147 q = settings.joint.target ;
0148 q(settings.joint.free) = x ;
0149 Jxn = jacob0(rob,q) ;
0150 Jxn = Jxn (settings.end.free, settings.joint.free) ;
0151 end
0152
0153 function ROBOT=dlr_7dof()
0154
0155
0156
0157
0158
0159
0160
0161 L1 = Link([ 0 0 0 pi/2], 'standard');
0162 L2 = Link([0 0 0.3 -pi/2],'standard');
0163 L3 = Link([0 0 0.4 -pi/2],'standard');
0164 L4 = Link([0 0 0.5 pi/2],'standard');
0165 L5 = Link([0 0 0.39 pi/2],'standard');
0166 L6 = Link([0 0 0 -pi/2],'standard');
0167 L7 = Link([0 0 0.2 0],'standard');
0168 ROBOT = SerialLink([L1,L2,L3,L4,L5,L6,L7], 'name', 'DLR/KUKA');
0169 end
0170 function U = policy_linear(x, null_settings)
0171
0172
0173
0174
0175
0176
0177
0178
0179
0180 U = null_settings.alpha .* ((null_settings.target - x));
0181 end