Custom Simscape component: Confustion with language and scripting structure
Show older comments
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 Comments
Adam Clark
on 25 Nov 2012
Andy
on 9 Nov 2013
Hi,
The workaround you used for question 3, how accurate is it? Does it change the system's behavior in anyway?
Thanks, Andy
Answers (1)
Joel Van Sickel
on 1 Dec 2020
0 votes
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.
Categories
Find more on Simscape Electrical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!