Contenuto principale

simscape.multibody.compileBlockDiagram

R2026b

Generate compiled multibody object from Simulink model

Since R2026b

    Description

    cmb = simscape.multibody.compileBlockDiagram(modelName) compiles the Simulink® model specified by modelName and generates a simscape.multibody.CompiledMultibody object. You can use the CompiledMultibody object to compute the states and dynamics of the multibody system using the Simscape™ Multibody™ MATLAB classes. You can then query various physical quantities such as joint primitive positions, velocities, and accelerations, and constraint forces and torques. The model must be loaded into memory and contain a Simscape Multibody network.

    example

    Examples

    collapse all

    This example shows how to generate a CompiledMultibody object from a Simulink model and use it to compute dynamics.

    Open the four-bar Simulink model and compile it to obtain a CompiledMultibody object.

    import simscape.Value simscape.op.* simscape.multibody.*
    openExample("sm/FourBarExample");
    modelName = "FourBar";
    load_system(modelName);
    cmb = simscape.multibody.compileBlockDiagram(modelName);

    Create an operating point to specify the joint primitive position and velocity targets and compute the state of the multibody system.

    jointState = OperatingPoint;
    jointState("Base-Crank Revolute/Rz/q") = Target(60, "deg", "High");
    jointState("Base-Rocker Revolute/Rz/q") = Target(90, "deg", "Low");
    jointState("Base-Crank Revolute/Rz/w") = Target(2.5, "rev/s", "High");
    state = computeState(cmb, jointState);

    Apply a torque to the bottom-right joint and compute the dynamics of the multibody system. Then, query the acceleration of another joint primitive in the mechanism.

    dict = JointActuationDictionary;
    dict("Base-Rocker Revolute/Rz") = RevolutePrimitiveActuationTorque(Value(10,"N*m"));
    dynamicsResult = computeDynamics(cmb, state, dict);
    results = componentResults(cmb, "Connector-Rocker Revolute", dynamicsResult);
    accel_top_right = results.Rz.Acceleration
    accel_top_right =
       1.3271e+04 (rad/s^2)

    Input Arguments

    collapse all

    Name of a Simulink model that contains a Simscape Multibody network, specified as a string scalar or character vector. The model must be loaded into memory before calling this function. Do not include the .slx file extension in the model name.

    The model must contain exactly one Simscape Multibody network. If the model contains multiple independent multibody networks, the function throws an error.

    Data Types: char | string

    Output Arguments

    collapse all

    Compiled multibody system, returned as a simscape.multibody.CompiledMultibody object. You can use the CompiledMultibody object to compute the states and dynamics of the multibody system. You can then query various physical quantities such as joint primitive positions, velocities, and accelerations, and constraint forces and torques.

    More About

    collapse all

    Version History

    Introduced in R2026b