I need help coding a custom block on Simscape
    4 次查看(过去 30 天)
  
       显示 更早的评论
    
Hi everyone, I'm struggling to code a custom block on Simscape. The purpose of this block is to convert hydraulique energy given by pressurized water to torque. This is what I have so far : 
component pelton_turbine
% Ce composant calcule le couple généré par l'eau sur la turbine.
% 🔹 Déclaration des ports
nodes
    H = foundation.hydraulic.hydraulic; % Port hydraulique
    R = foundation.mechanical.rotational.rotational; % Port mécanique rotatif
end
% 🔹 Déclaration des paramètres
parameters
    eta = {0.85, '1'};      % Rendement de la turbine
    rho = {1000, 'kg/m^3'}; % Densité de l'eau
    r = {0.5, 'm'};         % Rayon moyen de la roue
    g = {9.81, 'm/s^2'};    % Gravité
end
% 🔹 Déclaration des variables internes
variables
    Q = {0, 'm^3/s'};
    T = {0, 'N*m'};  % Couple généré
    H_head = {0, 'm'}; % Hauteur d'eau équivalente
end
equations
    % Débit hydraulique pris directement depuis le port H
    Q == H.q;
    % Calcul de la hauteur d'eau (pression convertie en mètre de colonne d'eau)
    H_head == H.p / (rho * g);
    % Calcul du couple généré par l'eau
    T == eta * rho * Q * H_head * r; 
    % Transmission du couple à l’axe mécanique
    R.t == T;
end
end
When I'm running it I have the error : Invalid reference to node balancing variable 'H.q'. Balancing variables may only
    be referenced from the 'branches' section. ChatGPT suggested to create a 'branch' section and put the Q inside but it doesn't work either. Do you have any suggestions for changes that could make that work ? 
Thanks in advance for the help, 
Nils  
0 个评论
回答(1 个)
  Yifeng Tang
    
 2025-3-26
        This compiled without an error
component pelton_turbine
% Ce composant calcule le couple généré par l'eau sur la turbine.
% 🔹 Déclaration des ports
nodes
    H = foundation.hydraulic.hydraulic; % Port hydraulique
    R = foundation.mechanical.rotational.rotational; % Port mécanique rotatif
end
% 🔹 Déclaration des paramètres
parameters
    eta = {0.85, '1'};      % Rendement de la turbine
    rho = {1000, 'kg/m^3'}; % Densité de l'eau
    r = {0.5, 'm'};         % Rayon moyen de la roue
    g = {9.81, 'm/s^2'};    % Gravité
end
% 🔹 Déclaration des variables internes
variables
    Q = {0, 'm^3/s'};
    T = {0, 'N*m'};  % Couple généré
    H_head = {0, 'm'}; % Hauteur d'eau équivalente
end
branches
    % Débit hydraulique pris directement depuis le port H
    Q : H.q -> *;
    % Transmission du couple à l’axe mécanique
    T:  R.t -> *;
end
equations
    % Calcul de la hauteur d'eau (pression convertie en mètre de colonne d'eau)
    H_head == H.p / (rho * g);
    % Calcul du couple généré par l'eau
    T == eta * rho * Q * sqrt(g*H_head) * r; 
end
end
Moving the equations in question to the branch section isn't hard.  The documentation on the syntax and sign convention is here.  You should check the equivalent equations very carefully to make sure the sign convention is consistent.
The equation for T needs some modification, too.  Otherwise the units won't match.  I suspect the heat term should have a sqrt, but you should verify.
0 个评论
另请参阅
类别
				在 Help Center 和 File Exchange 中查找有关 Foundation and Custom Domains 的更多信息
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

