Hi 松,
I understand that you are trying to compute the velocity of a block inside MATLAB Function and then use that value to directly drive the motion of a solid in your Simscape Multibody model, so that the animation in Mechanics Explorer follows your calculated trajectory rather than being determined by physics alone.
To help with this, I have attached an updated version testmodel_2.slx that demonstrates the setup you described.
In the updated model, the following changes were made:
- For the Prismatic Joint was configured so that Actuation → Force is set to Automatically Computed, and the Actuation → Motion setting was changed to Provided by Input.
- For the Simulink-PS Converter, the Input Handling → Filtering and derivatives option was set to Filter input, derivatives calculated, and the Input Handling → Input filtering order was set to Second-order filtering.
- Added a Clock block feeding the MATLAB Function (this is simply a time input to the function; you can change or replace it according to your needs).
- Inserted a Simulink-PS Converter after the MATLAB Function.
With these changes, the Brick Solid now moves along the prismatic axis according to the velocity computed in the MATLAB Function. You can replace the function logic with your own calculation to reflect the motion you want.
Helpful documentation you can refer to:
I hope you find this useful.