# Custom Statements

Custom statements allow advanced users to expand the set of MotionSolve model elements by adding new standard model element vocabulary. Custom statements can be mapped to one or more model elements.

Custom statements can be mapped to elements of the same type or of different types. You can choose the element name as well as the attribute names.

When a custom element has the same name as a pre-defined MotionSolve model element, the custom model element takes precedence. In other words, custom model elements override pre-defined model elements.

For instance, consider a PID controller:
The PID controller calculation involves three separate parameters: proportional, integral, and derivative values:
1. Proportional value determines the reaction to the current error and is represented by:(1) $K\left[u\right]$
2. Integral value determines the reaction based on the sum of recent errors:(2) $\frac{1}{s}\left[u\right]={x}_{1}$
3. Write this equation in another form:(3) ${\stackrel{˙}{x}}_{1}=u$
4. Derivative value determines the reaction based on the rate at which the error has been changing, having two parts:(4) $C\left[u\right]={x}_{3}$
5. Alternatively:(5) ${x}_{3}-C\left[u\right]=0$
6. And:(6) $s\left[{x}_{3}\right]={x}_{2}$
7. Alternatively:(7) ${\stackrel{˙}{x}}_{3}-{x}_{2}=0$
8. The weighted sum of these three actions is used to adjust the process via a control element, such as the position of a control valve:(8) ${x}_{1}+{x}_{2}+K\left[u\right]=y$

The proportional, integral, and derivative terms are summed to calculate the output of the PID controller.

Thus, you get the custom element (8) with three Control_Diffs (one explicit and two implicit) and one Reference_Variable.

## Create a Custom Statement

1. Edit the mapping file.
An entry is made to the mapping file declaring the custom function as shown in the image below:
The general syntax for the CustomElement element is as follows:
<CustomFunction
SYMBOL              = "string"
<Attribute
ID                 = "integer"
NAME               = "string"
TYPE               = "string"
DEFAULT            = "real"
/>
... (to be repeated for each attribute)
<Component
ID                 = "integer"
CTYPE              = "string"
[In addition, all attributes needed to define the Component completely based on its type]
/>
... (to be repeated for each component)
/>
Table 1. Children. ATTRIBUTE: Specifies the definition of a particular attribute of the custom element.
Attribute Description
ID Attribute identification number, (integer>0). This is a number that is unique among all attributes of the custom element.
NAME Name of the attribute that needs to be used in the MotionSolve XML.
TYPE Specifies the data type for the value of the attribute.
DEFAULT Specifies the default value to be used for the attribute.
Table 2. Children. COMPONENT - Specifies the definition of a particular component of the custom element.
Attribute Description
ID Component identification number, (integer>0). This is a number that is unique among all components of the custom element.
CTYPE Specifies the type of the component. Supported component types include:

Non-Usersub Cases

• GRAPHICS
• MARKER
• PART
• POINT_MASS
• STRING
Single Usersub Cases
• GFOSUB
• VFOSUB
• VTOSUB
• SFOSUB
• FIESUB
• CURSUB
• SURSUB
• UCOSUB
• GCOSUB
• MOTSUB
• REQSUB
• VARSUB
• DIFSUB
• SENSUB
• SEVSUB