当前位置:首页 >> 计算机软件及应用 >>

amesim simulink联合仿真


MATLAB/Simulink interface
Version 4.0 - March 2002

www.cadfamily.com

EMail:cadserv21@hotmail.com

The document is for study only,if tort to your rights,please inform us,we will delete

Copyright IMAGINE S.A. 1995-2002 AMESim is the registered trademark of IMAGINE S.A. AMESet is the registered trademark of IMAGINE S.A.

ADAMS is a registered United States trademark of Mechanical Dynamics, Incorporated. ADAMS/Solver and ADAMS/View are trademarks of Mechanical Dynamics, Incorporated. MATLAB and SIMULINK are registered trademarks of the Math Works, Inc. Netscape and Netscape Navigator are registered trademarks of Netscape Communications Corporation in the United States and other countries. Netscape's logos and Netscape product and service names are also trademarks of Netscape Communications Corporation, which may be registered in other countries. PostScript is a trademark of Adobe Systems Inc. UNIX is a registered trademark in the United States and other countries exclusively licensed by X / Open Company Ltd. Windows, Windows NT, Windows 2000 and Windows XP are registered trademarks of the Microsoft Corporation. X windows is a trademark of the Massachusetts Institute of Technology. All other product names are trademarks or registered trademarks of their respective companies.

www.cadfamily.com

EMail:cadserv21@hotmail.com

The document is for study only,if tort to your rights,please inform us,we will delete

AMESim 4.0 User Manual

Table of contents

Using the AMESim MATLAB/Simulink Interface. . . . . . . . . . . . . . . . . . . . . . .1
1. 2. 2.1. 2.2. 2.3. 3. 4. 5. 5.1. 5.2. 6. Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 Preliminaries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 C compiler requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 Supported versions of Simulink . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 Setting up the environment. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 Constructing the model in AMESim . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 Importing the model into Simulink . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 Co-simulation interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17 Usage of the co-simulation interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18 Concluding remarks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23

www.cadfamily.com

EMail:cadserv21@hotmail.com

i

The document is for study only,if tort to your rights,please inform us,we will delete

Table of contents

ii www.cadfamily.com

EMail:cadserv21@hotmail.com

The document is for study only,if tort to your rights,please inform us,we will delete

MATLAB/Simulink interface 4.0 User Manual

Using the AMESim MATLAB/Simulink Interface

1.

Introduction
The AMESim MATLAB/Simulink interface enables you to construct a model of a subsystem in AMESim and to convert it to a Simulink S-Function. The S-Function can then be imported into Simulink and used within a Simulink system just like any other S-Function. The interface is designed so that you can continue to use many of the AMESim facilities while the model is running in Simulink. In particular you can change the parameters of the AMESim model within AMESim in the normal way, examine the results within AMESim by creating plots just as if they were produced in a regular AMESim run. Normally you will have AMESim and Simulink running simultaneously so that you can use the full facilities of both packages. The process is illustrated below: Construct the AMESim model as a S-Function

Modify the AMESim submodel parameters

Complete the Simulink system

Run the simulation

Examine the AMESim submodel results in AMESim

Examine the Simulink control system results in Simulink

When the process is done, the AMESim model parameters may be changed within AMESim, as well as the Simulink parameters within Simulink. A series of runs can be performed. Typically, a controller can be designed for the system.
Organization of this manual

This manual describes both the standard interface and the co-simulation interface. The main part of the manual deals with the standard interface and section 5 looks at the differences between the standard and the co-simulation interface.

www.cadfamily.com

EMail:cadserv21@hotmail.com

1

The document is for study only,if tort to your rights,please inform us,we will delete

Chapter 1 Using the AMESim MATLAB/Simulink Interface

The structure of this manual is the following: Section 2 describes how you must set your working environment so that you can use the interface. Section 3 describes with a simple example how the AMESim submodel is created and converted to an S-Function. Section 4 describes how the AMESim model is imported into and run within Simulink. Section 5 describes the differences between the co-simulation interface and the standard interface. Section 6 gives a summary of the most important things to remember. Sometimes a section of text is only applicable to a UNIX or Linux environment. For such text the following presentation is used:

Using Unix:

Description for Unix/Linux environments. Sometimes a section of text is only applicable to a Windows environment. For such text the following presentation is used:

Using Windows:

Description for Windows environments. Note that a collection of utilities also exists for MATLAB so as to import/export data to and from AMESim. These are documented in chapter 7 of the main AMESim manual. It is assumed that the reader of this manual is already familiar with AMESim, MATLAB and Simulink.

2.
2.1.

Preliminaries
C compiler requirements
If you work on a UNIX or Linux platform, you will need an ANSI C Compiler that is supported by MATLAB/Simulink for creating S-functions. If you work on a PC with Windows NT, Windows 2000 or Windows XP, you must use Microsoft Visual C++ whether you use the Simulink interface or not.

2.2.

