
MapleSim^{™} Connector Template: Simulink^{®} Component Block Generation for DynamicSystems Objects

Author:
Date:




Description


Use this template to generate C code from a DynamicSystems object. You must first define the equations and parameters of the DynamicSystems object. You can then generate C code and an M script from that system object and create a block that can be used in a Simulink® model.
Before using this template, you must configure Maple™ to communicate with MATLAB®. For more information, see the Configuring a Computer for MATLAB(R) help topic.
Note: There is a problem with the compilation of the generated files using 'mex' command in MATLAB®. You need to rename the generated Cfile from cDC_Motor.c to DC_Motor.c by removing the leading "c" in the file name. You also need to change the function name definition on line 9 in the generated Cfile from "cDC_Motor" to "DC_Motor". With these changes, running the mscript in MATLAB® will generate the Simulink® Component Block correctly. This Template will be deprecated in the next MapleSim release. Use SimulinkComponentBlockGeneration template instead.


Component Equations


The sample model equations below can be replaced with equations for your DynamicSystems object. In the table below, specify the variables that will be used to define component equations and parameters in the Model Equations section.
For more information about creating system models, see the DynamicSystems help topic.


Model Equations


This example demonstrates how to create a DynamicSystems object with parameters.
 (3.1) 
 (3.2) 
 (3.3) 
To view the differential equations of a system, you can use the DynamicSystems[DiffEquation] command. In the example below, the system object is assigned to a variable called sys de. The de parameter is then used to display the differential equations.
 (3.4) 
 (3.5) 


Advanced Code Generation Settings


These settings specify the advanced options for the code generation process.

Code Optimization Options


Code optimization options specify whether equations are left in their implicit form or converted to an ordinary differential equation (ODE) system during the code generation process. Select one of the following options:
•

None: no optimization is performed; the default equations will be used in the generated code.

•

Partial: removes redundant equations from the system.

•

Full: performs index reduction to reduce the system to an ODE system or a differential algebraic equation (DAE) system of index 1, and removes redundant equations.



DAE Constraint Option


The Constraint Projection option specifies whether the constraints are satisfied in a DAE system by using constraint projection in the generated Simulink® block. Use this option to improve the accuracy of a DAE system that has constraints. If the constraint is not satisfied, the system result may deviate from the actual solution and could lead to an increase in error at an exponential rate.
Constraint projection is performed using the constraint projection routine in the External Model Interface, as described on The MathWorks™ web site, to control the drift in the result of the DAE system.
Default Constraint Projection Settings
The Maximum Allowable Iterations field specifies the maximum number of times that a projection is permitted to iterate to obtain a more accurate solution. The Maximum Allowable Relative Error field specifies the desirable error tolerance to achieve after the projection.
Maximum Allowable Iterations:
Maximum Allowable Relative Error:



Generate Simulink® Block


To generate an SFunction block in Simulink® directly, click Generate to Simulink. To generate and save the SFunction code to a file, click Save Code to Directory.

Type of Model



Note: You need to rename the generated Cfile from cDC_Motor.c to DC_Motor.c by removing the leading "c" in the file name. You also need to change the function name definition on line 9 in the generated Cfile from "cDC_Motor" to "DC_Motor".

View Code



Simulink® C SFunction code




Simulink® .mdl Block script








After generating the source code, save this worksheet in Maple.
