Subclassing closed source Simscape components

2 次查看(过去 30 天)
I would like to define a custom engine, starting from Simscape's Generic Engine. For instance, how should one replicate the engine braking example using inheritance?
The conserving port F has only speed properties. So, how can I add the braking torque?
Using the code below, I get an error saying that: 't' is not defined in this scope.
component MyEngine < sdl.engines.generic_engine
parameters(Size = variable)
TorqueEMB = {[-100 -200], 'N*m'}; % Engine motoring torque
SpeedEMB = {[ 600 1200], 'rpm'}; % Engine motoring speed
end
intermediates
Temb = tablelookup(SpeedEMB, TorqueEMB, F.w - B.w,...
interpolation = linear, ...
extrapolation = nearest); % Engine motoring brake torque
end
equations
t == -Temb;
end
end

回答(1 个)

Steve Miller
Steve Miller 2022-10-10
The diagnostic you have received is telling you that the variable you have used is not defined. You need to define the torque relative to nodes in the block. Look at the source code for the Ideal Torque Source to see the definition there.
The torque defined in the Generic Engine block is "trq". You can see this from Simscape logging. I believe you want to add an additional torque, not redefine the existing "trq", so I would recommend completing the definition of "t" in your code above.
--Steve
  2 个评论
Geraldo Rebouças
Geraldo Rebouças 2022-10-20
Hi Steve,
Thanks for the input, and sorry for the long time to reply.
I want to redefine the existing torque "trq", so that one has full propulsion torque when throttle "Thr" is 1 and full engine braking torque when throttle is zero.
I contacted MW support on this issue and he (Nicholas Wong) oriented me to model what I want to achieve using blocks and then use the "subsystem2ssc" command to generate an .ssc file. It does not use subclassing concepts, but solves the problem.
Now, this question is just a curiosity matter, as it seems not necessary/useful to customize using the OO approach as it seems there is no difference in developing models using blocks or code.
Steve Miller
Steve Miller 2022-10-20
Hi Geraldo - some engineers prefer to work in a schematic, some prefer to write equations in textual form. Using subsystem2ssc(), you can have both. The resulting set of equations will be the same once Simscape manipulates the equations, so whichever process you prefer, you can use.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Engines & Motors 的更多信息

产品


版本

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by