Samcef For Machine Tools : Tutorial

63
Samcef For Machine Tools: Tutorial for the Advanced Package How to easily build a Box in Box Machine, perform several computations with different level of details, add digital controllers to control the motion and optimize the mechatronic structure. [u1]

Transcript of Samcef For Machine Tools : Tutorial

Page 1: Samcef For Machine Tools : Tutorial

Samcef For Machine Tools:

Tutorial for the Advanced

Package

How to easily build a Box in Box Machine, perform several computations with different level of details, add digital

controllers to control the motion and optimize the mechatronic structure.

[u1]

Page 2: Samcef For Machine Tools : Tutorial

To include a MATLAB/Simulink controller into Mecano and to use it, one must follow the

explanation of the above sections. One of the differences with respect to the above procedure

is, that now a MATLAB/Simulink specific interface routine is needed. This interface routine will

replace the main program created by RTW, and is given in the user library:

If the user has MATLAB/Simulink/RTW release 12 (MCBX00).

If the user has MATLAB/Simulink/RTW release 13 (MCBX00).

If the user has MATLAB/Simulink/RTW release 14 to release R2008b (MCBX00).

1 Comments

2 Introduction

This document is designed to go further in non linear behavior of a Box in Box Machine Tool

by using flexible screw and linear motor. Digital controlling will also be used to show how

externally defined digital controllers (by using Simulink/Matlab) can be included in a

SAMCEF Mecano user module. Once this controller is available for analysis, we will include

it into the Box in Box model to drive and control the flexible screw. Finally, this tutorial will

demonstrate how this complex mechatronic machine can be optimized by using BOSS

Quattro. Two kind of optimization can be achieved :

we will first optimize the structural characteristics of the machine to enhance its static and

dynamic behavior,

after that, we will optimize the controller‟s gains in order to make the tool follow a prescribed

curve.

NB: You must have finished the standard tutorial to fully understand the current one. Some

details will be omitted to focus mainly on new notions. The starting model is the complete

non linear flexible model obtained at the end of the Standard tutorial where everything is

flexible and motion is controlled by 3 flexible screws along X, Y and Z.

3 Introducing the flexible screw (direction y)

4 Introducing the linear motor (direction x)

5 Create a linearized model for external computation and control (in Matlab/Simulink)

The principle of linearization is to perform a non linear analysis (MECANO) and to stop the

process at a given intermediate time. At this equilibrium point in time, we will make a Guyan

reduction of the model by using DYNAM. This can be done by generating a superelement and

thus the reduced Mass, Stiffness and Damping matrices of the system. The only retained

degrees of freedom will be those that are necessary to “plug” the controller on the complete

machine. In our case, as the controllers will be applied on the flexible screws, we only retain

the third node of the flexible screw elements and one node on the top surface of the Ram_Z

tool (see figure below).

CSM
高亮
Page 3: Samcef For Machine Tools : Tutorial

First, open the “Final_All_OK.sfield” file in Sfield

Select the “Solver” context by clicking on icon.

Verify that the analysis driver ( ) is “implicit non linear”.

Under „Solver Data‟ (in the Data Tree), edit the Epilog and remove the five RETURN lines to

execute the following lines (already present at the end of the Epilog):

! Parameters/commands for model linearization

.sub I 1

! Save elements matrices

ldyn 1

!

.algo

depfix 0

! Definition of super-element interface

.ret

I (/Point_1_Ram_Z) ! First input (Ram_Z)

! output (imposed force on hinge/screw X)

I (/Hinge_on_Point_ScX_lf+vertex_of_ScrewX)

! output (imposed force on hinge/screw Y)

I (/Hinge_on_Point_ScY_up+vertexof_ScrewY)

! output (imposed force on hinge/screw Z)

I (/Hinge_on_Point_ScZ_back+vertexof_ScrewZ)

.csup

ret

dynamic composant nval 10

! Dynam parameters

.sam

nalg 4

nval 30

! Skip element generation

inst 2

npr 1

Tell SAMCEF Field to generate the bank by clicking on „Convert‟ . Choose

Final_lin.dat as model name and change time interval from [0,1] to [0,0.4].

For Samcef versions prior to 10.1-02 : Once, your bank has been generated, you must edit it

to remove the line „KINI 1‟ in first .SUB I1 (this option isn‟t compatible with super-element

creation).

As SAMCEF Field can‟t chain analyses, you must launch the following sequence outside of

SAMCEF Field :

1) Dynamic : MECANO to compute the transient point where the model is linearized

Page 4: Samcef For Machine Tools : Tutorial

2) Modal analysis: DYNAM to generate the linearized model (.u18).

a) To do so, the SAMCEF command to generate linearized model is :

%SAM_EXE%\samcef.cmd ba,me,ba,dy Final_lin o 1 (*) (Banque : Final_lin.dat) (Entry : no specific entry)

For each BACON launched, you have to play the bank : File/Import/Bank File ‘enter’ two times and select Final_lin.dat press OK File/Export->computation Press OK Quit b) A more automatic way to launch analyses, is to create a file called bacon.ini containing : .MENU OFF mode echo 0 input 12 .fin 1 and to set an environment variable (SAM_HOME) to the directory containing this newly

created file. After that, you can type the launching command (*) c) Another way to launch analyses, is to use the given BOSS Quattro session lin.b4O - first launch BOSS and select your working directory and the lin.b4o file. Click on ‘Open’ - Once BOSS has started and lin.b4o has loaded, you should have the following picture

Page 5: Samcef For Machine Tools : Tutorial

- click on the red rocket to launch the linearization - At the end of the process, MATLAB is launched in order to import the reduced matrices

created by the MECANO/DYNAM computation as described in the next section.

6 Use of MATLAB to produce space-state matrices

MATLAB will be used to „import‟ the super-element just created. When a super element has

been created, it can be read into Matlab/Simulink using the samcef_read.m[u2] script

supplied. The use of this script is straight forward, and described in the m-file itself. The Mass,

Damping and Stiffness matrix of the super element will be read, together with a localization

vector, which contains a coded number (100*External_Node_number +

10*Component_number) per degree of freedom. The values in the localization vector will be

negative if the dof's have no values applied to them, and if Compacting = 'no'. If Compacting

= 'yes' the non-used degrees of freedom will be removed from the system. The user should

copy the m-file in the directory containing the problem_name_dy.u18. He must then launch

MATLAB from this directory or change to this directory inside MATLAB. To read the super-

element the user should type on the MATLAB prompt :

>> [MM,CC,KK,Local,Nmode,Phi,Iselar] = Samcef_read('Lin_model','dynamic', 'yes');

to import the dynamic super-element. The Phi matrix contains the transformation matrix

between the external (pre-selected at super element creation) degrees of freedom, and the

internal degrees of freedom (see super element theory page). The Iselar vector contains the

external degree of freedom identifiers (for Phi), which are coded the same way as the Local

vector.

CSM
文本方块
samcef_read-m003.m
Page 6: Samcef For Machine Tools : Tutorial

The MATLAB file Before_stsp.mat contains a copy of the MATLAB memory at this stage of

the process. Now we have imported Mass, Stiffness and Damping matrices, we will transform

