Main Content

simscape.multibody.RigidBody class

Package: simscape.multibody
Superclasses: simscape.multibody.Component

Construct rigid body

Description

Use an object of the simscape.multibody.RigidBody class to construct a rigid body. A RigidBody object is a hierarchical container and has a tree structure composed of rigidly connected frames and component objects.

By default, a newly created RigidBody object contains only one frame called reference. The reference frame serves as the root of the tree structure. You must explicitly add frames or component objects to a RigidBody object, and the new frame or component object must be rigidly connected to the tree structure of the RigidBody object. Note that the name of every frame or component object must be unique among the frames and objects at the same hierarchical level of the RigidBody object.

In a larger system, to connect to other frames or component objects, a RigidBody object must have at least one connector. By default, a newly created RigidBody object has zero connectors, and adding frames or component objects to a RigidBody object does not automatically create connectors. To add a connector, use the addConnector method. Note that you can add connectors only to the frames at the top level of the RigidBody object, and each frame can only have one connector.

See More About section for more information about the RigidBody class.

The simscape.multibody.RigidBody 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

rb = simscape.multibody.RigidBody creates a simscape.multibody.RigidBody object.

Properties

expand all

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

Example: "sphere"

Attributes:

GetAccess
public
SetAccess
Restricts access
NonCopyable
true
Transient
true

Names of the frames at the top level of a simscape.multibody.RigidBody object, returned as a string array.

Example: "reference"

Attributes:

GetAccess
public
SetAccess
Restricts access
NonCopyable
true
Transient
true

Methods

expand all

Examples

collapse all

This example shows how to add a frame, solid, and sub-rigid body to a rigid body.

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

    import simscape.multibody.*;
  2. Create a simscape.multibody.RigidBody object named rb. The rb object has one frame called reference and no connectors.

    rb = RigidBody
    rb = 
    
      RigidBody:
    
      No connectors.
    
      Frames:
    
      Frame        Parent  Source  Connector?
      ___________  ______  ______  __________
    
      "reference"  --      --      No        
    
      No components.
    
      RigidBody with properties:
    
             FrameNames: "reference"
         ComponentNames: [0×1 string]
            DoVisualize: 1
        FrameConnectors: [0×1 string]
  3. To add frames to the reference frame, create and add frames to a rigid transform object.

    First, create a simscape.multibody.RigidTransform object named rt. The rt object represents a translation along the positive y-axis of the base frame. The distance of the translation is 50 cm.

    rt = RigidTransform(StandardAxisTranslation(simscape.Value(50,"cm"),Axis.PosY));

    Then, use the addFrame method to add two frames, fa and fb, to the reference frame through the rt object.

    addFrame(rb,"fa","reference",rt);
    addFrame(rb,"fb","reference",rt);

    You can view the tree structure of the rb object by using the plotStructure method.

    plotStructure(rb);

    Frame Hierarchy of the Rigid Body Object

    The green vertexes represent the frames, and the green lines represent the rigid transforms between the frames. The arrows indicate the orientations of the rigid transforms. By default, a rigid transform maps vectors from the new frame to the parent frame.

  4. Add a simscape.multibody.Solid object to the rb object.

    First, create a simscape.multibody.Solid object called sphere. The sphere object represents a solid with a spherical shape. The sphere has a radius of 50 cm.

    sphere = Solid(Sphere(simscape.Value(50,"cm")));

    Then, use the addComponent method to add the sphere object to the fa frame. By default, a Solid object has one connector that you can connect to the rb object.

    addComponent(rb,"sphere","fa",sphere);

    Use the plotStructure method to show the tree structure of the rb object in a new figure.

    figure
    plotStructure(rb);

    Frame hierarchy with Solid

    The blue vertex represents the sphere object, and the pink link indicates the connection between the fa frame and the sphere object.

  5. Add a RigidBody object to the rb object as a subbody.

    Create an empty RigidBody object called subrb and add two new frames, f1 and f2, to the subrb object through the rt object.

    subrb = RigidBody;
    addFrame(subrb,"f1","reference",rt);
    addFrame(subrb,"f2","reference",rt);

    Because the subrb object has zero connectors, you must add at least one connector to the object. Use the addConnector method to add a connector to the f1 frame of the subrb object. The connector and frame have the same name.

    addConnector(subrb,"f1");

    Use the addComponent method to attach the subrb object to the fb frame through the f1 connector.

    addComponent(rb,"subrb","fb",subrb,"f1");

    Use the plotStructure method to show the tree structure of the rb object in a new figure.

    figure
    plotStructure(rb);

    Frame Hierarchy with a Subbody

    The red vertex represents the subrb object, and the pink line indicates the connection between the fb frame and the f1 connector of the subrb object.

More About

expand all

Version History

Introduced in R2022a