MV-1060: Build a Pendulum Model Using MDL Statements
In this tutorial, you will learn how to create a pendulum model using Model Definition Language (MDL), run a dynamic simulation of the model, plot the rotation of the pendulum and view the animation.
- You can open and edit in any text editor.
- It assists with model debugging.
- You can use conditional statements "if" for custom modeling requirements.
- You can build modular and reusable models.
- You can parameterize the models.
- You can use modeling entities which are not available through GUI (for example, CommandSets).
- Section 1: Entities in MDL
- A modeling entity is saved to MDL in the form of MDL statements. All MDL
statements begin with an asterisk (*). There are two types of entities:
- General Entities
- Definition Based Entities
- General Entities
-
- Have one statement to define the entity. They may have one or more statements to set their properties.
- Some examples include points, bodies, joints, etc.
- Each general entity has certain properties consistent with its type. For example, a point has the properties x-coordinate, y-coordinate, z-coordinate, label, state, and varname (variable name).
- Definition Based Entities
-
- Are defined through a block statement, called definition, and its instance is created in a model by an instantiation statement.
- The block generally begins with a *Define() statement and end with a *EndDefine() statement.
- The entity (or block) is comprised of a series of other MDL entities or members.
- These entities are reusable. Once defined, the same entity-definition may be instantiated several times within the same model or different model files.
- Section 2: Properties of Entities
-
- Each entity has variable, label, and other properties associated with it.
- Each entity should have a unique variable name.
- Following is the recommended convention for variable names which allows the user to identify the modeling entity during debugging. You are not restricted to this nomenclature, however you are encouraged to adopt it.
- Section 3: Global Variables
- MotionView comes with Global Variables, by
default, which are available for use anywhere in the model. These variables
are case sensitive. The table below lists some commonly used keywords and what they represent:
Table 3. Common keywords in MotionView B_Ground
Ground body P_Global_Origin
Global Origin V_Global_X, V_Global_Y, V_Global_Z
Vectors along the global XYZ axes Global_Frame
Global reference marker MODEL
Reference to the top level system of the model. - Section 4: MDL Statement Classification
-
- Topology Statements
- These are statements that define an entity and establish
topological relation between one entity and the other. For
example,
*Body(b_body, “Body”, p_cg)
. In this example, the *Body statement defines a body having its CG at pointp_cg
. Through this statement the body (b_body
) is topologically connected to pointp_cg
. - Property or Set Statements
- These statements assign properties to the entities created by topological entities. For example, *SetBody() is a property statement that assign mass and inertia properties to a body defined using *Body(). Since most of the property statements begin with “*Set”, they are generally referred as Set statements.
- Definition and Data
- Building upon the concept of a definition block, these
terminologies are used specifically with regard to container
entities such as Systems, Assembly, and Analysis.The block of statements when contained within a *Define() block are termed as a Definition. The statements within the block may include:
- Topology statements that define entities.
- Set statements that assign properties. These Set statements within a definition block are called "Default Sets", as they are considered as default values for the entities in the definition.
Any statements or block that resides outside the context of *Define() block are termed as Data. These include:- Set statements within a *BeginContext() block that relate to entities within a system, assembly, or analysis definition.
- Some of the *Begin statements, such as *BeginAssemblySelection and *BeginAnalysis.
- Section 5: MDL Model File Overview
-
- MDL model file is an ASCII file; it can be edited using any text editor.
- All statements in a model are contained within a *BeginMDL() - *EndMDL() block.
- The syntax of the MDL statement is an asterisk (*) followed by a valid statement with its arguments defined.
- Statements without a leading asterisk (*) are considered comments. In this tutorial, comment statements are preceded by // to improve readability. The comments are not read in by the MotionView graphical user interface and are removed if the model MDL is saved back or saved to a different file.
MDL accepts statements in any order, with a few exceptions.
To help you learn this language, the code in the tutorial examples will follow this structure://comments about the MDL file *BeginMDL(argument list) //Topology section *Point… *Body… *System(…) // definitions sub-section *DefineSystem(..)… .. .*EndDefine() //Property of entities directly in *BeginMDL()//Property section for entities within Systems and analysis *BeginContext() .. .. *EndContext() . *EndMDL
Create an MDL Model File
In this step you will create an MDL model file for the pendulum model.
Create Entity Declarations
Here, you will create the entity declarations necessary for the problem.
Load and Run the MDL Model File
In this step, you will run the MDL file you created in the step: Create Entity Declarations.
Animate and Plot the Results
Now you will animate and plot the results of the pendulum MDL model run.