-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsim4.m
More file actions
278 lines (230 loc) · 6.74 KB
/
Copy pathsim4.m
File metadata and controls
278 lines (230 loc) · 6.74 KB
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
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
path = 'figs' ;
if ~exist(path, 'dir')
mkdir(pwd, path);
end
sub_path = 'figs/sim4' ;
if ~exist(sub_path, 'dir')
mkdir(pwd, sub_path);
end
% sim4 parameters
sim_time= 200 ;
observer = 1; % withoutobserver = 1, EKF = 2, NonlinearObserver = 3
use_env_forces = 1; % 0 for no environmental forces , 1 for enalbling the environmental forces
enable_waves = 1; % 0 for not using waves, 1 for enabling the waves
use_fixed_con = 1 ; % 1 for fixed desired DP force, 0 for using PID controller
desired_DP_force = [1 1 1]*10^4;
% unnecessary parameters
use_thrust_allocation = 0 ; % 0 without thrust allocation , 1 with thrust allocation
allocation_method = 1; % 0 for quadratic programming method , and 1 for pseudo inverse method
ref_model = 1; % 0 for 0 desired setpoint , 1 for 4 corners
use_ref = 1 ; % 0 for desired setpoint without reference model , 1 use reference model ()
% environmental params
% wind parameters
mean_wind = 10 ;
mean_wind_direction = 180 ; % from north
N =100;
z = 3;
n = 0.468;
U_10 = 12 ;
params_wind = [N z n U_10];
% current parameters
mean_current_speed = 0.2 ;
mean_current_angle = 270 ; % from east
% waves parameters
H_s = 2.5 ;
T_p = 9 ;
dir = 225 * pi/180 ; % fromm north east
enable_waves = 1; % 0 for not using waves, 1 for enabling the waves
% run the simulation
sim('part1.slx') ;
% plotting
% data extraction
eta = logsout.getElement('eta') ;
eta_ekf = logsout.getElement('eta_ekf') ;
eta_nlo = logsout.getElement('eta_nlo') ;
nu = logsout.getElement('nu') ;
nu_ekf = logsout.getElement('nu_ekf') ;
nu_nlo = logsout.getElement('nu_nlo') ;
time= eta.Values.Time ;
% plotting
figure;
% Subplot 1: North component
subplot(3, 1, 1);
plot(time, eta.Values.Data(:, 1));
hold on;
plot(time, eta_ekf.Values.Data(1, :));
plot(time, eta_nlo.Values.Data(:,1));
xlabel('Time (sec)');
ylabel('Amplitude (m)');
legend('Real', 'EKF', 'NPO');
title('North Component');
% Subplot 2: East component
subplot(3, 1, 2);
plot(time, eta.Values.Data(:, 2));
hold on;
plot(time, eta_ekf.Values.Data(2,:));
plot(time, eta_nlo.Values.Data(:,2));
xlabel('Time (sec)');
ylabel('Amplitude (m)');
legend('Real', 'EKF', 'NPO');
title('East Component');
% Subplot 3: Psi component
subplot(3, 1, 3);
plot(time, eta.Values.Data(:, 3));
hold on;
plot(time, eta_ekf.Values.Data(3,:));
hold on;
plot(time,eta_nlo.Values.Data(:,3));
xlabel('Time (sec)');
ylabel('Amplitude (rad)');
legend('Real', 'EKF', 'NPO');
title('Psi Component');
% Setting a title for the entire figure
sgtitle('Observer eta Estimation (Including Waves)');
% Saving the figure
saveas(gcf, fullfile(sub_path, 'eta_sim4.png'));
figure;
% Subplot 1: North component
subplot(3, 1, 1);
plot(time, nu.Values.Data(1,:));
hold on;
plot(time, nu_ekf.Values.Data(1, :));
plot(time, nu_nlo.Values.Data(:, 1));
xlabel('Time (sec)');
ylabel('Amplitude (m/s)');
legend('Real', 'EKF', 'NPO');
title('North Component');
% Subplot 2: East component
subplot(3, 1, 2);
plot(time, nu.Values.Data(2,:));
hold on;
plot(time, nu_ekf.Values.Data(2,:));
plot(time, nu_nlo.Values.Data(:, 2));
xlabel('Time (sec)');
ylabel('Amplitude (m/s)');
legend('Real', 'EKF', 'NPO');
title('East Component');
% Subplot 3: Psi component
subplot(3, 1, 3);
plot(time, nu.Values.Data(3,:));
hold on;
plot(time, nu_ekf.Values.Data(3,:));
plot(time, nu_nlo.Values.Data(:, 3));
xlabel('Time (sec)');
ylabel('Amplitude (rad/s)');
legend('Real', 'EKF', 'NPO');
title('Psi Component');
% Setting a title for the entire figure
sgtitle('Velocity Estimation (Including Waves)');
% Saving the figure
saveas(gcf, fullfile(sub_path, 'nu_sim4.png'));
% xyplot
figure;
plot(eta.Values.Data(:, 1), eta.Values.Data(:, 2));
hold on;
plot(eta_ekf.Values.Data(1,:), eta_ekf.Values.Data(2,:));
hold on;
plot(eta_nlo.Values.Data(:, 1), eta_nlo.Values.Data(:, 2));
xlabel('North (m)');
ylabel('East (m)');
legend('Real', 'EKF', 'NPO');
title('XY-plot for Observer Output (Including Waves)');
% Saving the figure
saveas(gcf, fullfile(sub_path, 'xy_sim4.png'));
enable_waves = 0; % 0 for not using waves, 1 for enabling the waves
% run the simulation
sim('part1.slx') ;
% plotting
% data extraction
eta = logsout.getElement('eta') ;
eta_ekf = logsout.getElement('eta_ekf') ;
eta_nlo = logsout.getElement('eta_nlo') ;
nu = logsout.getElement('nu') ;
nu_ekf = logsout.getElement('nu_ekf') ;
nu_nlo = logsout.getElement('nu_nlo') ;
time= eta.Values.Time ;
% plotting
figure;
% Subplot 1: North component
subplot(3, 1, 1);
plot(time, eta.Values.Data(:, 1));
hold on;
plot(time, eta_ekf.Values.Data(1, :));
plot(time, eta_nlo.Values.Data(:,1));
xlabel('Time (sec)');
ylabel('Amplitude (m)');
legend('Real', 'EKF', 'NPO');
title('North Component');
% Subplot 2: East component
subplot(3, 1, 2);
plot(time, eta.Values.Data(:, 2));
hold on;
plot(time, eta_ekf.Values.Data(2,:));
plot(time, eta_nlo.Values.Data(:,2));
xlabel('Time (sec)');
ylabel('Amplitude (m)');
legend('Real', 'EKF', 'NPO');
title('East Component');
% Subplot 3: Psi component
subplot(3, 1, 3);
plot(time, eta.Values.Data(:, 3));
hold on;
plot(time, eta_ekf.Values.Data(3,:));
hold on;
plot(time,eta_nlo.Values.Data(:,3));
xlabel('Time (sec)');
ylabel('Amplitude (rad)');
legend('Real', 'EKF', 'NPO');
title('Psi Component');
% Setting a title for the entire figure
sgtitle('Observer eta Estimation (Without Waves)');
% Saving the figure
saveas(gcf, fullfile(sub_path, 'eta_sim4_without_waves.png'));
figure;
% Subplot 1: North component
subplot(3, 1, 1);
plot(time, nu.Values.Data(1,:));
hold on;
plot(time, nu_ekf.Values.Data(1, :));
plot(time, nu_nlo.Values.Data(:, 1));
xlabel('Time (sec)');
ylabel('Amplitude (m/s)');
legend('Real', 'EKF', 'NPO');
title('North Component');
% Subplot 2: East component
subplot(3, 1, 2);
plot(time, nu.Values.Data(2,:));
hold on;
plot(time, nu_ekf.Values.Data(2,:));
plot(time, nu_nlo.Values.Data(:, 2));
xlabel('Time (sec)');
ylabel('Amplitude (m/s)');
legend('Real', 'EKF', 'NPO');
title('East Component');
% Subplot 3: Psi component
subplot(3, 1, 3);
plot(time, nu.Values.Data(3,:));
hold on;
plot(time, nu_ekf.Values.Data(3,:));
plot(time, nu_nlo.Values.Data(:, 3));
xlabel('Time (sec)');
ylabel('Amplitude (rad/s)');
legend('Real', 'EKF', 'NPO');
title('Psi Component');
% Setting a title for the entire figure
sgtitle('Velocity Estimation (Without Waves)');
% Saving the figure
saveas(gcf, fullfile(sub_path, 'nu_sim4_without_waves.png'));
% xyplot
figure;
plot(eta.Values.Data(:, 1), eta.Values.Data(:, 2));
hold on;
plot(eta_ekf.Values.Data(1,:), eta_ekf.Values.Data(2,:));
hold on;
plot(eta_nlo.Values.Data(:, 1), eta_nlo.Values.Data(:, 2));
xlabel('North (m)');
ylabel('East (m)');
legend('Real', 'EKF', 'NPO');
title('XY-plot for Observer Output (Without Waves)');
% Saving the figure
saveas(gcf, fullfile(sub_path, 'xy_sim4_without_waves.png'));