Custom Simscape component: Confustion with language and scripting structure

2 visualizaciones (últimos 30 días)
Hi all,
I have been working on a behavioral Simscape model to simulate the dynamics of a solar panel using vector data containing temperature and irradiance to be used in a system comprised of mostly SimPower components. I feel like I am rather close but am still left with several problems that are preventing me from meeting my task:
1) Some of the constants that are required (line 28) I would prefer to be either locked or invisible to the user when editing block parameters.
2) There are some precursor calculations (line 42) that only need to be computed once as they are based on standard test condition values input by the user, but need to be made available as constants when computing the the desired output based on the weather data. Should these be computed in the 'function setup' portion? If so how can I make these available to the 'equations' because, as I understood, these values are not passed to the 'equations' section.
3) If I have a value with units and I want to subtract a dimensionless value from it how can this be achieved? For example, an error is produced when computing Rs (line 48).
4) In the 'equations' section, only the last computation of i is the desired output transferred to the rest of the system, the three equations above are just used to support it and are largely dependent on the new constants that are calculated in the 'function setup'. Is this the proper way to execute this?
5) I was planning to use the 'inputs' T and G as single scalar quantities fed from their daily vectors using some sort of clock on the input of the block. Is this the best way to do that or is there another way? Basically, as this panel will be the primary power source, I want it to update at a certain frequency to simulate the continuous nature of the device and system.
I have been scouring the help documents and forums trying to find a solution but have had no luck. If anyone can offer any suggestions or direct me to a helpful resource I would really appreciate it. [See attached code]
Thank you all so much,
Adam
component solar_panel
nodes
p = foundation.electrical.electrical; % +
n = foundation.electrical.electrical; % -
end
inputs
T = { 25.1, 'K' };
G = { 1000, 'W/m^2' };
end
variables
i = { 0, 'A' };
v = { 0, 'V' };
end
parameters
Ns = { 36, '1' }; % Number of cells
T_stc = { 298, 'K' }; % STC temperature, T
Voc_stc = { 21.2, 'V' }; % STC open circuit voltage, Voc
Isc_stc = { 1.93, 'A' }; % STC short circuit current, Isc
a = { 6.0e-4, 'K^-1' }; % Current temperature coefficient
b = { -3.97e-3, 'K^-1' } ; % Voltage temperature coefficient
N = { 1.7, '1' }; % Quality factor
G_stc = { 1000, 'W/m^2' }; % STC Irradiance, G
% Constants
k=1.38e-23; % Boltzman's constant
q=1.6e-19; % Charge of an electron
Eg=1.12; % Bandgap Voltage of Si, Eg
end
function setup
across( v, p.v, n.v );
through( i, p.i, n.i );
% **** This is where error checking/messages go *****
% if R <= 0
% error( 'Resistance value must be greater than zero' );
% end
% *** Precursor calculations ***
Vt_stc = N*k*T_stc/q; % Thermal voltage [V]
Io_stc = Isc_stc/(exp(Voc_stc/(Vt_stc))-1);% Saturation current [A]
dVdI_Voc = -1/Ns; % Derivative of I wrt V at V_oc, used for Rs calc
Xv = Io_stc/(Vt_stc)*exp(Voc_stc/(Vt_stc));
Rs = -dVdI_Voc -1/Xv; % Series resistance per cell [Ohms]
end
equations
Iph == G/G_stc*Isc_stc*(1+a*(T-T_stc))
Vt == N*k*T/q;
Io == Io_stc*(T/T_stc)^(3/N)*exp(-q*Eg/(N*k)*(1/T+-1/(T_stc)));
i == v/Voc_stc*Isc_stc; % Output
end
end
  2 comentarios
Adam Clark
Adam Clark el 25 de Nov. de 2012
OK, I have gotten the thing to compile, and seemed to have taken care of questions 2-4:
2) This is taken care of using the 'let, in' block
3) I used a workaround and just made a new variable 'Runit' with a unit magnitude and proper dimension.
4) See 2.
Unfortunately, the component is not behaving as desired. I set up a simple test circuit comprised of a 1 Ohm resistor in parallel to verify and I'm getting 0 V out. I think that it may have something to do with initial conditions. I am very new to Simulink/Simscape and still trying to get over this learning curve so any input helps. My updated code is attached.
Thanks,
Adam
component solar_panel
nodes
p = foundation.electrical.electrical; % +:right
n = foundation.electrical.electrical; % -:right
end
inputs
T = { 25.1, 'K' }; % T:left
G = { 1000, 'W/m^2' }; %G:left
end
variables
i = { 0, 'A' };
v = { 0, 'V' };
end
parameters
Ns = { 36, '1' }; % Number of cells
T_stc = { 298, 'K' }; % STC temperature, T
Voc_stc = { 21.2, 'V' }; % STC open circuit voltage, Voc
Isc_stc = { 1.93, 'A' }; % STC short circuit current, Isc
a = { 6.0e-4, 'K^-1' }; % Current temperature coefficient
b = { -3.97e-3, 'K^-1' } ; % Voltage temperature coefficient
N = { 1.7, '1' }; % Quality factor
G_stc = { 1000, 'W/m^2' }; % STC Irradiance, G
% Constants
k = { 1.38e-23, 'J/K' }; % Boltzman's constant, k
q = { 1.6e-19, 'c' }; % Charge of an electron, q
Eg = { 1.12, 'J' }; % Bandgap Voltage of Si, Eg
Runit = { 1, 'Ohm' };
end
function setup
across( v, p.v, n.v );
through( i, p.i, n.i );
% **** This is where error checking/messages go *****
% if R <= 0
% error( 'Resistance value must be greater than zero' );
% end
end
equations
let % *** Precursor calculations ***
Vt_stc = N*k*T_stc/q; % Thermal voltage
Io_stc = Isc_stc/(exp(Voc_stc/(Vt_stc))-1);% Saturation current
dVdI_Voc = -1/Ns;
Xv = Io_stc/(Vt_stc)*exp(Voc_stc/(Vt_stc));
Rs = -dVdI_Voc*Runit - 1/Xv; % Series resistance per cell
Iph = G/G_stc*Isc_stc*(1+a*(T-T_stc))
Vt = N*k*T/q;
Io = Io_stc*(T/T_stc)^(3/N)*exp(-q*Eg/(N*k)*(1/T+-1/(T_stc)));
in % Output
i == v/Vt_stc*Isc_stc;
end
end
end
Andy
Andy el 9 de Nov. de 2013
Hi,
The workaround you used for question 3, how accurate is it? Does it change the system's behavior in anyway?
Thanks, Andy

Iniciar sesión para comentar.

Respuestas (1)

Joel Van Sickel
Joel Van Sickel el 1 de Dic. de 2020
Answering 1: you can set visibility of values in simscape
This answer is part of a MATLAB Answers cleanup effort for unanswered questions that are outstanding.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by