Supported versions of Simulink
This manual is written for Simulink 4.1.1 (distributed with MATLAB 6.1), but the AMESim/Simulink interface was originally developed using Simulink 1.3c (MATLAB 4.2c) and has thus been tested using this version. It has also been tested with MATLAB 5.3. Note that the performance of the interface is higher with the newer version of Simulink. If you are using a different version of Simulink, some of the pictures of this manual will be different from the ones on your screen.

2 www.cadfamily.com

EMail:cadserv21@hotmail.com

The document is for study only,if tort to your rights,please inform us,we will delete

MATLAB/Simulink interface 4.0 User Manual

2.3.

Setting up the environment
In order to use the AMESim MATLAB/Simulink interface it is necessary to set an environment variable that points out the MATLAB installation directory. If this is not set, AMESim will not be able to find the files necessary to create S-functions. To find out if this environment variable is set, type the following line in a terminal window:
Using Unix: echo $MATLAB_ROOT

This should result in something like:
/opt/matlabr12.1

being printed on screen. If nothing is printed, or the message "MATLAB_ROOT: Undefined variable" is displayed, you must set this variable. To do this you need to know where MATLAB is installed. If your working environment is set up properly to run MATLAB, type either
which matlab whence matlab type matlab

(if you are using Cshell) or (if you are using Korn shell (ksh) or Bourne shell (sh)) or (for some versions of Bourne shells).

This will tell you the location of your version of MATLAB e.g.
/opt/matlabr12.1/bin/matlab

Remove the last two parts from this pathname to get the value to set for MATLAB_ROOT, in this case /opt/matlabr12.1. If you are using the Unix C shell, you can then set the environment variable as follows:
setenv MATLAB_ROOT /opt/matlabr12.1

This statement can also be added to your .cshrc file so that the environment variable is set every time you login. For Bourne or Korn shells the corresponding would be:
MATLAB_ROOT=/opt/matlabr12.1 ; export MATLAB_ROOT

Add these statements to your .profile file so that the environment variable is set every time you login.

www.cadfamily.com

EMail:cadserv21@hotmail.com

3

The document is for study only,if tort to your rights,please inform us,we will delete

Chapter 1 Using the AMESim MATLAB/Simulink Interface

Using Windows: echo %MATLAB%

This should result in something like:
C:\MATLAB6p1

being printed on screen. If the environment variable is not set, %MATLAB% is printed and you need to set the MATLAB environment variable to point to the MATLAB installation directory. This can be done from the Windows Control Panel. Another important point is that you path must contain the directory:
%windir%\System32

where %windir% is the Windows installation directory (a typical value for %windir% is C:\WINNT). You can check the content of your path by typing the command below and you can change it from the Windows Control Panel:
echo %Path%

2. 4. Configuration files
The configuration files for the AMESim/Simulink interface supplied with a standard AMESim installation assumes that all functions are written in C and that no extra libraries with user written functions are needed. If you write your submodels in Fortran or you use non-standard libraries in your model, some changes to the standard distribution files are needed. These changes can as all AMESim configurations be performed in two ways: globally for all users, or locally for the current directory (for a particular project). The files that can be customized are simulink.conf and simulink.make. They normally exist in the $AME/lib or (%AME%/lib) directory. For global customization, they should be edited there. Your system administrator should normally handle this. For local configuration, copy these files to your project directory and make the necessary changes to these files. AMESim looks in the current directory before looking in the standard area ($AME/lib or %AME%/lib), any changes made to the local files will therefore override the global configuration. The file simulink.conf contains instructions on which files are to be used to create the S-function for Simulink. This means that if you decide to make any local configurations this file must be edited, otherwise the global configuration will be used. The

4 www.cadfamily.com

EMail:cadserv21@hotmail.com

The document is for study only,if tort to your rights,please inform us,we will delete

MATLAB/Simulink interface 4.0 User Manual

standard simulink.conf is shown below.
######################################################### # # # This file specifies the AMESim export facility to # # Simulink. The entries are as follows: # # # # 1. the template to use for an explicit system. # # 2. the template to use for an implicit system. # # 3. the makefile to use. # # 4. the button title. # # 5. the script file to launch the companion software. # # # ######################################################### $AME/lib/imulink.etemp NULL $AME/lib/simulink.make Simulink\nInterface $AME/lib/simulink.launch

The lines beginning with # are comments. The line that all local configurations needs to change is the 3rd non-comment line (currently reading "$AME/lib/simulink.make"). This is the name of a file with instructions on how to create the Simulink S-function. If you want AMESim to use your local configuration, change this line to "./simulink.make" for instance. In the standard distribution, this file ($AME/lib/simulink.make) contains two lines, as in:
Using Unix: ${AME}/lib/amemex -c -g -I${AME}/lib ${AME}/lib/amemex

Using Windows: $(CC) -c -g -DWIN32 -I${MATLAB}/extern/include -I${MATLAB}/ simulink/include ${AME}/lib/amemex

The first line is the command for compiling the AMESim generated C file. This system is dependent and may therefore be different on your installation. The second line specifies the command used for creating the Simulink mex S-function. This is a small shell script (amemex) that runs the MATLAB utility mex. All arguments are passed on to mex. By modifying amemex more advanced customizations can be made than are possible using lines 1 and 3 in simulink.make.

