Sei sulla pagina 1di 20

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 19


About the Tutorial

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_exec ADAMS_host ADAMS_init ADAMS_inputs ADAMS_mode ADAMS_outputs ADAMS_pinput ADAMS_poutput ADAMS_prefix ADAMS_solver_type ADAMS_static ADAMS_sysdir ADAMS_uy_ids

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


Step Three - Adding Controls to the Adams Block Diagram

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_.mdl. This model contains the 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:
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

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 23


Step Three - Adding Controls to the Adams Block Diagram

All of the elements in the subsystem appear.

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.

Figure 10

Controls Block Diagram

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


Step Three - Adding Controls to the Adams Block Diagram

5. From the File menu, select Save As, and enter a file name for your controls block diagram. Table 1 Quantity 1 2 2 3 Topology in Tabular Form Library Sources Continuous Math Ops Sinks Block Type Step Transfer Function Sum Scope(not floating) Continuous Transfer Function Parameters 1 Numerator: [1040] Denominator: [0.001 1] Absolute tolerance: auto 2 Numerator: [950] Denominator: [0.001 1] Absolute tolerance: auto Scope 1 2 3 torque rotor_vel azimuth_pos

Step Parameters Step Time: 0.001 Initial Value: 0 Final value: 0.3 Sample time: 0.001 [X] Interpret vector parameters as 1-D [X] Enable zero crossing detection Sum Parameters 1 SumP Icon shape: rectangular List of signs: +[ ] 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.

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

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


Step Three - Adding Controls to the Adams Block Diagram

Table 1

File Types File Name File type: mytest.res mytest.req mytest.gra Results Requests Graphics What the file contains Adams/Solver analysis data and Adams/View graphics data Adams/Solver analysis data 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

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


Step Three - Adding Controls to the Adams Block Diagram

This plant uses the following variables: 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 Interprocess option Animation mode Simulation mode Discrete Computational Order Simulink Lead Adams Plant input interpolation order FORTRAN or C++ (will also set ADAMS_solver_type) Pipe (DDE) or TCP/IP; TCP/IP can allow different machines run Adams and MATLAB batch (Solver, uses .adm) or interactive (View, uses .cmd) discrete (Co-simulation) or continuous (Function Evaluation) For discrete mode, chooses if Simulink leads the integration (yes) or lags (no); if set to no, can remove algebraic loop 0 = zero-order hold; 1 = linear (discrete mode only, where Simulink leads)

Plant output extrapolation order 0 = zero-order hold; 1 = linear (discrete mode only, where Simulink leads) Plant input extrapolation order Plant output interpolation order Direct feedthrough 0 = zero-order hold; 1 = linear (discrete mode only, where Adams leads) 0 = zero-order hold; 1 = linear (discrete mode only, where Adams leads) 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) Sets Adams output rate (.res, .req, .gra) integer value (default: 1)

Number of communications per output step

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


Step Four - Simulating the Model

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 youre using Windows, a DOS window appears with the current simulation data. If youre 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.

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 33


Step Four - Simulating the Model

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.

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 35


Step Four - Simulating the Model

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.

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).

Figure 16

Adams Antenna Joint Peak Torque, Controlled

Potrebbero piacerti anche