-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNewRobot_Manipulability_Develop_limits.m
233 lines (190 loc) · 8.08 KB
/
NewRobot_Manipulability_Develop_limits.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
%% DEFINE NEW LIMB MODEL %%
clear
clc
close all
% This is a 3DOF Antropomorphic arm
% SWING
a2 = 0.3;
a3 = 0.4;
d1 = 0.1;
a = [0, a2, a3];
d = [d1, 0, 0];
alpha = [-pi/2, 0, 0];
offset = [0, 0, 0];
% Generate the link object associated with the robot model (DH param);
L1 = Link('d', d(1), 'a', a(1), 'alpha', alpha(1), 'offset', offset(1)); % coxa
L2 = Link('d', d(2), 'a', a(2), 'alpha', alpha(2), 'offset', offset(2)); % femur
L3 = Link('d', d(3), 'a', a(3), 'alpha', alpha(3), 'offset', offset(3)); %tibia
L = [L1, L2, L3];
Limb = SerialLink(L);
Limb.name = 'Limb';
Limb.gravity = [0; 0; 9.81]; % gravity acceleration vector expressed in the base frame
%% DEFINE INITIAL ROBOT MODEL
N_limb = 4;
W = 0.45;
L = 0.45;
T_tool = trotx(pi/2)*troty(pi/2)*trotz(pi/2);
q0_contact_swing = [0,0,pi/2];
ROBOT = Robot_model(W, L, Limb,q0_contact_swing, [1 1 1 1], T_tool);
%% DEFINE SCALING MATRIX
q_dot_lim_i = [1.5, 2, 3];
q_dot_lim = [];
for i=1:N_limb
q_dot_lim = [q_dot_lim, q_dot_lim_i];
end
Q_lim = diag(q_dot_lim);
%% INITIALIZE and PLOT
q0 = zeros(N_limb,Limb.n);
q0_contact = q0;
for i=1:N_limb
q0_contact(i,3) = pi/2;
end
figure('Name', 'Robot DH')
hold on
% Plot Robot
plot_robot(ROBOT, q0_contact);
%% PLOT FRAMES
% Initialize graphics elements
T_base0 = transl(0,0,ROBOT(1).base.t(3));
for i = 1:N_limb
h_root0{i} = trplot(eye(4));
end
h_base0 = trplot(T_base0,'rgb', 'length', 0.1, 'arrow');
h_CoM0 = plot3(0,0,0);
h_base_poly0 = plot3([0 0 0 0 0],[0 0 0 0 0],[0 0 0 0 0]);
h_support0 = plot3([0 0 0 0 0],[0 0 0 0 0],[0 0 0 0 0]);
% Create graphics
[T_limb_root,r_base, h_root, h_base, h_base_poly, h_support, h_CoM] = update_frames(ROBOT, q0_contact, T_base0, W, L, h_root0, h_base0, h_base_poly0, h_support0, h_CoM0);
clear h_root0 h_base0 h_CoM0 h_base_poly0 h_support0
%% BASE MANIPULABILITY ELLIPSOID
% Compute Grasp matrix and then Ellipsoid core
grasp_matrix = compute_grasp_matrix(r_base);
[E_base, Ja] = compute_base_ellipsoid_scaled(ROBOT, q0_contact, grasp_matrix, T_base0, Q_lim);
% Plot ellipsoid, in the base frame
%h_base_ellipse = plot_ellipse(E_base(1:3,1:3),[T_base0(1,4), T_base0(2,4), T_base0(3,4)], 'r', 'alpha', 0.6);
h_base_ellipse = plotEllipsoidLines(10*E_base(1:3,1:3)^-1,[T_base0(1,4), T_base0(2,4), T_base0(3,4)], 'r');
%% LIMB MANIPULABILITY ELLIPSOID
% Initialization
limbs_mask = [1 1 1 1]; % Visualize all limbs ellipsoid
% Initialize graphical element
for i=1:sum(limbs_mask)
h_limb_ellipses0{i} = plot_ellipse(eye(3));
end
[E_limbs, h_limb_ellipses] = limb_ellipsoids_general_scaled(ROBOT, q0_contact, limbs_mask, h_limb_ellipses0, Q_lim);
clear h_limb_ellipses0
pause
%% MOVE THE BASE
x_motion = 0.0;
y_motion = 0.0;
z_motion = -0.15;
T_base_in = T_base0;
[q_new, T_base] = translate_base(ROBOT, T_base_in, q0_contact, x_motion, y_motion, z_motion);
% Update graphics
plot_robot(ROBOT, q_new);
[T_limb_root,r_base, h_root, h_base, h_base_poly, h_support, h_CoM] = update_frames(ROBOT,q_new, T_base, W, L, h_root, h_base, h_base_poly, h_support, h_CoM);
%% BASE MANIPULABILITY ELLIPSOID
% Compute Grasp matrix and then Ellipsoid core
grasp_matrix = compute_grasp_matrix(r_base);
[E_base, Ja] = compute_base_ellipsoid_scaled(ROBOT, q_new, grasp_matrix, T_base, Q_lim);
% Plot ellipsoid, in the base frame
delete(h_base_ellipse);
h_base_ellipse = plotEllipsoidLines(10*E_base(1:3,1:3)^-1,[T_base(1,4), T_base(2,4), T_base(3,4)], 'r');
%% LIMB MANIPULABILITY ELLIPSOID
% Initialization
limbs_mask = [1 1 1 0]; % Visualize limbs ellipsoid
[E_limbs, h_limb_ellipses] = limb_ellipsoids_general_scaled(ROBOT, q_new, limbs_mask, h_limb_ellipses, Q_lim);
pause
%% MOVE THE BASE AGAIN
x_motion = -0.0;
y_motion = -0.0;
z_motion = 0.05;
T_base_in = T_base;
[q_new, T_base] = translate_base(ROBOT, T_base_in, q_new, x_motion, y_motion, z_motion);
% Update graphics
plot_robot(ROBOT, q_new);
[T_limb_root,r_base, h_root, h_base, h_base_poly, h_support, h_CoM] = update_frames(ROBOT,q_new, T_base, W, L, h_root, h_base, h_base_poly, h_support, h_CoM);
%% BASE MANIPULABILITY ELLIPSOID
% Compute Grasp matrix and then Ellipsoid core
grasp_matrix = compute_grasp_matrix(r_base);
[E_base, Ja] = compute_base_ellipsoid_scaled(ROBOT, q_new, grasp_matrix, T_base, Q_lim);
% Plot ellipsoid, in the base frame
delete(h_base_ellipse);
%h_base_ellipse = plot_ellipse(E_base(1:3,1:3),[T_base(1,4), T_base(2,4), T_base(3,4)], 'r', 'alpha', 0.6);
h_base_ellipse = plotEllipsoidLines(10*E_base(1:3,1:3)^-1,[T_base(1,4), T_base(2,4), T_base(3,4)], 'r');
%% LIMB MANIPULABILITY ELLIPSOID
% Initialization
limbs_mask = [1 0 0 0]; % Visualize limbs ellipsoid
[E_limbs, h_limb_ellipses] = limb_ellipsoids_general_scaled(ROBOT, q_new, limbs_mask, h_limb_ellipses, Q_lim);
pause
%% SEQUENTIAL MOTION
for i=1:8
pause
% MOVE THE BASE AGAIN
x_motion = 0.0;
y_motion = 0.0;
z_motion = 0.05;
T_base_in = T_base;
[q_new, T_base] = translate_base(ROBOT, T_base_in, q_new, x_motion, y_motion, z_motion);
% Update graphics
plot_robot(ROBOT, q_new);
[T_limb_root,r_base, h_root, h_base, h_base_poly, h_support, h_CoM] = update_frames(ROBOT,q_new, T_base, W, L, h_root, h_base, h_base_poly, h_support, h_CoM);
% BASE MANIPULABILITY ELLIPSOID
% Compute Grasp matrix and then Ellipsoid core
grasp_matrix = compute_grasp_matrix(r_base);
[E_base, Ja] = compute_base_ellipsoid_scaled(ROBOT, q_new, grasp_matrix, T_base, Q_lim);
% Plot ellipsoid, in the base frame
delete(h_base_ellipse);
% h_base_ellipse = plot_ellipse(E_base(1:3,1:3),[T_base(1,4), T_base(2,4), T_base(3,4)], 'r', 'alpha', 0.6);
h_base_ellipse = plotEllipsoidLines(10*E_base(1:3,1:3)^-1,[T_base(1,4), T_base(2,4), T_base(3,4)], 'r');
% LIMB MANIPULABILITY ELLIPSOID
% Initialization
limbs_mask = [1 1 1 1]; % Visualize limbs ellipsoid
[E_limbs, h_limb_ellipses] = limb_ellipsoids_general_scaled(ROBOT, q_new, limbs_mask, h_limb_ellipses,Q_lim);
end
pause
%% RISE ROBOT LF LIMB
i_rise = 1; % 1=LF, 2=LH, 3=RH, 4=RF
limb_names = ["LF*"; "LH*"; "RH*"; "RF*"];
ROBOT(i_rise).name = limb_names(i_rise, :);
close all
figure('Name','Robot DH')
hold on
q_new = move_limb(ROBOT, q_new, i_rise, 0, 0, 0.15);
plot_robot(ROBOT, q_new);
[T_limb_root,r_base, h_root, h_base, h_base_poly, h_support, h_CoM] = update_frames(ROBOT,q_new, T_base, W, L, h_root, h_base, h_base_poly, h_support, h_CoM);
%% BASE MANIPULABILITY ELLIPSOID
% Compute Grasp matrix and then Ellipsoid core
grasp_matrix = compute_grasp_matrix(r_base);
[E_base, Ja] = compute_base_ellipsoid_scaled(ROBOT, q_new, grasp_matrix, T_base, Q_lim);
% Plot ellipsoid, in the base frame
delete(h_base_ellipse);
h_base_ellipse = plotEllipsoidLines(10*E_base(1:3,1:3)^-1,[T_base(1,4), T_base(2,4), T_base(3,4)], 'r');
%% LIMB MANIPULABILITY ELLIPSOID
% Initialization
limbs_mask = [1 1 1 1]; % Visualize limbs ellipsoid
[E_limbs, h_limb_ellipses] = limb_ellipsoids_general_scaled(ROBOT, q_new, limbs_mask, h_limb_ellipses, Q_lim);
% SEQUENTIAL MOTION
for i=1:5
pause
% MOVE THE BASE AGAIN
x_motion = -0.02;
y_motion = -0.02;
z_motion = 0.02;
T_base_in = T_base;
[q_new, T_base] = translate_base(ROBOT, T_base_in, q_new, x_motion, y_motion, z_motion);
% Update graphics
plot_robot(ROBOT, q_new);
[T_limb_root,r_base, h_root, h_base, h_base_poly, h_support, h_CoM] = update_frames(ROBOT,q_new, T_base, W, L, h_root, h_base, h_base_poly, h_support, h_CoM);
% BASE MANIPULABILITY ELLIPSOID
% Compute Grasp matrix and then Ellipsoid core
grasp_matrix = compute_grasp_matrix(r_base);
[E_base, Ja] = compute_base_ellipsoid_scaled(ROBOT, q_new, grasp_matrix, T_base, Q_lim);
% Plot ellipsoid, in the base frame
delete(h_base_ellipse);
% h_base_ellipse = plot_ellipse(E_base(1:3,1:3),[T_base(1,4), T_base(2,4), T_base(3,4)], 'r', 'alpha', 0.6);
h_base_ellipse = plotEllipsoidLines(10*E_base(1:3,1:3)^-1,[T_base(1,4), T_base(2,4), T_base(3,4)], 'r');
% LIMB MANIPULABILITY ELLIPSOID
% Initialization
limbs_mask = [1 1 1 1]; % Visualize limbs ellipsoid
[E_limbs, h_limb_ellipses] = limb_ellipsoids_general_scaled(ROBOT, q_new, limbs_mask, h_limb_ellipses, Q_lim);
end