-
Notifications
You must be signed in to change notification settings - Fork 3
/
verification.m
106 lines (99 loc) · 1.95 KB
/
verification.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
%% Verification
% This will test the spacecraft model subject to a number of initial
% conditions and disturbances.
%% Test for rotation around orbit
% initialization: disturbance are set to 0, dt is increased to speed up the step
s = spacecraft;
s.Td = [0 0 0]';
s.Ts = 1.25;
s = s.update_x([0 0 0 0 0 0]');
% simulate until 1/8th an orbit period has passed (to stay out of any singularities).
while s.t < s.orbit_period/8
s = s.step;
end
% Test whether the rotation matches the expectation
if s.x_(2) > pi/4
disp 'No initial rotation'
s.theta
disp 'succes'
end
%% initial rotation around z
s = spacecraft;
s.Td = [0 0 0]';
s = s.update_x([0 0 pi/2 0 0 0]');
s.Ts = 10;
while s.t < s.orbit_period/8
s = s.step;
end
if s.x_(1) > pi/4
disp 'Initial rotation around z'
s.theta
disp 'succes'
end
%% Initial velocity
s = spacecraft;
s.Td = [0 0 0]';
s = s.update_x([0 0 0 1 0 0]');
s.Ts = .1;
while s.t < pi
s = s.step;
end
if s.x_(1) > pi
disp 'Initial rate around x'
s.theta
disp 'succes'
end
%% around y
s = spacecraft;
s.Td = [0 0 0]';
s = s.update_x([0 0 0 0 1 0]');
s.Ts = .1;
while s.t < pi
s = s.step;
end
if s.x_(2) > pi
disp 'Initial rate around y'
s.theta
disp 'succes'
end
%% around z
s = spacecraft;
s.Td = [0 0 0]';
s = s.update_x([0 0 0 0 0 1]');
s.Ts = .1;
while s.t < pi
s = s.step;
end
if s.x_(3) > pi
disp 'Initial rate around z'
s.theta
disp 'succes'
end
%% precession >> takes rather long to run
s = spacecraft;
s.Td = [0 0 0]';
s = s.update_x([0 0 0 1 1 1]');
s.Ts = 1;
while s.t < 1000
s = s.step;
end
%energy lost:
if abs(sum(s.J * s.rot.^2)-sum(s.J*[1 1 1]'.^2)) < 1.e-5
disp 'Energy lost ~ 0'
disp 'succes'
else
disp 'Energy lost > 0'
disp 'failure'
end
sum(s.J * s.rot.^2)-sum(s.J*[1 1 1]'.^2)
%% disturbance
s = spacecraft;
s.Td = [s.J(1,1) 0 0]';
while s.t < 9.99
s = s.step;
end
if s.x_(4) > 9.9
disp 'Single axis disturbance'
s.rot
disp 'succes'
end