Sie sind auf Seite 1von 132

1

Getting Started Using Adams/Controls

• Introducing and Starting the Tutorials

• Learning Adams/Controls with MATLAB Co-Simulation/Function Evaluation

• Learning Adams/Controls with Control System Import from MATLAB

• Learning Adams/Controls with Control System Import from MATLAB with S-Functions

• Learning Adams/Controls with Easy5 Co-Simulation/Function Evaluation

• Learning Adams/Controls with Control System Import from Easy5

2

Getting Started Using Adams/Controls

Introducing and Starting the Tutorials

Introducing and Starting the Tutorials

Overview

3

Overview

This chapter starts you off on the process of adding controls to your Adams model. Following this chapter are tutorials for some of the controls applications you can use with Adams/Controls: co-simulation and Control System Import with Easy5 or MATLAB. After you finish this chapter, continue with the tutorial that is specific to the controls application you are using.

This chapter contains the following sections:

• About the Tutorial

• How You’ll Learn Adams/Controls

• Starting Adams/View

• Step One - Build the Adams Model

• Step Two - Creating the Adams Plant Inputs and Outputs

Before doing these tutorials, you should be familiar with the basic features of the Adams/View interface. Refer to the online help for Adams/View for information about the Adams/View interface.

help for Adams/View for information about the Adams/View interface. This tutorial takes about two hours to

This tutorial takes about two hours to complete.

4

Getting Started Using Adams/Controls

About the Tutorial

About the Tutorial

The tutorials in this guide give you an overview of the four-step process of adding controls to an Adams

model. See Welcome to Adams/Controls > About the Adams/Controls Four-Step Process in

Adams/Controls online help, for a description of the four-step process. This chapter covers Steps One and Two of the process in depth. You'll learn how to:

Import an Adams model and run a trial simulation with Adams/View.

Use the Adams/Controls interface to identify the inputs and outputs from your Adams model, and create the files for the plant model in Easy5 and MATLAB/Simulink.

Steps Three and Four are covered in the chapters that follow for each controls application.

Introducing and Starting the Tutorials

How You’ll Learn Adams/Controls

5

How You’ll Learn Adams/Controls

By following the tutorials in this guide, you’ll apply the four-step process of using Adams/Controls on a simple antenna-pointing problem. The objective of the problem is to add a control system to the antenna that will move the antenna along a defined path to track a satellite signal.

For this tutorial, you will supply the torque that pivots the antenna in the azimuthal (horizontal) direction. The torque level will be computed by a control system, based on the error between the actual antenna position and the desired antenna position. This is more realistic than attaching an Adams motion to the pivot and driving the motion directly. By applying a torque, you can look at issues related to motor size in an actual mechanical system.

6

Getting Started Using Adams/Controls

Starting Adams/View

Starting Adams/View

In this section, you learn how to create a new directory and start Adams/Controls from within Adams/View in the UNIX and Windows environments.

In the UNIX environment, you start Adams/View from the Adams Toolbar, and then, from within Adams/View, you load the Adams/Controls plugin. For information on the Adams Toolbar, see the online

In the Windows environment, you start Adams/View from the Start menu, and then load the Adams/Controls plugin. For more information, see the online help for Running and Configuring Adams.

To start Adams/View:

1. Copy all of the files in install_dir/contro ls/examples/antenna to a new directory.

2. Do either of the following depending on the platform on which you are running Adams/View:

In UNIX, type the command to start the Adams Toolbar at the command prompt, and then

press Enter. Select the Adams/View tool

prompt, and then press Enter . Select the Adams/View tool . • In Windows, from the

.

In Windows, from the Start menu, point to Programs, point to MSC.Software, point to MD Adams 2010, point to AView, and then select Adams - View.

The Welcome dialog box appears, in the Adams/View main window.

Introducing and Starting the Tutorials

Step One - Build the Adams Model

7

Step One - Build the Adams Model

Now you’ll import an Adams model and familiarize yourself with its construction by following the next four sections:

• Build the Adams Model

• Loading Adams/Controls

• Familiarizing Yourself with the Model

• Running a Trial Simulation

Build the Adams Model

1. Select Import a File.

2. In the Start In text box on the Adams/View welcome screen, enter the name of your new directory (the one created in Step 1. in To start Adams/View: above).

This sets your new directory as your working directory.

3. Select OK to close the Adams/View welcome screen.

4. In the File Import dialog box, right-click the File to Read text box, and then select Browse.

The File Selection dialog box appears.

5. Select the file antenna.cmd.

6. Select OK.

The antenna model main_olt appears as shown in Figure 1.

7. To change the display of the antenna from a wire frame into a shaded, three-dimensional image, from the Main toolbox, select Render.

Elevation bearings

Antenna support

Azimuth rotor

Elevation bearings Antenna support Azimuth rotor Antenna Plate Reduction gear

Antenna

Elevation bearings Antenna support Azimuth rotor Antenna Plate Reduction gear

Plate

Elevation bearings Antenna support Azimuth rotor Antenna Plate Reduction gear

Reduction gear

Elevation bearings Antenna support Azimuth rotor Antenna Plate Reduction gear

8

Getting Started Using Adams/Controls

Step One - Build the Adams Model

Figure 1

Shaded Model of Antenna

Loading Adams/Controls

Because Adams/Controls is a plugin for Adams/View, you need to load Adams/Controls when you use it with Adams/View.

To load Adams/Controls:

1.

From the Tools menu, point to Plugin Manager.

2.

Select the Load checkbox next to Adams/Controls.

3.

Select OK.

Adams/View loads the Adams/Controls plugin. Notice that there is now a Controls menu on the main menu.

Note:

To automatically load Adams/Controls each time Adams/View starts up, select Load at Startup in the Plugin Manager.

Familiarizing Yourself with the Model

This model is designed so that its base turns in the azimuthal (horizontal) direction and its antenna tilts in the vertical direction.

To familiarize yourself with the model, locate the following components:

Azimuth rotor (peach) connected to ground by revolute joint.

Azimuth reduction gear (sky blue) connected to ground by revolute joint.

Azimuth plate (magenta) connected to ground by revolute joint.

Antenna support (silver) connected to plate by fixed joint.

Elevation bearings (peach) connected to support by fixed joint.

Antenna (sky blue) connected to bearings by revolute joint.

rotor_gear, couples the revolute joint at the rotor to the revolute joint at the reduction gear.

gear_plate, couples the revolute joint at the reduction gear to the revolute joint at the plate.

Running a Trial Simulation

To run a trial simulation with Adams/View:

1. From the Simulate menu, select Interactive Controls.

2. Enter the following in the Simulation Controls dialog box:

End Time: 0.5

Steps: 250

3. Select Start at equilibrium.

4. Select the Start tool

.
.

Introducing and Starting the Tutorials

Step One - Build the Adams Model

9

The base of the mechanism turns counterclockwise as the antenna tilts up and down.

Deactivating the Motion

Now that you know the model is working properly, you can begin the process of adding a control system to it. The first step is to deactivate the azimuthal motion on the model. After the motion has been deactivated, you will apply a torque to the joint .main_olt.azimuth_actuator based on values that the controls system package provides.

To deactivate the motion:

1.

From the Edit menu, select Deactivate.

 

The Database Navigator appears.

2.

Double-click the model main_olt.

A list of parts and motions appears.

3.

Scroll down the list and select azimuth_motion_csd.

4.

Select OK.

Adams/View deactivates the motion.

 

5.

Select the Reset to Start tool

5. Select the Reset to Start tool to reset the simulation back to its first frame.

to reset the simulation back to its first frame.

6.

Rerun the simulation.

Now that you’ve deactivated the azimuthal motion, the antenna moves up and down, but it does not sweep horizontally as it did during the last simulation.

Note:

You might detect some small movement in the azimuthal direction because the model has no constraints or restoring forces to control its natural movement. You should also notice that the bending of the antenna support beam decreases when the azimuthal motion is deactivated. The flexing illustrates that a certain amount of coupling takes place between the elevation and azimuthal movements.

10

Getting Started Using Adams/Controls

Step Two - Creating the Adams Plant Inputs and Outputs

Step Two - Creating the Adams Plant Inputs and Outputs

Now you’ll create the inputs and outputs on the Adams model by:

• Identifying the Adams Plant Inputs and Outputs

• Verifying Input Variables

• Verifying Input Functions

• Verifying Output Functions

• Exporting the Adams Plant Files for the Controls Application

Identifying the Adams Plant Inputs and Outputs

Figure 2 indicates the flow path of the input and output variables shared between the antenna model and its control system. This diagram shows that when you supply an input control torque to the antenna model, you send outputs azimuth_position and rotor_velocity to the controller.

The steps you follow to achieve this closed-loop circuit are:

Define the input and output variables in Adams/View.

Read in the plant and the input/output variables using Easy5 or MATLAB, create an Adams plant, and run a simulation.

Animate and plot the simulation results in Adams/View.

Modify the variables and repeat this process as necessary.

Input = control _torque Adams Output = azimuth_position and model rotor_velocity Control system
Input = control _torque
Adams
Output = azimuth_position and
model
rotor_velocity
Control
system