www.cadfamily.com

EMail:cadserv21@hotmail.com

5

The document is for study only,if tort to your rights,please inform us,we will delete

Chapter 1 Using the AMESim MATLAB/Simulink Interface

This is for advanced users only.
Using Unix:

If your model includes Fortran code simulink.make probably needs to be altered by adding a 3rd line specifying the additional libraries needed. An example on such a line is:
-L/opt/SUNWspro/SC3.0.1/lib -lF77 -lsunmath

This is highly system dependent and you probably need to ask your system administrator for the libraries used on your computer. If many users are using Fortran it is probably a good idea to let your system administrator change the simulink.make in the standard area ($AME/lib/simulink.make). Another reason to add a 3rd line is if your submodels use user written utilities or other non-standard files or libraries; this would typically be a change that you would do locally. For instance, if you would like to include a library called libmyfuncs.a which is stored in /home/my_name/library add the following line:
-L/home/my_name/library –lmyfuncs

If there already is a 3rd line in simulink.make, for instance for using Fortran, add your files at the beginning of the line as in:
-L/home/my_name/library -lmyfuncs -L/opt/SUNWspro/SC3.0.1/ lib -lF77 -lsunmath

Using Windows:

A reason to add a 3rd line is if your submodels use user written utilities or other nonstandard files or libraries; this would typically be a change that you would do locally. For instance, if you would like to include a library called myfuncs.lib which is stored in C:\home\my_name\library add the following line:
-link -libpath:C:\home\my_name\library myfuncs.lib

or
C:\home\my_name\library\myfuncs.lib

Each AMESim model 'remembers' which simulink.config was specified when it was created. This means that for any new simulation, the corresponding simulink.make will be used. Hence, it is necessary to rebuild the special icon created for the AMESim/Simulink interface, if you wish your model to use a different simulink.make.

6 www.cadfamily.com

EMail:cadserv21@hotmail.com

The document is for study only,if tort to your rights,please inform us,we will delete

MATLAB/Simulink interface 4.0 User Manual

3.

Constructing the model in AMESim

Figure 1 The process of constructing the AMESim model is described with the help of a simple example. You will understand the process better if you create and run the system yourself. The exercise can be completed within about an hour. Create the system shown in Figure 1 calling it skyhook. It consists of two masses connected with a spring which represent a quarter car suspension.

Note. :
two transducers determine the positions of the wheel and the car body; connected to the wheel is a spring to which the road profile is applied; the system is incomplete with three ports unconnected.

www.cadfamily.com

EMail:cadserv21@hotmail.com

7

The document is for study only,if tort to your rights,please inform us,we will delete

Chapter 1 Using the AMESim MATLAB/Simulink Interface

Figure 2 The force representing the damping in the suspension will be provided by Simulink and the output from the velocity transducers will be sent to Simulink. To complete the system it is necessary to add a special interface icon. Figure 2 shows this block added to the system.

Figure 3 To create the interface blocks, click on the Interface pulldown menu shown in Figure 3. This menu is designed to be used with the Simulink interface and other interfaces but in our case it will be Simulink. Select the item labeled Create export icon. This is used to define the variables which are provided and received by the companion software. From AMESim these variables are seen as inputs and outputs respectively. The dialog box shown in Figure 4 is produced.

8 www.cadfamily.com

EMail:cadserv21@hotmail.com

The document is for study only,if tort to your rights,please inform us,we will delete

MATLAB/Simulink interface 4.0 User Manual

Figure 4 Notice that in this figure there is a field with the label SimulCosim in it. This must be changed by clicking on the arrow in the right of the field and by selecting Simulink as in Figure 5. There is currently no input and output variable. By selecting the arrow buttons in the top corners, the number of input or output variables can be adjusted. You can have any number including 0 but a reasonable upper limit is 10. If you want more than this, it is better to use more than one interface block. In our example, we require two input variables and three output variables, so ensure that the fields have the values 2 and 3 respectively. The next stage is to get AMESim to create a specific icon for the interface. The number of ports is now specified but it is also necessary to add a label to each port. Hence, we will add text to give a name to the variables. In addition, we will give a general name for the whole interface block. Figure 5 shows text added in this way. Select each field and type an appropriate text string.

www.cadfamily.com

EMail:cadserv21@hotmail.com

9

The document is for study only,if tort to your rights,please inform us,we will delete

Chapter 1 Using the AMESim MATLAB/Simulink Interface

Figure 5 Note the three buttons labeled Clear all text, OK and Cancel. Click on Cancel to abandon the process. Click on Clear all text to remove any text you have entered. Click on OK to obtain the icon produced by AMESim.

An icon similar to that shown in Figure 6 will appear. Note the port position is denoted by >.

