Filter löschen
Filter löschen

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

15 Ansichten (letzte 30 Tage)
Swagatam Sengupta
Swagatam Sengupta am 9 Jul. 2020
Kommentiert: Crystal Blackwell am 26 Mär. 2021
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.
A = foundation.mechanical.rotational.rotational; % A:left
P = foundation.mechanical.translational.translational; % P:right
% 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
% Derived parameters
if or==2
orient = -1; % Drives in negative direction
orient = 1; % Drives in positive direction
t = { 0, 'N*m' }; % Torque
f = { 0, 'N' }; % Force
x = {value = { 0, 'm' }, priority = priority.high}; %Displacement
t : A.t -> *;
f : P.f -> *;
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;
  2 Kommentare
Crystal Blackwell
Crystal Blackwell am 25 Mär. 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
Crystal Blackwell am 26 Mär. 2021
Of course the other option is to remove your units from unnecessary places.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Juan Sagarduy
Juan Sagarduy am 5 Dez. 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


Mehr zu Brakes and Detents finden Sie in Help Center und File Exchange




Community Treasure Hunt

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

Start Hunting!

Translated by