User Subroutine Guidelines

User subroutines are created for various reasons. Some include:
  • To describe a physical phenomenon that is determined by non-trivial logical conditions.
  • When it is unpractical to formulate a complicated expression in an explicit form.
  • To take full advantage of a programming language like C/C++ or Fortran or a scripting language like Python or MATLAB.
    Note: Using user subroutines adds a level of complexity to your multibody model. We recommend using the built-in functions to model your system before using subroutines unless it is necessary or more convenient to use subroutines.

To use your own subroutines in MotionSolve, follow these steps:

  1. Create a Python, MATLAB, C/C++ or Fortran source file that contains the user defined modeling entity.
  2. Obtain a Dynamic-Link Library (DLL) or Shared Object (SO) by compiling and linking your user subroutine(s) - only for C/C++ or Fortran source code. No compiling is required for Python or MATLAB source code. Python routines are automatically compiled, and you can use compiled Python files with MotionSolve without the source files.
  3. Modify the corresponding entity in your multibody model to be "user defined" and to point to your DLL/SO or script file.
  4. Run MotionSolve, verifying that it picks up the appropriate DLL/SO or script file during simulation.
The above steps are described in detail in the subsequent sections.