these into a space-state model by using the second script supplied (to be copied in the current

directory) samcef_stsp.m.

The linearization made in Dynam implies that the Damping (CC) matrix is empty. One would

want to add some damping before creating space-state matrices in Matlab.

The user must type Local at the command prompt to look at the available dof‟s to be used as

input and output vectors.

The state-space format is the format used for controller design. When transforming the mass,

damping and stiffness matrix into the [A,B,C,D] state space form it is important to remove the

fixations from the super element. To do all this, the user must type:

>> [A,B,C,D] = Samcef_stsp(MM,CC,KK,Local,Fixation,Input,Output);

where three additional vectors must be defined, those define the boundary conditions of the

state space model (using a similar coding as for the Local vector):

Fixation(i) : Fixation number i is defined as :

100*Node_number + 10*Component_number + 0

Input(j) : force number j is applied to :

100*Node_number + 10*Component_number + 0

Output(k) : output number k is :

100*Node_number + 10*Component_number + 1*Type_number

With

Type_number = 1: Force

RamZ

Fixed Part SliderX

228

0

SliderY

220

6

191

7

224

7

Page 7: Samcef For Machine Tools : Tutorial

Type_number = 6: displacement

Type_number = 7: Velocity

Type_number = 8: Acceleration

In this case, no fixation has to be applied on the retained nodes so the Fixation vector is empty

(but must be assigned : Fixation=[]). The input and output vectors must be seen from the

super-element point of view. This means that super-element nodes that will be connected to

the controller must appear in the output vector !

In this case, the Local vector is :

Local =

Columns 1 through 6

191710 191720 191730 191740 191750 191760

Columns 7 through 12

220610 224710 228010 228110 228120 228130

Columns 13 through 18

228140 228150 228160 228210 228220 228230

Column 19

228240

The Input vector will be :

Input = [220610 224720 228030]

which means that 1st component of nodes 2206, 2247 and 2280 can be used as input to the

super-element. These represent the third nodes of the hinges used to pilot the screws in the 3

directions

And the Output vector :

Output =

Columns 1 through 6

191716 191726 191736 191746 191756 191766

Columns 7 through 12

191717 191727 191737 191747 191757 191767

Columns 13 through 18

191718 191728 191738 191748 191758 191768

Page 8: Samcef For Machine Tools : Tutorial

which means that all components (5th

digit) of node 1917 (4 first digits) can be used as output

to the super-element in terms of displacements (last digit=6), velocities (last digit=7) and

accelerations (last digit=8).

Now that space-state matrices (A, B, C and D) have been calculated, all the necessary

information needed for controller selection and linear simulation in Matlab/Simulink is

available.

7 Creation of User Mecano Module containing a controller

The matrices produced in the chapter 3 will be used for Controller Design. This part is not

described in detail here because it implies several not known programs (SchemeBuilder and

Simulink). Let‟s say we have a description of the „best‟ controller for our problem coming

from these programs. This chapter describes how to compile and link a new User Mecano

Module containing this controller.

Let‟s first rehearse how Mecano deals with controllers :

7.1 Utilization of a controller in Mecano

The definition of the sensor vector and command vector is given in the Bacon bank file. The

description of control boxes is given by .MCE DIGI element. The input data of the DIGI

element must be coherent with the definition in the user routines. This means that the number

of sensors and the number of commands must be the same, as well as the order used in both

the Simulink model and the commands. For example the first input variable in the Simulink

model must also be the first input variable defined in .MCC DIGI. A typical definition of the

digital controller element is given below:

.MCE I Element_number DIGI N Node_list

.MCC I Element_number DIGI CBOX Numbox

TACT T1 T2

CONS Id1 Id2 Id3

NF Func1

CINP List_of_input_codes

COUT List_of_output_codes

The Numbox variable above is the same one as the one defined in the MCBOXX routine

described hereafter. For a more detailed discussion on the .MCE DIGI element the user is

referred to the appropriate element page.

Remarks : Note also that user control is active only between activation (T1) and deactivation

time (T2).

CINP 116

117

COUT 111

CSM
文本方块
例子 .MCE I 3 DIGI N 2 .MCC I 3 DIGI CBOX 5 TACT 0.5 2.2 CONS (/M) (/C) (/K) (/KV) (/KP) NF (/Nfd) (/Nfv) (/Nfa) CINP 116 117 COUT 111
Page 9: Samcef For Machine Tools : Tutorial

7.2 Compiling and linking User Mecano

The user has to build a new MECANO module (see standard link procedure) with the

following routines:

- a switch routine to different control boxes

- control routines

1. The switch routine MCBOXX (located in the mcboxx.f file) [u3]has the following form:

Figure 1: Switch routine

It must be edited to change the numbers associated to the different controllers (NUMBOX).

2. The controller will be exported (using Real Time WorkShop from MathWorks) to a C code

routine. When doing this, RTW will produce a main routine that must be replaced by the

mcbxij_tpl.c interface routine (MATLAB/Simulink/RTW release 12). The way to export a controller

from Simulink is explained hereafter :

When a controller (e.g. : suspens.mdl) has been designed, it can be exported with Real Time

Workshop into a standard C program. RTW will then create the following:

A separate directory, specific to the controller.

source and header files.

the object files plus a "makefile"

an executable that is the stand-alone controller.

Page 10: Samcef For Machine Tools : Tutorial

The R(eal) T(ime) W(orkshop) options that should be used are given below:

The only default values that must be changed are :

in “Solver” options, Type must be changed from DISCRETE (no continuous states) to ode4

(RUNGE-KUTTA).

in “Workspace I/O”, check the States box in Save to workspace area.

in “Real-Time Workshop”, change System target file from grt.tlc to grt_malloc.tlc and

Template makefile from grt_default_tmf to grt_malloc_default_tmf.

After modifying these options, build your model. Several files are then created in a directory

called CURDIR\suspens_grt_malloc_rtw.

To link the controller with Mecano we now have to do the following:

Change to the directory where the MATLAB/Simulink controller is generated.

Copy mae.c file to the current directory.

Copy the interface routine mcbxij_tpl.c and rename it to what you want (e.g. user01.c).

Page 11: Samcef For Machine Tools : Tutorial

Edit user01.c and replace void MCBXIJ_TPL by void USER01

Edit the suspens.mk file and add: USER_SRCS = user01.c mae.c

Add the following compiler options to the variable OPTS = /Gz:

Launch the makefile too compile the interface routine (suspens.bat).

Remove the object file of the main program created by RTW (grt_malloc_main.obj)

Copy all .obj files in the “muser” directory of your Samcef installation

Copy also the mcboxx.f in the “muser” directory.

Open a command prompt window, go to the “muser” directory and type

linkuser.bat mecano

Copy the just created User Mecano Module from “muser\Exe” directory to your

official %SAM_EXE% directory (be sure to save the original one).

Some remarks :

different control boxes must have different names.

The "inputs" and "outputs" of the Simulink model must be of the type "Inport" and "Outport"

respectively, and not of the type "signal" (linear, sinusoidal,....).

It is both possible to use multiple controllers, and to use multiple times the same (source code)

