y_tANDx_t.m 11.8 KB
Newer Older
Farid Alijani's avatar
Farid Alijani committed
1
2
3
4
clc;
close all;
clear all;

Farid Alijani's avatar
Farid Alijani committed
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
%% Import Data 

% data 1: 
Pose_Matrix_data_1 = csvread('CAM_PID_.266_.0003_.014.txt',1,0);
Vel_Matrix_data_1 = csvread('vel_PID_.266_.0003_.014.txt',1,0);
Trans_Matrix_data_1 = csvread('Trans_PID_.266_.0003_.014.txt',1,0);

% time in position
TimeP_ros_data_1 = Pose_Matrix_data_1(:,1); % ros time, needs to be converted to sec...

% duriation =         end_time        -     start_time
  durationP_data_1 = (TimeP_ros_data_1(size(TimeP_ros_data_1,1),:) - TimeP_ros_data_1(1,:))*10^(-9); 
  
t_P_sec_data_1 = 0:durationP_data_1/size(TimeP_ros_data_1,1):durationP_data_1;
t_P_sec_data_1(:,size(t_P_sec_data_1,2)) = [];

% time in vel
TimeV_ros_data_1 = Vel_Matrix_data_1(:,1); % ros time, needs to be converted to sec...

% duriation =         end_time        -     start_time
  durationV_data_1 = (TimeV_ros_data_1(size(TimeV_ros_data_1,1),:) - TimeV_ros_data_1(1,:))*10^(-9);

t_V_sec_data_1 = 0:durationV_data_1/size(TimeV_ros_data_1,1):durationV_data_1;
t_V_sec_data_1(:,size(t_V_sec_data_1,2)) = [];

Farid Alijani's avatar
Farid Alijani committed
30
% -----------------------------------------------------------------------------------------------------
Farid Alijani's avatar
Farid Alijani committed
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
% data 2: 

Pose_Matrix_data_2 = csvread('CAM_PID_.28_0_.006.txt',1,0);
Vel_Matrix_data_2 = csvread('vel_PID_.28_0_.006.txt',1,0);
Trans_Matrix_data_2 = csvread('Trans_PID_.28_0_.006.txt',1,0);

% time in position
TimeP_ros_data_2 = Pose_Matrix_data_2(:,1); % ros time, needs to be converted to sec...

% duriation =         end_time        -     start_time
  durationP_data_2 = (TimeP_ros_data_2(size(TimeP_ros_data_2,1),:) - TimeP_ros_data_2(1,:))*10^(-9); 
  
t_P_sec_data_2 = 0:durationP_data_2/size(TimeP_ros_data_2,1):durationP_data_2;
t_P_sec_data_2(:,size(t_P_sec_data_2,2)) = [];

% time in vel
TimeV_ros_data_2 = Vel_Matrix_data_2(:,1); % ros time, needs to be converted to sec...
Farid Alijani's avatar
Farid Alijani committed
48

Farid Alijani's avatar
Farid Alijani committed
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
% duriation =         end_time        -     start_time
  durationV_data_2 = (TimeV_ros_data_2(size(TimeV_ros_data_2,1),:) - TimeV_ros_data_2(1,:))*10^(-9);

t_V_sec_data_2 = 0:durationV_data_2/size(TimeV_ros_data_2,1):durationV_data_2;
t_V_sec_data_2(:,size(t_V_sec_data_2,2)) = [];

% -----------------------------------------------------------------------------------------------------
% data 3: 

Pose_Matrix_data_3 = csvread('CAM_PID_.29_.00026_.015.txt',1,0);
Vel_Matrix_data_3 = csvread('vel_PID_.29_.00026_.015.txt',1,0);
Trans_Matrix_data_3 = csvread('Trans_PID_.29_.00026_.015.txt',1,0);

% time in position
TimeP_ros_data_3 = Pose_Matrix_data_3(:,1); % ros time, needs to be converted to sec...

% duriation =         end_time        -     start_time
  durationP_data_3 = (TimeP_ros_data_3(size(TimeP_ros_data_3,1),:) - TimeP_ros_data_3(1,:))*10^(-9); 
  
t_P_sec_data_3 = 0:durationP_data_3/size(TimeP_ros_data_3,1):durationP_data_3;
t_P_sec_data_3(:,size(t_P_sec_data_3,2)) = [];

% time in vel
TimeV_ros_data_3 = Vel_Matrix_data_3(:,1); % ros time, needs to be converted to sec...

% duriation =         end_time        -     start_time
  durationV_data_3 = (TimeV_ros_data_3(size(TimeV_ros_data_3,1),:) - TimeV_ros_data_3(1,:))*10^(-9);