Figure 2

Terminology for Adams Inputs and Outputs

Verifying Input Variables

Adams/Controls and controls applications, such as Easy5 and MATLAB, communicate by passing state variables back and forth. Therefore, you must define your model’s input and output variables (and the functions that those inputs and outputs reference) with a set of Adams state variables.

This step has already been done for you in the antenna model that you imported. When you create a model of your own, you will have to define the state variables for your input and output variables.

Introducing and Starting the Tutorials

Step Two - Creating the Adams Plant Inputs and Outputs

11

For this tutorial, you will only verify that the state variables in the antenna model and control system correspond to the correct input and output variables. For a description of state variables, see the online

help.

To verify the input variables:

1. From the Build menu, point to System Elements, point to State Variable, and then select Modify.

The Database Navigator appears.

2. Double-click the model main_olt.

The list of Adams variables appears.

the model main_olt . The list of Adams variables appears. Figure 3 List of Adams Variables

Figure 3

List of Adams Variables

3. Select control_torque.

4. Select OK.

12

Getting Started Using Adams/Controls

Step Two - Creating the Adams Plant Inputs and Outputs

The Create/Modify State Variable dialog box appears.

The Create/Modify State Variable dialog box appears. Figure 4 Modify State Variable Dialog Box 5. Look

Figure 4

Modify State Variable Dialog Box

5. Look in the F(time,

) = text box and verify that the run-time function for the input variable,

control_torque, is 0.0.

Because the control torque will get its value from the control application, the 0.0 will be overwritten during each step of the simulation.

6. Select Cancel to close the Modify State Variable dialog box.

Note:

After you close the box, click in the background of the screen to clear the selection of the model.

Verifying Input Functions

Now you’ll verify the function that references the input variable.

To verify the function that is referenced to the input variable control_torque:

1. From the Edit menu, select Modify.

The Database Navigator appears.

2. Double-click main_olt, and then double-click azimuth_actuator (azimuth_actuator is the name of the control torque).

Introducing and Starting the Tutorials

Step Two - Creating the Adams Plant Inputs and Outputs

The Modify Torque dialog box appears.

13

and Outputs The Modify Torque dialog box appears. 13 Figure 5 Modify Torque Dialog Box 3.

Figure 5

Modify Torque Dialog Box

3. Look in the Function text box and verify that the run-time function for the input variable reads:

VARVAL(.main_olt.control_torque).

Note:

VARVAL (variable value) is the Adams function that returns the value of the given variable. Notice that the function is defined as the value of the control_torque variable. In other words, the input control torque (azimuth_actuator) gets its value from the input variable.

4. Select Cancel to close the Modify Torque dialog box.

Verifying Output Functions

Now you’ll verify the output functions just as you verified the input functions in the previous section.

To verify the output functions:

1. From the Build menu, point to System Elements, point to State Variable, and then select Modify.

The Database Navigator appears.

14

Getting Started Using Adams/Controls

Step Two - Creating the Adams Plant Inputs and Outputs

2. Double-click the model main_olt.

The list of Adams variables appears.

3. Select azimuth_position.

4. Select OK.

The Create/Modify State Variable dialog box appears.

OK . The Create/Modify State Variable dialog box appears. Figure 6 Modify State Variable Dialog Box

Figure 6 Modify State Variable Dialog Box

5. Look in the F(time, AZ(MAR70, MAR26).

)

= text box to verify that the run-time function for the output variable is

This function returns the angle about the z-axis, the vertical axis about which the antenna rotates. Therefore, the function assigns the rotational position of the antenna to the output state variable.

6. Right-click the Name text box, point to ADAMS_Variable, point to Guesses, and then select rotor_velocity.

The Modify State Variable dialog box updates.

7. Look at the F(time,

) = text box and verify the run-time function for the output variable is

WZ(MAR21, MAR22, MAR22).

This function measures the rotational velocity of the rotor relative to ground.

8. Select Cancel to close the dialog box.

Exporting the Adams Plant Files for the Controls Application

In this section, you will export the Adams linear and nonlinear plant files.

To export the nonlinear plant files:

Introducing and Starting the Tutorials

Step Two - Creating the Adams Plant Inputs and Outputs

15

1.

From the Controls menu, select Plant Export.

The Adams/Controls Plant Export dialog box appears.

2.

In

the New Controls Plant text box, enter ant_test.

3.

In

the File Prefix text box, type ant_test for the filename.

This defines the prefix for the .adm, .cmd, .m, and .inf files created by the Plant Export dialog box.

4.

Right-click the Input Signal(s) text box, point to ADAMS_Variable, and then select Browse.

The Database Navigator appears.

5.

In

the Database Navigator, select control_torque, and then select OK.

6.

In

the Adams/Controls Plant Export dialog box, right-click the Output Signal(s) text box, point

to

ADAMS_Variable, and then select Guesses.

A

selection list appears.

7.

From the selection list, select rotor_velocity.

8.

Repeat Step 6, and then from the selection list, select azimuth_position.

 

Note:

It is important to maintain the above selection order for selecting output signals so that the model works properly with the example MATLAB or Easy5 model.

9.

From the Target Software pull-down menu, select the controls application you are using during this session: MATLAB or Easy5.

10.

Confirm that Analysis Type is set to non_linear and Initial Static Analysis is set to No.

 

Note:

If Analysis Type is set to linear and Initial Static Analysis is set to Yes, Adams/Controls conducts a static analysis before the linear analysis. Otherwise, Adams/Controls performs an initial conditions analysis.

11.

Verify that the Adams/Solver choice set as desired and Adams Host Name is set to your machine name.

Be sure that the name for Adams Host is a fully qualified hostname or localhost if using TCP/IP communication with co-simulation or function evaluation mode. This is not required for PIPE- based communication. (To be fully qualified, the hostname must contain the workstation and domain name.) If the Adams Host is not fully qualified, edit the value in the text box so that it is fully qualified.

16

Getting Started Using Adams/Controls

Step Two - Creating the Adams Plant Inputs and Outputs

Dynamic States Output performs an initial conditions analysis or a static analysis (if Initial Static Analysis is set to Yes), and computes the number of states (i.e., displacements, velocities) in the model. This is used by Easy5 for Function Evaluation mode. If your model has difficulty computing this properly, you can disable this feature, but you will not be able to use Function Evaluation mode unless the number for NUMBER OF STATES is modified in the .inf file from Plant Export. This may be relevant for Adams/Chassis models imported into Adams/View.

13. Verify that the Plant Export dialog box is completed as shown in the figure below.

Export dialog box is completed as shown in the figure below. This order is important. Figure
Export dialog box is completed as shown in the figure below. This order is important. Figure

This order is

important.

Figure 7

Adams/Controls Plant Export Dialog Box

14. Select OK.

Introducing and Starting the Tutorials

Step Two - Creating the Adams Plant Inputs and Outputs

17

Adams/Controls saves the input and output information in an .m (for MATLAB) or .inf file (for Easy5). It also generates a command file (.cmd) and a dataset file (.adm) that are used during the simulation process. Empty file called aviewAS.cmd is also created which will prevent the startup screen from displaying when simulating interactively with Adams/View.

Note:

The ant_test Controls Plant you just created is saved in the modeling database. By importing settings from an existing plant, you can generate new plants based on plants you already created.

To export the linear plant files (optional: not required for co-simulation or function evaluation):

1. From the Controls menu, select Plant Export.

2. In the Adams/Controls Plant Export dialog box, create a new controls plant by importing settings from a previous plant.

3. Change the file prefix from ant_test to ant_test_l.

4. Set Analysis Type to Linear.

5. Set Initial Static Analysis to Yes.

6. Select OK.

Adams/Controls generates the linear model of the Adams model in four matrices: ant_test_la,

ant_test_lb, ant_test_lc, and ant_test_ld.

Adams/Controls setup is complete after the plant files have been exported. Now you will go to the specific controls application (Easy5 or MATLAB) and complete the link between the controls and mechanical systems.

Note:

You have now finished the introduction to the Adams/Controls tutorials. To continue learning the Adams/Controls interface, go to the tutorials that follow this section. If you are using:

MATLAB Co-Simulation or Function Evaluation, go to Learning Adams/Controls

with MATLAB Co-Simulation/Function Evaluation

Control System Import with MATLAB, go to Learning Adams/Controls with

Control System Import from MATLAB

Control System Import from MATLAB with S-Functions, go to Learning

Adams/Controls with Control System Import from MATLAB with S-Functions

Easy5 Co-Simulation or Function Evalutation, go to Learning Adams/Controls with

Easy5 Co-Simulation/Function Evaluation

Control System Import with Easy5, go to Learning Adams/Controls with Control

System Import from Easy5

18

Getting Started Using Adams/Controls

Step Two - Creating the Adams Plant Inputs and Outputs

Learning Adams/Controls with MATLAB Co-Simulation/Function Evaluation

17

Learning Adams/Controls with MATLAB Co-Simulation/Function Evaluation

18

Getting Started Using Adams/Controls

Overview

Overview