controller.

The time steps are automatically managed by Mecano, e.g. the time step will depend on the

maximum time step of Mecano and on the sample rate of the controllers.

The user must either use discrete operators or the user can define a sample time on the input

signal, thus digitizing the controller. Because a digital controller will use constant entries

between two sample times, the output will only be changed at the sample time of the

controller.

This last point is important when using controllers that use not only positions, but also speeds

or accelerations as inputs. In that case the user should be aware that speeds and accelerations

couldn‟t be obtained from differentiating the position inside a control box. This occurs

because between sample times the input is assumed constant. In this case the user must read

the speed and acceleration directly from Mecano.

8 Using external digital controllers into SAMCEF Field

The digital controller chosen is a modified PID classical controller designed in

Matlab/Simulink and exported and linked into SAMCEF Mecano.

Administrator
文本高亮工具
Page 12: Samcef For Machine Tools : Tutorial

As the digital controller selection box isn‟t yet available in SAMCEF Field, we must use the

Epilog section to use this controller. We first must define reference (prescribed) functions in

term of displacement and velocities. These functions will be used as entry 6 and 7 for the

controller

.FCT

CREE FONCTION I (/NUMBERMAXFUNCTION+2)

CREE VALEURS Y U

BORNES 0 1

ANALYTIQUE "150*(SIN(6.28*$U))"

CREE

EXTRAIT (/NUMBERMAXFUNCTION+2) FCT (/NUMBERMAXFUNCTION+102)

DISCRET 100.

DERIV (/NUMBERMAXFUNCTION+102) FCT (/NUMBERMAXFUNCTION+102)

FUSION (/NUMBERMAXFUNCTION+102) FCT (/NUMBERMAXFUNCTION+102)

CREE

We can now define the controller itself.

!! Digital controller for Y-axis

Administrator
文本高亮工具
Page 13: Samcef For Machine Tools : Tutorial

.MCE I (/NUMBERMAXELEMENT+23) DIGI N (/Point_1_Ram_Z ) (/Point_2_Ram_Z )

$

(/Point_3_Ram_Z ) (/Point_4_Ram_Z ) (/Hinge_on_Point_ScY_up+vertexof_ScrewY )

.MCC I (/NUMBERMAXELEMENT+23) DIGI CBOX 3

TACT 0.

CONS (/Py_Gain) (/Iy_Gain) (/Dy_Gain) (/FF_Gain) (/Axis_Inertia)

NF (/NUMBERMAXFUNCTION+2) (/NUMBERMAXFUNCTION+102)

CINP 126 226 326 426 127 227 327 427

COUT 511

.sai archive styp 914 $

node i (/Hinge_on_Point_ScY_up+vertexof_ScrewY ) $

comp 1 2 4 5

The first line (.MCE) define the connectivity of the element. It‟s of type DIGI and acts on 5

points (4 inputs and 1 output from the controller point of view). The first four points

corresponds to entries 8, 9, 10 and 11. the fifth one correspond to out1.

The second line defines the characteristics of the controller :

CBOX 3 : the digital controller has been compiled into MECANO with number 3

TACT 0. : in our case, the controller is activated at the beginning of the motion

CONS …. : these 5 values represent the „constants‟ of the controller. These are the parameters

that will be used to tune the controller behavior. They correspond to entries 1, 2, 3, 4 and 5 on

the controller schema.

NF .. .. : these are the prescribed functions (called „consign‟). They correspond to entries 6

and 7 on the controller schema.

CINP … : The eight values represent entries 8 to 15 on the controller schema. Each value is

composed of 3 digits :

The first one identify the position on the MCE command (1 means the node

(/Point_1_Ram_Z ))

The second one represent the degree of freedom (1 for X, 2 for Y and 3 for Z)

The third and last represent the nature (6=displacement, 7=velocity, 8=acceleration)

In our case, the inputs are the four displacements and the four velocities in the Y direction.

COUT .. : The value is associated with the out1 box on the controller schema. The value is

again composed of 3 digits :

The first one identify the position on the MCE command (5 means the node

(/Hinge_on_Point_ScY_up+vertexof_ScrewY))

The second one represent the degree of freedom (1 because it‟s the only component of a

hinge‟s third node)

The third and last represent the nature (1=force)

We repeat the same procedure to the 2 other axes (X and Z). Now we have a complete

machine tool with 3 digital controllers included. To complete the model, we must define some

values for the controllers‟ constants (gains). They are introduced in the Notebook in order to

be selected as design variables for the controller tuning (made in BOSS Quattro).

9 BOSS Quattro : Structural optimization

This section will be described later

Administrator
文本高亮工具
Administrator
文本高亮工具
Page 14: Samcef For Machine Tools : Tutorial

10 BOSS Quattro : Controller tuning

Now that we have a complete mechatronics Machine tool, we will try to optimize the

controllers gains in order to make the tool follow prescribed trajectories. To do that, we have

to use another SAMCEF tool: BOSS Quattro.

BOSS Quattro is a task manager and a multi-disciplinary optimization software. The user has

to define what will be optimized and which variables will be modified to reach this goal. In

our case, the „objective function‟ will be the distance between a prescribed curve and the

trajectory followed by a point on the Machine Tool. The „design variables‟ will be the 3

controllers gains P, I and D.

10.1 Parametric study to find the D gain

Controller tuning follows some rules that are valid for linear tuning. In our case, where non

linear effects are present, we will follow the same method. These rules introduce several

notions that won‟t be described in this document. What we have to know is that we must first

find a reasonable value for the speed proportional gain D. To do so, we impose to the system

a step signal (in term of speed) as consign and we try to find the best D value that leads a

maximum overshoot of 20%. The process must also be stable (no more oscillation) after

maximum 1.5 pseudo oscillation.

To achieve this task, we use the Parametric engine of BOSS Quattro. This operation is

repeated for the 3 directions (3 independent controllers).

Normally, the parametric study should be done on the SAMCEF Field model. In our case, as

the parameters have no influence on the geometry, the data associated to Machine parts, the

mesh and so on (their influence is limited to the Epilog section). The methodology is, then, to

create the bacon data file only 1 time and to use this file for parametric study and optimization.

This process enhances also the performance (in term of speed) of the parametric and

optimization studies.

Page 15: Samcef For Machine Tools : Tutorial

10.1.1 START BOSS QUATTRO

Type: boss

And the Main Window will appear

10.1.2 CREATE A NEW STUDY

11

Tasks

Message Area

Scripts and

Engines

Page 16: Samcef For Machine Tools : Tutorial

11.1.1 ACCESS THE MODELS

Open the Models window

Open the file selection box

Select the Family "SAMCEF"

(should be the default choice)

Select the model

"Comau3axes_final_modifie.dat"

Select the Family “Samcef/Field”

Select the model

"Comau3axes_final_modifie.sfield"

11.1.2 READ THE VARIABLES FROM THE SAMCEF MODEL

1. Open the variable importation box

Page 17: Samcef For Machine Tools : Tutorial

2. Select model…

3. Click on “Import all Variables …”

4. Verify the operation

by launching the variable window

Page 18: Samcef For Machine Tools : Tutorial

