2 Creating and Exporting Mathematical Models in Maple - MapleSim Connector Help

Online Help

All Products    Maple    MapleSim


Home : Support : Online Help : MapleSim Toolboxes : MapleSim Connector : Getting Started Guide : MapleSimConnectorGSG/Chapter02

Contents     Previous     Next     Index

2 Creating and Exporting Mathematical Models in Maple

In Maple, you can use commands from the DynamicSystems package to create a system from first principles. Maple contains a data structure called a system object that encapsulates the properties of a dynamic system. This data structure contains information, for example, the description of the system, and the description of the inputs. Five different types of systems can be created.

• 

Differential equation or difference equation

• 

Transfer function as an expression

• 

Transfer function as a list of numerator and denominator coefficients

• 

State-space

• 

Zero, pole, gain

You can create a DynamicSystems object in a new worksheet and use commands from the MapleSimConnector package to generate source code programmatically and save it as a MATLAB® .m file.

2.1 Creating and Exporting a DynamicSystems Object Programmatically

First, load the DynamicSystems and MapleSimConnector packages in the Maple worksheet.

 

withDynamicSystems:

withMapleSimConnector:

To create a system object from the transfer function 1s2+as+b,  use the following command:

sysTransferFunction1s2+as+b

sys:=Transfer Functioncontinuous1 output(s); 1 input(s)inputvariable = u1soutputvariable = y1s

(1.1.1)

To view the details of the system, use the PrintSystem command.

 

PrintSystemsys

Transfer Functioncontinuous1 output(s); 1 input(s)inputvariable = u1soutputvariable = y1stf1,1 = 1s2+as+b

(1.1.2)

The default values for the input names (u1) and output names y1 have been used.  Alternatively, during creation of the system, different input and output names can be specified.

 

To define parameters values, use the following command:

para=1,b=1

par:=a=1,b=1

(1.1.3)

 

Finally, use the SBlock command to generate the source code and the SaveCode command to save the code as a .c file and MATLAB® .m file.

 

scriptSBlocksys,sys:-inputvariable,sys:-outputvariable,MyTransferFunction, parameters=par:

SaveCodeMyTransferFunction,extension=c,script1,interactive=true:

 

SaveCodeMyTransferFunction,extension=m,script2,interactive=true:

2.2 Example: DC Motor

Consider the classic example of the simplified DC motor. Using the built-in functionality of the DynamicSystems package in Maple, you can define the system model, and then visualize and simulate it before saving the code.

 

This example demonstrates how to define, analyze, and export a system programmatically.

To define, visualize and simulate a DC motor

1. In a new Maple worksheet, define the system model.

Differential Equation Model:

eq1L ⅆⅆtit+Rit=vtKⅆⅆtθt:

eq2Jⅆ2ⅆt2θt+bⅆⅆtθt+Ksθt=Kit:

 

Transfer Function Model:

sys_de  DiffEquation eq1,eq2, vt,θt,it :sys_tf  TransferFunctionsys_de: sys_tf:-tf1,1;sys_tf:-tf2,1;

KJLs3+bL+JRs2+KsL+K2+bRs+KsR

Js2+bs+KsJLs3+bL+JRs2+KsL+K2+bRs+KsR

(1.2.1)

In place of the above commands, you could use the PrintSystem command to display each part of the model.

 

2. Specify the parameters in the model.

Description

(Initial) Value

Units

Input Variables

Applied voltage

v=0

V

Output Variables

Motor shaft angular position

θ=0

rad

Motor current

i=0

A

Parameters

Moment of inertia of the motor

J=0.1

kgm2

Damping of the mechanical system

b=0.1

Nms

Electromotive force constant

K=0.1

NmA

Motor coil resistance

R=1

Ω

Motor coil inductance

L=0.5

H

External Spring Load Constant

Ks=0

Nm

params J=0.1,b=0.1, K=0.1, R=1,L=0.5,Ks=0 :

ics  i0=0, θ0=0, Dθ0=0:

 

3. Generate and save the source code as a .c file and MATLAB® .m file.  

cSFcn,  MBlockSBlocksys,sys:-inputvariable, sys:-outputvariable, MyTransferFunction, parameters=params, initialconditions=ics :

MapleSimConnector:-SaveCodeMyTransferFunction,cSFcn,extension=c,interactive=true:

MapleSimConnector:-SaveCodeMyTransferFunction,MBlock,extension=m,interactive=true:

With the basic tools shown in this guide, you are now ready to use the MapleSim Connector to solve many system design problems. Enter ?DynamicSystems and ?MapleSimConnector at a prompt in a Maple worksheet for more information about the commands used in this guide.

 

Contents     Previous     Next     Index


Download Help Document

Was this information helpful?



Please add your Comment (Optional)
E-mail Address (Optional)
What is ? This question helps us to combat spam