This chapter teaches you how to use Adams/Controls with MATLAB in co-simulation. It contains the following sections:

• About the Tutorial

• Step Three - Adding Controls to the Adams Block Diagram

• Step Four - Simulating the Model

Note:

Before beginning this tutorial, you should have finished Introducing and Starting the

Tutorials.

Learning Adams/Controls with MATLAB Co-Simulation/Function Evaluation

About the Tutorial

19

About the Tutorial

This chapter provides procedures for using Adams/Controls with MATLAB in co-simulation. It teaches you Steps 3 and 4 of the four-step process of adding controls to an Adams model. You will learn how to:

Add an Adams plant to your block diagram in MATLAB simulation.

Simulate an Adams model with a complex control system.

Plot simulation results.

20

Getting Started Using Adams/Controls

Step Three - Adding Controls to the Adams Block Diagram

Step Three - Adding Controls to the Adams Block Diagram

You will add controls to the Adams block diagrams by:

• Starting MATLAB

• Creating the Adams Block Diagram

• Constructing the Controls System Block Diagram

• Setting Simulation Parameters in the Plant Mask

Starting MATLAB

A note about your Adams license(s) : Running an Adams/Controls cosimulation will check out an Adams/Solver license and possibly an Adams/View license (for interactive simulations only). To ensure that you are able to run these products, you may need to close any Adams applications that use these licenses.

To start using MATLAB:

1. Start MATLAB on your system.

2. Change directories to the one in which your ant_test.m file resides (the working directory you specified during your Adams/Controls session).

You can do this by entering the following:

On Windows: cd c:\ new_dir , where new_dir is the name of your working directory.

On UNIX, cd / new_dir , where new_dir is the name of your working directory.

3. At the prompt (>>), type ant_test.

MATLAB echoes:

%%%INFO:Adams plant actuators names:

1 control_torque

%%%INFO:Adams plant sensors names:

1 rotor_velocity

2 azimuth_position.

4. At the prompt, type who to get the list of variables defined in the files.

MATLAB echoes the following relevant information:

ADAMS_cwd ADAMS_inputs ADAMS_poutput ADAMS_sysdir

ADAMS_exec ADAMS_mode ADAMS_prefix ADAMS_uy_ids

ADAMS_host ADAMS_outputs ADAMS_solver_type

ADAMS_init ADAMS_pinput ADAMS_static

Learning Adams/Controls with MATLAB Co-Simulation/Function Evaluation

Step Three - Adding Controls to the Adams Block Diagram

21

You can check any of the above variables by entering them in at the MATLAB prompt. For example, if you enter ADAMS_outputs, MATLAB displays all of the outputs defined for your mechanism:

ADAMS_outputs=

rotor_velocity!azimuth_position

Note:

If you want to import the linearized Adams model, use ant_test_l.m instead of ant_test.m. The main difference is in the ADAMS_mode variable:

In ant_test.m, ADAMS_mode=non_linear.

In ant_test_l.m, ADAMS_mode=linear.

Creating the Adams Block Diagram

To create the Adams block diagram:

1. At the MATLAB prompt, enter adams_sys.

This builds a new model in Simulink named adams_sys

MSC.Software S-Function block representing your mechanical system.

A selection window containing the Adams blocks appears. These blocks represent your Adams model in different ways:

mdl.

This model contains the

The S-Function represents the nonlinear Adams model.

The adams_sub contains the S-Function, but also creates several useful MATLAB variables.

The State-Space block represents a linearized Adams model.

The adams_sub block is created based on the information from the .m file (either from ant_test.m or ant_test_l.m). If the Adams_mode is nonlinear, the S-Function block is used in the adams_sub subsystem. Otherwise, the State_Space block is copied into adams_sub.

22

Getting Started Using Adams/Controls

Step Three - Adding Controls to the Adams Block Diagram

Step Three - Adding Controls to the Adams Block Diagram Figure 8 Simulink Selection Window 2.

Figure 8

Simulink Selection Window

2. From the File menu, point to New, and then select Model.

A new selection window for building your block diagram appears.

3. Drag and drop the adams_sub block from the adams_sys_ selection window onto the new selection window.

4. Double-click the adams_sub block.

Learning Adams/Controls with MATLAB Co-Simulation/Function Evaluation

Step Three - Adding Controls to the Adams Block Diagram

All of the elements in the subsystem appear.

23

Diagram All of the elements in the subsystem appear. 23 Figure 9 adams_sub block Note: The

Figure 9

adams_sub block

Note:

The inputs and outputs you defined for the model appear in the sub-block. The input and output names automatically match up with the information read in from the ant_test.m file.

Constructing the Controls System Block Diagram

The completed block diagram is in the file, antenna.mdl, in the examples directory. To save time, you can read in our diagram instead of building it. Remember to update the settings in the plant mask if you

decide to use this file (see Setting Simulation Parameters in the Plant Mask).

24

Getting Started Using Adams/Controls

Step Three - Adding Controls to the Adams Block Diagram

Note:

If the Simulink model containing the adams_sub block was created in an earlier version of Adams/Controls, you should run adams_sys again to create a new adams_sub block to replace the existing one for better performance.

Only one adams_sub block is permitted per Simulink model.

To construct the controls system block diagram:

1. At the MATLAB prompt, type simulink.

The Simulink library selection windows appear. Use the block icons from the windows to complete your controls block diagram. Each icon contains a submenu.

2. Double-click each icon to reveal its submenu.

3. Look at the controls block diagram Figure 10 and Table 1, which describes the topology in tabular form.

4. Drag and drop the appropriate blocks from the Simulink library to complete your block diagram as shown in Figure 10.

blocks from the Simulink library to complete your block diagram as shown in Figure 10 .

Figure 10

Controls Block Diagram

Learning Adams/Controls with MATLAB Co-Simulation/Function Evaluation

Step Three - Adding Controls to the Adams Block Diagram

25

5. From the File menu, select Save As, and enter a file name for your controls block diagram.

Table 1

Topology in Tabular Form

 

Quantity

Library

Block Type

1

Sources

Step

2

Continuous

Transfer Function

2

Math Ops

Sum

3

Sinks

Scope(not floating)

 

Step Parameters

 

Continuous Transfer Function Parameters

Step Time: 0.001

 

1

Numerator: [1040]

Initial Value: 0

 

Denominator: [0.001 1]

Final value: 0.3

 

Absolute tolerance: auto

Sample time: 0.001

 

2

Numerator: [950]

[X]

Interpret vector parameters as 1-D

Denominator: [0.001 1]

[X]

Enable zero crossing detection

Absolute tolerance: auto

Sum Parameters

 

Scope

1

SumP

 

1

torque

Icon shape: rectangular

2

rotor_vel

List of signs: +-

3

azimuth_pos

[

] Show additional parameters

 

2

SumV

 

Icon shape: rectangular

List of signs: +-

[

] Show additional parameters

Setting Simulation Parameters in the Plant Mask

To set the simulation parameters:

1. From the controls block diagram, double-click the adams_sub block.

2. From the new Simulink selection window, double-click the MSC.Software block.

26

Getting Started Using Adams/Controls

Step Three - Adding Controls to the Adams Block Diagram

The Adams Plant Mask dialog box appears.

Adams Block Diagram The Adams Plant Mask dialog box appears. Figure 11 Adams Plant Mask 3.

Figure 11

Adams Plant Mask

3. In the Output Files Prefix text box, enter ‘mytest’.

Be sure to enclose the name with single quotation marks. Adams/Controls will save your simulation results under this name in the three file types listed in Table 1

Table 1

Learning Adams/Controls with MATLAB Co-Simulation/Function Evaluation

Step Three - Adding Controls to the Adams Block Diagram

File Types

27

File Name

File type:

What the file contains

mytest.res

Results

Adams/Solver analysis data and Adams/View graphics data

mytest.req

Requests

Adams/Solver analysis data

mytest.gra

Graphics

Adams/View graphics data

4. Select the Adams solver type of Fortran.

To run the simulation using Adams/Solver (C++), you can change the setting to C++.

5. Select the Interprocess Option of PIPE(DDE).

This option defines the communication method between MATLAB and Adams. You can change this setting to TCP/IP, if you want to run MATLAB and Adams on separate machines and communicate using TCP/IP protocol. Using this protocol, Adams_host defines the machine on which Adams runs. For more information, see TCP/IP Communication Mode in the Adams/Controls help.

6. Select a simulation parameter for each text box.

Set Animation mode to interactive.

Animation mode controls whether you graphically monitor your simulation results in Adams/View (interactive), or you simulate with Adams/Solver (batch). See the online help for more details about animation modes.

Set Simulation mode to discrete.

This mode specifies that the simulation run in co-simulation -- Adams solves the mechanical system equations and that the controls application solves the control system equations. The variables exchanged between Adams and MATLAB are exchanged at "discrete" intervals. See the online help for more details about simulation modes.

7. Keep the default Communication Interval of 0.005.

The communication interval defines how often the communication between Adams and Simulink occurs. This will affect simulation speed and accuracy.

8. Keep the default Number of communications per output step of 1.

