-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsim2.m
More file actions
238 lines (166 loc) · 6.24 KB
/
Copy pathsim2.m
File metadata and controls
238 lines (166 loc) · 6.24 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
%%%%%%%%%%%%%%%%%%%%%%%%%%%% simulation 2 %%%%%%%%%%%%%%%%%%%%%%%%%
sub_path = 'figs/sim2/quadratic_prog_healthy' ;
if ~exist(sub_path, 'dir')
mkdir(pwd, sub_path);
end
% sim2 parameters
observer = 1; % withoutobserver = 1, EKF = 2, NonlinearObserver = 3
use_env_forces = 0; % 0 for no environmental forces , 1 for enalbling the environmental forces
enable_waves = 0; % 0 for not using waves, 1 for enabling the waves
allocation_method = 0; % 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 ()
use_thrust_allocation = 1 ; % 0 without thrust allocation , 1 with thrust allocation
use_fixed_con = 0 ; % 1 for fixed desired DP force, 0 for using PID controller
% unnecessary parameters
desired_DP_force = [0 0 0];
sim_time= 6000 ;
% simulate
sim('part1.slx')
% extract information
eta = logsout.getElement('eta') ;
desired_eta = logsout.getElement('set_point');
desired_eta = desired_eta.Values.Data ;
tau_d = logsout.getElement('tau_d');
tau_d = tau_d.Values.Data ;
out_thrust = logsout.getElement('out_thrust') ;
out_thrust = out_thrust.Values.Data;
alphas = logsout.getElement('alphas');
alphas = alphas.Values.Data;
thrusters_dynamics = logsout.getElement('thrusters_dynamics');
thrusters_dynamics = thrusters_dynamics.Values.Data;
des_nu = logsout.getElement('nu_d');
des_nu = des_nu.Values.Data;
nu = logsout.getElement('nu');
nu = nu.Values.Data;
nu = reshape(nu, [size(des_nu)]) ;
time= eta.Values.Time ;
% current pose
north = eta.Values.Data(: , 1) ;
east = eta.Values.Data(: , 2) ;
psi = eta.Values.Data(: , 3) * 180/pi ;
l = {'Surge' , 'Sway' , 'heave' ,'roll' ,'pitch' , 'Yaw' } ;
for i = 1:min(size(tau_d))
f = tau_d(: , i) ;
ff = thrusters_dynamics(: , i) ;
figure
plot(time , f)
hold on
plot(time, ff)
xlabel('Time (sec)')
ylabel('Magnitude (N) ')
legend('desired thrust' , 'allocated thrust')
title(sprintf('Performance of thrust allocation in %s', l{i}));
saveas(gcf, fullfile(sub_path , strcat( num2str(i), sprintf('allocation_sim%02d.png', 2))));
end
for i = 1:min(size(alphas))
f = alphas(: , i) ;
ff = out_thrust(: , i) ;
figure
plot(time , f)
xlabel('Time (sec)')
ylabel('Angle (rad) ')
title(sprintf(' Direction of thrust in thruster %0d', i));
saveas(gcf, fullfile(sub_path , strcat( num2str(i) , sprintf('output_thrust_direction_sim_%02d.png', 2))));
figure
plot(time, ff)
xlabel('Time (sec)')
ylabel('Thrust (N) ')
title(sprintf('Output thrust by thruster %02d', i));
saveas(gcf, fullfile(sub_path , strcat( num2str(i) , sprintf('output_thrust_magnitude_sim_%02d.png', 2))));
end
plot(desired_eta(: , 2) , desired_eta(: , 1))
hold on
plot(east, north) ;
hold on
indices = 1:1000:length(east) ;
selected_x = east(indices);
selected_y = north(indices);
selected_u = cos(-psi + (pi/2)) ;
selected_u = selected_u(indices);
selected_v = sin(-psi + (pi/2)) ;
selected_v = selected_v(indices);
quiver(selected_x, selected_y, selected_u, selected_v, 0.2, 'Color', 'r', 'LineWidth', 1.5);
title('XY plot')
xlabel('Position in East direction (m)')
ylabel('Position in North direction (m)')
legend('desired trajectory' , 'ship trajectory')
saveas(gcf, fullfile(sub_path , sprintf('xy_healthy_thrusters_%02d.png', 2)));
%%%%%%%%%%%%%%%%%% sim 2 but with pseudo inverse %%%%%%%%%%%%%%%%
sub_path = 'figs/sim2/pseudo_inverse_healthy' ;
if ~exist(sub_path, 'dir')
mkdir(pwd, sub_path);
end
% sim 2 part 2 params
allocation_method = 1 ; % pseudo inverse
% simulate
sim('part1.slx')
% extract information
eta = logsout.getElement('eta') ;
desired_eta = logsout.getElement('set_point');
desired_eta = desired_eta.Values.Data ;
tau_d = logsout.getElement('tau_d');
tau_d = tau_d.Values.Data ;
out_thrust = logsout.getElement('out_thrust') ;
out_thrust = out_thrust.Values.Data;
alphas = logsout.getElement('alphas');
alphas = alphas.Values.Data;
thrusters_dynamics = logsout.getElement('thrusters_dynamics');
thrusters_dynamics = thrusters_dynamics.Values.Data;
des_nu = logsout.getElement('nu_d');
des_nu = des_nu.Values.Data;
nu = logsout.getElement('nu');
nu = nu.Values.Data;
nu = reshape(nu, [size(des_nu)]) ;
time= eta.Values.Time ;
% current pose
north = eta.Values.Data(: , 1) ;
east = eta.Values.Data(: , 2) ;
psi = eta.Values.Data(: , 3) * 180/pi ;
l = {'Surge' , 'Sway' , 'heave' ,'roll' ,'pitch' , 'Yaw' } ;
for i = 1:min(size(tau_d))
f = tau_d(: , i) ;
ff = thrusters_dynamics(: , i) ;
figure
plot(time , f)
hold on
plot(time, ff)
xlabel('Time (sec)')
ylabel('Magnitude (N) ')
legend('desired thrust' , 'allocated thrust')
title(sprintf('Performance of thrust allocation in %s', l{i}));
saveas(gcf, fullfile(sub_path , strcat( num2str(i), sprintf('pallocation_sim%02d.png', 2))));
end
for i = 1:min(size(alphas))
f = alphas(: , i) ;
ff = out_thrust(: , i) ;
figure
plot(time , f)
xlabel('Time (sec)')
ylabel('Angle (rad) ')
title(sprintf(' Direction of thrust in thruster %0d', i));
saveas(gcf, fullfile(sub_path , strcat( num2str(i) , sprintf('poutput_thrust_direction_sim_%02d.png', 2))));
figure
plot(time, ff)
xlabel('Time (sec)')
ylabel('Thrust (N) ')
title(sprintf('Output thrust by thruster %02d', i));
saveas(gcf, fullfile(sub_path , strcat( num2str(i) , sprintf('poutput_thrust_magnitude_sim_%02d.png', 2))));
end
plot(desired_eta(: , 2) , desired_eta(: , 1))
hold on
plot(east, north) ;
hold on
indices = 1:1000:length(east) ;
selected_x = east(indices);
selected_y = north(indices);
selected_u = cos(-psi + (pi/2)) ;
selected_u = selected_u(indices);
selected_v = sin(-psi + (pi/2)) ;
selected_v = selected_v(indices);
quiver(selected_x, selected_y, selected_u, selected_v, 0.2, 'Color', 'r', 'LineWidth', 1.5);
title('XY plot')
xlabel('Position in East direction (m)')
ylabel('Position in North direction (m)')
legend('desired trajectory' , 'ship trajectory')
saveas(gcf, fullfile(sub_path , sprintf('pxy_healthy_thrusters_%02d.png', 2)));