Figure 6 The pointer will take on the appearance of the icon and can be treated like a normal AMESim component icon. Thus it can be mirrored, rotated, deleted or added to system sketch. All AMESim interface blocks have signal type ports. Connect the block inputs and output to the other components of the model as shown in Figure 2. It is worth mentioning 2 important points: You can have more than one interface block but if you do, they must all be of the same type (all Simulink standard interface blocks in the current example); the AMESim model must be explicit i.e. there cannot be any implicit variables, unless the co-simulation interface is used.

Change now to Submodel mode. The interface block will automatically be associated with a special submodel and you are not allowed to change these. For the other submodels select Premier submodel so as to get the simplest submodels.

10 www.cadfamily.com

EMail:cadserv21@hotmail.com

The document is for study only,if tort to your rights,please inform us,we will delete

MATLAB/Simulink interface 4.0 User Manual

Figure 7 Next, change to Parameter mode. Normally AMESim would create an executable program that you would start in Run mode. However, because the system contains Simulink interface blocks, an S-Function is created. The normal System Compilation window should appear (as in Figure 7) and the Parameter mode should be entered. If any error occurs, it is likely that the MATLAB environment variable is not properly set. In this case save the system, exit from AMESim and carry out the instruction for setting this variable as described in section 2. Enter new parameters for the components to values shown in the table below, leave all other parameters at their default values: Submodel Name on sketch if any Body mass mass [kg] current spring length [m] SPR00 spring rate [N/m] free length of spring [m] MAS002 Wheel mass mass [kg] current spring length [m] SPR00 Tire stiffness spring rate [N/m] free length of spring [m] duration of step 1 [s] output at start of stage 2 [null] UD00 output at end of stage 2 [null] duration of step 2 [s] 0.1 3 Title Value

MAS002

400 0.2 15000 0.2 40 0.05 200000 0.05 0.1 0.1

www.cadfamily.com

EMail:cadserv21@hotmail.com

11

The document is for study only,if tort to your rights,please inform us,we will delete

Chapter 1 Using the AMESim MATLAB/Simulink Interface

When you change from Parameter mode to Run mode, special data files containing the parameters are written. When you run the S-Function within Simulink, these files will be read. Hence, when you change any parameters, ensure you enter the Run mode. If not, your changes will not be seen by Simulink. At this point, you are ready to run the AMESim model within Simulink. Start Simulink in the normal way from a suitable shell window (Unix) or by double-clicking on its associated icon (Windows).

4.

Importing the model into Simulink
The AMESim model at this stage exists as an S-Function. It must be imported into Simulink. Remember that when you quit AMESim, the files defining your system are compressed into a single file. This means that Simulink would not have access to the SFunction. For this reason, it is normal to have AMESim and Simulink running simultaneously when using the interface. This way, you can change the parameters in the AMESim model and restart the simulation very rapidly. You can also examine the results in AMESim. Another mode of working is to quit AMESim but then to type in a terminal (Unix) or DOS (Windows) window:
AMEload skyhook

to expand the single file into its constituent parts. Simulink will then have access to all the files it needs. For the rest of this exercise it will be assumed you employ the first mode of working.

Figure 8 From within Simulink select the S-Function block (Figure 8) and add it to the display area, then set the parameters as shown in Figure 9. The name of the S-Function is skyhook_ i.e. the name of the system with an '_' added. This name must be entered in the first box. In the input box below this, two parameters must be entered. These are used to specify the characteristics of the AMESim result files.

12 www.cadfamily.com

EMail:cadserv21@hotmail.com

The document is for study only,if tort to your rights,please inform us,we will delete

MATLAB/Simulink interface 4.0 User Manual

Figure 9 With a normal AMESim run, a print interval is specified whereby the size of the results file can be controlled. Simulink runs in a somewhat different way and consequently the AMESim result files can become unacceptably large. To prevent this from occurring a special AMESim print interval is specified in the S-Function. The data added to the AMESim results file will be spaced with a time interval not less than this value. The first parameter indicates whether an AMESim results file is to be created. A value of 1 indicates it is to be created and any other number indicates it is not to be created. The second parameter indicates the special print interval. If a zero or negative value is entered, Simulink will add to the AMESim results file whenever it adds to its own results.

Add the values shown in Figure 9 so that there will be an AMESim results file but with a print interval restriction of 0.01 s. Complete the system as shown in Figure 10. Note that there are gain blocks, as well as summing junctions. The outputs from the S-Function are passed through the Demux block to form two kind of signals: The outputs from the AMESim model, labeled Bspeed and Wspeed. The signal which is passed to the Hit Crossing block.

If there are N outputs from the AMESim model, there will be N+1 outputs from the SFunction. The last output will always be connected to the Hit Crossing block.

www.cadfamily.com

EMail:cadserv21@hotmail.com

13

The document is for study only,if tort to your rights,please inform us,we will delete

Chapter 1 Using the AMESim MATLAB/Simulink Interface

Figure 10 Why is the extra output required? To understand why it is needed it is necessary to remember that the AMESim model probably contains discontinuities. AMESim has its method to deal with discontinuities and Simulink has, a different method that uses the Hit Crossing block. Since the model is run within Simulink, it must employ the Simulink method. The last output from the S-Function is a variable, which is normally positive but becomes negative near a discontinuity. When this happens the Hit Crossing block slows down the simulation greatly reducing the integration step. When the value goes positive again, the simulation can speed up. It is possible to omit the Hit Crossing block but simulation runs are likely to be less reliable and may take longer.

