*SetDiscreteStates()

Specifies the properties for the discrete states of a general state equation.

Syntax

*SetDiscreteStates(varname,{LIN,lin_value|CRV,crv,int_type,indep_var|EXPR,
expr|USER,sample_period_usr_sub}[,num_discrete_states][,sample_offset])

Arguments

varname
The variable name of the general state equation.
Data type: varname
LIN|CRV|EXPR|USER
A keyword that suggests the following argument for the sample period is either a linear value, curve, expression, or a user-defined subroutine.
See Comments below.
Data type: keyword
lin_value
Used in conjunction with the LIN keyword.
Specifies the sample period for the discrete state as a constant value.
Data type: real
crv
Used in conjunction with the CRV keyword.
Specifies the sample period for the discrete state through a curve.
This argument should resolve to a 2D curve defined using the *Curve statement.
Data type: Curve
int_type
A keyword that suggests the type of interpolation method to be used if the sample period refers to a curve.
Valid values are: AKIMA|CUBIC|LINEAR|QUINTIC.
Data type: keyword
indep_var
Solver expression that represents the independent variable to be used with the curve for the sample period, if the curve option is used.
Data type: Expression
expr
Used in conjunction with the EXPR keyword.
Specifies sample period for the discrete state using a solver expression.
Data type: Expression
sample_period_usr_sub
Used in conjunction with the USER keyword.
User-defined expression calling a subroutine to determine the sample period for the discrete state.
Data type: Expression
num_discrete_states
The number of discrete states in the state equation (default is 0).
Data type: integer
sample_offset
Optional argument which specifies the simulation time at which the sampling of the discrete states are to start. If no time is specified, the default value is 0.0.
Data type: real

Example

Example 1
*GeneralStateEquation( gse_0, "My Controller", 3, 
u_array, , icd_array )
  *SetDiscreteStates(gse_0, LIN, 0.5, 3, 1.0)
Example 2

 *Curve( crv_samp, "Sample Period Curve", 2D, CARTESIAN, WRITE, CURVE_POINTS, OPEN )
  *SetCurve( crv_0, FILE, "curve.csv", "Unknown", "Block 1", 
"x", FILE, "curve.csv", 
"Unknown", "Block 1", "y" )
  *GeneralStateEquation( gse_0, "My Controller", 3, 
u_array, , ic_array )
  *SetDiscreteStates(gse_0, CRV, crv_samp, `VZ({b_body.idstring}, 
{B_Ground.idstring}, 
{b_body.idstring}), 4)
Example 4

*GeneralStateEquation( gse_0, "My Controller", 3, 
u_array, , icd_array )
  *SetDiscreteStates(gse_0, USER,`USER(501, {b_body.idstring})`, 2, 0.5)
Example 3
*GeneralStateEquation( gse_0, "My Controller", 3, 
u_array, , icd_array )
  *SetDiscreteStates(gse_0, USER,`USER(501, {b_body.idstring})`, 2, 0.5)
Example 1
 
Example 2)
Example 3
x
Example 4
 *GeneralStateEquation( gse_0, "My Controller", 3, 
u_array, , icd_array )
 *SetDiscreteStates(gse_0, USER, `USER(501, {b_body.idstring})`, 2, 0.5)
The examples above demonstrate various usages of this statement:
  • In the first example, a constant linear value of 0.5 is used as the sampling period. The state equation has 3 discrete states and a sample offset of 1.0 (time unit) is used.
  • In Example 2, the sample period is specified using a curve crv_samp which is defined using *Curve. A velocity function is the independent variable for the curve. The number of discrete states is 4 and no sample offset is specified.
  • In Example 3, a solver expression is used to provide the sample period. Here, a step function is used which sets the sample period to 0.5 until the time is 1.0 (in time units) and then changes to 0.2 from 2.0 (time units).
  • In Example 4, a user subroutine is used to determine the sample period. An expression of type USER() passes 2 parameters (501 and the id of a body b_body) to the subroutine.

Context

*BeginMdl()

*DefineAssembly()

*DefineSystem()

*DefineAnalysis()

*BeginContext()

Comments

The sample period can be specified in four different ways. Use the LIN option to use a constant sample period through out the simulation. Non constant values can be specified using the other three methods. Use CRV option to specify sample period using a curve. If this option is used, the following two arguments would have to be the variable name of 2D curve defined using *Curve statement and independent variable (solver expression) to determine the value of the curve respectively. Use EXPR option to specify sample period using a solver expression. This option should be followed by a solver expression. Use the USER keyword to point to a user subroutine. This keyword should be followed by a solver expression USER().

For the sample period specified using user subroutine, a local library file and function can be specified in *SetLocalInterfaceDLL.

The num_discrete_states argument is used to indicate the number discrete states in the GSE and its value would be written in the ND argument of the GSE statement in ADAMS.