11.1.3 CREATE THE TASK TREE

Create the structure that is : a SAMCEF Field launching to create the BACON bank file,

followed by a Parametric tool (First task) on SAMCEF model analyzed with one

SAMCEF/Mecano sub-task (Non linear Analysis, without sensitivities computation).

Click on Parametric engine with Mb1, and “drop” it in the “tasks” window by clicking on

Mb2

Repeat the operation for Mecano and SamcefField tasks

Now create the links : click on bottom anchor of the Parametric box with Mb2 and drag to

the top anchor of Mecano box, release Mb2. If you missed the top anchor, a second Mecano

box should have appeared. Delete it by clicking on

Page 19: Samcef For Machine Tools : Tutorial

11.1.4 EXECUTE THE MECANO ANALYSIS AND SELECT THE RESULTS

To be able to import displacements within Boss/Quattro, we must first run the analysis.

Double-Click on the Mecano box ... (or click on )

Select the Results driver with toggle button and verify type is "Samcef" (should be selected

by default).

The results are obtained in 4 steps:

Step 1: Execute the Mecano analysis

Step 2: Read the available results

1 2 3 4

Page 20: Samcef For Machine Tools : Tutorial

Step 3: Select and Import the needed results

Here we select: - the Nature : Time dependant Displacement

- the Transformation : 1st Composante

- the Location : Node 8343 (Measured on top of Ram_Z)

- the Selection : All time steps

Select [Code 9163] Displacement /Comp.1 / Node 8343 / All / All values , and register as

"Displ_8343".

Repeat the same procedure for Node 9339.

Step 4: Read the values

11.1.5 PARAMETRIC : PROBLEM SETTINGS

Open the Parametric window by double-clicking on it and select the variables you want to

work with. Select them all then accept.

Page 21: Samcef For Machine Tools : Tutorial
Page 22: Samcef For Machine Tools : Tutorial

Note that you have to change the Min, Max and Step value for each Parameter. As these 3

parameters are independent (3 different directions), you can choose “Serial” mode.

Apply the same procedure for the functions (the objectives).

After that, create 2 parsed functions :

lsd = least square distance between the displacement of the Ram_Z node and the reference

(prescribed) one for each time step

in = signed difference of the two mentioned nodes displacements. The Ram_Z trajectory must

always lie UNDER the reference one

11.1.6 PARAMETRIC : RUN ANALYSES

1. CHECK SETTINGS

2. RUN ANALYSES

You can either check the settings or run analyses. Of course, if you run analyses, settings are

automatically checked before the computation.

Run the analyses. The choice of the optimal values for the 3 gains is deduced from the values

of the objective functions.

Page 23: Samcef For Machine Tools : Tutorial

11.2 Optimization studies to find the controller’s gains

Now that we have made a parametric study, we will use the found values (D_Gain, Dy_Gain

and Dx_Gain) as a starting point for 3 optimizations. Again, as each controller is independent

from the others, we have in fact three triplets of variables : P, I and D in each direction.

The BOSS Quattro session is built like the Parametric one except that we choose more design

variables and we define more objective functions and constraints.

11.2.1 Results for optimization of the Z controller

opt_mod_sin - Optimization report

Report date: Thu Jun 24 17:07:00 2004

11.2.2 Settings: Type of study Optimization

Algorithm GCM

Page 24: Samcef For Machine Tools : Tutorial

Convergence

Precision 0.01

Convergence Criteria Variation on variables -

Global perturbation 0.001 (based on current value)

Move limit No limit

Scaling of Variables By individual factor

Scaling of Functions Only when Mono-Objective

Check Check Standard

Switch Switch On

Listing Delete

Moving Variables

Bounds Full Range

External Relaxation Relaxation Disabled

Cut Cut=10

Degressive

Relaxation DRelax Inactive

11.2.3 Variables:

Name Lower

bound

Initial

value

Iteration

17

Upper

bound

_P_GAIN 1 10 80.6149 100

_D_GAIN 200000 300000 500000 500000

_I_GAIN 1 5 1 50

Page 25: Samcef For Machine Tools : Tutorial

11.2.4 Functions:

Name Objectif Initial

value

Iteration

17

Target

value Variation

lsz Minimize 1871.37 19.0921 0.0001 -98%

11.2.5 Constraints:

Name Lower

bound Initial value Iteration 17

Upper

bound

inz 0.01 -6.90433 ... -0.759583 ... *****

Page 26: Samcef For Machine Tools : Tutorial

5.39032 0.988479

11.2.6

11.2.7

The following pictures show the comparison of the prescribed and real trajectories in terms of

displacement and velocity.

Page 27: Samcef For Machine Tools : Tutorial

At the beginning (before the optimization) :

Page 28: Samcef For Machine Tools : Tutorial

At the end (after the optimization) :

Page 29: Samcef For Machine Tools : Tutorial

11.2.8 Results for optimization of the Y controller

12 opt_mod_sin_y - Optimization report

Report date: Thu Jun 24 17:26:33 2004

12.1.1 Settings: Type of study Optimization

Algorithm GCM

Convergence

Precision 0.01

Convergence Criteria Variation on objective functions -

Global perturbation 0.001 (based on current value)

Move limit No limit

Scaling of Variables By individual factor

Scaling of Functions Only when Mono-Objective

Check Check Standard

Switch Switch On

Listing Delete

Moving Variables

Bounds Full Range

External Relaxation Relaxation Disabled

Cut Cut=10

Degressive

Relaxation DRelax Inactive

12.1.2 Variables:

Name Lower

bound

Initial

value

Iteration

10

Upper

bound

_DY_GAIN 500000 1e+06 2e+06 2e+06

_PY_GAIN 1.5 15 50.4583 150

_IY_GAIN 1 10 10 40

Page 30: Samcef For Machine Tools : Tutorial
Page 31: Samcef For Machine Tools : Tutorial

12.1.3 Functions:

Name Objectif Initial

value

Iteration

10

Target

value Variation

lsy Minimize 1515.73 82.736 0.0001 -94%

12.1.4 Constraints:

Name Lower

bound Initial value Iteration 10

Upper

bound

iny 0.01 -5.05839 ...

7.39735

-2.49537 ...

3.27943 *****

Page 32: Samcef For Machine Tools : Tutorial

12.1.5

Page 33: Samcef For Machine Tools : Tutorial

12.1.6

12.1.7

The following pictures show the comparison of the prescribed and real trajectories in terms of

displacement and velocity.

Page 34: Samcef For Machine Tools : Tutorial

At the beginning (before the optimization) :

Page 35: Samcef For Machine Tools : Tutorial

At the end (after the optimization) :

Page 36: Samcef For Machine Tools : Tutorial

12.1.8 Results for optimization of the X controller

13 opt_mod_sin_x - Optimization report

Report date: Thu Jun 24 17:39:04 2004

13.1.1 Settings: Type of study Optimization

Algorithm GCM

Convergence

Precision 0.01

Convergence Criteria Variation on objective functions -

Global perturbation 0.001 (based on current value)

Move limit No limit

Scaling of Variables By individual factor

Scaling of Functions Only when Mono-Objective

Check Check Standard

