How can I find the center of gravity of a machine in SimMechanics 3.1.1 (R2009b)?
2 views (last 30 days)
Show older comments
MathWorks Support Team
on 5 Nov 2012
Edited: MathWorks Support Team
on 4 Apr 2019
I have multiple bodies at various locations in my SimMechanics model and I wish to know what the center of gravity is of the entire machine defined by the bodies. In other words, I want to know the World-reference CG location of all of the bodies multiplied by their masses. How can I do this?
Accepted Answer
MathWorks Support Team
on 4 Apr 2019
Edited: MathWorks Support Team
on 4 Apr 2019
The ability to do detect the center of gravity of a machine automatically is not availalble in SimMechanics 3.2 (R2010a_pre). You can use the following approach as a workaround:
You can define all bodies with their CG defined in the World Reference plain and then write a MATLAB script to manually perform this computation. This would use the FIND_SYSTEM and GET_PARAM commands to query this information as such;
% Get the Body blocks in the current model.
h=find_system(gcs,'ClassName','Body')
% Extract a vector of mass values.
masses=str2num(cell2mat(get_param(h,'Mass')))
% Extract a vector of CG locations.
for i=1:length(h)
CGstring=get_param(h{i},'CG')
p=textscan(CGstring,'%s','delimiter','$')
CGs(i,:)=str2num(p{1}{3})
end
% Take the weighted average of the CGs with the mass values.
machineCG = [0 0 0];
for i = 1:length(h)
machineCG = machineCG + masses(i)*CGs(i,:);
end
machineCG = machineCG/sum(masses);
In the case where all of the body CGs are not necessarily defined in world coordinates you may use the Body Sensor block to do this conversion for you but this requires hooking this block up manually to every body block in your model. Connect the body selector to the CG of the body block and select World Coordinate system for the output of position and send this information to workspace or wherever you wish to compute the CG.
0 Comments
More Answers (0)
See Also
Categories
Find more on Multibody Dynamics in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!