I need help coding a custom block on Simscape
7 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Antworten (1)
Yifeng Tang
am 26 Mär. 2025
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 Kommentare
Siehe auch
Kategorien
Mehr zu Foundation and Custom Domains finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!