Switch Switch On

Listing Delete

Moving Variables

Bounds Full Range

External Relaxation Relaxation Disabled

Cut Cut=10

Degressive

Relaxation DRelax Inactive

13.1.2 Variables:

Name Lower

bound Initial value

Iteration

12

Upper

bound

_DX_GAIN 1e+06 2.21025e+06 3e+06 3e+06

_PX_GAIN 2 44.7571 83.08 250

_IX_GAIN 1 20 19.9978 50

Page 37: Samcef For Machine Tools : Tutorial
Page 38: Samcef For Machine Tools : Tutorial

13.1.3 Functions:

Name Objectif Initial

value

Iteration

12

Target

value Variation

lsx Minimize 151.368 28.9124 0.0001 -80%

13.1.4 Constraints:

Name Lower

bound Initial value Iteration 12

Upper

bound

inx 0.01 -1.85326 ...

2.35809

-1.03103 ...

1.00841 *****

Page 39: Samcef For Machine Tools : Tutorial

13.1.5

13.1.6

The following pictures show the comparison of the prescribed and real trajectories in terms of

displacement and velocity.

Page 40: Samcef For Machine Tools : Tutorial

At the beginning (before the optimization) :

Page 41: Samcef For Machine Tools : Tutorial

At the end (after the optimization) :

Page 42: Samcef For Machine Tools : Tutorial

Finally, the following pictures show a circularity test : imposing a cosine displacement along

X and a sine along Y should lead to a circle trajectory. The red trajectory comes from the

prescribed curves along X and Y. The black one comes from the measured displacement of

the Ram_Z part of the Machine tool.

Page 43: Samcef For Machine Tools : Tutorial

Mcboxx.f 内容

SUBROUTINE MCBX00 (T,U,INIT,IDB,ITEST,Y,STATE,NBIN,NBOU,NBST) C

C Copyright SAMTECH - LTAS ............................. VERSION 13.1-03

C Responsable: "henrard" Librairies: Dev\"ME" Off\"ME" Date: 19-02-10

C

C Historique de la routine (creation,modification,correction)

C +--------------------------------------------------------------------+

C !Programmeur! Commentaires ! Date !Version!

C +-----------!---------------------------------------!--------!-------+

C ! apg ! CREATION !30-05-96! 7.0-10!

C ! TvE ! Updated version !31-05-02! 9.1-05!

C ! TvE ! Changed error messages !25-07-02! 9.1-05!

C ! TvE ! Control box identifier IDB !21-02-03!10.0-05!

C ! TvE ! Modified routine R12.1 V10.1 !29-04-04!10.1-05!

C ! Henrard ! Readded in SCM and copy to Ht/m000 !19-02-10!13.1-03!

C +--------------------------------------------------------------------+

C ! !

C ! FUNCTION OF ROUTINE: !

C ! !

C ! This file contains an example of a C-routine that acts as an !

C ! interface between MECANO and SIMULINK. This routine must be used !

C ! too replace the main program created by RTW. !

C ! !

C ! !

C ! LINK PROCEDURE MATLAB/SIMULINK - MECANO: !

C ! !

C ! Prerequisite: !

C ! !

C ! SAMCEF Mecano : Version 10.1-05 and higher !

C ! MATLAB/Simulink/RTW : Release 12.1 !

C ! !

C ! perform step 1 to 9 for compilation and linking: !

C ! --- ---------------------------------------------------------- --- !

C ! 1) Rename this FORTRAN file into a C file !

C ! cp mcbx00.f mcbxij.c !

C ! !

C ! --- ---------------------------------------------------------- --- !

C ! 2) Delete all FORTRAN lines in mcbxij.c !

C ! from SUBROUTINE... until 29001 FORMAT(...) !

C ! and last line END !

C ! !

C ! --- ---------------------------------------------------------- --- !

C ! 3) Remove comment cards "C " in mcbxij.c !

C ! !

C ! --- ---------------------------------------------------------- --- !

C ! 4) Choose a name for the interface routine in mcbxij.c !

C ! and rename: !

C ! void INTERFACE !

C ! into: !

C ! -> void mcbxij !

C ! or -> void mcbxij_ !

C ! (depending on the machine type) !

C ! or -> void MCBXIJ (for PC) !

C ! !

Page 44: Samcef For Machine Tools : Tutorial

C ! --- ---------------------------------------------------------- --- !

C ! 5) Move this file in the directory containing RTW sources and !

C ! object files of the controler. !

C ! !

C ! --- ---------------------------------------------------------- --- !

C ! 6) Compile the file mcbxij.c with the same compiler options !

C ! as used by MATLAB/SIMULINK for the controler. !

C ! !

C ! cc -O -std1 -ieee \ !

C ! -I. \ !

C ! -Imatlab_root/simulink/include \ !

C ! -Imatlab_root/extern/include \ !

C ! -Imatlab_root/rtw/c/src \ !

C ! -Imatlab_root/rtw/c/libsrc \ !

C ! -DMODEL=boxname \ !

C ! -DRT \ !

C ! -DNUMST=... \ !

C ! -DTID01EQ=... \ !

C ! -DNCSTATES=... \ !

C ! -DMT=... \ !

C ! -DHASESTDIO=... \ !

C ! -c mcbxij.c -o mcbxij.o !

C ! !

C ! where : + boxname is the matlab name of control box !

C ! + DRT,...DHASESTDIO are defined by in MATLAB !

C ! + matlab_root is the installation directory of MATLAB !

C ! !

C ! --- ---------------------------------------------------------- --- !

C ! 7) Write the switch to this routine in mcboxx.f !

C ! !

C ! SUBROUTINE MCBOXX (...) !

C ! ... !

C ! ELSEIF (NUMBOX.EQ. i) THEN !

C ! CALL MCBXij(...) !

C ! ELSE !

C ! ... !

C ! !

C ! --- ---------------------------------------------------------- --- !

C ! 8) compile mcboxx.f !

C ! !

C ! f77 -c -O mcboxx.f -o mcboxx.o !

C ! !

C ! --- ---------------------------------------------------------- --- !

C ! 9) link MECANO with !

C ! !

C ! mcboxx.o........created at point 8 !

C ! mcbxij.o........created at point 6 !

C ! boxname.o.......created by RTW in MATLAB !

C ! !

C ! Usage: samcef link mecano my_mecano *.o !

C ! !

C +--------------------------------------------------------------------+

C

C

IMPLICIT NONE

CSM
高亮
Page 45: Samcef For Machine Tools : Tutorial

C

INTEGER INIT,NBIN,NBOU,NBST,IDB,ITEST

DOUBLE PRECISION T,U(*),Y(*),STATE(*) C

INTEGER L09000 C

INTEGER LANGUE,IUWE,IUZZZ1,IAZZZ1,IEZZZ1

COMMON /SABIRS/ LANGUE,IUWE,IUZZZ1,IAZZZ1,IEZZZ1 C

IF (LANGUE.EQ.0) THEN

ASSIGN 19001 TO L09000

ELSE

ASSIGN 29001 TO L09000

ENDIF C

ITEST = 901

IEZZZ1= IEZZZ1 + 1