t_V_sec_data_3 = 0:durationV_data_3/size(TimeV_ros_data_3,1):durationV_data_3;
t_V_sec_data_3(:,size(t_V_sec_data_3,2)) = [];

% -----------------------------------------------------------------------------------------------------
% data 4: 
Pose_Matrix_data_4 = csvread('CAM_PID_.3_.0004_.02.txt',1,0);
Vel_Matrix_data_4 = csvread('vel_PID_.3_.0004_.02.txt',1,0);
Trans_Matrix_data_4 = csvread('Trans_PID_.3_.0004_.02.txt',1,0);
Farid Alijani's avatar
Farid Alijani committed
85
86
87
88
89
90
91
92
93
94

% time in position
TimeP_ros_data_4 = Pose_Matrix_data_4(:,1); % ros time, needs to be converted to sec...

% duriation =         end_time        -     start_time
  durationP_data_4 = (TimeP_ros_data_4(size(TimeP_ros_data_4,1),:) - TimeP_ros_data_4(1,:))*10^(-9); 
  
t_P_sec_data_4 = 0:durationP_data_4/size(TimeP_ros_data_4,1):durationP_data_4;
t_P_sec_data_4(:,size(t_P_sec_data_4,2)) = [];

Farid Alijani's avatar
Farid Alijani committed
95
96
97
98
99
100
101
102
103
% time in transposed_axis
TimeTrans_ros_data_4 = Trans_Matrix_data_4(:,1); % ros time, needs to be converted to sec...

% duriation =         end_time        -     start_time
  durationT_data_4 = (TimeTrans_ros_data_4(size(TimeTrans_ros_data_4,1),:) - TimeTrans_ros_data_4(1,:))*10^(-9); 
  
t_T_sec_data_4 = 0:durationT_data_4/size(TimeTrans_ros_data_4,1):durationT_data_4;
t_T_sec_data_4(:,size(t_T_sec_data_4,2)) = [];

Farid Alijani's avatar
Farid Alijani committed
104
105
106
107
108
109
110
111
112
113
114
% time in vel
TimeV_ros_data_4 = Vel_Matrix_data_4(:,1); % ros time, needs to be converted to sec...

% duriation =         end_time        -     start_time
  durationV_data_4 = (TimeV_ros_data_4(size(TimeV_ros_data_4,1),:) - TimeV_ros_data_4(1,:))*10^(-9);

t_V_sec_data_4 = 0:durationV_data_4/size(TimeV_ros_data_4,1):durationV_data_4;
t_V_sec_data_4(:,size(t_V_sec_data_4,2)) = [];

%% Pose estimation

Farid Alijani's avatar
Farid Alijani committed
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
%data 1:
x_t_1 = Trans_Matrix_data_1(:,4); % x_t
y_t_1 = Trans_Matrix_data_1(:,3); % y_t
theta_t_1 = Trans_Matrix_data_1(:,7); % yaw

Pose_X_data_1 = Pose_Matrix_data_1(:,4);
Pose_Y_data_1 = Pose_Matrix_data_1(:,3);
Theta_data_1 = Pose_Matrix_data_1(:,7);

%data 2:
x_t_2 = Trans_Matrix_data_2(:,4); % x_t
y_t_2 = Trans_Matrix_data_2(:,3); % y_t
theta_t_2 = Trans_Matrix_data_2(:,7); % yaw

Pose_X_data_2 = Pose_Matrix_data_2(:,4);
Pose_Y_data_2 = Pose_Matrix_data_2(:,3);
Theta_data_2 = Pose_Matrix_data_2(:,7);
Farid Alijani's avatar
Farid Alijani committed
132

Farid Alijani's avatar
Farid Alijani committed
133
134
135
136
137
138
139
140
141
142
143
%data 3:
x_t_3 = Trans_Matrix_data_3(:,4); % x_t
y_t_3 = Trans_Matrix_data_3(:,3); % y_t
theta_t_3 = Trans_Matrix_data_3(:,7); % yaw

Pose_X_data_3 = Pose_Matrix_data_3(:,4);
Pose_Y_data_3 = Pose_Matrix_data_3(:,3);
Theta_data_3 = Pose_Matrix_data_3(:,7);


%data 4:
Farid Alijani's avatar
Farid Alijani committed
144
145
146
147
x_t_4 = Trans_Matrix_data_4(:,4); % x_t
y_t_4 = Trans_Matrix_data_4(:,3); % y_t
theta_t_4 = Trans_Matrix_data_4(:,7); % yaw