This value controls the size of .res, .req,and gra files. It must be an integer larger than zero. For example, if the value is n, Adams/Controls writes to the output file once for every n communication steps. This size-control mechanism only works in discrete mode.

9. To save the change, select Apply.

10. Select Cancel to close the plant mask.

Note:

For more features in the Adams/Controls block, select More parameters, which reveals the following dialog box. Note that the dialog box will add and remove parameters depending on the settings.

28

Getting Started Using Adams/Controls

Step Three - Adding Controls to the Adams Block Diagram

28 Getting Started Using Adams/Controls Step Three - Adding Controls to the Adams Block Diagram

Learning Adams/Controls with MATLAB Co-Simulation/Function Evaluation

Step Three - Adding Controls to the Adams Block Diagram

This plant uses the following variables:

29

ADAMS_sysdir

Adams installation directory

ADAMS_inputs

Input variables View names vector

ADAMS_outputs

Outputs variables View names vector

ADAMS_prefix

Adams model files prefix (.adm, .cmd); also doubles as output files prefix

ADAMS_exec

Adams/Solver user library or keyword (e.g., acar_solver)

ADAMS_static

yes|no - initial static before Co-simulation(discrete)/Function Evaluation (continuous)

ADAMS_init

Initialization commands (i.e., Adams/View or Solver commands, depending on setting for Animation mode)

ADAMS_cwd

Current working directory (for TCP/IP)

ADAMS_host

Name of Adams server host (for TCP/IP)

ADAMS_mode

Linear or non-linear (i.e., co-sim, function eval)

ADAMS_solver_type

FORTRAN or C++ (used to set popup menu when first loaded)

The following settings can be chosen:

Adams/Solver type

FORTRAN or C++ (will also set ADAMS_solver_type)

Interprocess option

Pipe (DDE) or TCP/IP; TCP/IP can allow different machines run Adams and MATLAB

Animation mode

batch (Solver, uses .adm) or interactive (View, uses .cmd)

Simulation mode

discrete (Co-simulation) or continuous (Function Evaluation)

Discrete Computational Order - Simulink Lead Adams

For discrete mode, chooses if Simulink leads the integration (yes) or lags (no); if set to no, can remove algebraic loop

Plant input interpolation order

= zero-order hold; 1 = linear (discrete mode only, where Simulink leads)

0

Plant output extrapolation order

= zero-order hold; 1 = linear (discrete mode only, where Simulink leads)

0

Plant input extrapolation order

= zero-order hold; 1 = linear (discrete mode only, where Adams leads)

0

Plant output interpolation order

= zero-order hold; 1 = linear (discrete mode only, where Adams leads)

0

Direct feedthrough

yes|no - yes = Input directly effect output (continuous mode-only)

30

Getting Started Using Adams/Controls

Step Three - Adding Controls to the Adams Block Diagram

Communication interval

Time step at which Co-simulation exchange information (e.g.,0.005); also controls output for continuous mode (Function Evaluation)

Number of communications per output step

Sets Adams output rate (.res, .req, .gra) integer value (default: 1)

Learning Adams/Controls with MATLAB Co-Simulation/Function Evaluation

Step Four - Simulating the Model

31

Step Four - Simulating the Model

You will simulate your mechanical model and control system by:

• Setting the Simulation Parameters

• Executing the Simulation

• Pausing the Simulation

• Plotting from MATLAB

• Plotting from Adams/View

Setting the Simulation Parameters

To set the simulation parameters:

1. From the menus on the Simulink window, select Simulation, and then select Configuration Parameters.

The Simulation Parameters dialog box appears.

2. Enter the following simulation parameters:

For Start Time, enter 0.0 seconds.

For Stop Time, enter 0.25 seconds.

3. Select the Type text box for the Solver options:

Set the first text box to Variable-step.

Set the second text box to ode15s (stiff/NDF).

Accept the default values in the remaining text boxes.

4. Select OK to close the Simulation Parameters dialog box.

Executing the Simulation

To start the simulation:

Select Simulation -- Start.

After a few moments, a new Adams/View window opens and graphically displays the simulation.

If you’re using Windows, a DOS window appears with the current simulation data. If you’re using UNIX, the current simulation data scrolls across the MATLAB window.

Adams accepts the control inputs from MATLAB and integrates the Adams model in response to them. At the same time, Adams provides the azimuthal position and rotor velocity information for MATLAB to integrate the Simulink model. This simulation process creates a closed loop in which the control inputs from MATLAB affect the Adams simulation, and the Adams outputs affect the control input levels. See Figure 2 for an illustration of the closed loop simulation process.

32

Getting Started Using Adams/Controls

Step Four - Simulating the Model

Pausing the Simulation

The interactive capabilities of Adams/Controls let you pause the simulation in MATLAB and monitor the graphic results in Adams/View. Because MATLAB controls the simulation, you must pause the simulation from within MATLAB. You can plot simulation results during pause mode. This feature is only available when animation mode is set to interactive.

To pause the simulation:

1. A time display in the upper left corner of the Adams screen tracks the seconds of the simulation. To pause the simulation, move your cursor to the Simulink window, point to Simulation, and then select Pause.

MATLAB suspends the simulation.

2. Now go back to Adams/View. While the simulation is paused, you can change the orientation of the model with the View Orientation tools in the Main toolbox. These tools help you to look at the model from different vantage points.

you to look at the model from different vantage points. Figure 12 View Orientation Tools 3.

Figure 12

View Orientation Tools

3. Once you have finished reorienting the model, resume the simulation by selecting Simulation, and then Continue, from the toolbar on the Simulink window.

Adams/View closes automatically after the simulation finishes.

Plotting from MATLAB

You can plot any of the data generated in MATLAB. In this tutorial, you will plot the ADAMS_uout data that is saved in the adams_sub block. This block is shown in Figure 13.

Learning Adams/Controls with MATLAB Co-Simulation/Function Evaluation

Step Four - Simulating the Model

33

Evaluation Step Four - Simulating the Model 33 Figure 13 adams_sub Block To plot from MATLAB:

Figure 13

adams_sub Block

To plot from MATLAB:

At the MATLAB prompt, type in the following command:

>>plot (ADAMS_tout, ADAMS_uout)

The plot window opens and shows the time history of input from MATLAB to Adams. The Figure 14 shows you how the plot should look. Notice that the control torque reaches a peak, and then settles down as the antenna accelerates. As the antenna gets close to its final position, the torque reverses direction to slow down the antenna. The antenna moves past its desired position, and then settles down to the point of zero error. At this point, the torque value is also at zero.

To add labels to your plot:

At the MATLAB prompt, enter:

34

Getting Started Using Adams/Controls

Step Four - Simulating the Model

>>xlabel(‘Time in seconds’) >>ylabel(‘Control Torque Input, N-mm’) >>title(‘Adams/Controls Torque Input from MATLAB to Adams’)

The labels appear on the plot.

from MATLAB to Adams’) The labels appear on the plot. Figure 14 Control Torque Input from

Figure 14

Control Torque Input from MATLAB to Adams

Plotting from Adams/View

To plot from Adams/View:

1. Start Adams/View from your working directory and read in the command file, ant_test.cmd.

2. From the File menu, select Import.

The File Selection dialog box appears.

3. In the File Selection dialog box, select the following:

For the File Type, select Adams Results File.

Learning Adams/Controls with MATLAB Co-Simulation/Function Evaluation

Step Four - Simulating the Model

35

For Files to Read, select Read mytest.res.

For Model, select main_olt. Be sure to include the model name when you read in results files. Adams/View needs to associate the results data with a specific model.

4. Select OK.

The results are loaded. Now, you can plot any data from the cosimulation and play the animation.

5. From the Review menu, select Postprocessing.

Adams/View launches Adams/PostProcessor, a postprocessing tool that lets you view the results of the simulations you performed (see the Figure 15). Adams/PostProcessor has four modes:

animation, plotting, reports, and 3D plotting (only available with Adams/Vibration data). Note that the page in the plot/animation viewing area can contain up to six viewports to let you compare plots and animations.

to six viewports to let you compare plots and animations. Figure 15 Adams/PostProcessor Window 6. From

Figure 15

Adams/PostProcessor Window

6. From the dashboard, set Source to Results.

7. From the Simulation list, select mytest.

8. From the Result Set, select control_torque.

9. From the Component list, select Q.

10. Select Add Curves.

Adams/PostProcessor generates the curve.

36

Getting Started Using Adams/Controls

Step Four - Simulating the Model

To add labels to your plot:

1. In the treeview, navigate to the plot and select it.

2. In the Property Editor that appears, perform the following:

Uncheck Auto Title.

Set Title to Antenna Azimuth Control Torque in Adams.

Uncheck Auto Subtitle.

Set Subtitle to Using Matlab Continuous Controller.

3. Select the vertical axis.

4. In the Property Editor, in the Labels tab, set Label to Control Torque Input (N-mm).

Figure 16 illustrates the torque signal received from the MATLAB controller. The difference between this curve and the one plotted in Figure 14 is because the number of output steps (Adams has fewer outputs).