14 www.cadfamily.com

EMail:cadserv21@hotmail.com

The document is for study only,if tort to your rights,please inform us,we will delete

MATLAB/Simulink interface 4.0 User Manual

Important note:

If your AMESim model has more than one input coming from Simulink, the input signals to AMESim have their order reversed when compared to what is sent from Simulink. This is due to the fact that AMESim numbers the ports in counter-clockwise order while the Mux block in Simulink numbers them starting at the top. The output side of the interface block is not affected by this, since in that case the variables are numbered from the top in both softwares. This can be seen by comparing the model in AMESim and Simulink as shown in the figures below:

Next, set the simulation parameters to the values shown in Figure 11. Remember that
AMESim systems can be numerically stiff, this is particularly true for hydraulic and HCD

systems. This means that some of the time constants are very small and there can be very fast dynamics. For this reason, the only integration methods likely to succeed are the ones that are specially designed for this.

www.cadfamily.com

EMail:cadserv21@hotmail.com

15

The document is for study only,if tort to your rights,please inform us,we will delete

Chapter 1 Using the AMESim MATLAB/Simulink Interface

Figure 11 In Simulink it seems that both solvers for stiff systems are possible to use for AMESim models. In this particular case, use the ode15s (stiff/NDF) method (in older versions, Gear and Adams/Gear were the ones most suitable). Set the stop time to 5 seconds, this will be quite enough to produce some interesting results. Initiate the Simulink run and watch the output from the Scope block. This will give the input force supplied to the car suspension as shown in Figure 12.

Figure 12

16 www.cadfamily.com

EMail:cadserv21@hotmail.com

The document is for study only,if tort to your rights,please inform us,we will delete

MATLAB/Simulink interface 4.0 User Manual

Figure 13 Figure 13 shows the same quantity plotted within AMESim. If you chose to generate an AMESim result file, it is possible from within AMESim to access the full range of variables of the AMESim model. These can be plotted as from a normal AMESim simulation, Figure 14 shows the body and wheel displacements.

Figure 14

5.

Co-simulation interface
Two possibilities are offered to create an interface with Simulink: the standard interface and the co-simulation interface. Here we will explain what the differences are between the

www.cadfamily.com

EMail:cadserv21@hotmail.com

17

The document is for study only,if tort to your rights,please inform us,we will delete

Chapter 1 Using the AMESim MATLAB/Simulink Interface

two, and describe how to use the co-simulation interface.

5.1.

Introduction
The main difference between the two interfaces is that co-simulation interface uses two (or more) solvers, while the standard interface uses only one. This means that AMESim and Simulink use their own solver for the co-simulation interface whereas they both use the Simulink solver for the standard interface. Another difference is that with the standard interface the AMESim part is seen as a time continuous block in Simulink and in the cosimulation it is a time discrete block. Since the co-simulation block is seen as a discrete block it makes this interface very suitable for discrete controllers implemented in Simulink controlling an AMESim model. The figure below shows in more detail how the interfaces work. In the standard interface the AMESim part of the system gets state variables and input variables from Simulink and calculates state derivatives and output variables. The process of exchanging this information is controlled entirely by the Simulink solver. In this case one could say that we import the equations into Simulink. In the co-simulation case, the only exchanged variables are the input and output variables. The rate of exchange is in this case decided by a parameter that the user decides. As the name indicates the model is not entirely in the hands of one software (Simulink) but it is a co-operation between two (or more) software. It is important to realize that by exchanging only input and output variables at a certain sample rate there is a loss of information.
State derivatives AMESim subsystem Simulink subsystem+ solver

Output variables Input variables State variables Normal interface

AMESim subsystem+ solver

Output variables Input variables

Simulink subsystem+ solver

Co-simulation interface

Figure 15 The two AMESim-Simulink interfaces, exchange of information This can be compared with the difference between a continuous and a sampled controller. 18 www.cadfamily.com

EMail:cadserv21@hotmail.com

The document is for study only,if tort to your rights,please inform us,we will delete

MATLAB/Simulink interface 4.0 User Manual

Normally the smaller sample rate used the closer to the continuous result we get. Another possible problem is that the we loose information about possible cross couplings between the system since we do not communicate information about states and state derivatives. All these factors mean that co-simulation can be difficult to set up if the two separate systems are continuous. You should in that case try to find an interface between the systems where the coupling is as weak as possible. The obvious situation where co-simulation may be used is of course when the interface between the system is sampled, for instance when using a sampled controller.

5.2.

Usage of the co-simulation interface
We will reuse the AMESim system created earlier (Figure 1). Save the system as skyhookcosim. Now we add the interface block, the process is similar to when creating the standard Simulink interface, except that we select SimulCosim in the field labeled Type of interface instead of Simulink as shown below:

Go into Parameter mode and then Run mode. Next we create the Simulink system as shown in Figure 16. We use the same basic system as before with the difference that the name of the S-function is now skyhookcosim_. Another difference is that we do not use the "Hit Crossing" block. This means that we have the same number of outputs from the S-function as in the AMESim model (two in this case). Another difference is the number and type of parameters to the S-function.

www.cadfamily.com

EMail:cadserv21@hotmail.com

19

The document is for study only,if tort to your rights,please inform us,we will delete

Chapter 1 Using the AMESim MATLAB/Simulink Interface

Figure 16 Simulink model - Co-simulation Looking at the parameters for the S-function as shown in Figure 17 we see that we can send more than two parameters to the S-function. It is possible to give it only two parameters; in that case the other parameters will get default values.

Figure 17 The parameters to the S-function are shown in the table below. Note that if we want to set a value for the 4th parameter, it is necessary to give a value to all parameters before this one.

20 www.cadfamily.com

EMail:cadserv21@hotmail.com

The document is for study only,if tort to your rights,please inform us,we will delete

MATLAB/Simulink interface 4.0 User Manual

Parameter Sample time

Description Time between exchange of values between AMESim and Simulink As in AMESim

Default value

Required, no default value

AMESim communication interval Tolerance

Required, no default value

the same as in the AMESim run parameters popup the same as in the AMESim run parameters popup Helps DASSL to decide initialize the time step 0 or 1, 1 for displaying run statistics 0 or 1, 1 for extra discontinuity printouts 0 or 1, 1 for output of time on screen (not useful on PC)

1.0e-5

Max time step

1.0e20 s

Time range

100 s (do not change)

Show run statistics

1

Extra discontinuity points

0

Output details

0

The chosen sample time is on purpose chosen fairly large in this example to make it obvious what is happening. The displacement as seen from Simulink will then look as in Figure 18. Looking at the same variable in AMESim (Figure 19) we clearly see that the values seen in Simulink is sampled.

www.cadfamily.com

EMail:cadserv21@hotmail.com

21

The document is for study only,if tort to your rights,please inform us,we will delete

Chapter 1 Using the AMESim MATLAB/Simulink Interface

Figure 18 Displacement as seen in Simulink In the AMESim plot (Figure 19) we also see the effect of the sampling, the resulting body displacement is very poor. The input signal to the AMESim system is a time discrete signal as shown in Figure 20. This explains the differences seen between Figure 19 and Figure 21. By selecting a smaller sample time we could get a result more similar to the one we had with the standard interface. In Figure 21 and Figure 22 the sample time is set to 0.01s and the AMESim communication interval is also set to 0.01s.

Figure 19 Body displacement as seen in AMESim with a sample time 0.1s

22 www.cadfamily.com

EMail:cadserv21@hotmail.com

The document is for study only,if tort to your rights,please inform us,we will delete

MATLAB/Simulink interface 4.0 User Manual

Figure 20 Actual input to the AMESim model

Figure 21 Body displacement with a sample time of 0.01s

www.cadfamily.com

EMail:cadserv21@hotmail.com

23

The document is for study only,if tort to your rights,please inform us,we will delete

Chapter 1 Using the AMESim MATLAB/Simulink Interface

Figure 22 Actual input to the AMESim model using a sample interval of 0.01s

6.

Using more than one interface block

Remember that to do this all the blocks must be of the same type. Make sure you give each port a unique name. When the S-function is created, AMESim will concatenate all the inputs and concatenate all the outputs. To see how this is done, select Display interface status in the Interface menu. A dialog box (Figure 23) displays how the combined ports are arranged.

24 www.cadfamily.com

EMail:cadserv21@hotmail.com

The document is for study only,if tort to your rights,please inform us,we will delete

MATLAB/Simulink interface 4.0 User Manual

Figure 23

7.

Concluding remarks
This manual has presented a simple example to introduce the use of the Simulink interface. Before you start developing your own models, we now summarize the most important points: The input of the interface block in AMESim has its ports in reverse order compared with Simulink Remember to change from Parameters to Run mode in AMESim before running the simulation in Simulink For systems using the standard Simulink interface the following points are important: The AMESim model must be explicit i.e. there cannot be any implicit variables. The reason for this is that the Simulink integrators can handle only ordinary differential equations. Use the Hit crossings block in Simulink to ensure correct handling of discontinuities. Remember that the AMESim block is seen as a discrete block from Simulink. The parameters to the S-functions are as shown in the table in section 5.2.Usage of the co-simulation interface, and they are not the same as the parameters for the standard interface.



For systems using the co-simulation interface it is important to think of the following:

www.cadfamily.com

EMail:cadserv21@hotmail.com

25

The document is for study only,if tort to your rights,please inform us,we will delete

Chapter 1 Using the AMESim MATLAB/Simulink Interface

Important note:

Under some circumstances it is necessary to force Simulink to reload the AMESim model for each new simulation. To avoid any problem, it is recommended that this is done always. One way to achieve this is to clear the AMESim mex function from (Matlab) memory before starting a new simulation. This can be done in two ways, manually and automatically: The manual way is to type "clear mex" or "clear xxxx_" where xxxx is the AMESim system name. This needs to be done before each new simulation starts (or after each simulation). In Simulink version 2 and higher it is possible to specify a command to be executed after each simulation. Taking the Simulink system in Figure 10 as an example we can type:
set_param('skyhook/S-Function (AMESim system)','StopFcn','clear skyhook_')



at the Matlab command prompt. This makes Simulink unload the AMESim mex function after each simulation, and thus forcing it to be reloaded when a new simulation is run.

26 www.cadfamily.com

EMail:cadserv21@hotmail.com

The document is for study only,if tort to your rights,please inform us,we will delete

MATLAB/Simulink interface 4.0 User Manual

Reporting Bugs and using the Hotline Service
AMESim is a large piece of software containing many hundreds of thousands of lines of code. With software of this size it is inevitable that it contains some bugs. Naturally we hope you do not encounter any of these but if you use AMESim extensively at some stage, sooner or later, you may find a problem.

Bugs may occur in the pre- and post-processing facilities of AMESim, AMESet, AMECustom or in one of the interfaces with other software. Usually it is quite clear when you have encountered a bug of this type. Bugs can also occur when running a simulation of a model. Unfortunately it is not possible to say that, for any model, it is always possible to run a simulation. The integrators used in AMESim are robust but no integrator can claim to be perfectly reliable. From the view point of an integrator, models vary enormously in their difficulty. Usually when there is a problem it is because the equations being solved are badly conditioned. This means that the solution is ill-defined. It is possible to write down sets of equations that have no solution. In such circumstances it is not surprising that the integrator is unsuccessful. Other sets of equations have very clearly defined solutions. Between these extremes there is a whole spectrum of problems. Some of these will be the marginal problems for the integrator. If computers were able to do exact arithmetic with real numbers, these marginal problems would not create any difficulties. Unfortunately computers do real arithmetic to a limited accuracy and hence there will be times when the integrator will be forced to give up. Simulation is a skill which has to be learnt slowly. An experienced person will be aware that certain situations can create difficulties. Thus very small hydraulic volumes and very small masses subject to large forces can cause problems. The State count facility can be useful in identifying the cause of a slow simulation. An eigenvalue analysis can also be useful. The author remembers spending many hours trying to understand why a simulation failed. Eventually he discovered that he had mistyped a parameter. A hydraulic motor size had been entered making the unit about as big as an ocean liner! When this parameter was corrected, the simulation ran fine. It follows that you must spend some time investigating why a simulation runs slowly or fails completely. However, it is possible that you have discovered a bug in an AMESim submodel or utility. If this is the case, we would like to know about it. By reporting problems you can help us make the product better. On the next page is a form. When you wish to report a bug please photocopy this form and fill the copy. You telephone us, having the filled form in front of you means you have the information we need. Similarly include the information in an email. To report the bug you have three options: reproduce the same information as an email telephone the details fax the form

Use the fax number, telephone number or email address of your local distributor.

www.cadfamily.com

EMail:cadserv21@hotmail.com

The document is for study only,if tort to your rights,please inform us,we will delete

MATLAB/Simulink interface 4.0 User Manual

HOTLINE REPORT
Creation date: Company: Keywords (at least one):
Problem type: Bug Improvement Other

Created by: Contact:

Summary:

Description:

Involved operating system(s):
All Unix HP IBM SGI SUN Other: PC (all) Windows 2000 Windows NT Windows XP Linux Other:

Involved software version(s):
All AMESim (all) AMESim 3.0 AMESim 3.0.1 AMESim 3.5 AMESim 4.0 AMERun (all) AMERun 3.0 AMERun 3.5 AMERun 4.0 AMESet (all) AMESet 3.5 AMESet 4.0 AMECustom 4.0

www.cadfamily.com

EMail:cadserv21@hotmail.com

The document is for study only,if tort to your rights,please inform us,we will delete

MATLAB/Simulink interface 4.0 User Manual

Web Site
http://www.amesim.com FRANCE - UK (Auto) - ITALY - SWITZERLAND SPAIN - BENELUX - SCANDINAVIA

S.A.
5, rue Brison 42300 ROANNE - FRANCE Tel. : (33) 4-77-23-60-37 Fax : (33) 4-77-23-60-31 E.Mail : hotline@amesim.com

USA - CANADA - MEXICO

Software, Inc.
44191 Plymouth Oaks Blvd – Suite 300 PLYMOUTH (MI) 48170 - USA Tel. : (1) 734-207-5557 Fax : (1) 734-207-5556 E.Mail : imagine-us@amesim.com

GERMANY - AUSTRIA

Software GmbH
Technopark Argelsrieder Feld 13 D-82234 WEbLING - DEUTSCHLAND Tel. : (49) 81 53 9288-17 Fax : (49) 81 53 9288-11 E.Mail : imagine-germany@amesim.com

UNITED KINGDOM (All applications except Automotive)