WRITE(IUWE,L09000) C

RETURN C

C

19001 FORMAT(/' %%%E01-MCBX00, BOITE DE CONTROLE NON

PROGRAMMEE'/) VFR-3

29001 FORMAT(/' %%%E01-MCBX00, CONTROL BOX HAS NOT BEEN

DEFINED'/) VAN-3

C

C --- Remove everything above and including this line ---

C #include <math.h>

C #include <stdio.h>

C #include <stdlib.h> /* For exit */

C #include <string.h>

C

C #include "tmwtypes.h"

C #include "simstruc.h"

C #include "rt_sim.h"

C #include "rtwlog.h"

C #include "rt_nonfinite.h"

C

C #ifndef PUBLIC

C # define PUBLIC

C # define PRIVATE static

C #endif

C

C /* =====Interface between MECANO and SIMULINK=========================

C *

C * Abstract:

C *

C * t..................time

C * u_mec[nb_inputs]...input vector

C * y_mec[nb_outputs]..output vector

C * x_mec[nb_states]...state variable vector

C * flag_mec...........0 -> initialisations

C * 1 -> integration

C * idb................controller identifier

C * itest..............return code (number of samples executed)

CSM
高亮
CSM
高亮
CSM
高亮
Page 46: Samcef For Machine Tools : Tutorial

C * nb_inputs..........number of inputs (avalaible when flag=0)

C * nb_outputs.........number of outputs (avalaible when flag=0)

C * nb_states..........number of state variables (aval. flag=0)

C *

C * This routine should be used as follows:

C *

C * -Initialisation :

C * ...

C * if (FIRST RUN) then

C *

C * CALL with t=0.

C * flag=0

C * will initialize the simulink structure

C * and return model characteristics (nb_inputs,...)

C *

C * else if (RESTART)

C *

C * CALL with t><0.

C * flag=0

C * u[*]=u_restart

C * x[*]=x_restart

C * y[*]=y_restart

C * will initialize the simulink structure

C * prepare data's for restart

C * and return model characteristics (nb_inputs,...)

C * ...

C *

C * -Loop on time

C * ...

C * CALL with t =current time

C * u[*]=inputs

C * flag=1

C * will return t =next sample time

C * y =outputs

C * x =state variables

C * itest=number of treated samples

C * ...

C */

C

C #ifndef TRUE

C #define FALSE (0)

C #define TRUE (1)

C #endif

C

C #ifndef EXIT_FAILURE

C #define EXIT_FAILURE 1

C #endif

C #ifndef EXIT_SUCCESS

C #define EXIT_SUCCESS 0

C #endif

C

C #define QUOTE1(name) #name

C #define QUOTE(name) QUOTE1(name) /* need to expand name */

C

C #ifndef RT

Page 47: Samcef For Machine Tools : Tutorial

C # error "must define RT"

C #endif

C

C #ifndef MODEL

C # error "must define MODEL"

C #endif

C

C #ifndef NUMST

C # error "must define number of sample times, NUMST"

C #endif

C

C #ifndef NCSTATES

C # error "must define NCSTATES"

C #endif

C

C #ifndef RT_MALLOC

C # error "mcbxij.c requires RT_MALLOC to be defined"

C #endif

C

C #ifndef RT_MEMORY_ALLOCATION_ERROR

C const char *RT_MEMORY_ALLOCATION_ERROR = "memory allocation error";

C #endif

C

C #ifndef SAVEFILE

C # define MATFILE2(file) #file ".mat"

C # define MATFILE1(file) MATFILE2(file)

C # define MATFILE MATFILE1(MODEL)

C #else

C # define MATFILE QUOTE(SAVEFILE)

C #endif

C

C #define RUN_FOREVER -1.0

C

C /*====================*

C * External functions *

C *====================*/

C

C extern SimStruct *MODEL(void);

C

C #if NCSTATES > 0

C extern void rt_CreateIntegrationData(SimStruct *S);

C extern void rt_UpdateContinuousStates(SimStruct *S);

C # if defined (RT_MALLOC)

C extern void rt_DestroyIntegrationData(SimStruct *S);

C # endif

C #else

C # define rt_CreateIntegrationData(S) ssSetSolverName(S,"FixedStepDiscrete");

C # define rt_UpdateContinuousStates(S) ssSetT(S,ssGetSolverStopTime(S));

C #endif

C

C

C static void rt_OneStep(SimStruct *S)

C {

C

C sfcnOutputs(S,0);

CSM
高亮
CSM
高亮
CSM
文本方块
估计是由Matlab RTW编译Simulink模型生成的 .c文件里面有
Page 48: Samcef For Machine Tools : Tutorial

C sfcnUpdate(S,0);

C rt_UpdateDiscreteTaskSampleHits(S);

C if (ssGetSampleTime(S,0) == CONTINUOUS_SAMPLE_TIME) {

C rt_UpdateContinuousStates(S);

C }

C } /* end rtOneStep */

C

C

C void mcbxij_

C (t,u_mec,flag_mec,idbs,itest,

C y_mec,x_mec,nb_inputs,nb_outputs,nb_states)

C

C double *t, *u_mec, *y_mec, *x_mec;

C int *flag_mec, *itest, *idbs, *nb_inputs, *nb_outputs, *nb_states;

C {

C static SimStruct *S[50];

C const char *status;

C real_T finaltime = -2.0;

C static int num_sample_times;

C static int i;

C static double *u;

C static double intg_stop_time;

C static double *x;

C static double *y;

C static int flag;

C static int idb;

C static double t_restart;

C

C *itest = 0;

C flag = *flag_mec;

C idb = *idbs;

C t_restart = 0.;

C

C if (flag==0) {

C

C /* 1. Creation and initialisation of the structure*/

C

C /* Initialize the model */

C

C rt_InitInfAndNaN(sizeof(real_T));

C

C S[idb] = MODEL();

C

C if (ssGetErrorStatus(S[idb]) != NULL) {

C (void)fprintf(stderr,"Error during model registration: %s\n",ssGetErrorStatus(S[idb]));

C exit(EXIT_FAILURE);

C }

C if (finaltime >= 0.0 || finaltime == RUN_FOREVER) ssSetTFinal(S[idb],finaltime);

C sfcnInitializeSizes(S[idb]);

C sfcnInitializeSampleTimes(S[idb]);

C

C if ((status=rt_InitTimingEngine(S[idb])) != NULL) {

C (void)fprintf(stderr,"Failed to initialize sample time engine: %s\n", status);

C exit(EXIT_FAILURE);

C }

CSM
高亮
CSM
高亮
CSM
文本方块
在boxname.o文件里面需要提供该方法
Page 49: Samcef For Machine Tools : Tutorial

C rt_CreateIntegrationData(S[idb]);

C num_sample_times = ssGetNumSampleTimes(S[idb]);

C sfcnStart(S[idb]);

C

C /* Get adresses of Input, State and Output vectors */

C

C u = ssGetU(S[idb]);

C x = ssGetX(S[idb]);

C y = ssGetY(S[idb]);

C

C intg_stop_time = 0;

C

C *nb_inputs = ssGetNumInputs(S[idb]);

C *nb_outputs = ssGetNumOutputs(S[idb]);

C *nb_states = ssGetNumTotalStates(S[idb]);

C

C /* Prepare for restart */

C

C if (*t > 0.0) {

C

C while (t_restart < *t) {

C t_restart = rt_GetNextSampleHit(S[idb]);

C ssSetSolverStopTime(S[idb],t_restart);

C rt_OneStep(S[idb]);

C }

C for (i = 0; i < ssGetNumTotalStates(S[idb]); i++) {

C x[i] = x_mec[i];

C }

C for (i = 0; i < ssGetNumOutputs(S[idb]); i++) {

C y[i] = y_mec[i];

C }

C ssSetT(S[idb],t_restart);

C }

C return;

C }

C

C /* 2. Time integration */

C

C /* Get adresses of Input, State and Output vectors */

C

C u = ssGetU(S[idb]);

C x = ssGetX(S[idb]);

C y = ssGetY(S[idb]);

C

C while (ssGetT(S[idb]) <= *t) {

C *itest = *itest + 1;

C for (i = 0; i < ssGetNumInputs(S[idb]); i++) {

C u[i] = u_mec[i];

C }

C for (i = 0; i < ssGetNumTotalStates(S[idb]); i++) {

C x[i] = x_mec[i];

C }

C

C intg_stop_time = rt_GetNextSampleHit(S[idb]);

C ssSetSolverStopTime(S[idb], intg_stop_time);

Page 50: Samcef For Machine Tools : Tutorial

C while (ssGetT(S[idb]) < ssGetSolverStopTime(S[idb]) && ssGetT(S[idb]) < *t) {

C rt_OneStep(S[idb]);

C }

C if (ssGetT(S[idb]) == *t) {

C rt_OneStep(S[idb]);

C }

C }

C

C /* 3. Outputs */

C

C *t = ssGetT(S[idb]);

C *nb_inputs = ssGetNumInputs(S[idb]);

C *nb_outputs = ssGetNumOutputs(S[idb]);

C *nb_states = ssGetNumTotalStates(S[idb]);

C

C for (i = 0; i < ssGetNumOutputs(S[idb]); i++) {

C y_mec[i] = y[i];

C }

C for (i = 0; i < ssGetNumTotalStates(S[idb]); i++) {

C x_mec[i] = x[i];

C }

C return;

C }

C --- Remove everything below and including this line ---

C

END

Page 51: Samcef For Machine Tools : Tutorial

Digital Control Routines (Matlab/Simulink, User defined controllers)

This section describes only digital control, and how to incorporate digital controllers into

Mecano. If the user would like to design it's controller in Matlab/Simulink, before exporting it

to Mecano, the possibility exists to import a linearized Samcef model (in the form of a

Superelement) into MATLAB/Simulink. How to do this is described on Importing a

Superelement in MATLAB/Simulink page of the manual. Digital control boxes are defined by

user routines, and can be completely user defined routines or controllers exported by

MATLAB/Simulink).

General procedure for including a controller into Mecano

The flow chart is the following (figure 1). At the end of a converged time step, the software

gives a sensor vector to a user control routine. In function of the sensor vector (positions,

displacements, velocities and/or accelerations) and in function of a user state variable vector,

the user control routine has to return a command vector (forces, positions, displacements,

velocities and/or accelerations). The command vector is imposed at the next time step like a

boundary condition.

The software calls the user routine at any time and the user routine has to return the next

sample time in addition of command vector. Because of the command discontinuity, the user

must be aware that convergence difficulties may appear if the sample time and/or the

commands are not realistic.

Figure 1 : Flow chart

The user has to build a new MECANO module (see standard link procedure) with the

following routines:

-a switch routine to different control boxes

-control routines

The switch routine (MCBOXX) has the following form:

Page 52: Samcef For Machine Tools : Tutorial

An example of control routine with the associated data file is given in user library (MCBX01).

A control routine may be written not only by the user but also by a software like Simulink in

Matlab or Matrixx. Anyway such a routines must have the form as presented in figure 2.

Page 53: Samcef For Machine Tools : Tutorial

[u4][u5] Figure 2: Control routine

Remarks

Note that the next sampled time is taken into account only with automatic time

stepping. In addition it is a upper limit. In other words, the software interrogates user

routines with any time, but it respects times imposed by routine.

A pre-defined PID controler is available to the user.

CSM
矩形
CSM
矩形
Page 54: Samcef For Machine Tools : Tutorial

Utilization of a controller

The definition of the sensor vector and command vector is given in bank file. The description

of control boxes is given by .MCE DIGI element. The input data of the DIGI element must be

coherent with the definition in the user routines. This means that the number of sensors and

the number of commands must be the same, as well as the order used in both the Simulink

model and the commands. For example the first input variable in the Simulink model must

also be the first input variable defined in .MCC DIGI. A minimal definition of the digital

controller element is given below:

.MCE I Element_number DIGI N Node_list

.MCC I Element_number DIGI CBOX Numbox

TACT T1 T2

CINP List_of_input_codes

COUT List_of_output_codes

The Numbox variable above is the same one as the one defined in the MCBOXX routine and

must be in the range [1,1000]. For a more detailed discussion on the .MCE DIGI element the

user is referred to the appropriate element page.

Remarks

Note also that user control is active only between activation and deactivation time

Importing MATLAB/Simulink specific controllers

Digital controllers, that have been designed with the help of MATLAB/Simulink can be

exported to ANSI C-code (To do this the user needs the Real Time Workshop of

MATLAB). These ANSI C-controllers can then be compiled and linked with Mecano, so that

the digital controller has access to all nodal variables inside Mecano.

To include a MATLAB/Simulink controller into Mecano and to use it, one must follow the

explanation of the above sections. One of the differences with respect to the above procedure

is, that now a MATLAB/Simulink specific interface routine is needed. This interface routine will

replace the main program created by RTW, and is given in the user library:

If the user has MATLAB/Simulink/RTW release 12 (MCBX00).

If the user has MATLAB/Simulink/RTW release 13 (MCBX00).

Page 55: Samcef For Machine Tools : Tutorial

If the user has MATLAB/Simulink/RTW release 14 to release R2008b (MCBX00).

A description on how to modify this interface routine so as to incorporate the controller, and

how to compile and link a new version of Mecano is given below:

When a controller has been designed, it can be exported with Real Time Workshop

into a standard C program. RTW will the create the following:

o A separate directory, specific to the controller.

o source and header files.

o the object files plus a "makefile"

o an executable that is the stand alone controller.

The R(eal) T(ime) W(orkshop) options that should be used are given below:

Page 56: Samcef For Machine Tools : Tutorial
Page 57: Samcef For Machine Tools : Tutorial

This stand alone executable manages it's own time step (sampling time) and accepts input

variables and creates output variables. To link the controller with Mecano we now have to do

the following:

Change to the directory where the MATLAB/Simulink controller is generated.

Take the interface routine mcbx00.f (from the manual) and rename it to for example

mcbxij.c, the user can choose any name except for the names already used in the

routine mcboxx.f. [u6]

Remove all the lines of fortran code from this routine.

Un-comment all the C-code (remove the C character).

If multiple controllers are used, remove the following lines from the second till the

last mcbxij.c file:

#ifndef RT_MEMORY_ALLOCATION_ERROR

const char *RT_MEMORY_ALLOCATION_ERROR = "memory allocation error";

#endif

In the first interface routine, the above lines must NOT be removed.

choose a name for the routine and replace:

o UNIX (depending on the machine type): void INTERFACE -> void mcbxij_

o PC: void INTERFACE -> void MCBXIJ

Compile the interface routine (mcbxij.c) with the "makefile" created by RTW. To do

this the user has to perform the following steps:

Page 58: Samcef For Machine Tools : Tutorial

o Add the name mcbxij.c to the makefile "controler_name.mk", by adding the name

of the interface routine to the user source compile string: USER_SRCS =

mcbxij.c

o Remove the old main file from the Makefile, by removing grt_malloc_main.c

from the REQ_SRCS string.

o Add the following compiler options to the variable OPTS:

UNIX: OPTS = -std1

PC: OPTS = /Gd

o Launch the makefile to compile the interface routine.

To create a new user module of Mecano:

o On PC: copy the object files .o to the muser directory in the SAMCEF

distribution.

o On UNIX/Linux: copy the object files .o to the directory where you would like

to create the executable.

Now the selection of the controller has to be done in the routine MCBOXX as described in

the above paragraphs. This routine has to be compiled and (mecano) can then be linked with

the standard link procedure. When using controllers from MATLAB/Simulink the user has to

pay special attention to the following points:

different control boxes must have different names.

The "inputs" and "outputs" of the Simulink model must be of the type "Inport" and

"Outport" respectively, and not of the type "signal" (lineair, sinusoidal,....).

It is both possible to use multiple controllers, and to use multiple times the same

(source code) controller.

The time steps are automatically managed by Mecano, e.g. the time step will depend

on the maximum time step of Mecano and on the sample rate of the controllers.

The user must either use discrete operators or the user can define a sample time on the

input signal, thus digitizing the controller. Because a digital controller will use

constant entries between two sample times, the output will only be changed at the

sample time of the controller.

This last point is important when using controllers that use not only positions, but also speeds

or accelerations as inputs. In that case the user should be aware that speeds and accelerations

can not be obtained from differentiating the position inside a control box. This because

between sample times the input is assumed constant. In this case the user must read the speed

and acceleration directly from Mecano.

Two examples of the use of simple MATLAB/Simulink controllers are given:

Suspension with digital control.

Imposed position controller.

Page 59: Samcef For Machine Tools : Tutorial

13.1.7 Introduction In SAMCEF, the possibility exists to use user defined elements, material properties and/or

boundary conditions. For this, the user has access to user definable routines, which can be

compiled (using a fortran 77 compiler), and linked with the SAMCEF libraries to form a user

module. This user module has the same functionality as the original modules except that user

defined properties or elements are active. A description on how to compile a user module is

given in the paragraph below. A list of possible user defined possibilities is given in the

following paragraphs.

13.1.8 User Modules

13.1.8.1 Creation of User Modules

User module on UNIX: For customers that have by license the right to use SAMCEF object libraries, the link of

SAMCEF modules is obtained through the following command:

samcef link <module_name> <executable_file> <list_of_routines>

Example

The command

samcef link mecano /users/bill/mecano *.f

creates a "MECANO" module with all FORTRAN files (*.f) in the current directory. The new

executable file is /users/bill/mecano.

User module on PC (Windows):

On PC the user is referred to the Readme file in the Muser directory. The Muser directory is a

sub-directory in the Samcef root directory

The following paragraph explains how to introduce this new user module in the standard

procedure.

13.1.8.2 Definition of User Modules

The user can define its own modules in the same panel as its default variable definition. This

panel is obtained by selecting the [User Default] item of the [Edit] menu in the main

procedure panel. It is shown here again.

Page 60: Samcef For Machine Tools : Tutorial

The definition of user modules is saved in the user samrc.ini file as well.

To define a new module, select the [Module] item of the Add menu. To modify or delete an

existing user module, double-click on it in the user module list. In both case, the following

panel is prompted:

Page 61: Samcef For Machine Tools : Tutorial

The first field [Module Id] must contain a 2-character unique identifier by which the

module can be recognized among all others.

The second field [Samcef Id] can contain a 2-character identifier corresponding to the

equivalent SAMCEF module (e.g. me for MECANO if this module is a MECANO you

have linked in your directory with a user-element). This will allow the procedure to

behave as if it was MECANO when you use the module: launching of FAC, with the

correct LCP, etc.).