is because the number of output steps (Adams has fewer outputs). Figure 16 Adams Antenna Joint

Figure 16

Adams Antenna Joint Peak Torque, Controlled

Learning Adams/Controls with Control System Import from MATLAB

37

Learning Adams/Controls with Control System Import from MATLAB

38

Getting Started Using Adams/Controls

Overview

Overview

This chapter teaches you how to generate external system libraries (ESL) from control systems designed in MATLAB/Simulink and import them into Adams. It contains the following sections:

• Step Three – Setup MATLAB

• Step Four – Create Adams Target for Real Time Workshop

• Step Five – Create Simulink Model

• Step Six – Code Generation of Control System

• Step Seven – Create GSE from the Simulink Model

Learning Adams/Controls with Control System Import from MATLAB

About the Tutorial

39

About the Tutorial

This chapter provides the procedures to import control systems designed in MATLAB/Simulink into Adams. It relies on MATLAB/Real-Time Workshop to convert the control model to C-code. This tutorial is based on the files output from Adams/View in the previous chapter.

The antenna model is still used in this chapter. The controller used in last chapter will be modified to represent three different types of controllers: continuous, discrete, and hybrid (continuous/discrete). Those three simulink files (continuous.mdl, discrete.mdl, and hybrid.mdl) are in the examples directory. Copy them to the local directory.

If MATLAB/Simulink and Adams cannot be run on the same machine, you will have to perform additional steps to realize the cross-platform control system import. For more information, refer to the online help.

40

Getting Started Using Adams/Controls

Step Three – Setup MATLAB

Step Three – Setup MATLAB

First you will start MATLAB, and then you will create a simulink model for control system design. You will use the antenna model files from the last section, plus several additional files.

To start MATLAB:

1. Start MATLAB in the same directory as the one the model and Simulink files reside.

2. Set up the MEX utility, if not already set up.

Enter mex -setup from the MATLAB command window, and then select the appropriate compiler. (see http://support.adams.com under Hardware & Software Requirements for a list of supported compilers)

3. At the prompt (>>), type ant_test.

MATLAB displays:

%%%INFO:Adams plant actuators names:

1 control_torque

%%%INFO:Adams plant sensors names:

1 rotor_velocity

2 azimuth_position.

4. At the prompt, type who to view the list of variables defined in the files.

MATLAB displays the following relevant information:

ADAMS_cwd ADAMS_inputs ADAMS_poutput ADAMS_sysdir

ADAMS_exec ADAMS_mode ADAMS_prefix ADAMS_uy_ids

ADAMS_host ADAMS_outputs ADAMS_solver_type

ADAMS_init ADAMS_pinput ADAMS_static

You can check any of the above variables by entering them at the MATLAB prompt. For example, if you enter Adams_outputs, MATLAB displays all of the outputs defined for your mechanism. For example:

ADAMS_outputs = rotor_velocity!azimuth_position

Learning Adams/Controls with Control System Import from MATLAB

Step Four – Create Adams Target for Real Time Workshop

41

Step Four – Create Adams Target for Real Time Workshop

In order to generate the external system library from the MATLAB/Simulink model, you need to generate some special files for MATLAB/Real-Time Workshop (RTW). You will customize the makefile template and source code template for Adams based on the version of MATLAB your are using. Once this is done, you can use the customized template files for other Simulink models.

To create the Real-Time Workshop files for the Adams/Controls model:

1. At the MATLAB prompt (>>), type setup_rtw_for_adams

This will automatically detect the version of Matlab you are using and create the makefile template and source code template for Adams. This function will also build template for specific versions of Matlab if desired by entering the desired version token as an argument:

setup_rtw_for_adams('<version')) For help with this, enter setup_rtw_for_adams('h').

You should see the following message for success in this step:

%%% Successfully created files for Adams library export from MATLAB/RTW.

You should also confirm that in your working directory that .tlc and .tmf files were created by this step.

Alternatively, since the function setup_rtw_for_adams also uses process.py, you can still setup using the old method:

(Optional method if not using setup_rtw_for_adams function)

1. Set the MATLAB_ROOT environment variable to the MATLAB installation directory. For example:

On Windows (DOS shell): set MATLAB_ROOT= c:\matlab78\

On UNIX (c shell): setenv MATLAB_ROOT /usr/matlab_78/

On UNIX (korn shell): export MATLAB_ROOT = /usr/matlab_78/

Change the directory paths to match your installation.

2. In the directory where your Adams model resides, issue the following command, where $adams_dir is the directory in which Adams is installed:

On UNIX:

mdadams2010 -c python ($adams_dir)/controls/utils/process.py -v 78 exit

On Windows:

mdadams2010 python ($adams_dir)\controls\utils\process.py -v 78

Alternatively, you can copy the process.py file from the <adams_dir>/controls/utils/ directory on UNIX or <adams_dir>\controls\utils\ on Windows to the current directory and issue the following command:

On UNIX:

42

Getting Started Using Adams/Controls

Step Four – Create Adams Target for Real Time Workshop

mdadams2010 -c python process.py -v 78 exit

On Windows:

mdadams2010 python process.py -v 78

The argument -v 78 stands for MATLAB 7.8 (R2009a).

This command customizes several files from the MATLAB installation for the Adams target and your computer setup. You should notice several new files in your working directory with a .tlc extension and two new files with a .tmf extension. These are files required by MATLAB’s Real Time Workshop in the steps that follow. For help with process.py, use the -h flag (i.e., process.py -h).

Note:

The value for MATLAB_ROOT should have no quote, no spaces (on Windows, get short names with command dir /x), and a final slash on the path.

Learning Adams/Controls with Control System Import from MATLAB

Step Five – Create Simulink Model

43

Step Five – Create Simulink Model

To create the Simulink template for the control system:

1. Enter setio at the MATLAB prompt.

MATLAB creates a template model with the inport(s) and outport(s) defined, as shown in Figure

17.

and outport(s) defined, as shown in F i g u r e 17 . Figure 17

Figure 17

Simulink Template

Based on this template, you can design continuous, discrete, or hybrid control systems. For this tutorial, this step is information only. Since you already have these files copied into the local directory, you can delete this "io" model and use one of the examples.

2. To open hybrid.mdl, from the File menu, select Open. Or, double-click the file in the file browser. Optionally, you may also open discrete.mdl and/or continuous.mdl and run the rest of the tutorial with those for comparison.

In the following context, the hybrid control system will be used as the example to illustrate the process. The Figure 18 shows the hybrid system and Table 1 shows the topology.

44

Getting Started Using Adams/Controls

Step Five – Create Simulink Model

Using Adams/Controls Step Five – Create Simulink Model Figure 18 Table 1 Hybrid Control System Hybrid

Figure 18

Table 1

Hybrid Control System Hybrid Control System Topology

Quantity

Library

Block Type

1

Sources

Step

2

Continuous

Transfer Function

2

Discrete

Transfer Function

5

Math Ops

Sum

1

Math Ops

Gain

2

Ports

Import

1

Ports

Outport

Step Parameters

 

Continuous Transfer Function Parameters

Learning Adams/Controls with Control System Import from MATLAB

Step Five – Create Simulink Model

45

Step Time: 0.001

 

1

Numerator: [1040]

Initial Value: 0

 

Denominator: [0.001 1]

Final value: 0.3

 

Absolute tolerance: auto

Sample time: 0.001

 

2

Numerator: [950]

[X]

Interpret vector parameters as 1-D

Denominator: [0.001 1]

[X]

Enable zero crossing detection (greyed out)

Absolute tolerance: auto

Discrete Transfer Function Parameters

Sum Parameters

1

Numerator: [657.4]

1

SumP

Denominator: [1 -.3679]

Icon shape: rectangular

Sample time: 0.001

List of signs: +-

2

Numerator: [600 5]

[

] Show additional parameters

Denominator: [1 -.3679]

2

SumV

Sample time: 0.001

Icon shape: rectangular

Gain

 

List of signs: +-

Gain: 0.5

 

[

] Show additional parameters

Multiplication: Element-wise(K, *u)

3

SumP1

[ ] Show additional parameters

 

Icon shape: rectangular

Import

 

List of signs: +-

Name:

rotor_velocity

[

] Show additional parameters

Port number:

1

4

SumV1

Name:

azimuth_position

Icon shape: rectangular

Port number:

2

List of signs: +-

Outport

   

[

] Show additional parameters

Name:

control_torque

5

Icon shape: Round

Port number:

1

List of signs: ++

   

[

] Show additional parameters

46

Getting Started Using Adams/Controls

Step Six – Code Generation of Control System

Step Six – Code Generation of Control System

First you will configure MATLAB/Real-Time Workshop and then you will create the external system library from the Simulink model.

Given a controller designed with the appropriately designated inports and outports, the following steps are required to export the model using RTW.

1. From the Tools menu, point to Real-Time Workshop, and then select Options.

The Simulation Parameters dialog box appears.

2. Verify that Generate code only is not selected.

3. Complete the Simulink Parameters dialog box for MATLAB, as shown Figure 19.

