304 lines
10 KiB
Matlab
Executable File
304 lines
10 KiB
Matlab
Executable File
%% Funzione che calcola gli spostamenti in modalità triassiale per i Tilt Link
|
|
function [AlfaX,AlfaY,TempDef_RSN,ARRAYdateRSN,ErrRSNLink] = elaborazione_RSN(conn,...
|
|
IDcentralina,DTcatena,MEMS,rRSN,ris_acc,tolleranzaAcc,angRSN,Tmax,Tmin,TempDef_RSN,...
|
|
NodoRSNLink,ARRAYdateRSN,NuovoZeroRSN,NdatiMedia,Ndatidespike,ErrRSNLink,datainiRSN,...
|
|
pos_inst,FileName)
|
|
|
|
% Inizio del ciclo di elaborazione
|
|
text = 'elaborazione_RSN function started';
|
|
fileID = fopen(FileName,'a');
|
|
fmt = '%s \r';
|
|
fprintf(fileID,fmt,text);
|
|
|
|
if NuovoZeroRSN == 1
|
|
if NdatiMedia > Ndatidespike
|
|
Ndati = NdatiMedia;
|
|
else
|
|
Ndati = Ndatidespike;
|
|
end
|
|
ini = round(Ndati/2)+1;
|
|
if rem(Ndati,2) == 0
|
|
ini = ini+1;
|
|
end
|
|
clear NDati
|
|
angRSN = angRSN(ini:end,:);
|
|
ris_acc = ris_acc(ini:end,:);
|
|
TempDef_RSN = TempDef_RSN(ini:end,:);
|
|
ARRAYdateRSN = ARRAYdateRSN(ini:end,1);
|
|
ErrRSNLink = ErrRSNLink(ini:end,:);
|
|
end
|
|
|
|
Nnodi = rRSN;
|
|
|
|
% Inizio del ciclo di elaborazione
|
|
text = 'Elaboration of RSN Link started';
|
|
fprintf(fileID,fmt,text);
|
|
|
|
TempDef_RSN = TempDef_RSN';
|
|
[rr,cc] = size(angRSN);
|
|
if MEMS == 2
|
|
cc = cc/2;
|
|
else
|
|
cc = cc/3;
|
|
end
|
|
|
|
%% Controllo delle risultanti di accelerazione
|
|
if MEMS == 2 % Il controllo lo eseguo solo per i MEMS FreeScale
|
|
ris_acc = ris_acc'; % Nodi in riga, date in colonna
|
|
[r,c] = size(ris_acc);
|
|
|
|
% controllo che le matrici con le risultanti delle accelerazioni e
|
|
% le matrici con i dati di angolo di inclinazione assoluto
|
|
% abbiano le stesse dimensioni (r con cc e c con rr perchè matrice
|
|
% ris_acc è trasposta!)
|
|
if r~=cc
|
|
text = ['Warning! Number of row of absolute angle data do not correspond '...
|
|
'to the number of acceleration cosine vector!'];
|
|
fprintf(fileID,fmt,text);
|
|
end
|
|
if c~=rr
|
|
text = ['Warning! Number of column of absolute angle data do not correspond '...
|
|
'to the number of acceleration cosine vector!'];
|
|
fprintf(fileID,fmt,text);
|
|
end
|
|
cont = 1; % contatore
|
|
cont2 = 1; % contatore
|
|
|
|
angRSN = angRSN';
|
|
textA = 'There are not correction of RSN Link based on acceleration vectors filter';
|
|
textA2 = 'There are not correction of RSN Link based on uncalibrated acceleration vectors';
|
|
|
|
for j = 2:c % Data
|
|
nodo = 1;
|
|
for i = 1:r % Nodo
|
|
% se il valore assoluto della differenza è maggiore della
|
|
% tolleranza, pongo l'angolo pari al valore precendete
|
|
if abs(ris_acc(i,j)-ris_acc(i,j-1)) > tolleranzaAcc
|
|
angRSN(nodo:nodo+1,j) = angRSN(nodo:nodo+1,j-1);
|
|
textA = ['' num2str(cont) ' correction executed for RSN Link - Acceleration vector filter!'];
|
|
cont = cont+1;
|
|
end
|
|
if ris_acc(i,j) < 0.8 || ris_acc(i,j) > 1.3 % Il nodo è fuori taratura!
|
|
if j == 1
|
|
nn = 2;
|
|
while nn <= c
|
|
if ris_acc(i,nn) < 0.8 || ris_acc(i,nn) > 1.2
|
|
angRSN(nodo:nodo+1,j) = angRSN(nodo:nodo+1,nn);
|
|
break
|
|
end
|
|
end
|
|
else
|
|
angRSN(nodo:nodo+1,j) = angRSN(nodo:nodo+1,j-1);
|
|
TempDef_RSN(i,j) = TempDef_RSN(i,j-1);
|
|
end
|
|
textA2 = ['' num2str(cont2) ' correction executed for RSN Link - uncalibrated Acceleration vector!'];
|
|
cont2 = cont2+1;
|
|
end
|
|
nodo = nodo+2;
|
|
end
|
|
end
|
|
fprintf(fileID,fmt,textA);
|
|
fprintf(fileID,fmt,textA2);
|
|
else
|
|
[c,r] = size(ris_acc);
|
|
angRSN = angRSN';
|
|
end
|
|
|
|
%% Temperatura
|
|
cont3 = 0; % contatore
|
|
FileTemperature = ['' IDcentralina '-' DTcatena '-RSN-Therm.csv'];
|
|
if isfile(FileTemperature) == 1
|
|
DatiRaw = csvread(FileTemperature);
|
|
[rDR,cDR] = size(DatiRaw);
|
|
DatiRaw(:,1) = DatiRaw(:,1) + 730000;
|
|
else
|
|
rDR = 1;
|
|
cDR = 1;
|
|
end
|
|
textT = 'There are not correction of RSN Link based on temperature filter';
|
|
for b = 1:c % Data
|
|
nodo = 1;
|
|
for a = 1:r % Nodo
|
|
% NON considero i dati al di sopra dei 80 °C o al di sotto dei -30 °C!
|
|
if TempDef_RSN(a,b) > Tmax || TempDef_RSN(a,b) < Tmin
|
|
cont3 = cont3+1;
|
|
if b == 1
|
|
if isfile(FileTemperature) == 1
|
|
RawDate = find(DatiRaw(:,1)<=datenum(datainiRSN));
|
|
if isempty(RawDate) == 1
|
|
cc = 2;
|
|
while cc <= c
|
|
if TempDef_RSN(a,cc) > Tmax || TempDef_RSN(a,cc) < Tmin
|
|
cc = cc+1;
|
|
else
|
|
break
|
|
end
|
|
end
|
|
TempDef_RSN(a,b) = TempDef_RSN(a,cc);
|
|
angRSN(nodo:nodo+1,b) = angRSN(nodo:nodo+1,cc);
|
|
else
|
|
if isnan(DatiRaw(RawDate(end),a+1)) == 0
|
|
TempDef_RSN(a,b) = cellstr(num2str(DatiRaw(b+1,RawDate(end))));
|
|
angRSN(nodo:nodo+1,b) = cellstr(num2str(DatiRaw(1+a*2:2+a*2,RawDate(end))));
|
|
if ErrRSNLink(b,jj) == 0
|
|
ErrRSNLink(b,jj) = 0.5;
|
|
end
|
|
wardat = 'Temperature data of RSN Link nodes corrected using Raw Data of reference Csv file.';
|
|
fprintf(fileID,fmt,wardat);
|
|
else
|
|
cc = 2;
|
|
while cc <= c
|
|
if TempDef_RSN(a,cc) > Tmax || TempDef_RSN(a,cc) < Tmin
|
|
cc = cc+1;
|
|
else
|
|
break
|
|
end
|
|
end
|
|
TempDef_RSN(a,b) = TempDef_RSN(a,cc);
|
|
angRSN(nodo:nodo+1,b) = angRSN(nodo:nodo+1,cc);
|
|
end
|
|
end
|
|
else
|
|
cc = 2;
|
|
while cc <= c
|
|
if TempDef_RSN(a,cc) > Tmax || TempDef_RSN(a,cc) < Tmin
|
|
cc = cc+1;
|
|
else
|
|
break
|
|
end
|
|
end
|
|
TempDef_RSN(a,b) = TempDef_RSN(a,cc);
|
|
end
|
|
else
|
|
TempDef_RSN(a,b) = TempDef_RSN(a,b-1);
|
|
angRSN(nodo:nodo+1,j) = angRSN(nodo:nodo+1,j-1);
|
|
if ErrRSNLink(b,jj) == 0
|
|
ErrRSNLink(b,jj) = 0.5;
|
|
end
|
|
end
|
|
textT = ['' num2str(cont3) ' correction executed for RSN Link - Temperature filter!'];
|
|
end
|
|
nodo = nodo+2;
|
|
end
|
|
end
|
|
|
|
if rDR~=1 && cDR~=1 && isempty(DatiRaw) == 0
|
|
RawDate1 = find(DatiRaw(:,1)<=ARRAYdateRSN(1));
|
|
if isempty(RawDate1) == 1
|
|
RawDate2 = 1;
|
|
elseif RawDate1(end) == rDR
|
|
RawDate2 = find(ARRAYdateRSN(:,1)>DatiRaw(end,1));
|
|
else
|
|
RawDate2 = find(ARRAYdateRSN(:,1)>DatiRaw(RawDate1(end)+1,1));
|
|
end
|
|
else
|
|
RawDate1 = [];
|
|
RawDate2 = 1;
|
|
end
|
|
if isempty(RawDate1) == 0 && isempty(RawDate2) == 0
|
|
Dati = [DatiRaw(1:RawDate1(end),:); ARRAYdateRSN(RawDate2(1):end) TempDef_RSN(:,RawDate2(1):end)' angRSN(:,RawDate2(1):end)'];
|
|
elseif isempty(RawDate1) == 1 && isempty(RawDate2) == 0
|
|
Dati = [ARRAYdateRSN TempDef_RSN' angRSN'];
|
|
else
|
|
Dati = DatiRaw;
|
|
end
|
|
% Elimino appoggio più vecchio di un mese
|
|
RawDate3 = find(Dati(:,1)<now-30);
|
|
if isempty(RawDate3) == 0
|
|
[rDati,~] = size(Dati);
|
|
if RawDate3(end) == rDati
|
|
else
|
|
Dati = Dati(RawDate3(end)+1:end,:);
|
|
end
|
|
end
|
|
if isfile(FileTemperature) == 1
|
|
delete(FileTemperature);
|
|
end
|
|
Dati(:,1) = Dati(:,1) - 730000;
|
|
csvwrite(FileTemperature,Dati);
|
|
|
|
TempDef_RSN = TempDef_RSN';
|
|
angRSN = angRSN';
|
|
fprintf(fileID,fmt,textT);
|
|
|
|
% modifica di alcuni nodi in particolare
|
|
angRSN = azzeramenti(conn,IDcentralina,DTcatena,angRSN,NodoRSNLink,...
|
|
ARRAYdateRSN,FileName);
|
|
|
|
AlfaX = zeros(rr,Nnodi);
|
|
AlfaY = zeros(rr,Nnodi);
|
|
for i = 1:Nnodi
|
|
if pos_inst == 1
|
|
AlfaX(:,i) = angRSN(:,(i-1)*2+1); % ax
|
|
AlfaY(:,i) = angRSN(:,(i-1)*2+2); % ay
|
|
elseif pos_inst == 2
|
|
AlfaX(:,i) = -angRSN(:,(i-1)*2+1); % ax
|
|
AlfaY(:,i) = -angRSN(:,(i-1)*2+2); % ay
|
|
elseif pos_inst == 3
|
|
AlfaX(:,i) = -angRSN(:,(i-1)*2+1); % ax
|
|
AlfaY(:,i) = -angRSN(:,(i-1)*2+2); % ay
|
|
elseif pos_inst == 4
|
|
AlfaX(:,i) = angRSN(:,(i-1)*2+1); % ax
|
|
AlfaY(:,i) = angRSN(:,(i-1)*2+2); % ay
|
|
elseif pos_inst == 5
|
|
AlfaX(:,i) = angRSN(:,(i-1)*2+2); % ay
|
|
AlfaY(:,i) = -angRSN(:,(i-1)*2+1); % ax
|
|
elseif pos_inst == 6
|
|
AlfaX(:,i) = -angRSN(:,(i-1)*2+2); % ay
|
|
AlfaY(:,i) = angRSN(:,(i-1)*2+1); % ax
|
|
elseif pos_inst == 7
|
|
AlfaX(:,i) = -angRSN(:,(i-1)*2+2); % ay
|
|
AlfaY(:,i) = angRSN(:,(i-1)*2+1); % ax
|
|
elseif pos_inst == 8
|
|
AlfaX(:,i) = angRSN(:,(i-1)*2+2); % ay
|
|
AlfaY(:,i) = -angRSN(:,(i-1)*2+1); % ax
|
|
end
|
|
end
|
|
|
|
fclose(fileID);
|
|
% Approssimo i dati con il corretto numero di cifre decimali
|
|
[AlfaX,AlfaY,TempDef_RSN] = approx(AlfaX,AlfaY,TempDef_RSN,FileName);
|
|
|
|
%% Calcolo differenziali
|
|
NomeFileX = ['' IDcentralina '-' DTcatena '-RifX.csv'];
|
|
NomeFileY = ['' IDcentralina '-' DTcatena '-RifY.csv'];
|
|
if NuovoZeroRSN == 0 % prima elaborazione
|
|
csvwrite(NomeFileX,AlfaX(1,:));
|
|
AlfaX = AlfaX - AlfaX(1,:);
|
|
csvwrite(NomeFileY,AlfaY(1,:));
|
|
AlfaY = AlfaY - AlfaY(1,:);
|
|
else % Ci sono già dei dati elaborati
|
|
RIF_X = csvread(NomeFileX);
|
|
AlfaX = AlfaX - RIF_X;
|
|
RIF_Y = csvread(NomeFileY);
|
|
AlfaY = AlfaY - RIF_Y;
|
|
end
|
|
|
|
[r,~] = size(ErrRSNLink);
|
|
Matrice_err = zeros(r,rRSN);
|
|
for i = 1:r % date
|
|
d = 1;
|
|
for n = 1:rRSN % nodi
|
|
j = 1;
|
|
err = ErrRSNLink(i,d:d+3);
|
|
while j <= 4
|
|
if err(1,j) == 1
|
|
Matrice_err(i,n) = 1;
|
|
break
|
|
elseif err(1,j) == 0.5 && Matrice_err(i,n) ~= 1
|
|
Matrice_err(i,n) = 0.5;
|
|
end
|
|
j = j+1;
|
|
end
|
|
d = d+4;
|
|
end
|
|
end
|
|
ErrRSNLink = Matrice_err';
|
|
|
|
text = 'RSN Link elaboration executed correctly. elaborazione_RSN function closed';
|
|
fileID = fopen(FileName,'a');
|
|
fmt = '%s \r';
|
|
fprintf(fileID,fmt,text);
|
|
fclose(fileID);
|
|
|
|
end |