Creating a Human model from scratch

Creating a Human model from scratch#

The following tutorial teaches you how to construct an AnyBody model, when starting with a blank AnyScript file. When you work with more complex models, you will realize the given code structure is actually quite universal.

STEP 1

Open a new AnyScript file (Ctrl + I) and type in the Main declaration shown below. This file now becomes the main model file, and all its contents (e.g, model objects, simulation objects) should be typed between the two curly braces.

Main =
{

};

STEP 2

Link a libdef.any file to specify the AMMR directories that you wish to import the human model from. If instructions for installing the Demo AMMR in the previous chapter were exactly followed, the file path typed below should work. Otherwise, make the necessary changes.

#include "<ANYBODY_PATH_MYFILES>/AnyBody.8.0.x/AMMR.v3.0.0-Demo/libdef.any"
Main =
{

};

STEP 3

Create an empty Model folder to hold your model components, and an AnyBodyStudy object (named Study) which can run Kinematics and Inverse Dynamics simulations on your model.

#include "<ANYBODY_PATH_MYFILES>/AnyBody.8.0.x/AMMR.v3.0.0-Demo/libdef.any"
Main =
{

    AnyFolder Model =
    {

    };


    AnyBodyStudy Study =
    {
        Gravity = {0,-9.81,1}; // Gravity Vector
        tStart = 0; // Start time
        tEnd = 1; // End time
    };
};

STEP 4

The next statement will create a reference to the Model folder within Study, thus instructing the simulation to only consider model objects (i.e. segments, forces, motion drivers etc.) contained within Model.

Note

You can create any number of such references. It allows mixing and matching of model components in simulations. For example, if three separate AnyFolder objects contained models of a human, chair and bicycle, we could create two AnyBodyStudy objects - one with references to (human & chair) and the other simulating (human & bicycle).

#include "<ANYBODY_PATH_MYFILES>/AnyBody.8.0.x/AMMR.v3.0.0-Demo/libdef.any"
Main =
{

    AnyFolder Model =
    {

    };


    AnyBodyStudy Study =
    {
        AnyFolder &ModelForSim = .Model; // '&' creates a local reference to existing folder
        Gravity = {0,-9.81,1}; // Gravity Vector
        tStart = 0; // Start time
        tEnd = 1; // End time
    };
};

STEP 5

The AMMR contains multiple musculoskeletal models (e.g., human cow, rat etc.). Type the following statement to import the human body model alone. The file path <ANYBODY_PATH_BODY> is defined in libdef.any - Have a look in there.

#include "<ANYBODY_PATH_MYFILES>/AnyBody.8.0.x/AMMR.v3.0.0-Demo/libdef.any"
Main =
{
    #include "<ANYBODY_PATH_BODY>/HumanModel.any"

    AnyFolder Model =
    {

    };


    AnyBodyStudy Study =
    {
        AnyFolder &ModelForSim = .Model; // '&' creates a local reference to existing folder
        Gravity = {0,-9.81,1}; // Gravity Vector
        tStart = 0; // Start time
        tEnd = 1; // End time
    };
};

STEP 6

Create a reference to the human body model inside Model so that it is considered a part of the simulations in Study.

#include "<ANYBODY_PATH_MYFILES>/AnyBody.8.0.x/AMMR.v3.0.0-Demo/libdef.any"
Main =
{
    #include "<ANYBODY_PATH_BODY>/HumanModel.any"

    AnyFolder Model =
    {
        AnyFolder &Human = .HumanModel.BodyModel;
    };


    AnyBodyStudy Study =
    {
        AnyFolder &ModelForSim = .Model; // '&' creates a local reference to existing folder
        Gravity = {0,-9.81,1}; // Gravity Vector
        tStart = 0; // Start time
        tEnd = 1; // End time
    };
};

STEP 7

First add the lines of code highlighted in yellow below. An explanation follows.

