MapleSim[Multibody][BuildSimCode] - generate simulation code based on a MapleSim/Multibody model module
Calling Sequence
Parameters
Description
Options
Examples
See Also
BuildSimCode(MSimMultibodyModel, options)
MSimMultibodyModel - Maple module of a system created using the BuildEQs command or retrieved from a MapleSim/Multibody store file (`.lib`) using the GetModel command.
options - (optional) equations of the form keyword = value
Important: The BuildSimCode command has been deprecated. Use the templates in the MapleSim templates folder to analyze your model instead. For more information, see Opening MapleSim Templates.
The BuildSimCode command can be used to generate optimized procedures and functions in a variety of output languages. Unless the SilentMode option is set to true, BuildSimCode indicates the location and argument syntax for any generated functions.
Matrix outputs are returned as column matrices in the column-major format.
'TargetDir' = string
A string indicating the directory to which the BuildSimCode command exports the generated simulation code. If the string is assigned to a directory that does not exist or not assigned to a directory, BuildSimCode exports the simulation code to the current directory as defined by the currentdir command. This option is ignored if the 'Language' option is set to MapleProc or MapleFunc.
'Exports' = set
The 'Exports' option indicates the functions for which BuildSimCode exports code. Two different syntaxes can be used depending on whether you want to use pre-defined or user-defined functions. The arguments of the generated functions are dependent on the selected 'Language' option.
- Pre-defined Functions: in this case, 'Exports' is equated to a set of strings. Each string indicates a particular pre-defined function (that is, 'Exports' = {"Xdot", "Reactions"}). For more information about pre-defined functions, see the kinematics and dynamics help pages. The allowable strings are listed in the table below:
Allowable Strings
"Xdot"
The first time derivatives of state variables, that is, ⅆ⁢pⅆt and ⅆ⁢qⅆt .
"Reactions"
The m reaction loads corresponding to either the vReactions or vLambda column matrix of the model, depending on the 'AugType' option used in BuildEQs when the model was generated.
"PosCons"
The m position-level constraint equations corresponding to the GetPosCons() function of the model.
"VelCons"
The m velocity-level constraint equations corresponding to the GetVelCons() function of the model.
"JacPos"
The m x n Jacobian matrix of the position constraint equations with respect to the generalized coordinates, corresponding to the model's xJacPos export. The matrix is exported as an array using column-major ordering.
"JacVel"
The m x n Jacobian matrix of the velocity constraint equations with respect to the generalized speeds, corresponding to the model's xJacVel export. The matrix is exported as an array using column-major ordering.
"VelRHS"
Right side of the velocity-level kinematic constraint equations, corresponding to the vVelRHS column matrix of the model.
"AccRHS"
Right side of the acceleration-level kinematic constraint equations, corresponding to the vAccRHS column matrix of the model.
"C"
The m x n coefficient matrix of constraint reactions, corresponding to the xC export of the model.
"M"
The n x n mass matrix, corresponding to the xM export of the model.
"F"
The n x 1 right side of the dynamic equations, corresponding to the vF column matrix of the model.
"A"
The first matrix returned by the export GetAYBSysODEs(). For more information, see the Dynamic Exports help page.
"B"
The third matrix returned by the export GetAYBSysODEs(). For more information, see the Dynamic Exports help page.
User-defined Vectors and Matrices: if a user-defined Matrix or Vector has been created in a Maple worksheet, you can export it to any of the languages supported by BuildSimCode. You can use a list of lists instead of using strings.
'Exports' = {[["Func1Name", Func1VectorOrMatrix, Func1Subs], ["Func2Name", Func2VectorOrMatrix, Func2Subs], ...]}
The first element in each sublist is a string indicating the name of the function to be generated. The second element is a Matrix or Vector object that has been created in a Maple worksheet. The final element in each sublist is a list of equations defining symbols that are not known inputs, parameters, or state variables. In most cases, this entry is left as an empty list (that is, [ ]).
'Language'= string
A string indicating the format of the exported simulation code. Allowable strings are listed in the table below:
"MapleProc"
Generates a Maple procedure of the form
PROCNAME(NumStates, t, vX, Output)
This procedure is designed to be integrated using dsolve/numeric.
Tip: Use this option only when generating a procedure for the derivative of the model's state variables. All of the model parameters and inputs must be replaced by numeric values or functions of time to use this option.
"MapleFunc"
Creates a Maple function of the form
Output = FUNCNAME(t,vX,Params,Input)
where t is time, vX is the column matrix of state variables q and p, Params and Inputs are the parameters and inputs required to evaluate the procedure (use the model functions GetParams() and GetInputs() commands to identify them) and Output is the computed output.
"Cproc"
Creates a C-procedure of the form
PROCNAME(t,vX,Params,Inputs,Output)
"BB_SFunc"
This option applies when the MapleSim Connector is installed. When selected, BuildSimCode creates an object in the Maple worksheet and saves the MATLAB® script required to automatically generate a Simulink® S-Function of the chosen procedure to the designated 'TargetDir'.
The resulting Simulink® block will be an input or output block with no internal states. To facilitate this process, the state variables vX are moved from the State Variable Array to the Inputs Array.
"BB_SFunc_WithIntegrator"
The resulting Simulink® block will contain internal states (corresponding to the model's vX column matrix) and an integrator that will advance the state variables in time.
'Optimize'= boolean
A Boolean value indicating whether to apply optimization routines to the simulation code before the final code generation. The default value is true.
'NumericSubs'= list
A list of equations of the form `parameter=value`. Any parameters or functions that are not included in this list are left as inputs to the generated simulation code.
'ICs'= list
A list of floats indicating the initial conditions for subsequent integration. The ordering of this list is assumed to correspond to the order of the state variables in the model's vX export. This option is ignored unless the 'Language' option is set to "BB_SFunction_WithIntegrator".
'SilentMode'= boolean
Setting this option to true hides the output generated by the BuildSimCode command. The default value is true.
Important: The BuildSimCode command has been deprecated. Use the templates in the MapleSim document folder to analyze your model instead.
The example below shows an embedded MapleSim model of a planar slider-crank mechanism. In this example, the embedded component name is Simulation0 and the model name is SliderCrank. When the code is generated, you can use the BuildSimCode command to export a Maple procedure to a worksheet.
leArguments≔InputString=MapleSim:-Multibody:-GetMultibodyInput⁡Simulation0,ModelName=SliderCrank,KinSimpType=Simplify,DynSimpType=Simplify,AugType=Lagrange,MaxSmallQOrder=1,SaveToLib=true,SilentMode=false:MapleSim:-Multibody:-BuildEQs⁡op⁡leArguments:
Analyzing system...
Performing constraint analysis...
The system has 1 degree(s) of freedom. It is modeled using 3 generalized coordinate(s) coupled by 2 algebraic constraint(s).
Peforming a dynamic analysis using an augmented Lagrange formulation - system variables shown below:
Dynamic analysis complete.
Saving model for future use...:
Model saved to: C:/SliderCrank.lib
Use `Model := MapleSim:-Multibody:-GetModel("C:/SliderCrank.lib"):` to retrieve stored model.
leNumericSubs≔G=9.81,m_1=1,m_2=1,m_3=3,F⁡t=0:
leArguments≔SliderCrank,Language=MapleProc,Optimize=true,NumericSubs=leNumericSubs,Baumgarte=2,2,Exports=Xdot,SilentMode=false:MapleSim:-Multibody:-BuildSimCode⁡op⁡leArguments:
Order of the State Variable Array:
ⅆⅆt⁢s_P2⁡t,ⅆⅆt⁢theta_R1⁡t,ⅆⅆt⁢theta_R5⁡t,s_P2⁡t,theta_R1⁡t,theta_R5⁡t
Order of the Constant Parameter Array:
Order of the Inputs Array:
--------------Processing Xdot-------------
Procedure `pXdot` created in the Maple workspace.
pXdot(NumStates, t, States, StateDerivatives) #compatible with `dsolve/numeric`
4⁢functions+25⁢subscripts+96⁢assignments+83⁢multiplications+60⁢additions+3⁢divisions
----duration: .63e-1 seconds----
eval⁡pXdot
procN,t,vX_in,XDOTlocalzz;zz:=array⁡1..59;zz[1]:=sin⁡vX_in[6];zz[2]:=0.2500000000*zz[1];zz[38]:=zz[2];zz[3]:=cos⁡vX_in[6];zz[39]:=−1.*zz[3];zz[40]:=zz[1];zz[4]:=sin⁡vX_in[5];zz[5]:=cos⁡vX_in[5];zz[6]:=−0.5000000000*zz[3]*zz[4]+0.5000000000*zz[1]*zz[5];zz[41]:=zz[6];zz[7]:=0.5000000000*zz[1]*zz[4]+0.5000000000*zz[3]*zz[5];zz[42]:=zz[7];zz[43]:=zz[2];zz[2]:=−1.*zz[6]+zz[1]*vX_in[4];zz[44]:=zz[2];zz[8]:=−1.*zz[7]+zz[3]*vX_in[4];zz[45]:=zz[8];zz[46]:=−1.*zz[3];zz[47]:=zz[6];zz[48]:=zz[2];zz[49]:=zz[1];zz[50]:=zz[7];zz[51]:=zz[8];zz[2]:=vX_in[3]^2;zz[52]:=−0.2500000000*zz[2]*zz[3];zz[53]:=−0.2943000000*zz[5];zz[54]:=2.452500000*zz[3];zz[55]:=vX_in[1];zz[56]:=vX_in[2];zz[57]:=vX_in[3];zz[6]:=2.*zz[5];zz[7]:=0.5000000000*vX_in[2]^2;zz[8]:=2.*zz[4];zz[4]:=zz[7]*zz[4] − 1.*zz[6]*vX_in[2] − 0.5000000000*zz[2]*zz[4]+zz[6] − 4.*vX_in[4]*vX_in[3] − 1.*zz[8];zz[9]:=4.*vX_in[4]+4.*vX_in[1];zz[2]:=vX_in[4] − 0.5000000000*zz[5]*zz[2];zz[5]:=zz[7]*zz[5];zz[7]:=zz[8]*vX_in[3];zz[8]:=zz[8]*vX_in[2];zz[58]:=zz[1]*zz[4]+zz[5]+zz[8]+zz[2] − 1.*zz[7]+zz[9] − 1.*zz[6]*zz[3] − 4.;zz[59]:=−1.*zz[5] − 1.*zz[8] − 1.*zz[2]+zz[7] − 1.*zz[9]+zz[6]*zz[1]+zz[3]*zz[4];zz[21]:=0.4000000000*zz[38];zz[22]:=0.4000000000*zz[39];zz[23]:=0.4000000000*zz[40];zz[26]:=0.1290000000 − 1.*zz[43]*zz[21];zz[27]:=zz[44] − 1.*zz[43]*zz[22];zz[28]:=zz[45] − 1.*zz[43]*zz[23];zz[29]:=zz[48] − 1.*zz[46]*zz[21];zz[30]:=−1.*zz[46]*zz[22];zz[31]:=−1.*zz[46]*zz[23];zz[32]:=zz[51] − 1.*zz[49]*zz[21];zz[33]:=−1.*zz[49]*zz[22];zz[34]:=−1.*zz[49]*zz[23];zz[24]:=133.3333333*zz[41];zz[25]:=133.3333333*zz[42];zz[30]:=zz[30] − 1.*zz[47]*zz[24];zz[31]:=zz[31] − 1.*zz[47]*zz[25];zz[33]:=zz[33] − 1.*zz[50]*zz[24];zz[34]:=zz[34] − 1.*zz[50]*zz[25];zz[1]:=1/zz[26];zz[27]:=zz[27]*zz[1];zz[28]:=zz[28]*zz[1];zz[30]:=zz[30] − 1.*zz[29]*zz[27];zz[31]:=zz[31] − 1.*zz[29]*zz[28];zz[33]:=zz[33] − 1.*zz[32]*zz[27];zz[34]:=zz[34] − 1.*zz[32]*zz[28];zz[2]:=1/zz[30];zz[31]:=zz[31]*zz[2];zz[34]:=zz[34] − 1.*zz[33]*zz[31];zz[13]:=0.4000000000*zz[52];zz[10]:=zz[54] − 1.*zz[13]*zz[43];zz[11]:=zz[58] − 1.*zz[13]*zz[46];zz[12]:=zz[59] − 1.*zz[13]*zz[49];zz[14]:=133.3333333*zz[53];zz[11]:=zz[11] − 1.*zz[14]*zz[47];zz[12]:=zz[12] − 1.*zz[14]*zz[50];zz[15]:=zz[10]*zz[1];zz[11]:=zz[11] − 1.*zz[15]*zz[29];zz[12]:=zz[12] − 1.*zz[15]*zz[32];zz[16]:=zz[55];zz[17]:=zz[56];zz[18]:=zz[57];zz[19]:=zz[11]*zz[2];zz[12]:=zz[12] − 1.*zz[19]*zz[33];zz[20]:=zz[12]/zz[34];zz[37]:=zz[19] − 1.*zz[20]*zz[31];zz[1]:=zz[15] − 1.*zz[20]*zz[28] − 1.*zz[37]*zz[27];zz[36]:=zz[1];zz[2]:=zz[14] − 1.*zz[20]*zz[25] − 1.*zz[37]*zz[24];zz[35]:=zz[2];XDOT[1]:=zz[13] − 1.*zz[20]*zz[23] − 1.*zz[37]*zz[22] − 1.*zz[36]*zz[21];XDOT[2]:=zz[2];XDOT[3]:=zz[1];XDOT[4]:=zz[16];XDOT[5]:=zz[17];XDOT[6]:=zz[18]end proc
Dynamic Exports, Kinematic Exports, MapleSim, MapleSim[Multibody][BuildEQs], MapleSim[Multibody][BuildExpression](deprecated), MapleSim[Multibody][BuildPlot](deprecated), MapleSim[Multibody][BuildSimulation](deprecated), MapleSim[Multibody][GetModel](deprecated), MapleSim[Multibody][GetMultibodyInput]
Download Help Document