Csi
Csi
Csi
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
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
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 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:
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 MATLABs 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.
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.
Hybrid Control System Hybrid Control System Topology Library Sources Continuous Discrete Math Ops Math Ops Ports Ports Block Type Step Transfer Function Transfer Function Sum Gain Import Outport Continuous Transfer Function Parameters
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 (greyed out) Discrete Transfer Function Parameters 1 Numerator: [657.4] Denominator: [1 -.3679] Sample time: 0.001 2 Numerator: [600 5] Denominator: [1 -.3679] Sample time: 0.001 Gain Gain: 0.5 Multiplication: Element-wise(K, *u) [ ] Show additional parameters Import Name: Name: Outport Name: control_torque rotor_velocity Port number: 1 azimuth_position Port number: 2
Sum Parameters 1 SumP Icon shape: rectangular List of signs: +[ ] Show additional parameters 2 SumV Icon shape: rectangular List of signs: +[ ] Show additional parameters 3 SumP1 Icon shape: rectangular List of signs: +[ ] Show additional parameters 4 SumV1 Icon shape: rectangular List of signs: +[ ] Show additional parameters 5 Icon shape: Round List of signs: ++ [ ] Show additional parameters
Port number: 1
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
Figure 20
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
Reduces global RAM usage, because parameters are not declared in the global parameters
structure.
Figure 21
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 ..\hybrid.lib and object ..\hybrid.exp *** Created ADAMS dll C:\adams_controls_getting_started\antenna\hybrid_rsim_rtw>exit /B 0
### Successful completion of Real-Time Workshop build procedure for model: hybrid
Figure 22
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.
Figure 23
Information Window
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.
7. Press F8 to open Adams/PostProcessor. 8. Plot and animate, as desired. Adams/PostProcessor displays the plot of azimuth position versus time, as shown in below figure.
Figure 25
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.
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.
Figure 26
Optionally, if you repeat the tutorial to create ESL's for discrete and continuous models, and rerun, 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.
Figure 27
Re-run Result