While the previous step included the human body model in Model, a key piece of machinery was still missing - Motion constraints. In fact, you will see a warning message if the model is loaded now. While motion prescription in elaborated on in the making things move tutorial, a basic AnyBody requirement is that the number of motion constraints (called motion drivers in AnyBody) must at least equal the number of DOFs of the model.

The total number of DOFs & motion constraints can be found by double clicking the Study object in the Model tree. This opens the Object Description which will show 378 DOFs but only 336 constraints. Therefore 42 more motion constraints are needed to make the simulation work. The AMMR thankfully provides 42 default soft drivers (see this tutorial which introduces soft drivers) which set joint angle values that hold the body in a default standing posture. These are termed DefaultMannequinDrivers and are included in the Model folder below.

Due to the inclusion of soft drivers, solver settings need to be readjusted (see yellow highlting in code below). You can now gradually add more complex hard drivers (e.g, to constrain feet to ground, maintain balance etc.) to your model, which automatically over-ride the constraints enforced by soft drivers. The alternative would have been to create all 42 constraints manually before the simulation could even be tested - a debugging nightmare in the making!

#include "<ANYBODY_PATH_MYFILES>/AnyBody.8.0.x/AMMR.v3.0.0-Demo/libdef.any"
Main =
{
    #include "<ANYBODY_PATH_BODY>/HumanModel.any"

    AnyFolder Model =
    {
        AnyFolder &Human = .HumanModel.BodyModel;
        AnyFolder &MotionDrivers = .HumanModel.DefaultMannequinDrivers;
    };


    AnyBodyStudy Study =
    {
        AnyFolder &ModelForSim = .Model; // '&' creates a local reference to existing folder
        Gravity = {0,-9.81,1}; // Gravity Vector
        tStart = 0; // Start time
        tEnd = 1; // End time

        InitialConditions.SolverType = KinSolOverDeterminate;
        Kinematics.SolverType = KinSolOverDeterminate;
    };
};

STEP 8

Add the highlighted code to create generalized reaction forces at the pelvis which support the model’s weight.

It consists of 6 generalized forces applied on the human model by the Ground frame and is composed of 3 linear forces and 3 moments. The reaction force is constructed by an AnyReacForce class containing references to the kinematic measures (see this tutorial on kinematic measures) of the Pelvis w.r.t ground.

#include "<ANYBODY_PATH_MYFILES>/AnyBody.8.0.x/AMMR.v3.0.0-Demo/libdef.any"
Main =
{
    #include "<ANYBODY_PATH_BODY>/HumanModel.any"

    AnyFolder Model =
    {
        AnyFolder &Human = .HumanModel.BodyModel;
        AnyFolder &MotionDrivers = .HumanModel.DefaultMannequinDrivers;

        AnyReacForce HumanGroundResiduals =
        {
        AnyKinMeasure& PelvisPosX = .Human.Interface.Trunk.PelvisPosX;
        AnyKinMeasure& PelvisPosY = .Human.Interface.Trunk.PelvisPosY;
        AnyKinMeasure& PelvisPosZ = .Human.Interface.Trunk.PelvisPosZ;
        AnyKinMeasure& PelvisRotX = .Human.Interface.Trunk.PelvisRotX;
        AnyKinMeasure& PelvisRotY = .Human.Interface.Trunk.PelvisRotY;
        AnyKinMeasure& PelvisRotZ = .Human.Interface.Trunk.PelvisRotZ;
        };

    };


    AnyBodyStudy Study =
    {
        AnyFolder &ModelForSim = .Model; // '&' creates a local reference to existing folder
        Gravity = {0,-9.81,1}; // Gravity Vector
        tStart = 0; // Start time
        tEnd = 1; // End time

        InitialConditions.SolverType = KinSolOverDeterminate;
        Kinematics.SolverType = KinSolOverDeterminate;
    };
};

STEP 9

Load the model and run the InverseDynamics analysis contained within Study. Refer to this tutorial on how to view/plot the simulation outputs.

We encourage you to experiment further by adding more complex model components such as motion drivers, external forces etc. to the current model. Refer to these tutorials to understand these features better.