# COUSUB/COUXX/COUXX2

ModelingUsed to specify a user coupler element.

## Definition

Coupler constraints are used to constrain the relative translational and/or the rotational motion of two or three joints. By using a subroutine-based formulation, for example, you can specify a variable coupler ratio based on system states, relational operators, and logical expressions. A typical example is a nonlinear coupler multiplier ratio defined as a function of an input joint velocity.

## Use

User-defined coupler entity example:

<Constraint_UserConstr
id                  = id     ...
usrsub_param_string = "USER(r1,… r30)"
usrsub_dll_name     = "NULL">
</Constraint_UserConstr>

## Format

Fortran Calling Syntax
SUBROUTINE COUSUB (ID, TIME, PAR, NPAR, DISP, NDISP, IFLAG, PHI)
SUBROUTINE COUXX (ID, TIME, PAR, NPAR, DISP, NDISP, IFLAG, DFDA)
SUBROUTINE COUXX2 (ID, TIME, PAR, NPAR, DISP, NDISP, IFLAG, D2FDA2)
C Calling Syntax
void  STDCALL  COUSUB (int *id, double *time, double *par, int *npar, double *disp, int *ndisp, int *iflag, double *phi)
void  STDCALL  COUXX (int *id, double *time, double *par, int *npar, double *disp, int *ndisp, int *iflag, double *DFDA)
void  STDCALL  COUXX2 (int *id, double *time, double *par, int *npar, double *disp, int *ndisp, int *iflag, double *D2FDA2)
Python Calling Syntax
def COUSUB(id, time, par, npar, disp, ndisp, iflag):
return phi
def COUXX(id, time, par, npar, disp, ndisp, iflag):
return dfda
def COUXX2(id, time, par, npar, disp, ndisp, iflag):
return dfda2
MATLAB Calling Syntax
function phi = COUSUB(id, time, par, npar, disp1, ndisp, iflag)
function dfda = COUSUBXX(id, time, par, npar, disp1, ndisp, iflag)
function d2fda2 = COUSUBXX2(id, time, par, npar, disp1, ndisp, iflag)

## Attributes

ID
[integer]
The coupler element identifier.
TIME
[double precision]
The current simulation time.
PAR
[double precision]
An array that contains the constant arguments from the list provided in the user-defined statement.
NPAR
[integer]
The number of entries in the PAR array.
DISP
[double precision]
The array of instantaneous joint displacements.
NDISP
[integer]
The size of the DISP array.
IFLAG
[logical]
The initialization flag.

## Output

PHI
[double precision]
The scalar output value of the coupler subroutine.
DFDA
[double precision]
The vector output value of dimension NDISP that contains the partial derivative of PHI with respect to the displacement DISP.
D2FDA2
[double precision]
The vector output value of dimension NDISP that contains the second partial derivative of PHI with respect to the displacement DISP.

## Example

def COUSUB(id, time, par, npar, disp, ndisp, iflag):
phi = disp+par*disp
return phi
def COUXX(id, time, par, npar, disp, ndisp, iflag):
dfda =2*
dfda =1.0dfda = par
return dfda
def COUXX2(id, time, par, npar, disp, ndisp, iflag):
d2fda2 = 2*
return d2fda2