dialog box for MATLAB, as shown F i g u r e 19 . Figure 19

Figure 19

Simulation Parameters

4. From the treeview on the left side of the window, select Solver.

The dialog box displays the Solver options as shown in Figure 20

Learning Adams/Controls with Control System Import from MATLAB

Step Six – Code Generation of Control System

47

MATLAB Step Six – Code Generation of Control System 47 Figure 20 Simulation Parameters - Solver

Figure 20

Simulation Parameters - Solver Options

5. Set Solver options Type to Variable-Step. (If selecting Fixed-step solver, Set Mode to SingleTasking.).

6. Under zero-crossing options, set Zero-crossing control to Disable All.

Note:

Zero-crossing support is experimental in Adams/Controls, and not available in Adams/Mechatronics. If you have zero-crossing in your model, and you would like try to use them in Adams/Controls, simply select Use local settings or Enable All to turn them on, and Adams SENSOR's will be created via Controls System Import that use the zero-crossings functions.

7. From the treeview on the left side of the window, select Optimization.

The dialog box displays the Advanced options as shown in the Figure 21.

8. Verify that Inline parameters is selected. Enabling Inline parameters has the following effects:

Real-Time Workshop uses the numerical values of model parameters, instead of their symbolic names, in generated code.

48

Getting Started Using Adams/Controls

Step Six – Code Generation of Control System

Reduces global RAM usage, because parameters are not declared in the global parameters structure.

are not declared in the global parameters structure. Figure 21 Simulation Parameters - Advanced Options 9.

Figure 21

Simulation Parameters - Advanced Options

9. Select Apply.

10. Select the Real-Time Workshop tab.

11. To begin code generation and build the RTW library, select Build.

Messages will appear in the MATLAB command window indicating successful code generation and RTW library creation. You should see messages that end with the following:

Creating library

*** Created ADAMS dll C:\adams_controls_getting_started\antenna\hybrid_rsim_rtw>exit /B 0

\hybrid.lib

and object

\hybrid.exp

Learning Adams/Controls with Control System Import from MATLAB

Step Six – Code Generation of Control System

49

### Successful completion of Real-Time Workshop build procedure for model: hybrid

The library you created will be in your working directory.

50

Getting Started Using Adams/Controls

Step Seven – Create GSE from the Simulink Model

Step Seven – Create GSE from the Simulink Model

First you will start Adams/View and import the command file, and then simulate your Adams model containing the GSE for the control system.

To start Adams/View and load the command file:

1. Launch Adams/View and import the file ant_test.cmd.

2. Load the Adams/Controls plugin, if not already loaded.

3. From the Controls menu, point to Control System, and then select Import.

The Adams/Controls System Import dialog box appears.

4. Select Import I/O Signals from Existing Controls Plant.

5. From the Database Navigator, select ant_test for the plant. The values for the Output Signals and Input Signals text boxes appear.

6. Complete the dialog box as shown in Figure 22, and then select OK.

dialog box as shown in F i g u r e 22 , and then select

Figure 22

Adams/Controls System Import Dialog Box

Learning Adams/Controls with Control System Import from MATLAB

Step Seven – Create GSE from the Simulink Model

51

Adams/View displays information on the GSE created (See Figure 23). The Database Navigator shown in Figure 24 shows the GSE and its associated arrays.

23 ). The Database Navigator shown in Figure 24 shows the GSE and its associated arrays.

Figure 23

Information Window

52

Getting Started Using Adams/Controls

Step Seven – Create GSE from the Simulink Model

Step Seven – Create GSE from the Simulink Model Figure 24 Database Navigator To simulate your

Figure 24

Database Navigator

To simulate your model:

1. From the Settings menu, point to Solver, and then select Dynamics.

The Solver Setting dialog box displays.

2. Change Formulation to SI2.

3. Set Category to Executable.

4. Set Hold License to No.

This setting is critical to using the RTW dll in repeated simulations in Adams/View.

When you rewind/stop a simulation in Adams/View, the RTW dll is released and reacquired, thereby resetting the discrete states and counters to their original state. Changing this behavior by issuing commands in Adams/View causes unexpected simulations after the first one.

5. Select Close.

6. Run a simulation with a step size of .001s and duration of .25s.

During the simulation, the antenna motion behaves the same as the one in the co-simulation.

Learning Adams/Controls with Control System Import from MATLAB

Step Seven – Create GSE from the Simulink Model

7. Press F8 to open Adams/PostProcessor.

8. Plot and animate, as desired.

53

Adams/PostProcessor displays the plot of azimuth position versus time, as shown in below figure.

of azimuth position versus time, as shown in below figure. Figure 25 Plot of Azimuth Position

Figure 25

Plot of Azimuth Position vs. Time

A comparison of the results of the above simulation, Co-simulation, and Function Evaluation simulation is conducted (the latter two not performed in this tutorial). In all cases, the output step (sampling time in discrete simulation) is set to .001 second. The control torque versus time from three simulations is plotted in Figure 26. As shown, the result from the simulation with imported GSE is almost the same as that from Function Evaluation simulation. The control torque from the Co-simulation is slightly larger in magnitude because the one-step delay introduced by the discrete control system results in a control-mechanical system with less damping.

54

Getting Started Using Adams/Controls

Step Seven – Create GSE from the Simulink Model

Your RTW dll can contain discrete states and counters. When performing repeated simulations (for example, design of experiments or design optimization), these entities need to be reset to their original values at the beginning of each simulation. When you rewind a simulation in Adams/View, the RTW dll is released and reacquired, thereby resetting the discrete states and counters to their original state. Changing this behavior by issuing commands in Adams/View causes unexpected simulations after the first one.

causes unexpected simulations after the first one. Figure 26 Control Torque vs. Time Optionally, if you

Figure 26

Control Torque vs. Time

Optionally, if you repeat the tutorial to create ESL's for discrete and continuous models, and re- run, you should see a plot like Figure 27. Note that the step excitation is slightly different for each model, and delays are caused by discrete states, so you should see differences in the responses accordingly.

Learning Adams/Controls with Control System Import from MATLAB

Step Seven – Create GSE from the Simulink Model

55

with Control System Import from MATLAB Step Seven – Create GSE from the Simulink Model 55

Figure 27

Re-run Result

56

Getting Started Using Adams/Controls

Step Seven – Create GSE from the Simulink Model

Learning Adams/Controls with Control System Import from MATLAB with S-Functions

55

Learning Adams/Controls with Control System Import from MATLAB with S- Functions

56

Getting Started Using Adams/Controls

Overview

Overview

This chapter teaches you how to use Adams/Controls with Control System Import from MATLAB with S-Functions. It contains the following sections:

• Step Three - Generate S-Function Using Real-Time Workshop

• Step Four - Use S-Function to Create Adams External System Library

• Step Five - Use S-Function without source code to Create ESL

• Step Six - Expose S-Function Parameters to Adams

• Step Seven - Use the S-Function ESL in Adams Control System Import

Learning Adams/Controls with Control System Import from MATLAB with S-Functions

Step Three - Generate S-Function Using Real-Time Workshop

57

Step Three - Generate S-Function Using Real-Time Workshop

Setup MATLAB

First you will start MATLAB, and then you will create a Simulink model for control system design. You will use the antenna model files from the last section, plus several additional files.

To start MATLAB:

1. Start MATLAB in the same directory as the one the model and Simulink files reside.

2. Set up the MEX utility, if not already set up.

