MATLAB Answers

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

9 views (last 30 days)
Swagatam Sengupta
Swagatam Sengupta on 9 Jul 2020
Answered: Juan Sagarduy on 5 Dec 2020
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

  0 Comments

Sign in to comment.

Answers (1)

Juan Sagarduy
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

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!

Translated by