[Multibody] Get body frame list from Matlab script

1 次查看(过去 30 天)
Since it's not possible to display lines directly in mechanics explorer, I'm plotting speeds on a separate 2D plot for several points of a vehicle. These points correspond to the origins of all the frames defined for a solid block.
How can I access the list of these frames from a Matlab script and retrieve their origins?
By accessing this list, there will be no need to redefine all the 3D coordinates within the script at each change or add to the frame list.

回答(1 个)

Yifeng Tang
Yifeng Tang 2021-4-30
You'll probably need to attach a Transform Sensor to each solid so you can get all kinds of kinematic information of the solid. Some script snippets that may be useful:
% find all solid blocks
solids=find_system(modelA,'LookUnderMasks','all','FollowLinks','on', 'RegExp', 'on', 'ReferenceBlock','sm_lib/Body Elements/Brick Solid');
solids=[solids; find_system(modelA,'LookUnderMasks','all','FollowLinks','on', 'RegExp', 'on', 'ReferenceBlock','sm_lib/Body Elements/Cylindrical Solid')];
solids=[solids; find_system(modelA,'LookUnderMasks','all','FollowLinks','on', 'RegExp', 'on', 'ReferenceBlock','sm_lib/Body Elements/Ellipsoidal Solid')];
solids=[solids; find_system(modelA,'LookUnderMasks','all','FollowLinks','on', 'RegExp', 'on', 'ReferenceBlock','sm_lib/Body Elements/Extruded Solid')];
solids=[solids; find_system(modelA,'LookUnderMasks','all','FollowLinks','on', 'RegExp', 'on', 'ReferenceBlock','sm_lib/Body Elements/File Solid')];
solids=[solids; find_system(modelA,'LookUnderMasks','all','FollowLinks','on', 'RegExp', 'on', 'ReferenceBlock','sm_lib/Body Elements/Revolved Solid')];
solids=[solids; find_system(modelA,'LookUnderMasks','all','FollowLinks','on', 'RegExp', 'on', 'ReferenceBlock','sm_lib/Body Elements/Spherical Solid')];
To add blocks (e.g. sensor) programmatically: add_block (https://www.mathworks.com/help/simulink/slref/add_block.html)
To connect blocks: add_line (https://www.mathworks.com/help/simulink/slref/add_line.html)
You of course will also need scripts to retrieve the sensor readings

类别

Help CenterFile Exchange 中查找有关 Bodies 的更多信息

产品


版本

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by