Farid Alijani's avatar
Farid Alijani committed
148
149
Pose_X_data_4 = Pose_Matrix_data_4(:,4);
Pose_Y_data_4 = Pose_Matrix_data_4(:,3);
Farid Alijani's avatar
Farid Alijani committed
150
Theta_data_4 = Pose_Matrix_data_4(:,7);
Farid Alijani's avatar
Farid Alijani committed
151
152
153


% Reference Circle 
Farid Alijani's avatar
Farid Alijani committed
154
thresh_X = .0013;
Farid Alijani's avatar
Farid Alijani committed
155
theta = 0:.001:2*pi;
Farid Alijani's avatar
Farid Alijani committed
156

Farid Alijani's avatar
Farid Alijani committed
157
% needs to be adjusted manually if docking platform is replaced!
Farid Alijani's avatar
Farid Alijani committed
158
159
160
ref_x = -.2025;
ref_y = -.0185;

Farid Alijani's avatar
Farid Alijani committed
161
162
163
164
165
x_circle = thresh_X*cos(theta) + ref_x; % ref_X needs to be recorded
y_circle = thresh_X*sin(theta) + ref_y; % ref_Y needs to be recorded

%% Velocity estimation

Farid Alijani's avatar
Farid Alijani committed
166
167
168
169
% data 1:
Vel_X_data_1 = Vel_Matrix_data_1(:,2);
Vel_Y_data_1 = Vel_Matrix_data_1(:,3);
Omega_Z_data_1 = Vel_Matrix_data_1(:,7);
Farid Alijani's avatar
Farid Alijani committed
170
171


Farid Alijani's avatar
Farid Alijani committed
172
173
174
175
% data 2:
Vel_X_data_2 = Vel_Matrix_data_2(:,2);
Vel_Y_data_2 = Vel_Matrix_data_2(:,3);
Omega_Z_data_2 = Vel_Matrix_data_2(:,7);
Farid Alijani's avatar
Farid Alijani committed
176
177


Farid Alijani's avatar
Farid Alijani committed
178
179
180
181
% data 3:
Vel_X_data_3 = Vel_Matrix_data_3(:,2);
Vel_Y_data_3 = Vel_Matrix_data_3(:,3);
Omega_Z_data_3 = Vel_Matrix_data_3(:,7);
Farid Alijani's avatar
Farid Alijani committed
182

Farid Alijani's avatar
Farid Alijani committed
183
184
185
186
187
% data 4:
Vel_X_data_4 = Vel_Matrix_data_4(:,2);
Vel_Y_data_4 = Vel_Matrix_data_4(:,3);
Omega_Z_data_4 = Vel_Matrix_data_4(:,7);
%% Plot
Farid Alijani's avatar
Farid Alijani committed
188

Farid Alijani's avatar
Farid Alijani committed
189
% Camera Pose Estimation
Farid Alijani's avatar
Farid Alijani committed
190
191

figure;
Farid Alijani's avatar
Farid Alijani committed
192
set(gcf,'color','white');
Farid Alijani's avatar
Farid Alijani committed
193
subplot(311);
Farid Alijani's avatar
Farid Alijani committed
194
195
196
197
198
199
200
plot(t_P_sec_data_1,Pose_X_data_1,'LineWidth',2.1);
hold on
plot(t_P_sec_data_2,Pose_X_data_2,'r','LineWidth',1.7);
hold on
plot(t_P_sec_data_3,Pose_X_data_3,'g','LineWidth',1.8);
hold on
plot(t_P_sec_data_4,Pose_X_data_4,'m','LineWidth',1.3);
Farid Alijani's avatar
Farid Alijani committed
201
title('Camera Pose Estimation');
Farid Alijani's avatar
Farid Alijani committed
202
203
204
ylabel('${x_{mar}}$ [m]','interpreter','latex','FontSize',14);

l2 = legend('${P_y = 0.266, I_y = 0.0003, D_y = 0.014}$', '${P_y = 0.28, I_y = 0, D_y = 0.006}$','${P_y = 0.29, I_y = 0.00026, D_y = 0.015}$','${P_y = 0.3, I_y = 0.0004, D_y = 0.02}$');
Farid Alijani's avatar
Farid Alijani committed
205
206
set(l2,'interpreter','latex','FontSize',9);
% legend('boxoff');
Farid Alijani's avatar
Farid Alijani committed
207
208