Qinetiq
Systems integration Rm 163 Bldg A22 Qinetiq Winfrith Winfrith Technology Center DORCHESTER, Dorset, DT2 8XJ - UNITED KINGDOM Tel. : (44) (01305) 212120 Fax : (44) (01305) 212113 E.Mail : rwcooke@qinetiq.com

JAPAN

RIKEI Corporation
AMESim Technical Center 1-26-2, Nishi-Shinjuku, Shinjuku-ku TOKYO 163-0535 - JAPAN Tel. : (81)-3-3345-2149 Fax : (81)-3-3345-2165 E.Mail : imagine-japan@amesim.com

www.cadfamily.com

EMail:cadserv21@hotmail.com

The document is for study only,if tort to your rights,please inform us,we will delete

SOUTH KOREA

SHINHO Systems Co., Ltd.
<137-131> Dongil B/D 7F, 2-12 Yangjae-Dong, Seocho-Gu SEOUL - SOUTH KOREA Tel. : (82)-2-579-0434 Fax : (82)-2-579-0439 E.Mail : iclee@shinho-systems.co.kr

BRAZIL

KEOHPS
CELTA – Parc Tec ALFA Rod. SC 401-km 01 – CEP 88030-000 FLORIANOPOLIS – SC BRAZIL Tel. : (55) 48 239 – 2281 Fax : (55) 48 239 – 2282 E.Mail : info@keohps.com

HUNGARY

Budapest University of Technology & Economics
Department of Fluid Mechanics H-1111 BUDAPEST, Bertalan L. U. 4- 6 HUNGARY Tel. : (36) 1 463 4072 / 463 2464 Fax : (36) 1 463 3464 E.Mail : vad@simba.ara.bme.hu

CHINA

United Right Technology
Room 716-717 North Office Tower Beijing, New World Center No.3-B Chong Wen MenWai dajie, Postal Code: 100062, BEIJING, P.R CHINA Tel: (86) 10-67082450(52)(53)(54) Fax: (86) 10-67082449 E.Mail: urt@urtgroup.com

www.cadfamily.com

EMail:cadserv21@hotmail.com

The document is for study only,if tort to your rights,please inform us,we will delete

赞助商链接
相关文章:
simulink与AMESim联合仿真
simulinkAMESim联合仿真_交通运输_工程科技_专业资料。较强可操作性 Simulink 与 AMSIM 联合仿真的方法虽然随着新材料、电机技术、控制学和先进制造技术等的发展,...
amesim、MatlaB联合仿真(最全面)接口设置
amesim、MatlaB联合仿真(最全面)接口设置_计算机软件及应用_IT/计算机_专业资料。...amesim 的安装目录 注意: 一定要检查系统变量添加的完全,我们看一下帮助文档...
amesim和simulink联合仿真%20设置[1]
2.2 联合仿真实现 AMESimSimulink联合仿真是通过 AMESim 中的界面菜单下的创建 输出图标功能与 Simulink 中的 S 函数实现连接的。 具体实现过程是在 ...
基于Simulink AMESim联合仿真
基于SimulinkAMESim 联合仿真作者:王鹏宇王庆年胡安平于远彬 摘要:本文对混合动力客车制动力分配系数 β 的确定进行分析。在并行再生制动系统基础 上,提出通过调节气压...
AMESim与MATLAB Simulink联合仿真技术及在发动机主动隔...
AMESim 与 MATLAB\Simulink 联合仿真技术及在发动机主动隔振中 的应用作者:肖勇 摘要:介绍了 AMESim 软件与 MATLAB\Simulink 的接口技术,并使用 AMESim 与 MATLAB...
AMEsim与Matlab_simulink联合仿真技术
9 0 AMES Matlab_S AMESim 与 Matlab_Simulink 联合仿真技术机械电子系 0802 班 李敏 M200870228 摘要: 摘要:根据 AMESim 与 Matlab/Simulink 软件各自的特点,...
论文基于AMESim与MatlabSimulink联合仿真技术的接口...
论文基于AMESim与MatlabSimulink联合仿真技术的接口..._信息与通信_工程科技_专业资料。营销策划论文:基于 AMESim 与 Matlab\Simulink 联合仿真技术的接口与应用研究 ...
AMESim R11和Simulink联合的方法
AMESim R11和Simulink联合的方法_数学_自然科学_专业资料。联合仿真1. 点击 amesim 2. 选择 tool 菜单中的 options——AMESim preferences。 3. 弹出 AMESim pr...
[分享]AMESim 8.0和Matlab联合仿真无法编译问题解决方案
AMESim 8.0 卸载, 安装 AMESim7.0, 破解后, 运行 7.0 提供的 simulink 联合仿真 demo, 可以正常编译, 但发现无法创建 simulink 接口, 即在接口创建界面,...
car与simulink联合仿真大总结
基于AMESim和Simulink的... 4页 免费 汽车级Simulink建模与仿... 46页 1下载...分享】 分享】car 与 simulink 联合仿真大总结 一直困扰我的 acar 与 simulink...
更多相关标签: