Learning Adams/Controls with MATLAB Getting Started Using Adams/Controls
18 Overview This chapter teaches you how to use Adams/Controls with MATLAB. It contains the following sections: About the Tutorial Step Three - Adding Controls to the MD Adams Block Diagram Step Four - Simulating the Model Before beginning this tutorial, you should have finished Introducing and Starting the Tutorials. 19 Learning Adams/Controls with MATLAB About the Tutorial This chapter provides procedures for using Adams/Controls with MATLAB. It teaches you Steps 3 and 4 of the four-step process of adding controls to an MD Adams model. You will learn how to: Add an MD Adams plant to your block diagram in MATLAB simulation. Simulate an MD Adams model with a complex control system. Plot simulation results. Getting Started Using Adams/Controls
20 Step Three - Adding Controls to the MD Adams Block Diagram You will add controls to the MD Adams block diagrams by: Starting MATLAB Creating the MD Adams Block Diagram Constructing the Controls System Block Diagram Setting Simulation Parameters in the Plant Mask Starting MATLAB A note about your MD 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_cwdAdams_inputsAdams_poutputAdams_sysdir Adams_execAdams_modeAdams_prefixAdams_uy_ids Adams_hostAdams_outputsAdams_solver_type Adams_initAdams_pinputAdams_static 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= 21 Learning Adams/Controls with MATLAB rotor_velocity!azimuth_position 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 MD Adams Block Diagram To create the MD 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 MD Adams blocks appears. These blocks represent your MD Adams model in different ways: The S-Function represents the nonlinear MD Adams model. The adams_sub contains the S-Function, but also creates several useful MATLAB variables. The State-Space block represents a linearized MD 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. Figure 1 Simulink Selection Window Note: If you want to import the linearized MD Adams model, use ant_test_l.m instead of ant_test.m. Getting Started Using Adams/Controls
22 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. All of the elements in the subsystem appear. Figure 2 adams_sub block 23 Learning Adams/Controls with MATLAB 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. Getting Started Using Adams/Controls
24 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 ). 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. Step time: 0.001 Initial value: 0 Final value: .3 Sample time: .001 3. Look at the controls block diagram below 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 below. 5. From the File menu, select Save As, and enter a file name for your controls 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. Note: Be sure to set the step block parameters as follows: 25 Learning Adams/Controls with MATLAB Figure 3 Topology in Tabular Form Figure 4 Controls Block Diagram Quantity LibraryBlock Type 1 SourcesStep 2 Continuous Transfer Function 2 Math Ops Sum 3 Sinks Scope (not floating) 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 Continuous Transfer Function Parameters 1 Numerator: [1040] Denominator: [0.001 1] Absolute tolerance: auto Getting Started Using Adams/Controls
26 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. The MD Adams Plant Mask dialog box appears. Figure 5 MD Adams Plant Mask 27 Learning Adams/Controls with MATLAB Getting Started Using Adams/Controls
28 29 Learning Adams/Controls with MATLAB 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. 4. Keep the default Interprocess Option of PIPE(DDE). This option defines the communication method between MATLAB and MD Adams. You can change this setting to TCP/IP, if you want to run MATLAB and MD Adams on separate machines and communicate using TCP/IP protocol. Using this protocol, Adams_host defines the machine on which MD Adams runs. For more information, see TCP/IP Communication Mode in the Adams/Controls help. 5. Keep the default Adams solver type of Fortran. To run the simulation using Adams/Solver (C++), you can change the setting to C++. 6. Keep the default Communication Interval of 0.005. The communication interval defines how often the communication between MD Adams and Simulink occurs. This will affect simulation speed (and accuracy). 7. Keep the default Number of communications per output step of 1.0. This value controls the size of .res, .gra, and .out 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. 8. Select a simulation parameter for each text box. Set Simulation mode to discrete. This mode specifies that MD Adams solve the mechanical system equations and that the controls application solve the control system equations. See the online help for more details about simulation modes. 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. 9. Set the parameters for initializing the MD Adams model: Initial Static Simulation Flag: Set Adams_static to yes or no to control whether or not a static analysis should be performed. Adams_static is a parameter in the MATLAB workspace that is passed in through the ant_test.m file (which sets the default). If Adams_static is yes, MD Adams performs a static analysis. 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 Getting Started Using Adams/Controls
30 Initialization commands: MATLAB string that holds the MD Adams commands. Default is Adams_init. 10. To save the change, select Apply. 11. Select Cancel to close the plant mask. Note: In batch mode, the static (or initial condition) analysis is performed first, followed by the user-defined initialization commands in Adams_init. In interactive mode, the procedure is reversed. 31 Learning Adams/Controls with MATLAB 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 End 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. 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. MD Adams accepts the control inputs from MATLAB and integrates the MD Adams model in response to them. At the same time, MD 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 MD Adams simulation, and the MD Adams outputs affect the control input levels. Getting Started Using Adams/Controls
32 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. 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 shaded in the following figure. Figure 6 adams_sub Block To plot from MATLAB: At the MATLAB prompt, type in the following command: 33 Learning Adams/Controls with MATLAB >>plot (Adams_tout, Adams_uout) The plot window opens and shows the time history of input from MATLAB to MD Adams. The following figure 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: >>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 7 Control Torque Input from MATLAB to Adams Getting Started Using Adams/Controls
34 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. 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 below). 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. 35 Learning Adams/Controls with MATLAB Figure 8 Adams/PostProcessor Window Menu bar Menu toolbar Treeview Property editor Status toolbar Dashboard Viewports Page Getting Started Using Adams/Controls
36 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. 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 h3 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). The following figure illustrates the torque signal received from the MATLAB controller. The difference between this curve and the one plotted earlier is because the number of output steps (MD Adams has fewer outputs). Figure 9 MD Adams Antenna Joint Peak Torque, Controlled 37 Learning Adams/Controls with MATLAB Getting Started Using Adams/Controls
Code Addicts - The Python Starter Kit - An In-Depth and Practical Course For Beginners To Python Programming. Including Detailed Step-By-step Guides and Practical Demonstrations. (2017)