Main Content

computeDynamics

R2026b

Class: simscape.multibody.CompiledMultibody
Namespace: simscape.multibody

Compute dynamics results of compiled multibody model

Since R2024a

Description

dynamicsResult = computeDynamics(cmb,state) computes the dynamics results of the compiled multibody model, cmb, with the state, state.

dynamicsResult = computeDynamics(cmb,state,uniformGravity) computes the dynamics results of the compiled multibody model with the uniform gravity, uniformGravity.

example

dynamicsResult = computeDynamics(cmb,state,jointActuation) computes the dynamics results of the compiled multibody model with the joint actuations, jointActuation.

example

dynamicsResult = computeDynamics(cmb,state,jointAcceleration) computes the dynamics results of the compiled multibody model with the joint accelerations, jointAcceleration.

dynamicsResult = computeDynamics(cmb,state,externalForceTorque) computes the dynamics results of the compiled multibody model with the external forces and torques, externalForceTorque.

dynamicsResult = computeDynamics(cmb,state,uniformGravity,jointActuation,jointAcceleration,externalForceTorque) computes the dynamics results of the compiled multibody model with the specified uniform gravity, joint actuations, joint accelerations, and applied external forces and torques. These input arguments are optional, and the computeDynamics method can accept one or more types of arguments in any order.

Input Arguments

expand all

Compiled multibody system represented by a simscape.multibody.CompiledMultibody object.

State of the compiled multibody system. Use a State object to query the positions and velocities of the specified joint component.

Uniform gravity, specified as a simscape.multibody.UniformGravity object. The UniformGravity object specifies the gravitational acceleration vector to apply uniformly to all bodies in the compiled multibody system.

You cannot specify a UniformGravity object if the compiled multibody system contains a Gravitational Field.

Joint primitive actuations, specified as a simscape.multibody.JointActuationDictionary object. The JointActuationDictionary object stores the forces and torque to apply to the joint primitives in the compiled multibody system.

Joint primitive accelerations, specified as a simscape.multibody.JointAccelerationDictionary object. The JointActuationDictionary object stores the accelerations to apply to the joint primitives in the compiled multibody system.

External forces and torques, specified as a simscape.multibody.ExternalForceTorqueDictionary object. The ExternalForceTorqueDictionary object stores the forces and torques to apply to the frame connectors in the compiled multibody system.

Output Arguments

expand all

Dynamics results of the multibody model, returned as a simscape.multibody.DynamicsResult object. You can use the DynamicsResult object to query the dynamics results, such as the accelerations of desired joint primitives.

Attributes

Accesspublic

To learn about attributes of methods, see Method Attributes.

Examples

expand all

The example shows how to compute the dynamics of a four-bar mechanism with a given joint state and actuation.

Open the model from the Creating a Four Bar Multibody Mechanism in MATLAB example. Create a simscape.multibody.Multibody object, fb, of the four-bar model for the specified links.

openExample("sm/CreateAFourBarMechanismInMATLABExample");
fb = fourBar(simscape.Value(1,"m"),simscape.Value(0.8,"m"),...
                      simscape.Value(0.4,"m"),simscape.Value(0.7,"m"));

Compile the four-bar model and specify the joint targets.

cfb = compile(fb);
op = simscape.op.OperatingPoint;
op("Bottom_Left_Joint/Rz/q") = simscape.op.Target(60,"deg","High");
op("Bottom_Right_Joint/Rz/q") = simscape.op.Target(90,"deg","Low");

Compute the current state of the model.

state = computeState(cfb,op);

Construct an actuation torque of 10 N*m for the revolute joint primitive and apply the torque to the bottom-right joint.

dict = simscape.multibody.JointActuationDictionary;
torque = simscape.multibody.RevolutePrimitiveActuationTorque(...
                     simscape.Value(10,"N*m"));
dict("Bottom_Right_Joint/Rz") = torque;

Solve the dynamics of the four-bar model with the given state and actuation. Then, query the accelerations of the other joints in the model.

dynamicsResult = computeDynamics(cfb,state,dict);
topRight = componentResults(cfb,"Top_Right_Joint",dynamicsResult);
topRight.Rz.Acceleration
ans =
   35.5178 (rad/s^2)
topLeft = componentResults(cfb,"Top_Left_Joint",dynamicsResult);
topLeft.Rz.Acceleration
ans =
   71.2999 (rad/s^2)
bottomLeft = componentResults(cfb,"Bottom_Left_Joint",dynamicsResult);
bottomLeft.Rz.Acceleration
ans =
   54.1937 (rad/s^2)

This example shows how to specify uniform gravity when computing the dynamics of a multibody system.

Open the model from the Creating a Four Bar Multibody Mechanism in MATLAB example. Create a simscape.multibody.Multibody object, fb, of the four-bar model for the specified links.

openExample("sm/CreateAFourBarMechanismInMATLABExample");
fb = fourBar(simscape.Value(12,"cm"),simscape.Value(10,"cm"),...
                      simscape.Value(5,"cm"),simscape.Value(8,"cm"));

Compile the four-bar model and compute the state from the specified joint targets.

cfb = compile(fb);
op = simscape.op.OperatingPoint;
op("Bottom_Left_Joint/Rz/q") = simscape.op.Target(60,"deg","High");
op("Bottom_Right_Joint/Rz/q") = simscape.op.Target(90,"deg","Low");
state = computeState(cfb,op);

Create a simscape.multibody.UniformGravity object with the gravitational acceleration directed along the negative y-axis.

ug = simscape.multibody.UniformGravity(simscape.Value([0 -9.81 0],"m/s^2"))
ug =
  UniformGravity with properties:

    Gravity: [0 -9.8100 0] (m/s^2)

Compute the dynamics of the four-bar model with the uniform gravity applied. Query the joint acceleration to verify that gravity produces a non-zero result.

dynamics = computeDynamics(cfb,state,ug);
jointResult = componentResults(cfb,"Bottom_Left_Joint",dynamics);
jointResult.Rz.Acceleration
ans =
  -70.7282 (rad/s^2)

Version History

Introduced in R2024a