-
Notifications
You must be signed in to change notification settings - Fork 2
/
Driver_Code_Kinematic_and_Dynamic_Engagement_Case_I.m
153 lines (119 loc) · 3.15 KB
/
Driver_Code_Kinematic_and_Dynamic_Engagement_Case_I.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
% Driver Code
%% clear commands
clear all
close all
clc
%% kinematic engagement
time = 500; %seconds
Ts = 0.1;
% x(1) :: hP
% x(2) :: dP
% x(3) :: gammaP
% x(4) :: hE
% x(5) :: dE
% x(6) :: gammaE
% x(7) :: R
% x(8) :: beta
beta_0 = 0;
R_0 = sqrt((30000 - 0)^2 + (10000 - 10000)^2);
x0_kin = [10000, 0, 0, 10000, 30000, pi, R_0, beta_0];
x = zeros(8,time/Ts);
for ii = 1:time/Ts
if ii == 1
[~,xx] = ode45(@(t,x)kinsim(t,x), [ii ii+1]*Ts , x0_kin);
else
[~,xx] = ode45(@(t,x)kinsim(t,x), [ii ii+1]*Ts , x(:,ii-1) );
end
x(:,ii) = xx(end,:);
%%% Intersample Fuzing %%%%%%%%
[detonate , missDistance ] = fuzeKin( xx );
if detonate
missDistance
break
end
%%% Intersample Fuzing %%%%%%%%
% if (ii*Ts)>500
% missDistance
% break
%
% end
end
figure(1)
p1 = plot( x(2,1:ii)/1000 , x(1,1:ii)/1000 , 'b' );
hold on
plot( x(2,1)/1000 , x(1,1)/1000 , 'bx' )
plot( x(2,ii)/1000 , x(1,ii)/1000 , 'bo' )
p2 = plot( x(5,1:ii)/1000 , x(4,1:ii)/1000 , 'r' );
plot( x(5,1)/1000 , x(4,1)/1000 , 'rx' )
plot( x(5,ii)/1000 , x(4,ii)/1000 , 'ro' )
hold off
ylimits = ylim;
xlimits = xlim;
axis equal
ylim([0 ylimits(2)])
xlim([0 xlimits(2)])
legend([p1,p2],{'Pursuer','Evader'},'interpreter','latex','Location','best')
ylabel('$h$ (km)','interpreter','latex')
xlabel('$d$ (km)','interpreter','latex')
%% dynamic engagement
% x(1) :: VP
% x(2) :: gammaP
% x(3) :: hP
% x(4) :: dP
% x(5) :: VE
% x(6) :: gammaE
% x(7) :: hE
% x(8) :: dE
x0_dyn = [450, 0, 10000, 0, 450, pi, 10000, 30000];
x2 = zeros(8,time/Ts);
for ii = 1:time/Ts
if ii == 1
[~,xx] = ode45(@(t,x)dynsim(t,x), [ii ii+1]*Ts , x0_dyn );
else
[~,xx] = ode45(@(t,x)dynsim(t,x), [ii ii+1]*Ts , x2(:,ii-1) );
end
x2(:,ii) = xx(end,:);
%%% Intersample Fuzing %%%%%%%%
[detonate , missDistance ] = fuze( xx );
if detonate
missDistance
break
end
%%% Intersample Fuzing %%%%%%%%
% if (ii*Ts)>500
% missDistance
% break
%
% end
end
figure(2)
p1 = plot( x2(4,1:ii)/1000 , x2(3,1:ii)/1000 , 'b' );
hold on
plot( x2(4,1)/1000 , x2(3,1)/1000 , 'bx' )
plot( x2(4,ii)/1000 , x2(3,ii)/1000 , 'bo' )
p2 = plot( x2(8,1:ii)/1000 , x2(7,1:ii)/1000 , 'r' );
plot( x2(8,1)/1000 , x2(7,1)/1000 , 'rx' )
plot( x2(8,ii)/1000 , x2(7,ii)/1000 , 'ro' )
hold off
ylimits = ylim;
xlimits = xlim;
axis equal
ylim([0 ylimits(2)])
xlim([0 xlimits(2)])
legend([p1,p2],{'Pursuer','Evader'},'interpreter','latex')
ylabel('$h$ (km)','interpreter','latex')
xlabel('$d$ (km)','interpreter','latex')
figure(3)
plot( [1:ii]*Ts , x2(1,1:ii) , 'b' )
hold on
plot( [1:ii]*Ts , x2(5,1:ii) , 'r')
hold off
legend('$V_{\rm P}$','$V_{\rm E}$','interpreter','latex')
ylabel('$V$ (m/s)','interpreter','latex')
xlabel('$t$ (s)','interpreter','latex')
grid on
axis tight
ylimits = ylim;
xlimits = xlim;
ylim([0 ylimits(2)])
xlim([0 xlimits(2)])