-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathzScaling.m
324 lines (278 loc) · 8.45 KB
/
zScaling.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
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
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
%%% Titus Braber - Vision-based stabilization of micro quadrotors
%%% 2D simulation of a quad
% close all;
clear all;clc;
% This line defines what this settings file does runs and plots
% Scaling information
testName = 'Scaling';
modelName = 'sim/';
subName = '/';
run('plotSettings.m')
if(~exist([ myset.path modelName testName]))
mkdir([ myset.path modelName testName])
end
set(0,'defaultlinelinewidth',1.5)
% savePlots = 1;
savePlots = 0;
%% Run code
% Algorithm or Groundtruth
control.runHor = 1;
control.runVert = 1;
% Takeoff or start from hover
takeoff = 0;
% takeoff = 1;
% Noise or no noise
noise = 0;
noise = 1;
% Only dynamics scaling, no control scaling => Effect on the quad
scalePowerX = 3;
scalePowerZ = 2;
scalePowerNoise = 2; % Make sure noise does have a higher influence.
% control scaling => NO effect on the quad
% scalePowerX = 5;
% scalePowerZ = 3;
% scalePowerNoise = 2; % Make sure noise does have a higher influence.
FPSscaler = 1;
% Set the ranges
FPSRange =20*FPSscaler;
range = (10:-1:1)/10;
%% (Initial) Conditions
% End time
t_end = 20;
% End the simulation if the algorithm triggers
triggerStopX = 0;
triggerStopZ = 0;
if(takeoff)
% Takeoff
% Start with FFstart seconds thrust
control.thrustfactor = 2;
control.FFstart = 0.6;
q0 = [1,0.1,degtorad(0),0,0,0]'; % Start at 0.1 meter so we don't /0
else
% From Hover, but give it a slight push to make sure div !=0
control.thrustfactor = 1.1;
control.FFstart = 0.1;
q0 = [1,1,degtorad(0),0,0,0]';
end
control.setpoint = [1,1,0,0,0,0];
%% Set gains and limits
% N.B. THEY ARE POSSIBLY SCALED IN scaling()!
% Set the gains during slowdown
slowdownGainX = 0;
slowdownGainZ = 10;
% Set the desired starting Gains.
startGainX = 0;
startGainZ = 0;
% Increasing gain per second
gainHor = 0.3;
gainVert = 2;
% Set the I gains
IgainHor = 0.5;
IgainVert = 0.25;
% Set the stability fractions
control.stableFractionHor = 0.6;
control.stableFractionVert = 0.6;
% Set the cov limits
control.covLimitHor = -6.0e-3;
covLimitVertBase = -4.5e-2;
%% Less interesting settings
% Set the slowed down DivY
control.SlowedDownDivZ = 0.5;
control.restartHor = 0;
control.restartVert = 0;
% The noise on the vision
visionNoise = 1/30000*noise;
% IMU specifications
GyroNoise = (0.005^2)*noise; % True noise value from datasheet.
GyroFreq = 1/80;
% Set the window sizes
windowbase = 30;
delaybase = 15;
% Set the desired divergence
control.divHor = 0;
control.divVert = 0;
% Slowmotion animation
slowmo =1/1;
covPlotScale = 1;
%% Run and plot
for compensation = 1:3
if(compensation == 1)
% Only dynamics scaling, no control scaling => Effect on the quad
scalePowerX = 3;
scalePowerZ = 2;
scalePowerNoise = 2;
elseif(compensation == 2)
% control scaling => NO effect on the quad
scalePowerX = 5;
scalePowerZ = 3;
scalePowerNoise = 3;
else
% control scaling => NO effect on the quad
scalePowerX = 5;
scalePowerZ = 3;
scalePowerNoise = 2; % Make sure noise does have a higher influence.
end
SimQuadPD();
%% Plot & Save
set(groot,'DefaultAxesColorOrder',parula(length(range)));
% DistanceX
loop = 1;
for fps = FPSRange
figure
hold on
xlabel('Time ($s$)', 'Interpreter', 'Latex');
ylabel('Position ($m$)', 'Interpreter', 'Latex');
for scale = range
% plotReport(time{loop},stateX{loop}(:,1),loop);
plot(time{loop},stateX{loop}(:,1));
loop = loop+1;
end
lh = colorbar( 'Direction','reverse');
set(lh,'Limits',[0.1 1]);
ylabel(lh, 'Scale')
set(lh,'Ticks',wrev(range),'TickLabels',{range});
axis([0 t_end 0.8 1.25])
grid on
subName = ['/distanceX_' num2str(fps,'%d\n') 'fps_' num2str(compensation-1,'%d\n') 'comp_'];
if(savePlots)
run('latexPlot.m');
end
end
% DistanceZ
loop = 1;
for fps = FPSRange
figure
hold on
xlabel('Time ($s$)', 'Interpreter', 'Latex');
ylabel('Height ($m$)', 'Interpreter', 'Latex');
for scale = range
% plotReport(time{loop},stateX{loop}(:,2),loop);
plot(time{loop},stateX{loop}(:,2));
loop = loop+1;
end
lh = colorbar( 'Direction','reverse');
set(lh,'Limits',[0.1 1]);
ylabel(lh, 'Scale')
set(lh,'Ticks',wrev(range),'TickLabels',{range});
% axis([0 t_end -0.5 3.5])
% axis([0 t_end 0 2])
grid on
subName = ['/distanceZ_' num2str(fps,'%d\n') 'fps_' num2str(compensation-1,'%d\n') 'comp_'];
if(savePlots)
run('latexPlot.m');
end
end
%%
% GainTimeX
loop =1;
for fps = FPSRange
figure
hold on
xlabel('Time ($s$)', 'Interpreter', 'Latex');
ylabel('Control Gain', 'Interpreter', 'Latex');
for scale = range
% title(['Horizontal X axis: ' num2str(fps,'%1.3f\n') ' (fps)']);
plot(covTime{loop},pstateX{loop});
loop=loop+1;
end
lh = colorbar( 'Direction','reverse');
set(lh,'Limits',[0.1 1]);
ylabel(lh, 'Scale')
set(lh,'Ticks',wrev(range),'TickLabels',{range});
grid on
subName = ['/gainTimeX_' num2str(fps,'%d\n') 'fps_' num2str(compensation-1,'%d\n') 'comp_'];
if(savePlots)
run('latexPlot.m');
end
end
% GainTimeZ
loop =1;
for fps = FPSRange
figure
hold on
xlabel('Time ($s$)', 'Interpreter', 'Latex');
ylabel('Control Gain', 'Interpreter', 'Latex');
for scale = range
% title(['Vertical Z axis: ' num2str(fps,'%1.3f\n') ' (fps)']);
plot(covTime{loop},pstateZ{loop});
loop=loop+1;
end
lh = colorbar( 'Direction','reverse');
set(lh,'Limits',[0.1 1]);
ylabel(lh, 'Scale')
set(lh,'Ticks',wrev(range),'TickLabels',{range});
grid on
subName = ['/gainTimeZ_' num2str(fps,'%d\n') 'fps_' num2str(compensation-1,'%d\n') 'comp_'];
if(savePlots)
run('latexPlot.m');
end
end
set(groot,'DefaultAxesColorOrder',defaultColorOrder);
end
set(groot,'DefaultAxesColorOrder',parula(length(range)));
loop = 1;
for fps = FPSRange
figure
hold on
xlabel('Time ($s$)', 'Interpreter', 'Latex');
ylabel('Height ($m$)', 'Interpreter', 'Latex');
for scale = range(1:end-1)
% plotReport(time{loop},stateX{loop}(:,2),loop);
plot(time{loop},stateX{loop}(:,2));
loop = loop+1;
end
% h = findobj(gca,'Type','line');
% lh = legend([h(10) h(1)],{num2str([1 0.1]', 'Scale = %1.1f')});
% lh = legend(cellstr(num2str(range', 'Scale = %1.1f')));
lh = colorbar( 'Direction','reverse');
set(lh,'Limits',[0.1 1]);
ylabel(lh, 'Scale')
set(lh,'Ticks',wrev(range),'TickLabels',{range});
% axis([0 t_end -0.5 3.5])
grid on
subName = ['/distanceZ_' num2str(fps,'%d\n') 'fps_' num2str(compensation-1,'%d\n') 'comp_zoomed_'];
if(savePlots)
run('latexPlot.m');
end
end
set(groot,'DefaultAxesColorOrder',defaultColorOrder);
%%
% triggerScaleX
loop = 1;
figure
for fps = FPSRange
hold on
% title('Horizontal Gain triggered in Scale vs Time');
xlabel('Scale', 'Interpreter', 'Latex');
ylabel('Time ($s$)', 'Interpreter', 'Latex');
plot(range,triggerX(1+(loop-1)*length(range):loop*length(range)),'*');
loop = loop+1;
lh = legend('Trigger','location','southeast');
set(lh,'FontSize',11);
set(lh,'Interpreter','Latex');
grid on
end
subName = ['/triggerScaleX_'];
if(savePlots)
run('latexPlot.m');
end
%%
% triggerScaleZ
loop = 1;
figure
for fps = FPSRange
hold on
% title('Horizontal Gain triggered in Scale vs Time');
xlabel('Scale', 'Interpreter', 'Latex');
ylabel('Time ($s$)', 'Interpreter', 'Latex');
plot(range,triggerZ(1+(loop-1)*length(range):loop*length(range)),'*');
loop = loop+1;
lh = legend('Trigger','location','southeast');
set(lh,'FontSize',11);
set(lh,'Interpreter','Latex');
grid on
end
subName = ['/triggerScaleZ_'];
if(savePlots)
run('latexPlot.m');
end