How can I feed a vector Simulink signal into my Simscape model?

I have a Simscape model that simulates a simple mass-spring damper system, from the Mass-Spring-Damper with Controller example, linked below:
I replaced the PID controller with a constant block for the value of the 'Ideal Force Source' and a scope to view the model's output. I would like to be able to compare different input signals sent to the 'Ideal Force Source' via a vector signal defined in the constant block. However, when I tried to change the scalar value in the constant block to a vector, I got the below error messages:
Error in port widths or dimensions. 'Output Port 1' of 'simple_vector/Constant' is a one dimensional vector with 4 elements.
Component:Simulink | Category:Model error
Error in port widths or dimensions. 'Input Port 1' of 'simple_vector/Simulink-PS Converter' is a one dimensional vector with 1 elements.
Component:Simulink | Category:Model error
Attached is my model, 'simple_vector.slx'.
How can I use a vector signal as the input to a Simscape model?

 Risposta accettata

Explanation of error:

This error is fundamentally caused by the fact while most Simulink blocks support vector (and even matrix) signals, most Simscape blocks do not support these types of signals. As such, the error you receive in the model is when the Simulink vector signal is first converted into a Simscape Physical Signal. Please refer to the documentation page for Basic Principles of Modeling Physical Networks  for further information on Physical Signals, linked below:

Workaround:

As a workaround, in order to run your model, you will need to pass each value of the vector individually to the Simscape model. To easily do this without creating a new subsystem, use a 'For Each Subsystem' block to run the Simscape model for each element of the vector. Note: This will only work if 'Log simulation data' is set to 'None' for Simscape. (Model config > Simscape > Data Logging > Log simulation data). 
The reference page for the For Each Subsystem block can be found here:
Attached is a modified version of your model,'simple_vector_for_each.slx' which uses the 'For Each Subsystem' block.

Più risposte (0)

Prodotti

Release

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by