subplot(312);
Farid Alijani's avatar
Farid Alijani committed
209
210
211
212
213
214
215
216
plot(t_P_sec_data_1,Pose_Y_data_1,'LineWidth',1.8);
hold on
plot(t_P_sec_data_2,Pose_Y_data_2,'r','LineWidth',1.7);
hold on
plot(t_P_sec_data_3,Pose_Y_data_3,'g','LineWidth',1.6);
hold on
plot(t_P_sec_data_4,Pose_Y_data_4,'m','LineWidth',1.4);
ylabel('${y_{mar}}$ [m]','interpreter','latex','FontSize',14);
Farid Alijani's avatar
Farid Alijani committed
217
218

subplot(313);
Farid Alijani's avatar
Farid Alijani committed
219
220
221
222
223
224
225
plot(t_P_sec_data_1,Theta_data_1,'LineWidth',1.8);
hold on
plot(t_P_sec_data_2,Theta_data_2,'r','LineWidth',1.7);
hold on
plot(t_P_sec_data_3,Theta_data_3,'g','LineWidth',1.6);
hold on
plot(t_P_sec_data_4,Theta_data_4,'m','LineWidth',1.4);
Farid Alijani's avatar
Farid Alijani committed
226

Farid Alijani's avatar
Farid Alijani committed
227
xlabel('$ time [s]$','interpreter','latex','FontSize',14);
Farid Alijani's avatar
Farid Alijani committed
228
ylabel('${\theta_{mar}}$ [rad]','interpreter','latex','FontSize',14);
Farid Alijani's avatar
Farid Alijani committed
229
230


Farid Alijani's avatar
Farid Alijani committed
231
% Control Signals
Farid Alijani's avatar
Farid Alijani committed
232

Farid Alijani's avatar
Farid Alijani committed
233
% control signals
Farid Alijani's avatar
Farid Alijani committed
234
figure;
Farid Alijani's avatar
Farid Alijani committed
235
set(gcf,'color','white');
Farid Alijani's avatar
Farid Alijani committed
236

Farid Alijani's avatar
Farid Alijani committed
237
238
239
240
241
242
243
244
subplot(311);
plot(t_V_sec_data_1,Vel_X_data_1,'LineWidth',1.8);
hold on
plot(t_V_sec_data_2,Vel_X_data_2,'r','LineWidth',1.7);
hold on
plot(t_V_sec_data_3,Vel_X_data_3,'g','LineWidth',1.6);
hold on
plot(t_V_sec_data_4,Vel_X_data_4,'m','LineWidth',1.4);
Farid Alijani's avatar
Farid Alijani committed
245

Farid Alijani's avatar
Farid Alijani committed
246
247
title('Control Signals');
ylabel('$\dot{x}_{Rob}$ [m/s]','interpreter','latex','FontSize',14);
Farid Alijani's avatar
Farid Alijani committed
248

Farid Alijani's avatar
Farid Alijani committed
249
250
251
l2 = legend('${P_y = 0.266, I_y = 0.0003, D_y = 0.014}$', '${P_y = 0.28, I_y = 0, D_y = 0.006}$','${P_y = 0.29, I_y = 0.00026, D_y = 0.015}$','${P_y = 0.3, I_y = 0.0004, D_y = 0.02}$');
set(l2,'interpreter','latex','FontSize',11);
legend('boxoff');
Farid Alijani's avatar
Farid Alijani committed
252

Farid Alijani's avatar
Farid Alijani committed
253

Farid Alijani's avatar
Farid Alijani committed
254
255
256
257
258
259
260
261
262
subplot(312);
plot(t_V_sec_data_1,Vel_Y_data_1,'LineWidth',1.8);
hold on
plot(t_V_sec_data_2,Vel_Y_data_2,'r','LineWidth',1.7);
hold on
plot(t_V_sec_data_3,Vel_Y_data_3,'g','LineWidth',1.6);
hold on
plot(t_V_sec_data_4,Vel_Y_data_4,'m','LineWidth',1.4);
ylabel('$\dot{y}_{Rob}$ [m/s]','interpreter','latex','FontSize',14);
Farid Alijani's avatar
Farid Alijani committed
263

Farid Alijani's avatar
Farid Alijani committed
264
265
266
267
268
269
270
271
subplot(313);
plot(t_V_sec_data_1,Omega_Z_data_1,'LineWidth',1.8);
hold on
plot(t_V_sec_data_2,Omega_Z_data_2,'r','LineWidth',1.7);
hold on
plot(t_V_sec_data_3,Omega_Z_data_3,'g','LineWidth',1.6);
hold on
plot(t_V_sec_data_4,Omega_Z_data_4,'m','LineWidth',1.4);
Farid Alijani's avatar
Farid Alijani committed
272
xlabel('$ time [s]$','interpreter','latex','FontSize',14);
Farid Alijani's avatar
Farid Alijani committed
273
274
275
ylabel('$\dot{\theta}_{Rob}$ [rad/s]','interpreter','latex','FontSize',14);