Enter mex -setup from the MATLAB command window, and then select the appropriate compiler. (see http://support.adams.com under Hardware & Software Requirements for a list of supported compilers)

3. At the prompt (>>), type ant_test.

MATLAB displays:

%%%INFO:Adams plant actuators names:

1 control_torque

%%%INFO:Adams plant sensors names:

1 rotor_velocity

2 azimuth_position.

4. At the prompt, type who to view the list of variables defined in the files.

MATLAB displays the following relevant information:

ADAMS_cwd ADAMS_inputs ADAMS_poutput ADAMS_sysdir

ADAMS_exec ADAMS_mode ADAMS_prefix ADAMS_uy_ids

ADAMS_host ADAMS_outputs ADAMS_solver_type

ADAMS_init ADAMS_pinput ADAMS_static

You can check any of the above variables by entering them at the MATLAB prompt. For example, if you enter Adams_outputs, MATLAB displays all of the outputs defined for your mechanism. For example:

ADAMS_outputs = rotor_velocity!azimuth_position

Create Simulink Model

The purpose of these steps is to generate a model that is to be used for creation of the S-Function using the S-Function target in Real-Time Workshop. The models supported by Adams/Controls are firstly limited by those restrictions enforced by MATLAB/Real-Time workshop itself. Please consult the Mathworks documentation for the official limitations, but a summary of these can be found in the

58

Getting Started Using Adams/Controls

Step Three - Generate S-Function Using Real-Time Workshop

Limitations section. In addition, Adams/Controls has its own limitations for S-Functions support for ESL creation/use, also listed.

For this example, you can simply open the Simulink model discrete.mdl, shown in Figure 27:

model discrete.mdl , shown in F i g u r e 27 : Figure 27 Discrete

Figure 27

Discrete model

To create the Simulink template for the control system:

1. Enter setio at the MATLAB prompt.

MATLAB creates a template model with the inport(s) and outport(s) defined, as shown in Figure

28.

Learning Adams/Controls with Control System Import from MATLAB with S-Functions

Step Three - Generate S-Function Using Real-Time Workshop

59

Step Three - Generate S-Function Using Real-Time Workshop 59 Figure 28 You can discard this model

Figure 28

You can discard this model using the finished discrete.mdl.

Simulink Template

Generate S-Function from RTW

Once the Simulink model is created, you will convert this to an S-Function using Real-Time Workshop. To do this, the model must be configured properly.

1. In the model discrete.mdl, select Simulation Configuration Parameters.

2. From the treeview on the left side of the window, select Solver.

The dialog box displays the Solver options as shown in Figure 29.

60

Getting Started Using Adams/Controls

Step Three - Generate S-Function Using Real-Time Workshop

Step Three - Generate S-Function Using Real-Time Workshop Figure 29 Configuration Parameters 3. Here, under Solver

Figure 29

Configuration Parameters

3. Here, under Solver options, Type, select Variable-Step. Any variable-step solver will be fine at this point (for example, ode45), as long as you don't choose a discrete solver for a model with continuous states.

Note:

You can choose either Variable-step or Fixed-step solvers in MATLAB/Simulink. The choice will affect the model code that is generated from RTW, in particular to how sample times are handled. This is important to Adams since Adams will be integrating the model, not MATLAB/RTW. In this regard, the Variable-step integrator is recommended since Adams/Solver uses mainly variable-step integrators, and this will ensure the outputs and states are computed properly. If you would still like to use a Fixed-step integrator setting, the model should have at least one continuous state to produce the code for Adams that will handle the sample times properly. For example, if you have a discrete-only model, add a dummy continuous block (for example, Integrator) to the model.

Learning Adams/Controls with Control System Import from MATLAB with S-Functions

Step Three - Generate S-Function Using Real-Time Workshop

61

Tip:

To look for differences in sample times between Fixed-Step and Variable-step integrators settings, look for the function ssIsSampleHit(), which handles evaluation of code at sample times.

As a MATLAB requirement, an RTW-generated S-Function must have the same type of integrator setting as the model that will use it (that is, both Fixed-step, or both Variable-step).

4. Select Tools Real-Time Workshop Options. Under Target selection, select Browse and choose the S-Function Target, rtwsfcn.tlc.

Browse and choose the S-Function Target, rtwsfcn.tlc . Figure 30 Discrete/Configuration 5. Select Apply to apply

Figure 30

Discrete/Configuration

5. Select Apply to apply your changes, and then select Build to build the S-Function.

62

Getting Started Using Adams/Controls

Step Three - Generate S-Function Using Real-Time Workshop

You should see messaging in the main MATLAB window about the build process, which should conclude with this message upon a successful build (here, for 32-bit Windows; the extension will depend on the platform):

### Created MEX-file discrete_sf.mexw32 In your working directory, you should find that RTW has created a directory called discrete_sfcn_rtw containing the source files for generating your S-Function,

discreate_sf.mexw32.

files for generating your S-Function, discreate_sf.mexw32 . Figure 31 S-Function 6. Furthermore, you should see that

Figure 31

S-Function

6. Furthermore, you should see that RTW created an S-Function block which now supplants your Simulink model (here discrete.mdl):

Learning Adams/Controls with Control System Import from MATLAB with S-Functions

Step Three - Generate S-Function Using Real-Time Workshop

63

Step Three - Generate S-Function Using Real-Time Workshop 63 Figure 32 This is the block to

Figure 32

This is the block to be included in the Simulink model for the Adams External System Library.

Function block

64

Getting Started Using Adams/Controls

Step Four - Use S-Function to Create Adams External System Library

Step Four - Use S-Function to Create Adams External System Library

Setup MATLAB

If you haven't already done so, open ant_test.m in MATLAB as described in the section Step Three - Generate S-Function Using Real-Time Workshop. This will create variables required and modify the MATLAB path to pickup setup scripts and functions.

Create Adams Target for RTW

Here you will customize the makefile template and source code template for Adams. Once this is done, you can use the customized template files for other Simulink models.

To create the Real-Time Workshop files for the Adams/Controls model:

1. At the MATLAB prompt (>>), type setup_rtw_for_adams

This will automatically detect the version of Matlab you are using and create the makefile template and source code template for Adams. This function will also build template for specific versions of Matlab if desired by entering the desired version token as an argument:

setup_rtw_for_adams('version') For help with this, enter setup_rtw_for_adams('h').

2. You should see the following message for success in this step:

%%% Successfully created files for Adams library export from MATLAB/RTW.

3. You should also confirm that in your working directory that .tlc and .tmf files were created by this step.

Create Simulink Model

In this case, since the S-Function block created previously represents the Adams model with the same inputs and outputs, we can use the setio command to generate the input/output template for this S- Function (which will use the input/output information provided by ant_test.m).

Learning Adams/Controls with Control System Import from MATLAB with S-Functions

Step Four - Use S-Function to Create Adams External System Library

1. Run setio.

65

to Crea te Adams External System Library 1. Run setio . 65 2. Copy S-Function block

2. Copy S-Function block to setio model, and connect the inputs appropriately.

3. Save as discrete_sf_mdl.mdl:

the inputs appropriately. 3. Save as discrete_sf_mdl.mdl : Code Generation of Control System First you will

Code Generation of Control System

First you will configure MATLAB/Real-Time Workshop and then you will create the External System Library from the Simulink model.

Given a controller designed with the appropriately designated inports and outports, the following steps are required to export the model using RTW.

1. From the Tools menu, point to Real-Time Workshop, and then select Options.

The Simulation Parameters dialog box appears.

2. Verify that Generate code only is not selected.

66

Getting Started Using Adams/Controls

Step Four - Use S-Function to Create Adams External System Library

- Use S-Function to Create Adams External System Library Figure 33 Rapid Simulation Target 4. From

Figure 33

Rapid Simulation Target

4. From the treeview on the left side of the window, select Solver. The dialog box displays the Solver options as shown in Figure 34.

Learning Adams/Controls with Control System Import from MATLAB with S-Functions

Step Four - Use S-Function to Create Adams External System Library

67

- Use S-Function to Crea te Adams External System Library 67 Figure 34 Configuration Parameters -

Figure 34

Configuration Parameters - Solver

5.

Set Solver options Type to Variable-Step (it must be the same Type as specified when generating the S-Function). (If selecting Fixed-step solver, Set Mode to SingleTasking.)

6.

Under zero-crossing options, set Zero-crossing control to Disable All.

Note:

Zero-crossing support is experimental in Adams/Controls, and not available in Adams/Mechatronics. If you have zero-crossing in your model, and you would like try to use them in Adams/Controls, simply select Use local settings or Enable All to turn them on, and Adams SENSOR's will be created via Controls System Import that use the zero- crossings functions.

7.

From the treeview on the left side of the window, select Optimization.

The dialog box displays the Advanced options as shown in the figure below.

8.

Verify that Inline parameters is selected. Enabling Inline parameters has the following effects:

Real-Time Workshop uses the numerical values of model parameters, instead of their symbolic names, in generated code.

68

Getting Started Using Adams/Controls

Step Four - Use S-Function to Create Adams External System Library

Reduces global RAM usage, because parameters are not declared in the global parameters structure.

are not declared in the global parameters structure. Figure 35 Configuration Parameters - Optimization 9. Select

Figure 35 Configuration Parameters - Optimization

9. Select Apply

10. Select the Real-Time Workshop tab.

11. To begin code generation and build the RTW library, select Build.

Messages will appear in the MATLAB command window indicating successful code generation and RTW library creation. You should see messages that end with the following:

Creating library

discrete_sf_mdl.exp ### Created Adams External System Library discrete_sf_mdl.dll

C:\adams_temp\sfunction\discrete_sf_mdl_rsim_rtw>exit /B 0 ### Successful completion of Real-Time Workshop build procedure for model: discrete_sf_mdl The library you created will be in your working directory.

\discrete_sf_mdl.lib

and object

\

Learning Adams/Controls with Control System Import from MATLAB with S-Functions

Step Five - Use S-Function without source code to Create ESL

69

Step Five - Use S-Function without source code to Create ESL

Another way to generate an ESL using an S-Function is to exclude the source code for the S-Function to protect proprietary information. Here, we will copy some main files and generate a duplicate model to show that this should produce the same results as if the source code is available. These next steps assume that you have performed the all steps previously. You may omit this portion of the tutorial and skip to parameterization next, if desired.

Create Simulink Model

1. Create a directory within your working directory called "no_source_code" and copy the following files:

ant_test.adm

ant_test.cmd

ant_test.m

discrete.mdl

• ant_test.cmd • ant_test.m • discrete.mdl 2. Restart MATLAB in this directory. 3. Build the S-Function

2. Restart MATLAB in this directory.

3. Build the S-Function in RTW from discrete.mdl using S-Function target in the same manner as in

previous Generate S-Function from RTW:

a. Open discrete.mdl

b. Build with RTW using the S-Function target.

70

Getting Started Using Adams/Controls

Step Five - Use S-Function without source code to Create ESL

Step Five - Use S-Function without source code to Create ESL 4. Save this model as

4. Save this model as discrete_sf_mdl.mdl.

Code Generation of Control System

1. As described in the previous section, load ant_test.m in MATLAB and use Adams/Controls setup_rtw_for_adams script to generate Adams/Controls-modified RSIM target.

2. Modify model with S-Function to choose RSIM target and build the S-Function again - this will create an object file that can be used in later steps to build the Adams/Controls ESL from RTW.

3. Provide the following when distributing the model to the person who will make the Adams/Controls ESL from RTW:

discrete_sf.mexw32

discrete_sf.h discrete_sfcn_rtw/discrete_sf.h discrete_sfcn_rtw/discrete_mid.h discrete_sfcn_rtw/discrete_sid.h discrete_sfcn_rtw/discrete_sf_private.h discrete_sfcn_rtw/discrete_sf_types.h discrete_sfcn_rtw/discrete.mk discrete_sfcn_rtw/discrete_sf_data.c (if applicable) discrete_sf_mdl_rsim_rtw/discrete_sf.obj discrete_sf_mdl.mdl

4. To mimic what you would see at the receiver's end, first create a new directory called new_model. Then, using the files from Step 3, retain the directory structure and copy all of these files to new_model.

5. Also, move the files ant_test.m, ant_test.adm, and ant_test.cmd to the directory new_model.

6. Run ant_test.m in Matlab.

7. Open discrete_sf_mdl.mdl, and run setio to create the inputs and outputs for this model. Copy the inports and outports to discrete_sf_mdl.mdl so it looks like in Figure 36:

Learning Adams/Controls with Control System Import from MATLAB with S-Functions

Step Five - Use S-Function without source code to Create ESL

71

Five - Use S-Function without source code to Create ESL 71 Figure 36 Discrete S-Fucntion -

Figure 36

Discrete S-Fucntion - No Source

8.

Rename the model to discrete_sf_no_source.mdl.

9.

Run setup_rtw_for_adams to generate the RSIM target files in the folder new_model.

10.

Choose Tools Real-Time Workshop Options, and select the RSIM target for the System Target File.

11.

Select Generate code only to make the proper directory needed for the build. We will copy the S-Function object file created previously to the RTW directory created by this process.

72

Getting Started Using Adams/Controls

Step Five - Use S-Function without source code to Create ESL

Step Five - Use S-Function without source code to Create ESL 12. Select Apply and then

12. Select Apply and then click Generate code. You should see a directory called discrete_sf_no_source_rsim_rtw in the working directory, as below:

Learning Adams/Controls with Control System Import from MATLAB with S-Functions

Step Five - Use S-Function without source code to Create ESL

73

Five - Use S-Function without source code to Create ESL 73 13. Place the S-Function object

13. Place the S-Function object file created previously ("discrete_sf_mdl_rsim_rtw/discrete_sf.obj") in the directory of the new model's name ("discrete_sf_no_source_rsim_rtw/discrete_sf.obj").

14. In Configuration Parameters, uncheck the Generate code only option under the Real-Time Workshop tab, and then select Apply:

74

Getting Started Using Adams/Controls

Step Five - Use S-Function without source code to Create ESL

Step Five - Use S-Function without source code to Create ESL 15. Select Build to build

15.

Select Build to build the ESL using the Adams/Controls-modified RSIM target.

You should see the following messaging in the MATLAB window:

### Created Adams External System Library discrete_sf_no_source.dll

C:\adams_temp\sfunction\no_source_code\new_model\discrete_sf_no_ source_rsim_rtw>exit /B 0

### Successful completion of Real-Time Workshop build procedure for model: discrete_sf_no_source

Note:

If you see a RTW message that it is compiling discrete_sf.c, then you have not performed the steps properly, as it should not have a discrete_sf.c provided.

Learning Adams/Controls with Control System Import from MATLAB with S-Functions

Step Five - Use S-Function without source code to Create ESL

75

Note:

The main RTW details can be found also written for another example here:

How do I build my model that contains an RTW generated S-function block if I do not have the source code?

How do I build my model containing a C-MEX S-function if I don't have the S- function C source file using Real-Time Workshop?

76

Getting Started Using Adams/Controls

Step Six - Expose S-Function Parameters to Adams

Step Six - Expose S-Function Parameters to Adams

This section shows how to parameterize your S-Function such that you may be able to automatically create design variables for these parameters in Adams. This section is optional and may be omitted if you do not need to parameterize your S-Function.

Select Parameters

To parameterize an S-Function for Adams, when building the S-Function block using an S-Function target, first create parameters for the Simulink model.

1. Here we will create parameters "Kp1" and "Kp2" to parameterize the gain of the two transfer functions:

we will create parameters "Kp1" and "Kp2" to parameterize the gain of the two transfer functions:

Learning Adams/Controls with Control System Import from MATLAB with S-Functions

Step Six - Expose S-Function Parameters to Adams

77

Step Six - Expose S-Functi on Parameters to Adams 77 2. Note that you must remove

2. Note that you must remove the square brackets [ ] to parameterize this field. The model should now look like the following:

78

Getting Started Using Adams/Controls

Step Six - Expose S-Function Parameters to Adams

Step Six - Expose S-Function Parameters to Adams 3. Here, we will set the values of

3. Here, we will set the values of the parameters to what they were originally:

>> Kp1=657.4

Kp1 =

657.4000

>> Kp2 = 600.5

Kp2 =

600.5000

Code Generation of Control System

1. Build the S-Function using the S-Function target in RTW and choose the parameters to be Global (tunable) Parameters.

2. Select Tools Real-Time Workshop Options, select the Optimization tab on the left side, and check the Inline parameters option:

Learning Adams/Controls with Control System Import from MATLAB with S-Functions

Step Six - Expose S-Function Parameters to Adams

79

Step Six - Expose S-Functi on Parameters to Adams 79 3. Select Configure . This will

3. Select Configure. This will allow you to select Kp1 and Kp2 add them to the list of Global (tunable) parameters. Do this as below:

80

Getting Started Using Adams/Controls

Step Six - Expose S-Function Parameters to Adams

C

Step Six - Expose S-Function Parameters to Adams C 4. Choose the Real-Time Workshop tab in

4. Choose the Real-Time Workshop tab in the Configuration parameters:

Learning Adams/Controls with Control System Import from MATLAB with S-Functions

Step Six - Expose S-Function Parameters to Adams

81

Step Six - Expose S-Functi on Parameters to Adams 81 5. Under Configuration Parameters, select th

5. Under Configuration Parameters, select the Real-Time Workshop tab, and select the S-Function Target for the System Target File.

6. Select Apply and then Build. This should create the file discrete_sf_data.c which will contain the parameters selected:

/* Block parameters (auto storage) */ Parameters_discrete discrete_DefaultParameters = {

6.574E+002,

/* Kp1 : '<Root>/Discrete Transfer Fcn' */

600.5

/* Kp2 : '<Root>/Discrete Transfer Fcn1' */};

7. As in the section, "Step Four - Use S-Function to Create Adams External System Library", create

a new model based on your S-Function block, which now has the parameter exposed within it.

In the following steps, you will build the ESL using the Adams/Controls-modified RSIM target and again choose the same parameters to be Global (tunable) Parameters.

82

Getting Started Using Adams/Controls

Step Six - Expose S-Function Parameters to Adams

Step Six - Expose S-Function Parameters to Adams 9. Under Configuration Parameters, select th e Real-Time

9. Under Configuration Parameters, select the Real-Time Workshop tab, and select the Adams/Controls-modified RSIM target for the System Target File.

Learning Adams/Controls with Control System Import from MATLAB with S-Functions

Step Six - Expose S-Function Parameters to Adams

83

Step Six - Expose S-Functi on Parameters to Adams 83 10. Select Apply and then Build

10. Select Apply and then Build. This should create the file discrete_sf_mdl_data.c which will contain the parameters selected (as well as their size (here: 1x1):

/* Block parameters (auto storage) */

Parameters rtP = { /* RTWSFunction_P1_Size : '<Root>/RTW S-Function' */

{ 1.0, 1.0 }, 6.574E+002,

/* Kp1 : '<Root>/RTW S-Function'*/ /* RTWSFunction_P2_Size : '<Root>/RTW S-Function'*/

{ 1.0, 1.0 }, 600.5

/* Kp2 : '<Root>/RTW S-Function'*/ };

Following the steps in the section, Step Seven - Use the S-Function ESL in Adams Control System Import,

you can use Control System Import to load the ESL:

84

Getting Started Using Adams/Controls

Step Six - Expose S-Function Parameters to Adams

Create GSE from the Simulink Model

Parameters to Adams Create GSE from the Simulink Model 1. After loading the ESL, Adams/Controls will

1. After loading the ESL, Adams/Controls will show these variables in the Adams Information window:

Object Name