Adams 2021.3 Getting Started Using Adams Controls
Adams 2021.3 Getting Started Using Adams Controls
3
Getting Started: Adams Controls
Corporate Europe, Middle East, Africa
MSC Software Corporation MSC Software GmbH
5161 California Ave, Suite 200 Am Moosfeld 13
University Research Park 81829 Munich, Germany
Irvine, CA 92617 Telephone: (49) 89 431 98 70
Telephone: (714) 540-8900 Email: [email protected]
Email: [email protected]
Japan Asia-Pacific
MSC Software Japan Ltd. MSC Software (S) Pte. Ltd.
KANDA SQUARE 16F 100 Beach Road
2-2-1 Kanda Nishikicho, Chiyoda-ku #16-05 Shaw Tower
Tokyo 101-0054, Japan Singapore 189702
Telephone: (81)(3) 6275 0870 Telephone: 65-6272-0082
Email: [email protected] Email: [email protected]
Worldwide Web
www.mscsoftware.com
Support
http://www.mscsoftware.com/Contents/Services/Technical-Support/Contact-Technical-Support.aspx
Disclaimer
This documentation, as well as the software described in it, is furnished under license and may be used only in accordance with the
terms of such license.
MSC Software Corporation reserves the right to make changes in specifications and other information contained in this document
without prior notice.
The concepts, methods, and examples presented in this text are for illustrative and educational purposes only, and are not intended
to be exhaustive or to apply to any particular engineering problem or design. MSC Software Corporation assumes no liability or
responsibility to any person or company for direct or indirect damages resulting from the use of any information contained herein.
User Documentation: Copyright © 2021 MSC Software Corporation. Printed in U.S.A. All Rights Reserved.
This notice shall be marked on any reproduction of this documentation, in whole or in part. Any reproduction or distribution of this
document, in whole or in part, without the prior written consent of MSC Software Corporation is prohibited.
This software may contain certain third-party software that is protected by copyright and licensed from MSC Software suppliers.
Additional terms and conditions and/or notices may apply for certain third party software. Such additional third party software terms
and conditions and/or notices may be set forth in documentation and/or at http://www.mscsoftware.com/thirdpartysoftware (or successor
website designated by MSC from time to time). Portions of this software are owned by Siemens Product Lifecycle Management, Inc.
© Copyright 2021
The MSC Software logo, MSC, MSC Adams, MD Adams, and Adams are trademarks or registered trademarks of MSC Software
Corporation in the United States and/or other countries. Hexagon and the Hexagon logo are trademarks or registered trademarks of
Hexagon AB and/or its subsidiaries. FLEXlm and FlexNet Publisher are trademarks or registered trademarks of Flexera Software.
Parasolid is a registered trademark of Siemens Product Lifecycle Management, Inc. All other trademarks are the property of their
respective owners.
ADAM:V2021.3:Z:Z:Z:DC-GS-CONT
Documentation Feedback
At MSC Software, we strive to produce the highest quality documentation and welcome your feedback.
If you have comments or suggestions about our documentation, write to us at: documentation-
[email protected].
Please include the following information with your feedback:
Document name
Release/Version number
Chapter/Section name
Topic title (for Online Help)
Brief description of the content (for example, incomplete/incorrect information, grammatical
errors, information that requires clarification or more details and so on).
Your suggestions for correcting/improving documentation
You may also provide your feedback about MSC Software documentation by taking a short 5-minute
survey at: http://msc-documentation.questionpro.com.
Note: The above mentioned e-mail address is only for providing documentation specific
feedback. If you have any technical problems, issues, or queries, please contact Technical
Support.
1
Antenna
Elevation bearings
Plate
Antenna support
Reduction gear
Azimuth rotor
Note: To automatically load Adams Controls each time Adams View starts up, select Load at
Startup in the Plugin Manager.
The base of the mechanism turns counterclockwise as the antenna tilts up and down.
4. Select OK.
Adams View deactivates the motion.
5. Select the Reset to Start tool 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.
Control
system
3. Double-click control_torque.
The Create/Modify State Variable dialog box appears.
8 Getting Started Using Adams Controls
Step Two - Creating the Adams Plant Inputs and Outputs
4. 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.
5. 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.
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. Look in the F(time, ...) = text box to verify that the run-time function for the output variable is
AZ(MAR70, MAR26).
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.
5. 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.
6. 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.
7. Select Cancel to close the dialog box.
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.
12. If Target Software is set to Easy5, verify that Dynamic States Output is selected.
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 (that is, 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.
13. Verify that the Plant Export dialog box is completed as shown in the figure below.
12 Getting Started Using Adams Controls
Step Two - Creating the Adams Plant Inputs and Outputs
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 Plugins tab, click on the Controls container and 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.
Introducing and Starting the Tutorials 13
Step Two - Creating the Adams Plant Inputs and Outputs
Notes: 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:
Note: Before beginning this tutorial, you should have finished Introducing and Starting the Tutorials.
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.
16 Getting Started Using Adams Controls
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
Notes: 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.
Learning Adams Controls with MATLAB Co-Simulation/Function Evaluation 17
Step Three - Adding Controls to the Adams Block Diagram
Note: An error or warning symbol may appear at the State-Space block indicating that the
ADAMS_a, ADAMS_b, ADAMS_c and ADAMS_d variables do not exist in
workspace. This is normal and can be ignored when the model has been exported as
non-linear from the Adams controls plant export as in this example.
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.
18 Getting Started Using Adams Controls
Step Three - Adding Controls to the Adams Block Diagram
2. From the File menu, point to New, and then select Blank 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.
Learning Adams Controls with MATLAB Co-Simulation/Function Evaluation 19
Step Three - Adding Controls to the Adams Block Diagram
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.
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.
5. From the File menu, select Save As, and enter a file name for your controls block diagram.
Learning Adams Controls with MATLAB Co-Simulation/Function Evaluation 21
Step Three - Adding Controls to the Adams Block Diagram
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 2-1
Note: If no output files are required, then insert empty single quotes ('').
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.
Learning Adams Controls with MATLAB Co-Simulation/Function Evaluation 25
Step Three - Adding Controls to the Adams Block Diagram
26 Getting Started Using Adams Controls
Step Three - Adding Controls to the Adams Block Diagram
export
LD_LIBRARY_PATH=/scratch/Adams/20xx/linux64:$LD_LIBR
ARY_PATH
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.
>>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.
• 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 Results tab, select Postprocessor.
Adams View launches Adams PostProcessor, a postprocessing tool that lets you view the results of the
simulations you performed (see the Figure 14). 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 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://www.mscsoftware.com/Support/Platform-Support/Default.aspx under Hardware & Software
Requirements for a list of supported compilers)
3. At the prompt (>>), type ant_test.
MATLAB displays:
34 Getting Started Using Adams Controls
Step Four – Create Adams Target for Code Generation
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
To create the Code Generation 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:
Learning Adams Controls with Control System Import from MATLAB 35
Step Five – Create Simulink Model
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 Linux:
adams2021_3 -c python ($adams_dir)/controls/utils/process.py -v 9.1 exit
• On Windows:
adams2021_3 python ($adams_dir)\controls\utils\process.py -v 9.1
Alternatively, you can copy the process.py file from the <adams_dir>/controls/utils/
directory on Linux or <adams_dir>\controls\utils\ on Windows to the current directory
and issue the following command:
• On Linux:
adams2021_3 -c python process.py -v 9.1 exit
• On Windows:
adams2021_3 python process.py -v 9.1
The argument -v 9.1 stands for MATLAB 9.1 (R2016b).
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 (that is,
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.
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 17 shows the hybrid system and Table 1 shows the topology.
Learning Adams Controls with Control System Import from MATLAB 37
Step Five – Create Simulink Model
4. From the treeview on the left side of the window, select Solver.
The dialog box displays the Solver options as shown in Figure 19
40 Getting Started Using Adams Controls
Step Six – Code Generation of Control System
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.
7. From the treeview on the left side of the window, select Optimization → Signals and Parameters.
The dialog box displays the Advanced options as shown in the Figure 20.
8. Set the Default parameter behavior to Inlined. Check the Inline Invariant Signals checkbox.
Enabling Inline parameters has the following effects:
• Code Generation uses the numerical values of model parameters, instead of their symbolic
names, in generated code.
Learning Adams Controls with Control System Import from MATLAB 41
Step Six – Code Generation of Control System
• Reduces global RAM usage, because parameters are not declared in the global parameters
structure.
9. Select Apply.
10. Select the Code Generation tab.
11. To begin code generation and build the RTW library, select Code → C/C++ Code → Build Model.
Messages will appear in the MATLAB command window indicating successful code generation and
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 Code Generation build procedure for model:
hybrid
The library you created will be in your working directory.
42 Getting Started Using Adams Controls
Step Seven – Create GSE from the Simulink Model
Adams View displays information on the GSE created (See Figure 22). The Database Navigator shown
in Figure 23 shows the GSE and its associated arrays.
Learning Adams Controls with Control System Import from MATLAB 43
Step Seven – Create GSE from the Simulink Model
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.
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 .01 second. The control torque versus time from three
simulations is plotted in Figure 25. 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.
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 26. 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.
46 Getting Started Using Adams Controls
Step Seven – Create GSE from the Simulink Model
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://www.mscsoftware.com/Support/Platform-Support/Default.aspx 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:
48 Getting Started Using Adams Controls
Step Three - Generate S-Function Using Code Generation
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
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 51
Step Three - Generate S-Function Using Code Generation
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 Code → C/C++ Code → Code Generation Options. Under Target selection, select Browse
and choose the S-Function Target, rtwsfcn.tlc.
Figure 30 Discrete/Configuration
5. Select Apply to apply your changes, and then select Build to build the S-Function.
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, discrete_sf.mexw32.
52 Getting Started Using Adams Controls
Step Three - Generate S-Function Using Code Generation
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):
This is the block to be included in the Simulink model for the Adams External System Library.
Learning Adams Controls with Control System Import from MATLAB with S-Functions 53
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 Code Generation. This will create variables required and modify the MATLAB path to
pickup setup scripts and functions.
To create the Code Generation 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.
2. Copy S-Function block to setio model, and connect the inputs appropriately.
3. Save as discrete_sf_mdl.mdl:
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.
56 Getting Started Using Adams Controls
Step Four - Use S-Function to Create Adams External System Library
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 → Signals and Parameters.
The dialog box displays the Advanced options as shown in the figure below.
8. Verify that Default parameter behavior is set to Inlined. Check the Inline Invariant Signals
checkbox. Enabling Inline parameters has the following effects:
• Code Generation uses the numerical values of model parameters, instead of their symbolic names,
in generated code.
Learning Adams Controls with Control System Import from MATLAB with S-Functions 57
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.
9. Select Apply
10. Select the Code Generation 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.lib and object...\
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 Code Generation build procedure for
model: discrete_sf_mdl
The library you created will be in your working directory.
58 Getting Started Using Adams Controls
Step Five - Use S-Function without source code to Create ESL
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:
60 Getting Started Using Adams Controls
Step Five - Use S-Function without source code to Create ESL
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:
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 Code Generation
tab, and then select Apply:
62 Getting Started Using Adams Controls
Step Five - Use S-Function without source code to Create ESL
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
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.
16. To use this ESL in Adams, See the section Step Seven - Use the S-Function ESL in Adams Control System
Import.
Learning Adams Controls with Control System Import from MATLAB with S-Functions 63
Step Six - Expose S-Function Parameters to Adams
Note: The main RTW details can be found also written for another example here:
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:
64 Getting Started Using Adams Controls
Step Six - Expose S-Function Parameters to Adams
Learning Adams Controls with Control System Import from MATLAB with S-Functions 65
Step Six - Expose S-Function Parameters to Adams
2. Note that you must remove the square brackets [ ] to parameterize this field. The model should now
look like the following:
66 Getting Started Using Adams Controls
Step Six - Expose S-Function Parameters to Adams
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
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:
Learning Adams Controls with Control System Import from MATLAB with S-Functions 67
Step Six - Expose S-Function Parameters to Adams
5. Under Configuration Parameters, select the Code Generation 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.
8. In model with S-Function, select Kp1 and Kp2 as Global (tunable) parameters again:
Learning Adams Controls with Control System Import from MATLAB with S-Functions 69
Step Six - Expose S-Function Parameters to Adams
9. Under Configuration Parameters, select the Code Generation tab, and select the Adams Controls-
modified RSIM target for the System Target File.
70 Getting Started Using Adams Controls
Step Six - Expose S-Function Parameters to Adams
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:
Learning Adams Controls with Control System Import from MATLAB with S-Functions 71
Step Six - Expose S-Function Parameters to Adams
1. After loading the ESL, Adams Controls will show these variables in the Adams Information window:
Object Name : .main_olt.discrete_sf_gse.RTWSFunction_P1_Size_1_1
Object Type : Variable
Parent Type : General_State_Equation
Real Value(s) : 1.0 NO UNITS
Units : no_units
Note: The "size" parameters denote the size of the MATLAB array that stores the parameters.
You may ignore these values.
2. Run a simulation for 0.25 seconds, 250 steps with the default parameter settings.
3. Save this simulation as "baseline".
4. Select Tools → Table Editor to modify the parameters from your ESL.
Learning Adams Controls with Control System Import from MATLAB with S-Functions 73
Step Six - Expose S-Function Parameters to Adams
6. Run another simulation for 0.25 seconds, 250 steps with the new parameter settings.
7. Save this simulation as "new".
74 Getting Started Using Adams Controls
Step Seven - Use the S-Function ESL in Adams Control System Import
8. Switch to PostProcessor and plot the azimuth position for the baseline vs. new results. You should
see something similar to the plot below:
6. Complete the dialog box as shown in Figure 37, and then select OK.
Note: Before beginning this tutorial, you should have finished Introducing and Starting the Tutorials, and
have the Adams Extension for Easy5 installed (refer to the online help for more information).
Starting Easy5
To start Easy5:
Start Easy5 on your system from the directory that contains the file with the antenna example. This
is the working directory that you created in Step One - Build the Adams Model.
The Easy5 main window appears.
Note: The next two sections describe how to create a new Adams Interface block, and how to
configure it to run different analyses. You should review these sections before proceeding to
Constructing the Controls System Block Diagram where you will actually create a model (or
load the existing example).
2. Select Select/Configure Adams model in the lower left corner of the Component Data Table.
The Adams Interface dialog box appears as shown in Figure 41.
Learning Adams Controls with Easy5 Co-Simulation/Function Evaluation 81
Step Three - Adding Controls to the Adams Block Diagram
3. Select ant_test.
4. Select Co-Simulation (Discrete).
Notes on the simulation options:
Options for Function Evaluation (1 and 2) are continuous simulation methods, integrating
completely within Easy5. Option for co-simulation (3) is a discrete simulation method where Easy5
integrates the Easy5 model, and Adams integrates the Adams model, exchanging data at a specified
communication interval.
82 Getting Started Using Adams Controls
Step Three - Adding Controls to the Adams Block Diagram
Regarding Feedthrough: Feedthrough refers to whether the inputs directly affect the outputs (for
example, forces directly affect accelerations), or not (for example, forces do not directly affect
positions, velocities). In other words, if you've linearized a nonlinear Adams model and represented
it as A, B, C, and D matrices and the matrix D is zero at all times, then there is no feed-through from
the input variables to the output variables. If the matrix D is not zero at all times, then there is feed-
through from the input variables to the output variables.
Options for Linear State Matrices (4 and 5) are linear methods that are solved completely within
Easy5.
For information on choosing a simulation method, see the online help.
5. Select Done.
The Adams Interface dialog box closes, and the Component Data Table now looks like in Figure 42:
Tip: For a description of the component inputs, outputs, and states, select the Info button
Learning Adams Controls with Easy5 Co-Simulation/Function Evaluation 83
Step Three - Adding Controls to the Adams Block Diagram
Note: You configure the Adams block the first time by reading in an .inf file. This defines
the extension inputs, such as ADAMS_Animation_Mode, ADAMS_Solver, and so on.
Subsequent reconfigurations of the block by reading in a new .inf file do not
overwrite the existing setting. You can change the settings of the extension inputs at any
time by manually resetting them before closing the Adams block CDT using the OK
button.
6. In the Component Data Table, in the Inputs tab, enter a value for the following input modes:
• For ADAMS_Animation_Mode, enter 1 to define interactive mode as the animation mode. For
more details about animation modes, see the Adams Controls online help.
• For ADAMS_Output_Interval (output rate interval), enter .001.
• For Communication_Interval (communication rate interval between Adams and Easy5), enter
0.001. It should not be larger than the ADAMS_Output _Interval.
Note: The ADAMS_Output _Interval in the Component Data Table determines the rate at
which Adams Controls writes its result to file (and updates the animation, if in
interactive mode). It is the interval at which the result is written to file once. It has the
lower limit of Time Increment (see step 5), and works best if ADAMS_Output
_Interval is a multiple of Time Increment for integration. The same rule applies to the
Strip Chart output rate.
• Alternatively, if you select Option 1 in step 4, the Component Data Table appears as follows:
• In function evaluation mode, the communication interval option is not needed because the
integrators determine the communication interval.
• Leave Use_ADAMS_ICs at its default (1).
If the Use_ADAMS_ICs flag is set to 1, the model uses the Adams initial conditions.
If the flag is set to 0, the model relies on Easy5 to provide the initial conditions (for example,
starting a simulation from the end of the last run simulation, which is stored in Easy5).
• Set the parameters as shown in Figure 43.
84 Getting Started Using Adams Controls
Step Three - Adding Controls to the Adams Block Diagram
5. Connect the input blocks by clicking once on the First Order Lag block and then on the Adams
Mechanism Block.
Easy5 labels this connection as S_Out_LA11.
6. Connect the output blocks in the diagram by clicking on the Adams Mechanism Block and then on
the Summing Junction block. Be sure to connect the azimuth+position output to the first Summing
Junction block (SJ) and the rotor_velocity output to the second Summing Junction block (SJ11).
7. Connect the Strip Chart to the Adams Mechanism Block.
Be sure to connect only the rotor_velocity output to the Strip Chart.
The rotor_velocity output corresponds to the rotor-velocity signal from the Adams Mechanism
Block.
86 Getting Started Using Adams Controls
Step Four - Simulating the Model
8. Click the Strip Chart using the middle mouse button to display the Component Data Table. Set the
sample period TAU to .001, and then select OK.
Note: You must edit the connection from the Adams Mechanism Block to the Strip Chart
because Easy5 automatically connects the state vector from the Adams block to the
display variable on the Strip Chart.
9. From the File menu, select Save As, and then enter a file name for your controls block diagram.
You have now created the controls block diagram.
Note: If you are using the completed block diagram from the file, antenna.0.ezmf, which
was provided for you in the examples directory, you may find that the Plot
Specification Form opens with information that is unnecessary for this tutorial. After
removing this information, the Plot Specification Form should look like the shown in
Figure 45.
88 Getting Started Using Adams Controls
Step Four - Simulating the Model
4. Select the variables that you want to plot for the simulation.
For this tutorial, you will select three variables: rotor_velocity, azimuth_position, and S_Out_ LA11.
a. Under Dependent Variables, select the Variable #1 field.
Select the icon next to the field. The Select Plot Variables select list appears.
b. Expand the AD component, and then double-click rotor_velocity to select it.
The rotor_velocity component now appears as Variable #1 to be plotted.
• Repeat this procedure for the second and third variable. For the second variable, select
azimuth_position, and for the third, select S_Out_ LA11 (the input to the Adams block
as indicated in Figure 44).
The finished Plot Specification Form should look like the one in Figure 46.
5. Return to the General tab in the Simulation Data Form window, and then specify the following
simulation parameters:
Learning Adams Controls with Easy5 Co-Simulation/Function Evaluation 89
Step Four - Simulating the Model
Note: The Adams model is initialized to the current simulation time in Easy5.
2. Start and pause the simulation by selecting Continue and Break on the interactive plot window.
Adams View accepts the control inputs from Easy5 and integrates the Adams model in response to
them. At the same time, Adams provides the azimuthal position and rotor velocity information for
Easy5 to integrate the Simulink model. The simulation process creates a closed loop in which the
control inputs from Easy5 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.
2. Now go back to Adams View. While the simulation is paused, you can change the orientation of the
model with the View Manipulation Strip in the Main menu. These tools help you to look at the model
from different vantage points.
3. Once you have finished reorienting the model, select Continue to continue the simulation.
Adams View closes automatically after the simulation finishes.
in Easy5 by selecting a variable from the Plot Selection Menu. In this tutorial, you’ll plot the curve for control
torque.
Note: You can plot any data from the simulation and rerun the animation from Adams View.
Learning Adams Controls with Easy5 Co-Simulation/Function Evaluation 93
Step Four - Simulating the Model
In the previous chapter, you configured the Adams component of the antenna controller model to
run in co-simulation mode. Because you want the controller to execute as a set of equations inside
Adams, you must reconfigure the Adams Mechanism component to be in function-evaluation mode.
Failure to reconfigure the Adams component may result in a model that does not behave correctly in
Adams. If you have already configured your Adams component to be in function-evaluation mode,
you may skip 2.
2. To reconfigure the Adams component:
a. Double-click the Adams Mechanism Block to open the Component Data Table (CDT) shown
in Figure 52.
Learning Adams Controls with Control System Import from Easy5 97
Step Three - Export Your Easy5 Model
b. Select Select/Configure Adams Model to open the Configure Adams block panel.
98 Getting Started Using Adams Controls
Step Three - Export Your Easy5 Model
c. Select ant_test as the exported Adams model and choose the first option for execution mode:
Function Evaluation (no feedthrough).
d. Close the panel by selecting Done.
The Component Data Table for the Adams Mechanism Block is updated as shown next.
Learning Adams Controls with Control System Import from Easy5 99
Step Three - Export Your Easy5 Model
Note: The following Adams block inputs in the CDT are not relevant:
ADAMS_Animation_Mode, ADAMS_Output_Interval, and Use_Adams_ICs.
Messages in the message line at the bottom of the Easy5 window show the progress of the library
build. After a successful build, you will have two new files in your working directory. The first file
is a binary demand-loaded library file (named antenna.dll on Windows, antenna.sl on
HP-UX11 workstations, or antenna.so on other Linux platforms). The second file (named
antenna.esl.ezanl) contains the parameter values and other information the Easy5 model
needs. If you need to move these files to another directory (for example, to make the Easy5 model
available to other Adams users), you must move the two files together or the exported Easy5 model
will not work.
c. Exit Easy5.
4. When you have finished examining the Information window, select Close.
The Easy5 controls system has now been incorporated into your Adams model. Next you'll run a
simulation to see how it performs.
Learning Adams Controls with Control System Import from Easy5 103
Step Five - Run a Simulation