State Space Representation of a Custom Simscape Component
11 ビュー (過去 30 日間)
古いコメントを表示
I am trying to create a custom Simscape component whose differential algebraic equation is put into a state space representation.
When I ssc_build the library, I get the following error.
>> ssc_build optHydro
Generating Simulink library 'optHydro_lib' in the current directory 's:\atG_Tasks\Wave_to_Wave_Tuning\JE101 Hydrodynamic Library for Simscape' ...
Failed to generate 'optHydro_lib'
Caused by:
Error using optHydro.jespring>setup (line 43)
Provided units 'm/s' and 'm' are not commensurate.
for the custom component file jespring.ssc
component jespring
% Translational Springy
% The block represents an ideal mechanical linear spring mass damper system
%
% Connections R and C are mechanical translational conserving ports.
% The block positive direction is from port R to port C. This means that
% the force is positive if it acts in the direction from R to C.
% Copyright 2005-2008 The MathWorks, Inc.
nodes
R=foundation.mechanical.translational.translational; %r:top
C=foundation.mechanical.translational.translational; %c:bottom
end
variables
f = { 0, 'N'}; %force through
v = { 0, 'm/s'}; %velocity across
x = { 0, 'm'}; %position across
end
parameters
spr_rate = { 1000, 'N/m' }; % Spring rate
mass = { 1, 'kg' }; % Mass
damper = {20, 'N/(m/s)' }; % Damping
init_vel = { 0, 'm/s' }; % Initial velocity
init_def = { 0, 'm' }; % Initial deformation
end
function setup
if spr_rate <= 0
pm_error('simscape:GreaterThanZero','Spring rate' )
end
if mass <= 0
pm_error('simscape:GreaterThanZero','Mass' )
end
if damper <= 0
pm_error('simscape:GreaterThanZero','Damping' )
end
across(v,R.v,C.v); %velocity variable from node r to c
through(f,R.f,C.f); %force variable from node r to c
% x = init_def;
% v= init_vel;
z=[init_def; init_vel];
A=[0 1; -spr_rate/mass -damper/mass];
B=[0;1];
C=[0 1];
end
equations
z.der == A*z+B*f;
v == C*z;
end
end
As I understand the error, Simscape doesn't like the fact that the state vector, z includes physical variables with different units. Can anyone please suggest a way around this limitation?
0 件のコメント
回答 (1 件)
Guy Rouleau
2012 年 5 月 15 日
Interesting... I never tried combining states with different units into a vector.
Since your example is a simple linear spring+damper, it is easy to rearrange the equations. Something like the following should do the job:
v.der == k*x/m + c*v/m;
x.der == v;
I am curious... is it a test for something more complex you are planning to implement?
参考
カテゴリ
Help Center および File Exchange で Creating Custom Components and Libraries についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!