The third field contains the full name of your module, i.e. the one that will appear in

the menu.

The last field provides the executable file. The [Browse] button can be used to open a

file selection window.

To confirm the addition or the modification of a user module, click on [OK].

To cancel the addition or the modification of a user module, click on [CANCEL].

To delete an existing user module, click on [DELETE].

Notes

1. One can consider that SAMCEF modules have the same Id. for the "Module Id" and

the "Samcef Id"

2. If the user module is not a SAMCEF module, you can leave the SAMCEF Id free (the

default is the Module Id).

13.1.8.3 Using user modules

User modules can be called in a quite similar way as standard SAMCEF module. Just pick

them in the [User] sub-menu of the [Add Module] or [Run Module] in the main procedure

panel.

13.1.9 User defined I/O files [Mecano] When using user defined routines it sometimes might be useful/necessary to have access to

external files. These files may contain input/output data, or they may be used to interface

between Mecano and an external program. Because Mecano uses several temporary files

Page 62: Samcef For Machine Tools : Tutorial

during an analysis, it is dangerous for the user to define it's own file units to read and write,

due to a conflict between files. To circumvent this problem, and to facilitate the use of

external files in user routines, Mecano has the following mechanism to manage user I/O files:

The user can define several I/O files by giving the names to Mecano (via the routine

rgioun.f)

Mecano will open these files at the beginning of the analysis, and will close the files

after Mecano has terminated.

In the user routines the user has access to the file name and the file unit that has been

assigned to this file (by Mecano).

In the routine rgioun.f the user must define the number of I/O files (maximum 20 files) he

would like to use. For every file the following values must be defined:

NAME: Name of the user defined I/O file.

STAT: Indicator to tell if the file already exists.

ACTI: Indicator to tell if it is a read only file.

ACCE: Indicator for direct or sequential access.

FORM: Indicator for formatted/unformatted file.

DELE: Indicator for deletion of file.

In the user routines, the user will have access to the file name and the file unit via the

following common bloc:

COMMON /IOFILE/ NAME,IOUNIT,NFILES

where NAME is a CHARACTER*256 array of size 20, and IOUNIT is a integer array of size 20.

The file rgioun.f has to be compiled together with the user sub-routine to make the user

defined I/O files available in the user module.

User defined routines

User defined material properties and user elements, which are available in all

modules:

o User defined elements

o User defined materials

o ...

User defined boundary conditions, which are only available in Mecano:

o General constraint equation CNLI

o Non-linear force FNLI

o User defined volume flux

o User defined surface flux

o ...

Page 63: Samcef For Machine Tools : Tutorial