How can I set a block parameter dynamically during simulation? (e.g. with workspace variable)

Hi there! I have encountered a problem while using Simmechanics: I have a masked block with a single parameter "height". I want this parameter to be changed dynamically during simulation. This means, instead of writing a value in the parameters field, I want to use a workspace variable. I have tried using a workspace variable, but the block reads the variable only on simulation start and then never again. How can I solve this? Thank you very much, Hans

 Respuesta aceptada

What does that "height" variable reference? If it's inside SimMechanics blocks, then that value cannot be changed mid-simulation. It's only if your variable is on a Simulink block (Constant, Gain, etc.) that this will work.
For example,
  • If "height" can be fed in using a Simulink Constant block that is connected to a motion-actuated Joint block in SimMechanics, then this approach would work.
  • If "height" is a parameter in a Solid or Rigid Transform block, then you will not be able to change these values mid-simulation.
Also, if your model has the possibility for a tunable "height" variable, you still need to pause the simulation, update the diagram, and then resume the simulation for the changes to take effect.
- Sebastian

8 comentarios

I'm modelling a fuel tank. The tank is modelled as a solid. Its shape is defined by a function, which calculates a 2d shape, which is later rotated to create a 3d object. Here, "height", is the variable which defines the filling level of the tank. During the simulation, the filling level changes. This is what I want to model. The variable is used as a parameter in the simmechanics block "cross section" entry. If I understand you correctly, only simulink blocks can have "dynamic" parameters, but simmechanics blocks not? This is weird, because I've already created a simmechanics block with dynamic mass/inertia and it worked. But in this new case, with a dynamic geometry, it seems to not work....
Are you using SimMechanics First Generation blocks? In this one you can specify variable mass/inertia.
Also, if you're modeling the filling of a tank, you could use variable mass/inertia to take care of those dynamics, right?
Hansm
Hansm el 26 de Mayo de 2015
Editada: Hansm el 26 de Mayo de 2015
I'm using SimMechanics Second generation. Is it possible to mix first and second generation?
After your answer I re-evaluated my model with the dynamic mass. I've found an error, which fooled me into thinking the mass has changed. :(
So, is it true that the parameters of a SimMechanics block cannot be changed during simulation? If this is true, I have one final question: is there any way to create a block with a variable mass in second generation SimMechanics?
I wouldn't recommend mixing first and second generation -- all the masses/inertias/forces/moments wouldn't necessarily translate if you try to communicate between two different types of blocks using regular Simulink signals.
And that's right, variable mass/inertia is one of the 2 features that (as of R2015a) is available in First Generation but not in Second Generation. The other is the point-on-curve constraint.
One way that you can still establish a variable-mass situation is by using an External Force + Torque block to apply a variable force to your system. For example, if you're simply modeling the vertical (up-down) dynamics of a tank filling up, you can take advantage of this assumption and apply a variable downward force equal to the weight of the water in the tank. That is,
Force = Density*Area*Height
where Height could be a time-varying signal that affects that downward force acting on your mechanical system.
If you need to worry about translation and rotation in other directions, I suppose you could try add more forces and torques about other axes using that same External Force/Torque block.
- Sebastian
Thank you for that hint!
Would it be possible to write a Simscape module with dynamic mass and use it in a SimMechanics model?
I wouldn't recommend it. If you use a mass on the Simscape side, it will only affect that joint -- however, all the masses/inertias for all dimensions on the SimMechanics side will not consider this mass, thereby leading to potential inconsistencies.
Hi , Sebastian ,
could you please give me some advice on hou to update the datas from workspace to simulink ,while the the simulation in on ? i have datas from sensors varing with time ,now i want to send them to simulink model to get a 'real-time' simulation .
Many thanks from china

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Productos

Preguntada:

el 23 de Mayo de 2015

Comentada:

el 15 de Mayo de 2019

Community Treasure Hunt

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

Start Hunting!

Translated by