Main Content

simscape.multibody.Multibody Class

Namespace: simscape.multibody
Superclasses: simscape.multibody.Component

Specify structure of multibody system

Since R2022a

Description

Use an object of the simscape.multibody.Multibody class to construct a multibody system. A Multibody object is a hierarchical container that can have any type of component object, and each component object represents a part or a subsystem of the multibody system. See simscape.multibody.Component for more information about different component objects.

By default, a newly created Multibody object is empty. You can use the methods of the Multibody object to construct a multibody system, prepare the Multibody object for analyses, or create a corresponding Simulink® model. See the More About section for more information about the Multibody class.

The simscape.multibody.Multibody class is a handle class.

Class Attributes

Sealed
true
ConstructOnLoad
true
HandleCompatible
true
RestrictsSubclassing
true

For information on class attributes, see Class Attributes.

Creation

Description

mb = simscape.multibody.Multibody creates an empty simscape.multibody.Multibody object.

example

Properties

expand all

Names of the component objects at the top level of the simscape.multibody.Multibody object, returned as a string array.

Example: "Base_Bar"

Attributes:

GetAccess
public
SetAccess
Restricts access
NonCopyable
true
Transient
true

Gravitational acceleration in the multibody system, specified as a simscape.Value object that represents a 3-by-1 or 1-by-3 vector with a unit of linear acceleration. The elements of the vector specify the gravity in the x, y, and z directions of the world frame. In a hierarchical simscape.multibody.Multibody object, the Gravity property of the higher-level Multibody object overrides the Gravity property of its contained Multibody objects.

Attributes:

GetAccess
public
SetAccess
public
NonCopyable
true
Transient
true

Methods

expand all

Examples

collapse all

This example shows how to assemble instances of a modularly designed link into a double pendulum. This double pendulum moves in the x-y plane of the world frame.

To avoid typing the namespace name for the classes, you can use the import function.

import simscape.Value simscape.op.* simscape.multibody.*;

Construct a Double Pendulum

  • Create a simscape.multibody.Multibody object to construct the double pendulum. By default, a newly created Multibody object is empty.

doublePendulum = Multibody
doublePendulum = 
  Multibody:

  No connectors.

  No components.

  No connections.

  Multibody with properties:

     ComponentNames: [0x1 string]
            Gravity: [0 0 -9.8066] (m/s^2)
        DoVisualize: 1
    FrameConnectors: [0x1 string]

  • Create two links by using the custom function described in the Link Creation Function section. To add the links to the doublePendulum object, you can use the addComponent method. The upper link has a length of 12 cm and the red color. The lower link has a length of 8 cm and the blue color. The two links have rectangular shapes with the default density.

upperLength = Value(12,"cm");
lowerLength = Value(8,"cm");
addComponent(doublePendulum,"Upper_Link",link(upperLength,[1 0 0]));
addComponent(doublePendulum,"Lower_Link",link(lowerLength,[0 0 1]));
joint = RevoluteJoint;
addComponent(doublePendulum,"World_Upper_Joint",joint);
addComponent(doublePendulum,"Upper_Lower_Joint",joint);
  • Add the world frame to the doublePendulum object and connect the positive end of the upper link to the world frame via the revolute joint named World_Upper_Joint. To make the connection, you can use the connectVia function.

addComponent(doublePendulum,"World",WorldFrame);
connectVia(doublePendulum,"World_Upper_Joint","World/W","Upper_Link/pos_end");
  • Connect the positive end of the lower link to the negative end of the upper link via the revolute joint named Upper_Lower_Joint.

connectVia(doublePendulum,"Upper_Lower_Joint","Upper_Link/neg_end","Lower_Link/pos_end");
  • Reorient the gravity from negative z-direction to the negative y-direction because the double pendulum moves only on the x-y plane of the world frame.

doublePendulum.Gravity = circshift(doublePendulum.Gravity,-1);

To specify the initial position for the upper link, you can use the simscape.op.Target.

op = OperatingPoint;
op("World_Upper_Joint/Rz/q") = Target(60,"deg","High");

To see the components in the doublePendulum object, you can type:

doublePendulum
doublePendulum = 
  Multibody:

  No connectors.

  Components:

  Name                 Type          
  ___________________  ______________

  "Lower_Link"         Rigid Body    
  "Upper_Link"         Rigid Body    
  "Upper_Lower_Joint"  Revolute Joint
  "World"              World Frame   
  "World_Upper_Joint"  Revolute Joint

  Connections:

  Connector 1           Connector 2          
  ____________________  _____________________

  "Lower_Link/pos_end"  "Upper_Lower_Joint/F"
  "Upper_Link/neg_end"  "Upper_Lower_Joint/B"
  "Upper_Link/pos_end"  "World_Upper_Joint/F"
  "World/W"             "World_Upper_Joint/B"

  Multibody with properties:

     ComponentNames: [5x1 string]
            Gravity: [0 -9.8066 0] (m/s^2)
        DoVisualize: 1
    FrameConnectors: [0x1 string]

Link Creation Function

You can use this function to create a link with specific length and color. Frames at the ends of the link are always exposed as connectors for connections to joints. See more information about creating a link, see Simple Link.

function link = link(length,color)

    import simscape.Value simscape.multibody.*;

    link = RigidBody;
    offset = length/2;
    addFrame(link,"neg_end","reference",RigidTransform(StandardAxisTranslation(offset,Axis.NegX)));
    addFrame(link,"pos_end","reference",RigidTransform(StandardAxisTranslation(offset,Axis.PosX)));

    % Add component
    solid = Solid(GeneralExtrusion(roundedRect(length,Value(2,"cm")),Value(1,"cm")),...
                  UniformDensity,SimpleVisualProperties(color));
    addComponent(link,"Body","reference",solid);

    % Connectors
    addConnector(link,"neg_end");
    addConnector(link,"pos_end");

end

function xs = roundedRect(length,width)
% Return the cross section of a rectangle with rounded ends
    angles = (-90:10:+90)'*pi/180;
    semi = width/2*[cos(angles) sin(angles)]+repmat([length/2 0],size(angles));
    xs = [semi;-semi];
end

More About

expand all

Version History

Introduced in R2022a