-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathsetupSystemJLSPPC.m
More file actions
190 lines (149 loc) · 5.07 KB
/
Copy pathsetupSystemJLSPPC.m
File metadata and controls
190 lines (149 loc) · 5.07 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
% sets up JLSPPC system for simulations
% 'inputs' are system, sched
% system params are set inside here
% pulls these settings outside of run script
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% SYSTEM INIT/SETUP
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% NOTE -- following notation and descriptions in paper,
% N_VEH sets the number of comms channels
% (even though systems may not represent vehicles)
% must have equal number comms channels for controls and measurements
% (each "agent" has an input channel and an output channel)
switch system
case 'SCALAR'
% controller settings
U_MAX = 1;
U_MIN = -1;
N_QUANT_LEVELS = 33; % quantization levels
Q = 10;
Qf = 10*Q;
R = 1;
% process/measurement noise
W_gen = 1; % cov for process noise input with Bw
V = 1;
% initial covariance
P_1 = 9;
% Scalar integrator
A = 1;
Bu = 1;
Bw = Bu;
C = 1; % position output
X_MAX = [];X_MIN = [];
CODEBOOK = linspace(U_MIN,U_MAX,N_QUANT_LEVELS);
case 'SISO_DOUBLE_INTEGRATOR'
% 1 input, 1 output
% controller settings
U_MAX = 10;
U_MIN = -10;
N_QUANT_LEVELS = 15; % quantization levels
Q = [10,0;0,1];
Qf = 10*Q;
R = 1;
% process/measurement noise
W_gen = 1; % cov for process noise input with Bw
V = 1;
% cov... uncertain position but better-known velocity (closer to zero)
P_1 = [25,0;0,9];
% Double Integrator
A =[1,1;0,1];
Bu = [0.5;1];
Bw = Bu;
C = [1 0]; % position output
X_MAX = [];X_MIN = [];
CODEBOOK = linspace(U_MIN,U_MAX,N_QUANT_LEVELS);
case 'MIMO_DOUBLE_INTEGRATOR'
% 2 inputs, 2 outputs
% controller settings
U_MAX = [1;10];
U_MIN = [-1;-10];
N_QUANT_LEVELS = 15; % quantization levels
Q = [10,0;0,1];
Qf = 10*Q;
R = eye(2);
% process/measurement noise
W_gen = eye(2); % cov for process noise input with Bw
V = eye(2);
% cov... uncertain position but better-known velocity (closer to zero)
P_1 = [25,0;0,9];
% Double Integrator
A =[1,1;0,1];
Bu = eye(2);
Bw = Bu;
C = eye(2); % full state output
X_MAX = [];X_MIN = [];
CODEBOOK = linspace(min(U_MIN),max(U_MAX),N_QUANT_LEVELS);
case 'MIMO_RELATIVE_MEASUREMENTS'
% controller settings
U_MAX = 10*ones(N_VEH,1);
U_MIN = -10*ones(N_VEH,1);
N_QUANT_LEVELS = 9; % quantization levels
Q1 = [10,0;0,1];
Q = kron(eye(N_VEH),Q1);
Qf = 10*Q;
R = eye(N_VEH);
% process/measurement noise
W_gen = .1*eye(N_VEH); % cov for process noise input with Bw
V = 1*eye(N_VEH);
% cov... uncertain position but better-known velocity (closer to zero)
P_11 = [25,0;0,9];
P_1 = kron(eye(N_VEH),P_11);
% A, B: set of double integrators
% Double Integrator
A1 =[1,1;0,1];
Bu1 = [0.5;1];
A = kron(eye(N_VEH),A1);
Bu = kron(eye(N_VEH),Bu1);
Bw = Bu;
% C: relative position measurements
C = zeros(N_VEH,size(A,1));
C(1,1) = 1;
for i = 2:N_VEH
C(i,(2*i-3)) = -1;
C(i,(2*i-1)) = 1;
end
X_MAX = [];X_MIN = [];
CODEBOOK = linspace(min(U_MIN),max(U_MAX),N_QUANT_LEVELS);
end
% make W for KF based on W_gen (KF uses APA' + W form)
W = Bw*W_gen*Bw';
% check
if( length(ALPHAC_BAR)~=N_VEH )
disp('WARNING: alpha_c, Nv mismatch')
end
if( length(ALPHAM_BAR)~=N_VEH )
disp('WARNING: alpha_m, Nv mismatch')
end
if( rem(size(C,1),N_VEH) )
disp('WARNING: Nv not into C')
end
if( rem(size(Bu,2),N_VEH) )
disp('WARNING: Nv not into Bu')
end
% estimation init
x_hat_1 = zeros(size(A,1),1);
% random time-series realizations
% note -- use W_gen here (Bw*w is the process noise input)
w = sqrt(W_gen)*randn(size(Bw,2),SIM_LENGTH);
v = sqrt(V)*randn(size(C,1),SIM_LENGTH);
% packet loss sequences
alpha_m = zeros(N_VEH,SIM_LENGTH);
alpha_c = zeros(N_VEH,SIM_LENGTH);
alpha_a = zeros(N_VEH,SIM_LENGTH);
for k = 1:SIM_LENGTH
alpha_m(:,k) = (sign(rand(N_VEH,1) - (1-(ALPHAM_BAR)))*0.5 + 0.5);
alpha_c(:,k) = (sign(rand(N_VEH,1) - (1-(ALPHAC_BAR)))*0.5 + 0.5);
alpha_a(:,k) = (sign(rand(N_VEH,1) - (1-(ALPHAA_BAR)))*0.5 + 0.5);
end
%%%%%%%%%%%%%%%%%%
if(strfind(sched,'piggyback'))
if(TAU_A~=TAU_M)
disp('warning - resetting ta to tm')
TAU_A = TAU_M;
end
ALPHAA_BAR = ALPHAM_BAR;
elseif(strfind(sched,'NoACK'))
TAU_A = 0;
end
% schedule time series
[PI_C,PI_M,PI_A,TAU_AC,T_S] = createSchedule(sched,N_VEH,SIM_LENGTH,TAU_C);