% Trajectory
Farid Alijani's avatar
Farid Alijani committed
276

Farid Alijani's avatar
Farid Alijani committed
277
figure;
Farid Alijani's avatar
Farid Alijani committed
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
set(gcf,'color','white');
subplot(131);
plot(Pose_Y_data_1,Pose_X_data_1,'b','LineWidth',2);
% hold on
% quiver(abs(Pose_Y_data_1),Pose_X_data_1,gradient(Pose_Y_data_1),gradient(Pose_X_data_1),'r--','LineWidth',.1);

hold on
plot(Pose_Y_data_2,Pose_X_data_2,'r','LineWidth',2);
% hold on
% quiver(abs(Pose_Y_data_2),Pose_X_data_2,gradient(Pose_Y_data_2),gradient(Pose_X_data_2),'m--','LineWidth',.1);

hold on
plot(Pose_Y_data_3,Pose_X_data_3,'g','LineWidth',2);
% hold on
% quiver(abs(Pose_Y_data_3),Pose_X_data_3,gradient(Pose_Y_data_3),gradient(Pose_X_data_3),'k--','LineWidth',.1);

hold on
plot(Pose_Y_data_4,Pose_X_data_4,'m','LineWidth',2);
% hold on
% quiver(abs(Pose_Y_data_4),Pose_X_data_4,gradient(Pose_Y_data_4),gradient(Pose_X_data_4),'b--','LineWidth',.1);

hold on
plot(y_circle,x_circle,'k--','LineWidth',3.4);

title('Approach zone + SM zone + Target area');
ylabel('${x}_{mar}$ [m]','interpreter','latex','FontSize',14);
axis([-.65 .05 -1.6 -.19]);

subplot(132);
plot(Pose_Y_data_1,Pose_X_data_1,'b','LineWidth',2);
hold on
plot(Pose_Y_data_2,Pose_X_data_2,'r','LineWidth',2);
hold on
plot(Pose_Y_data_3,Pose_X_data_3,'g','LineWidth',2);
hold on
plot(Pose_Y_data_4,Pose_X_data_4,'m','LineWidth',2);
hold on
plot(y_circle,x_circle,'k--','LineWidth',3.4);

title('SM zone + Target area');
xlabel('${y}_{mar}$ [m]','interpreter','latex','FontSize',14);
axis([-.025 0.005 -.29 -.19]);

subplot(133);
plot(Pose_Y_data_1,Pose_X_data_1,'b','LineWidth',2);
hold on
plot(Pose_Y_data_2,Pose_X_data_2,'r','LineWidth',2);
hold on
plot(Pose_Y_data_3,Pose_X_data_3,'g','LineWidth',2);
hold on
plot(Pose_Y_data_4,Pose_X_data_4,'m','LineWidth',2);
hold on
plot(y_circle,x_circle,'k--','LineWidth',3.4);

title('Target area');
axis([-.0205 -.0168 -.2054 -.199]);
l = legend('${P_y = 0.266, I_y = 0.0003, D_y = 0.014}$', '${P_y = 0.28, I_y = 0, D_y = 0.006}$','${P_y = 0.29, I_y = 0.00026, D_y = 0.015}$','${P_y = 0.3, I_y = 0.0004, D_y = 0.02}$','${Target}$');
set(l,'interpreter','latex','FontSize',11);


% 
% % Transposed Axis
Farid Alijani's avatar
Farid Alijani committed
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
% figure;
% subplot(3,1,1);
% plot(t_T_sec_data_4,x_t_4,'LineWidth',1.5);
% ylabel('z_{t}');
% title('Transposed Axis');
% 
% 
% subplot(3,1,2);
% plot(t_T_sec_data_4,y_t_4,'LineWidth',1.5);
% ylabel('y_{t}');
% 
% subplot(3,1,3);
% plot(t_T_sec_data_4,theta_t_4,'LineWidth',1.5);
% xlabel('time');
% ylabel('yaw');
% 
% 
% figure;
% set(gcf,'color','white');
% plot(Pose_Y_data_4,Pose_X_data_4,'b','LineWidth',2);
% xlabel('y_{mar}');
% ylabel('x_{mar}');
% 
% figure;
% set(gcf,'color','white');
% plot(y_t_4,x_t_4,'b','LineWidth',2);
% xlabel('y_t');
% ylabel('x_t');
% axis([-.1 .1 .19 1.55]);