Simscape custom model: Invalid use of the operand '+'
17 views (last 30 days)
Show older comments
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 Comments
Crystal Blackwell
on 25 Mar 2021
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
on 26 Mar 2021
Of course the other option is to remove your units from unnecessary places.
Answers (1)
Juan Sagarduy
on 5 Dec 2020
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
0 Comments
See Also
Categories
Find more on Applications in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!