State Space Representation of a Custom Simscape Component

11 ビュー (過去 30 日間)
James Eder
James Eder 2012 年 5 月 15 日
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?

回答 (1 件)

Guy Rouleau
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?
  1 件のコメント
James Eder
James Eder 2012 年 5 月 16 日
Thanks for replying Guy.
Yes, this is a test case for a more complicated case. Eventually, I would like to pass the block the A,B,C matrices as parameters with an arbitrary order.
I may have made some progress on trying to get rid of the unit discrepancy, by multiplying rows and columns of the state space and A,B,C matrices by other united parameters.
However, all is not well yet. Right now, I am still getting 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>equations (line 53)
Function 'A_mat' is not supported.
when I ssc_build the following revised code:
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
z= {0,'m'}; %internal state
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
second={1,'s'};
kilogram={1,'kg'};
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_state=[init_def; init_vel*second];
A_mat=[0/second 1/second;-spr_rate*second/mass -damper/mass];
B_mat=[0*second/kilogram; second/mass];
C_mat=[0/second 1/second];
end
equations
z.der==A_mat*z + B_mat*f;
v==C_mat*z_state;
end
end
Do you have any suggestions?
One fall back plan I have is to just "hard code" different versions of this component to reflect the different orders of the system. It won't be that clean, but I think I can make it work.
Thanks again for your interest.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeCreating Custom Components and Libraries についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by