MATLAB Answers

[Multibody] Get body frame list from Matlab script

조회 수: 1(최근 30일)
Ben Rancici
Ben Rancici 2021년 3월 15일
답변: Yifeng Tang 2021년 4월 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

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by