Simscape custom model: Invalid use of the operand '+'

조회 수: 19 (최근 30일)
Swagatam Sengupta
Swagatam Sengupta 2020년 7월 9일
댓글: Crystal Blackwell 2021년 3월 26일
Hi,
I have made a custom simscape model similar to the wheel axle mechanism but with more paramters to calculate the dynamic torque and import the ssc model using the simscape component. Below mentioned is the model code
A compilation error comes up saying that : "Invalid use of +. At least one of the operands must be scalar or the operands must be the same size. The units of the operands must be commensurate"
So to avoid this, i tried indexing (for eg: R{1},x{1}) but then there is a new error "Illegal use of indexing". As there is a "acos" function the input should be a constant. How do i get around this issue?
component mounting_body
% Mounting Body
% The block represents the saddle and hydraulic cylinder mechanism as an ideal converter
% between mechanical rotational and mechanical translational motions. The
% mechanism has two connections: port A corresponds to the saddle pivot point and is a
% mechanical rotational conserving port; port P corresponds to the
%Cylinder piston rod and is a mechanical translational conserving port.
%
% The The block positive directions are from
% A to the reference point and from reference point to P. The saddle positive
% rotation causes the wheel periphery to move in positive or negative direction,
% depending on the "Mechanism orientation" parameter setting.
% Copyright 2005-2016 The MathWorks, Inc.
nodes
A = foundation.mechanical.rotational.rotational; % A:left
P = foundation.mechanical.translational.translational; % P:right
end
parameters
% Mask parameter visibilities are customized by a second file that is
% not available to users. If you copy and publish this Simscape(TM) file
% inside your own custom library, then the drop-down menu for mechanism
% orientation will be lost.
R = { 0.05, 'm' }; % Saddle radius
or = { 1, '1' }; % Mechanism orientation
c_rod = { 0.800, 'm' };% Connecting rod length
l = { 0.650, 'm' };% Distance piston fixed point to saddle centre
end
% Derived parameters
if or==2
parameters(Access=private)
orient = -1; % Drives in negative direction
end
else
parameters(Access=private)
orient = 1; % Drives in positive direction
end
end
variables
t = { 0, 'N*m' }; % Torque
f = { 0, 'N' }; % Force
x = {value = { 0, 'm' }, priority = priority.high}; %Displacement
end
branches
t : A.t -> *;
f : P.f -> *;
end
equations
assert(R>0)
x.der == P.v;
t + orient*sin(acos(((R^2+(x+c_rod)^2-l^2)/(2*(x+c_rod)*R))))*f == 0;
P.v - orient*R*A.w == 0;
end
end
  댓글 수: 2
Crystal Blackwell
Crystal Blackwell 2021년 3월 25일
For issues with units, for example, calculations with polynomials etc try using the value function to get the value of the quantity without the units, perform the math and reassign the units afterwards using a variable = { result of calc, reassigned unit} statement. If your calculation is slightly different (mine was a polynomial) try using a variation of this method.
Hope this helps..
Crystal Blackwell
Crystal Blackwell 2021년 3월 26일
Of course the other option is to remove your units from unnecessary places.

댓글을 달려면 로그인하십시오.

답변 (1개)

Juan Sagarduy
Juan Sagarduy 2020년 12월 5일
Hi there
It looks like the syntax in that line has a problem. Furthermore, all Simscape keywords are not in blue. This indicates that you have not saved the file as mounting_body.ssc This is required to compile the library.
Regards Juan

카테고리

Help CenterFile Exchange에서 Applications에 대해 자세히 알아보기

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by