%% TSFS04: Elektriska drivsystem
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% TSFS04: Elektriska drivsystem. Script till Laboration 3.
% Laboration 3: skellettfil
% Datum: 111212
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Märkdata för motorn                        %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Rated.P      = ;% [W]                 Fyll i här
Rated.U_D    = ;% [V]                 Fyll i här
Rated.U_Y    = ;% [V]                 Fyll i här
Rated.I_Y    = ;% [A]                 Fyll i här
Rated.I_D    = ;% [A]                 Fyll i här
Rated.N      = ;% [rpm]               Fyll i här
Rated.n_poles= ;% Antal poler         Fyll i här
Rated.f_s    = ;% [Hz] - Märkfrekvens Fyll i här
Rated.N_s    = Rated.f_s*60*2./Rated.n_poles;  % [rpm]
Rated.w_s    = Rated.f_s*2*pi*2./Rated.n_poles;% [rad/s]
Rated.n_ph   = 3; % Antal faser


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Resultat från Momentprov                     %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Torque.U_H_ref= 220;
Torque.U_H    = [];%[V]   Fyll i här
Torque.N      = [];%[rpm] Fyll i här
Torque.T_meas = [];%[Nm]  Fyll i här
Torque.I_L    = [];%[A]   Fyll i här

% Fixa skalfel hastighetsmätning
Torque.N  = 1495*Torque.N./max(Torque.N);

% Fixa momentoffset i mätdata
Torque.T_meas  = Torque.T_meas-min(Torque.T_meas);


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Tomgångsprov                                 %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% Mätningar 
Idle.U_H  = ;% [V]       Fyll i här
Idle.I_L  = ;% [A]       Fyll i här
Idle.P_I  = ;% [W]       Fyll i här
Idle.P_II = ;% [W]       Fyll i här
Idle.RPM  = 1495;% [rpm] 

% Beräkningar
Idle.Q = (Idle.P_II-Idle.P_I)*sqrt(3);
Idle.P = Idle.P_I+Idle.P_II;
Idle.phi = ;% [rad] Fyll i här
Idle.P_check = 3*Idle.U_H/sqrt(3)*Idle.I_L*cos(Idle.phi);

% Jämför resultaten och visa procentuell skillnad
abs(1-Idle.P_check./Idle.P)*100


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Mätta reistanser (mätta direkt med resistansmätare) %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Direct.R_1  = []; % Fyll i här


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Prov med låst rotor                                 %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% Mätningar 
Blocked.U_H  = ;% [V]   Fyll i här
Blocked.I_L  = ;% [A]   Fyll i här
Blocked.P_I  = [];% [W] Fyll i här
Blocked.P_II = [];% [W] Fyll i här

% Beräkningar
Blocked.Q = (Blocked.P_II-Blocked.P_I)*sqrt(3);
Blocked.P = Blocked.P_I+Blocked.P_II;
Blocked.phi = ;% [rad] Fyll i här
Blocked.P_check = 3*Blocked.U_H/sqrt(3)*Blocked.I_L*cos(Blocked.phi);

% Jämför resultaten och visa procentuell skillnad
abs((1-Blocked.P./Blocked.P_check)*100)


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Uppgift 1
% Beräkning av tomgångsreaktans och impedans för låst 
% rotor samt resistans och reaktans vid märkfrekvens 
% för blocked rotor test
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Model.X_nl = ;% Fyll i här
Model.R_bl = ;% Fyll i här
Model.X_bl = ;% Fyll i här

Model.P_rot = ;% Fyll i här
Model.T_fric = ;% Fyll i här

Model.X_2 = ;% Fyll i här
Model.X_1 = Model.X_2; 
Model.X_m  = ;% Fyll i här
Model.R_2 = ;% Fyll i här


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Uppgift 2
% Räkna ut theveninekvivalenta motstånd
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Model.Z_1_eq = ; % Fyll i här TIPS: Använd "i" eller "j" som i "Z=R+i*X" rakt av
Model.R_1_eq = real(Model.Z_1_eq);
Model.X_1_eq = imag(Model.Z_1_eq);

% Använd att momentet är uppmätt vid D-koppling , UH = 220V
% Räkna ut theveninekvivalent spänning. Eftersom D-koppling användes var det 
% huvudspänning över lindningarna så "per fas" spänningen är U_H
Torque.V_1_eq = abs(); % Fyll i här


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Uppgift 3
% Plotta momentkurva
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Plot.N  =  (0:1:Rated.N_s)';
Plot.s = ; % Fyll i här
Plot.T_mech = ; % Fyll i här

figure;
plot(Plot.N,Plot.T_mech);%
hold on
plot(Torque.N,Torque.T_meas,'rx','linestyle','-')

legend('','') % Fyll i här
title('Modeled and Measured Torque. Measurements adjusted for Torque offset and Speed scale')
xlabel('Speed [RPM]')
ylabel('Torque [Nm]')
axis([]) %Fyll i här [minX maxX minY maxY]


