[Multibody] Get body frame list from Matlab script

3 views (last 30 days)
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.

Answers (1)

Yifeng Tang
Yifeng Tang on 30 Apr 2021
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

Products


Release

R2020b

Community Treasure Hunt

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

Start Hunting!