How can I set a block parameter dynamically during simulation? (e.g. with workspace variable)
You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Show older comments
0 votes
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
Accepted Answer
Sebastian Castro
on 25 May 2015
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 Comments
Hansm
on 25 May 2015
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....
Sebastian Castro
on 25 May 2015
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?
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
Hansm
on 8 Jun 2015
Thank you for that hint!
Hansm
on 17 Jun 2015
Would it be possible to write a Simscape module with dynamic mass and use it in a SimMechanics model?
Sebastian Castro
on 17 Jun 2015
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.
tq yu
on 15 May 2019
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
More Answers (0)
Categories
Find more on Multibody Dynamics in Help Center and File Exchange
Products
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)