Students Guide

download Students Guide

of 102

description

Adams multi-body dynamics

Transcript of Students Guide

  • 1ADAMS/Controls Version 12TRAINING

  • 2Contents

    Contents

    Chapter 1: Welcome to ADAMS/Controls Training 6A Brief History of ADAMS 7About Mechanical Dynamics 8Getting Help in Class 9Getting Help at Your Job Site 10A Recap of Basic ADAMS Terminology 11 Design Methodology with/without ADAMS/Controls 12

    Chapter 2: Modeling Controls in ADAMS 15Open Loop Control Systems 16Closed Loop Controls Systems 17ADAMS/Controls Process 19ADAMS/Controls Compatibility with CSS 20

  • 3Contents

    Contents

    Chapter 3: Overview of Using ADAMS/Controls 22ADAMS/Controls Goal: create ADAMS Plant for simulation

    24Four Step Process 25Step 1: Exporting Plant Files from ADAMS for the CSS 26 Step 2: Creating the Plant in CSS 30Step 3: Connecting the ADAMS Plant and adjusting the

    simulation parameters 34Step 4: Running simulations from the CSS 37Workshop 1: The Controls Process 43

    Chapter 4: Setting Up Your ADAMS model for Plant Export 53Creating Plant Inputs and Plant Outputs 54ADAMS Variable Types 55Creating Input State Variables 56Creating Output State Variables 58Specifying Plant Input/Output for Plant Export 59State Variable Order in Plant Inputs/Outputs 60 Workshop 2: Creating State Variables 61

  • 4Contents

    Contents

    Chapter 5: Simulation Modes: Discrete vs. Continuous 69Discrete Mode 70Continuous Mode 71Continuous vs. Discrete Mode 74Co-simulation Process 76State Repartitioning 78Output Step Size/Sampling Rate 79Workshop 3 : Discrete vs. Continuous Results 80

    Chapter 6: Preparing Simulations 89Licenses (or) Should View be running? 90Speeding Up Simulations 91Initialization Commands 92 Workshop 4: Initialization Commands 93

    Chapter 7: Advanced Topics 97User Libraries/Subroutines 98 Debugging Models: General Tips 100Error Messages: Plant Communication Error 101

  • 5 Contents

  • 6Chapter 1: Welcome to ADAMS/Controls Training

    Chapter 1: Welcome to ADAMS/Controls Training

    Within this chapter, you will find the following topics:

    A Brief History of ADAMS 7About Mechanical Dynamics 8Getting Help in Class 9Getting Help at Your Job Site 10A Recap of Basic ADAMS Terminology 11 Design Methodology with/without ADAMS/Controls 12

  • 7A Brief History of ADAMS

    Chapter 1: Welcome to ADAMS/Controls Training

    ADAMS: Automatic Dynamic Analysis of Mechanical Systems.Technology has been around for 25 years.Mechanical Dynamics Incorporated formed by researchers that developed the base ADAMS code at University of Michigan, Ann Arbor, Michigan, USA.Large displacement code.Systems based analysis.Original product was the ADAMS/Solver, an application that solves non-linear numerical equations. Models are built up in text format then submitted to Solver. In the early 90s, the ADAMS/View GUI was released which allowed the user to build, simulate and examine results in a single environment.Today, industry focused products are being produced such as ADAMS/Car, ADAMS/Rail, ADAMS/Engine etc.

  • 8About Mechanical Dynamics

    Chapter 1: Welcome to ADAMS/Controls Training

    Find a list of ADAMS products at:

    http://www.adams.com/mdi/product/modules.htm

    Learn about the ADAMS CAD/CAM/CAE integration at:

    http://www.adams.com/mdi/product/partner.htm

    Find additional training at:

    http://support.adams.com/training/training.html

    or your local support center.

    Get custom information at my.adams.com:

    http://my.adams.com

  • 9Getting Help in Class

    Chapter 1: Welcome to ADAMS/Controls Training

    Performing searches on any online ADAMS guide.

  • 10

    Getting Help at Your Job Site

    Chapter 1: Welcome to ADAMS/Controls Training

    Online guides

    Use the Help menu in the ADAMS toolbar

    Knowledge Base

    Go to http://support.adams.com/

    and select Technical Support Knowledge Base

    ASK Email-Based Users Group

    Go to http://support.adams.com/

    and select Technical Support ASK Email Listservers

    Consulting Services

    Go to http://support.adams.com/

    and select Expert Consultants

    Technical Support

    To read the Service Level Agreement, go to http://support.adams.com/ and select Technical Support Standard Service Level Agreement

    To find you support center, go to http://support.adams.com/and select Technical Support Support Centers

  • 11

    A Recap of Basic ADAMS terminology.

    Chapter 1: Welcome to ADAMS/Controls Training

    ADAMS/SolverThe solution engine.

    ADAMS/Solver Deck (*.adm file)The actual ASCII format file submitted to the ADAMS/Solver.

    ADAMS/Solver Command (*.acf file)An ASCII file which contains commands to control how the ADAMS/Solver runs the model.

    ADAMS/Solver Output Files.Graphics (*.gra file) Information about how graphics work.Request (*.req file) Contains output for a user-defined set of results.Results (*.res file) - Contains state results for every entity. Message (*.msg file) Information about the solver/simulation/problems.Output (*.out file) Output including initial conditions and request, and content can depend on output specifications.

  • 12

    Why You Use ADAMS/Controls: Typical Design Methodology

    Chapter 1: Welcome to ADAMS/Controls Training

    PhysicalPrototype

    Design Verification& Testing

    Controls Designer

    Mechanical Designer

    Concept

    Design

    Design

  • 13

    Design Methodology with ADAMS/Controls

    Chapter 1: Welcome to ADAMS/Controls Training

    Controls Designer

    Mechanical Designer

    Share same model

    VirtualPrototype

    Concept

    PhysicalPrototype

    Design Verification& Testing

    Design

    Design

  • 14

    Notes

    Chapter 1: Welcome to ADAMS/Controls Training

  • 15

    Chapter 2: Modeling Controls with ADAMS

    Chapter 2: Modeling Controls with ADAMS

    Within this chapter, you will find the following topics:

    Open Loop Control Systems 16Closed Loop Controls Systems 17ADAMS/Controls Process 19ADAMS/Controls Compatibility with CSS 20

  • 16

    Open Loop Control Systems

    Chapter 2: Modeling Controls with ADAMS

    Open loop performance is determined by the calibration Open loop not generally troubled with instability Open loop not generally high performance Open Loop Example: automatic toaster uses timer

    Control Elements

    PlantReferenceInput Controlled Output

    Controlvariable

    Disturbance

    Transfer Function = Controlled OutputReference Input

  • 17

    Closed Loop Control Systems

    Chapter 2: Modeling Controls with ADAMS

    A closed loop control system is one in which the control action is dependent on the output (usually), using feedback.

    Feed back is

    A property of a closed loop system which permits the output (or some

    other state of the system) to be compared with the input (or some

    other state of the system), so that the appropriate control action

    may be formed as some function of both the output and the input.

    Benefits of a closed-loop system over an open-loop system: Provides increased accuracy to track an input signal Reduced sensitivity to variations in the system Reduced effect of non-linearities Increased bandwidthExample: home thermostat

  • 18

    Closed Loop Control Systems

    Chapter 2: Modeling Controls with ADAMS

    Control Elements Plant

    FeedbackElements

    +-/+

    ReferenceInput

    Controlvariable

    Controlled Output

    Disturbance

    FeedbackSignal

    ActuatingSignal

    Transfer Function = Controlled OutputReference Input

    Controller

  • 19

    ADAMS/Controls Process

    Chapter 2: Modeling Controls with ADAMS

    ADAMSPlant

    Controlvariable

    Controlled Output

    Produced by ADAMS/Controls:

    Control Elements

    ADAMSPlant

    FeedbackElements

    +-/+

    Inserted into your CSS model for simulation:

  • 20

    ADAMS/Controls Compatibility with CSS

    Chapter 2: Modeling Controls with ADAMS

    ADAMS/Controls v12.0 is compatible with:

    MATLAB EASY5MATRIXx

    (MATRIXx support will parallel Mathworks support)

    See the Partner Integration information at www.adams.comfor specific release compatibility. For ADAMS v12.0, this can be found at:

  • 21

    Notes

    Chapter 2: Modeling Controls with ADAMS

  • 22

    Notes

    Chapter 2: Modeling Controls with ADAMS

  • 23

    Chapter 3: Overview of Using ADAMS/Controls

    Chapter 3: Overview of Using ADAMS/Controls

    Within this chapter, you will find the following topics:

    ADAMS/Controls Goal: create ADAMS Plant for simulation 24Four Step Process 25Step 1: Exporting Plant Files from ADAMS for the CSS 26Step 2: Creating the Plant in CSS 30Step 3: Connecting the ADAMS Plant and adjusting the simulation parameters 34Step 4: Running simulations from the CSS 37Workshop 1: The Controls Process 43

  • 24

    ADAMS/Controls Goal: Create Plant for Simulation

    Chapter 3: Overview of Using ADAMS/Controls

    Steps for setting up your model in ADAMS for use with ADAMS/Controls.

    Goal: create ADAMS model to insert into controls model

    Example: Antenna Control ProblemAzimuth and Elevation DOFFlexible supportDisturbance to elevation loopInput torques applied

  • 25

    Four Step Process

    Chapter 3: Overview of Using ADAMS/Controls

    Mechanical System Simulation- Create ADAMS model

    -Define control inputs and -sensor outputs

    - Create ADAMS model-Define control inputs and -sensor outputs

    Control System Design

    - Build system block diagram- Include ADAMS block

    - Build system block diagram- Include ADAMS block

    - Export model- Create .m or .inf file

    - Export model- Create .m or .inf file

    1

    - Connect inputs and outputs -Perform simulation of -combined systems

    - Connect inputs and outputs -Perform simulation of -combined systems

    - Simulate and analyze- Visualize system in motion

    - Simulate and analyze- Visualize system in motion

    Mechanical System Simulation

    Control System Design

    2

    3 4

  • 26

    Four Step Process: Step 1

    Chapter 3: Overview of Using ADAMS/Controls

    Step 1: Exporting the Plant Files from ADAMS for the controls simulation software (CSS)

    Example: Create or obtain antenna model; define variables to be used as inputs and outputs to antenna model (forces, torques to control antenna motion; azimuth and elevation position measurements)

    Mechanical System Simulation

    - Create ADAMS model- Define control inputs and sensor outputs

    - Create ADAMS model- Define control inputs and sensor outputs

    - Export model- Create .m or .inf file

    - Export model- Create .m or .inf file

    1

  • 27

    Four Step Process: Step 1 (continued)

    Chapter 3: Overview of Using ADAMS/Controls

    Step 1 (continued): Exporting the Plant Files from ADAMS for the CSS

    Plant export feature will create files specifically to generate an ADAMS antenna plant in the CSS:.adm and .cmd files that describe mechanical model.acf file includes solver commands (not necessarily used) .m file for MATLAB; .inf for MATRIXx and EASY5

  • 28

    Four Step Process: Step 1 (continued)

    Chapter 3: Overview of Using ADAMS/Controls

    Step 1 (continued): Exporting the Plant Files from ADAMS for the CSS

    Example: antenna model produces .m shown below

    addpath( 'F:\PROGRA~1\ADAMS1~2.0/controls' ) ;addpath( 'F:\PROGRA~1\ADAMS1~2.0\controls\matlab' ) ;% ADAMS / MATLAB Interface - Release 12.0.0ADAMS_sysdir = 'F:\PROGRA~1\ADAMS1~2.0' ;ADAMS_exec = '' ;ADAMS_prefix = 'ant_test' ;if (exist([ADAMS_prefix,'.adm']))

    ADAMS_static = 'no' ;ADAMS_init = '' ;ADAMS_inputs = 'control_torque' ;ADAMS_outputs = 'rotor_velocity!azimuth_position' ;ADAMS_pinput = '.main_olt.tmp_MDI_PINPUT' ;ADAMS_poutput = '.main_olt.tmp_MDI_POUTPUT' ;ADAMS_uy_ids = [

    123] ;

    ADAMS_mode = 'non-linear' ;tmp_in = decode( ADAMS_inputs ) ;tmp_out = decode( ADAMS_outputs ) ;disp( ' ' ) ;disp( '%%% INFO : ADAMS plant actuators names :' ) ;disp( [int2str([1:size(tmp_in,1)]'),blanks(size(tmp_in,1))',tmp_in] ) ;disp( '%%% INFO : ADAMS plant sensors names :' ) ;disp( [int2str([1:size(tmp_out,1)]'),blanks(size(tmp_out,1))',tmp_out] ) ;disp( ' ' ) ;clear tmp_in tmp_out ;

    elsedisp( ' ' ) ;disp( '%%% ERROR : missing ADAMS plant model file !!!' ) ;disp( ' ' ) ;

    end% ADAMS / MATLAB Interface - Release 12.0.0

    Paths

    Model Files Prefix (produced by plant

    export)

    Variables

  • 29

    Four Step Process: Step 1 (continued)

    Chapter 3: Overview of Using ADAMS/Controls

    Step 1 (continued): Exporting the Plant Files from ADAMS for the CSS

    Example: antenna model produces .inf shown below

    C:\Program Files\ADAMS 12.0

  • 30

    Four Step Process: Step 2

    Chapter 3: Overview of Using ADAMS/Controls

    Step 2: Creating the Plant in CSS

    Create control model (except for plant)Read in the .m/.inf file to set up the paths, variables

    Control System Design

    - Build system block diagram- Include ADAMS block

    - Build system block diagram- Include ADAMS block

    2

  • 31

    Four Step Process: Step 2(continued)

    Chapter 3: Overview of Using ADAMS/Controls

    Step 2 (continued): Creating the Plant in CSS

    MATLABAfter the .m is read into MATLAB, type adams_sys which will generate the ADAMS plant

  • 32

    Four Step Process: Step 2 (continued)

    Chapter 3: Overview of Using ADAMS/Controls

    Step 2 (continued): Creating the Plant in CSS

    MATLABDouble click the adams_sub block to see:Input and output names are automatically createdWorkspace hooks are also automatically created

  • 33

    Four Step Process: Step 2(continued)

    Chapter 3: Overview of Using ADAMS/Controls

    Step 2 (continued): Creating the Plant in CSS

    EASY5Create an ADAMS Extension which references the .inf file created in Step 1

  • 34

    Four Step Process: Step 3

    Chapter 3: Overview of Using ADAMS/Controls

    Step 3: Connecting the ADAMS Plant and adjusting the simulation parameters in the CSS

    - Connect inputs and outputs - Perform simulation of combined systems

    - Connect inputs and outputs - Perform simulation of combined systems

    Control System Design

    3

  • 35

    Four Step Process: Step 3 (continued)

    Chapter 3: Overview of Using ADAMS/Controls

    Step 3 (continued): Creating the Plant in CSS

    MATLAB Plant MaskDouble click the Mechanical Dynamics block to bring up the maskHere you select modes from and gain access to the full capabilities of ADAMS/Controls

  • 36

    Four Step Process: Step 3 (continued)

    Chapter 3: Overview of Using ADAMS/Controls

    Step 3 (continued): Creating the Plant in CSS

    EASY5Double click the Mechanical Dynamics block to bring up the Component Data TableHere you select modes from and gain access to the full capabilities of ADAMS/Controls

  • 37

    Four Step Process: Step 4

    Chapter 3: Overview of Using ADAMS/Controls

    Step 4: Running simulations from the CSS

    Example: Antenna model will simulate according to controls inputs (forces, torques, etc.)

    - Simulate and analyze- Visualize system in motion

    - Simulate and analyze- Visualize system in motion

    Mechanical System Simulation

    4

  • 38

    Four Step Process: Step 4 (continued)

    Chapter 3: Overview of Using ADAMS/Controls

    Step 4(continued): Running simulations from the CSS

    Use Simulation Parameters in MATLAB to control the control system integrator step size, end time, and integrator settings.

  • 39

    Four Step Process: Step 4 (continued)

    Chapter 3: Overview of Using ADAMS/Controls

    Step 4(continued): Running simulations from the CSS

    Interactive vs. Batch ModesInteractive mode launches ADAMS/View (vcontrols.exe will use the .cmd file and see the model update)Batch mode launches ADAMS/Solver (scontrols.exe will use the .adm file and will not see the model update, but will run faster)

    Set animation mode here

  • 40

    Step 4 (continued)

    Chapter 3: Overview of Using ADAMS/Controls

    Step 4(continued): Running simulations from the CSS

    MATLAB Notes:

    Input and output variables are automatically saved to the workspace (if adams_sub block is used)Use/modify MATLAB variable names to push data onto the mask instead of editing the mask entries directlyMask variables are accessible via command line if you wish to set them manually or in a MATLAB script

  • 41

    Four Step Process: Step 4 (continued)

    Chapter 3: Overview of Using ADAMS/Controls

    Step 4(continued): Running simulations from the CSS

    EASY5Use Analysis Simulation to control the control system integrator step size, end time, and integrator settings.

  • 42

    Four Step Process: Step 4 (continued)

    Chapter 3: Overview of Using ADAMS/Controls

    Step 4(continued): Running simulations from the CSS

    Interactive vs. Batch ModesInteractive mode launches ADAMS/View (vcontrols.exe will use the .cmd file and see the model update)Batch mode launches ADAMS/Solver (scontrols.exe will use the .adm file and will not see the model update, but will run faster)In EASY5, set the animation mode with the ANI_MOD variable in the ADAMS block:

  • 43

    Workshop 1: The Controls Process

    Chapter 3: Overview of Using ADAMS/Controls

    In this workshop, you will export a non-linear ADAMS model to your CSS (MATLAB or EASY5) by creating state variables for inputs and outputs to you ADAMS plant. You will also setup a pre-built controls model to observe how the co-simulation process works.

    1. Open ADAMS/View.

    NT: Select Start Programs ADAMS 12.0 AView ADAMS - View

    Unix: Open a shell and type the alias adams120which points to the mdi script to launch the ADAMS toolbar. Next, select the ADAMS/View button (1st button).

    2. Select 'Import File' and find the 'antenna.cmd' file in the /Workshop1-General/ folder to load the antenna model.

    3. Simulate the antenna model for 0.5 seconds and 100 steps to see what it does. Note the gear and applied torque at the base.

    4. Load the ADAMS/Controls plugin with Tools Plugins Controls Load

    5. Select Controls Plant Export

  • 44

    Workshop 1: The Controls Process

    Chapter 3: Overview of Using ADAMS/Controls

    To work with MATLAB, follow steps 6 20.

    To work with EASY5, follow steps 21 38.

    MATLAB Steps

    6. Specify information about this mechanical model as MATLAB is going to see it. Enter the following:

    File Prefix: ant_test - this tells ADAMS to write out a ant_test.m file containing state variable and file location information that MATLAB understands.

    Plant Input: tmp_MDI_PINPUT. This contains the variable, control_torque - our plant input signal.

    Plant Output: tmp_MDI_POUTPUT. This contains the variabless, rotor_velocity & azimuth_position - our plants outputs.

    Control package: MATLAB

    Type: non_linear - our plant is a nonlinear description of our mechanical system (as opposed to linearized about some operating point).

    7. Select 'OK' to write out a plant description.

    We've supposedly written out a valid description of our mechanical system that MATLAB can handle. Now to import it into MATLAB.

  • 45

    Workshop 1: The Controls Process

    Chapter 3: Overview of Using ADAMS/Controls

    8. Start MATLAB by typing matlab'. Ensure that you're in the working directory where your .m file is. You can use cd and ls in the MATLAB environment to navigate through directories.

    9. Load the ant_test.m file that you just made in ADAMS into MATLAB by simply typing the name of the file (ant_test).

    10. Type 'who' to give you a listing of all the variables currently defined in the MATLAB environment. See that you now have several ADAMS_*** variables defined in MATLAB. These tell MATLAB how to interact with ADAMS.

    11. Type the highly intuitive command 'adams_sys' to build a Simulink block representing your mechanical system.

    12. The block named adams_sub represents your non-linear mechanical system. Note it's two outputs (that you've previously defined) and the single input.

    13. Select File Open from the Simulink window containing your ADAMS plant block. Select 'antenna.mdl' to read in a pre-made control system for the antenna. The adams_sub block has already been added (with the adams_sys MATLAB command).

    14. In the Simulink window containing all of the control system elements, select Simulation Simulation Parameters.. and set:

    Stop time = 0.5

    Max. Step size = 0.001

  • 46

    Workshop 1: The Controls Process

    Chapter 3: Overview of Using ADAMS/Controls

    15. Select OK'.

    16. Select Simulation Start to run a simulation.

    17. Take a look at the output by double clicking the terminal icons labeled 'rotor_vel' and 'azimuth_pos'.

    18. Note that the azimuth position has been driven to a fixed value and the rotor velocity has increased then dropped back to zero.

    19. Change the control parameters (step function end value, gain value) and resimulate.

    20. Change the animation mode in the ADAMS plant mask (batch vs. interactive) - note solution speed difference.

  • 47

    Workshop 1: The Controls Process

    Chapter 3: Overview of Using ADAMS/Controls

    EASY5 Steps

    21. Specify information about this mechanical model as EASY5 is going to see it. Enter the following:

    File Prefix: ant_test - this tells ADAMS to write out a ant_test.inf file containing state variable and file location information that EASY5 understands.

    Plant Input: tmp_MDI_PINPUT. This contains the variable, control_torque - our plant input signal.

    Plant Output: tmp_MDI_POUTPUT. This contains the variabless, rotor_velocity & azimuth_position - our plants outputs.

    Control package: MATRIXx_and_EASY5

    Type: non_linear - our plant is a nonlinear description of our mechanical system (as opposed to linearized about some operating point).

    22. Select 'OK' to write out a plant description.

    We've supposedly written out a valid description of our mechanical system that EASY5 can handle. Now to import it into EASY5.

    23. Start EASY5:UNIX: Type easy5'. Windows: Start Programs EASY5 61Ensure that you're in the working directory where the antenna.mf.0 model and ant_test.inf are.

  • 48

    Workshop 1: The Controls Process

    Chapter 3: Overview of Using ADAMS/Controls

    24. Open the EASY5 model antenna.mf.0

    The EASY5 model opens. Notice that it already contains an ADAMS non-linear model block, so you do not need to create one. Note it's two outputs (that you've previously defined) and the single input.

    Now, before you connect the AD block to the rest of the system, initialize the AD block

    25. Open up the Component Data Table for the AD block and select Spawn ADAMS Interface

    26. Enter the name of the .inf file (ant_test.inf).

    27. Enter 25 for the maximum number of states.

    28. Enter 3 to submit a co-simulation (discrete) analysis.

    Your AD block is now initialized.

    29. Select OK in the AD Component Data Table.

    30. Select Build Create Executable to compile and link the model.

    31. In the EASY5 main menu, select Analysis Simulationand set:

    Title: my_antennaStop time = 0.25

    Time Increment = 0.001

  • 49

    Workshop 1: The Controls Process

    Chapter 3: Overview of Using ADAMS/Controls

    32. Toggle Plot Results to yes, and select Show/Edit Plot Variables.

    The Plot Specification Form opens.

    33. Select Show Name List to query the available variables to plot. Select Y1, Y2, S2 LA, and S2 SF as variables to plot.

    34. Select OK to set-up the plots.

    35. Select Execute and Close to submit the simulation.

    If the animation mode is set to interactive (ANI_MOD = 1) , the simulation will be submitted with graphic updates to the ADAMS model during the co-simulation; if set to 0, a batch simulation will be submitted, which provides no graphical feedback. Note that the batch simulation takes less time.

    36. Take a look at the output by looking at the plots that EASY5 has created.

    Y1 vs. Time (rotor velocity)

    Y2 vs. Time (azimuth position)

    S2 SF vs. Time (desired step function input)

    S2 SL vs. Time (actual torque input)

  • 50

    Workshop 1: The Controls Process

    Chapter 3: Overview of Using ADAMS/Controls

    Note that the azimuth position has been driven to a fixed value and the rotor velocity has increased then dropped back to zero.

    37. Change the control parameters (step function end value, gain value) and resimulate.

  • 51

    Notes

    Chapter 3: Overview of Using ADAMS/Controls

  • 52

    Notes

    Chapter 3: Overview of Using ADAMS/Controls

  • 53

    Chapter 4: Setting Up Your ADAMS Model for Plant Export

    Chapter 4:Setting Up Your ADAMS Model for Plant Export

    Within this chapter, you will find the following topics:

    Steps to setup your model for a Plant Export 54ADAMS Variable Types 55Creating Input State Variables 56Creating Output State Variables 58Creating Plant Inputs and Outputs 59State Variable Order in Plant Inputs/Outputs 60 Specifying Plant Input/Output for Plant Export 61Workshop 2: Creating State Variables 62

  • 54

    Steps to setup your model for a Plant Export

    Chapter 4:Setting Up Your ADAMS Model for Plant Export

    In order to export your plant model, you must define the inputs and outputs to your plant.

    To do so:

    1. Create the state variables to which will be the inputs and outputs to your plant

    2. Create Plant Inputs and Outputs which hold the state variables from step 1

    3. Use a single Plant Input and Plant Output to export your plant files using the ADAMS/Controls Plant Export dialog box.

    ADAMSPlant

    PlantInput

    Plant Output

    Both contain a list of state variables

  • 55

    ADAMS Variable Types

    Chapter 4:Setting Up Your ADAMS Model for Plant Export

  • 56

    Creating Input State Variables

    Chapter 4:Setting Up Your ADAMS Model for Plant Export

    Input Variables

    Create state variables to hold inputs.

    Leave function = 0 (usually)

    Initial values will be used if an initial static simulation is performed

  • 57

    Assign Input State Variables to Actuators

    Chapter 4:Setting Up Your ADAMS Model for Plant Export

    Assign the state variables which define your plant inputs to the actuators (e.g., forces) in the model with the VARVAL function.

  • 58

    Creating Output State Variables

    Chapter 4:Setting Up Your ADAMS Model for Plant Export

    Create any valid runtime expression to provide an output to the CSS.

    Example: azimuth angle, elevation angle

  • 59

    Creating Plant Inputs and Plant Outputs

    Chapter 4:Setting Up Your ADAMS Model for Plant Export

    Create Plant Inputs and Plant Outputs in your ADAMS model to provide inputs and outputs to your ADAMS plant. You specify one Plant Input and one Plant Output for your ADAMS plant, but they may contain as many variables as you desire.

    ADAMSPlant

    PlantInput

    Plant Output

    Both contain a list of state variables

  • 60

    State Variable Order in Plant Input/Output Elements

    Chapter 4:Setting Up Your ADAMS Model for Plant Export

    The state variable order in the Plant Input and Plant Output elements is very important, because it determines the order which the variables must be defined in the CSS.

  • 61

    Specifying Plant Inputs/Outputs for Plant Export

    Chapter 4:Setting Up Your ADAMS Model for Plant Export

    Once the Plant Inputs and Outputs are created, reference these in the Plant Export dialog box.

    Using plant inputs and outputs instead of state variables allows users to edit inputs and outputs to the plant more robustly (for example, for a large number of state variables, the Plant Input/Output can be edited, rather than specifying them one by one in the Plant Export dialog box)

  • 62

    Workshop 2: Creating State Variables & Plant Inputs/Outputs

    Chapter 4:Setting Up Your ADAMS Model for Plant Export

    In this workshop, you create a model to control the position of a ball on a beam-balancing mechanism. To do so, you will create state variables and a plant input and output for you non-linear plant export of the ball-beam model (the following are general steps; see the Appendix for an exact solution).

    1. Open the 'ball_beam.cmd' file in the /Workshop2-General/ folder from ADAMS/Controls.

    2. Simulate the ball and beam model for 10 seconds and 200 time steps - the ball should fall off the beam due to an initial velocity assignment to the beam.

    We're going to try to balance the ball on a point off of the beam's center point by controlling a torque applied to the beam.

    3. Create 3 state variables that will be used for plant (this mechanical system) communication. As you're going to make your ADAMS model compatible with an existing control system, use the following names for the 3 state variables:

    Beam_Angle

    Position

    Torque_In

    4. Two of these 3 variables are the outputs of our plant. Define functions for these variables as follows:

    Beam_Angle = angle of the beam w.r.t. horizontal from the front view: AZ(.ball_beam.beam.cm)

    Position = position of ball center of mass (CM) along the beam top surface where the initial position is at distance = 0 and the value increases to the right:

    DX(.ball_beam.ball.cm,.ball_beam.beam.ref,.ball_beam.beam.ref)

  • 63

    Workshop 2: Creating State Variables & Plant Inputs/Outputs

    Chapter 4:Setting Up Your ADAMS Model for Plant Export

    5. Simulate the system again for 10 seconds and 200 steps, then go to the PostProcessor and see if your Beam_Angle and Position variable values look to be correct.

    6. Specify a value for the Torque_In state variable (for example, torque = 5). The next step will hook this value to the Torque that is applied to the beam.

    7. Tell the Torque on the beam (Sforce SFO1) to get it's magnitude from the state variable Torque_In. Use a VARVAL() in the Sforce function definition to do this.

    8. Simulate the system - the beam should rotate due to the applied torque. Change the torque value in the state variable and resimulate to ensure that the value of the state variable is getting picked up by the torque SFO1.

    9. Set the Torque_In state variable value back to zero with Build System Elements State Variable Modify.

    10. Create a Plant Input with Build Controls Toolkit Plant Input

    Plant Input Name: MDI_PINPUTVariable Name: Torque_In

    11. Create a Plant Output with Build Controls Toolkit Plant Output

    Plant Output Name: MDI_POUTPUTVariable Name: Beam_Angle, Position

    IMPORTANT: Take care that you get the order correct for the outputs (they have to synch up with the existing controls model).

  • 64

    Workshop 2: Creating State Variables & Plant Inputs/Outputs

    Chapter 4:Setting Up Your ADAMS Model for Plant Export

    To work with MATLAB, follow steps 12-27.

    To work with EASY5, follow steps 28-51.

    MATLAB Steps

    12. Export the plant with Controls Plant Export

    File Prefix = ball_testPlant Input = MDI_PINPUT

    Plant Output = MDI_POUTPUTControl Package = MATLAB

    13. Start MATLAB from a new x-window by typing matlab.

    14. Type 'ball_test' - the .m file that we just exported from ADAMS - this sets up the state variables needed in MATLAB.

    15. Type adams_sys' this creates a plant that you can use in MATLAB.

    16. Select File Open = ball_beam.mdl . This opens the previously made MATLAB control schematic. Copy the plant from adams_sys to the ball beam control model.

    Now, before you use MATLAB to simulate the combined controls/mechanical system, set up your environment:

    17. Set simulation parameters (Simulation Simulation Parameters):

    End time = 4 secondsSolver = ode15s (stiff integrator)

  • 65

    Workshop 2: Creating State Variables & Plant Inputs/Outputs

    Chapter 4:Setting Up Your ADAMS Model for Plant Export

    Next, set the ADAMS plant properties

    18. Double click the 'Mechanical Dynamics' block

    19. Set the Output files prefix to 'ball_results

    Note: be sure to include the quotes ( )

    20. Set the simulation modes to discrete

    21. Set the animation mode to interactive.

    22. Select OK to save.

    23. Simulate the control system containing the ADAMS block by doing a Simulation Start.

    24. View results in MATLAB:

    If stripcharts in MATLAB aren't visible, double click the scope icons labelled 'Position', 'Force input', etc. The MATLAB strip charts can be autoscaled if the signal disappears by hitting the binocular icon.

    Next, look at results in ADAMS/Controls.

    25. Open ADAMS/PPT and select File Import

    26. Select Analysis Files

    27. Choose 'ball_results.gra' or 'aplant_out.gra' file (if you used the default output name)

    You can now animate the mechanical system.

  • 66

    Workshop 2: Creating State Variables & Plant Inputs/Outputs

    Chapter 4:Setting Up Your ADAMS Model for Plant Export

    EASY5 Steps

    28. Export the plant with Controls Plant Export

    File Prefix = ball_testPlant Input = MDI_PINPUTPlant Output = MDI_POUTPUTControl Package = MATRIXx_and_EASY5

    29. Start EASY5 from a new x-window by typing easy5.

    30. Open the existing EASY5 model ball_beam_noad.mf.0.

    Notice that the model does not contain the non-linearADAMS plant block.

    31. Select the block Add or the keystroke CRTL-A to open the Add Components dialog box.

    32. Select Extensions in the Open Libraries field, and select AD ADAMS Nonlinear Block to create an ADAMS (AD) block.

    An icon will follow your cursor until you select the location to create it.

    33. Place the AD block in the right of the model, between the LA block and the two unit gain blocks.

    Now, before you connect the AD block to the rest of the system, initialize the AD block

    34. Open up the Component Data Table for the AD block and select Spawn ADAMS Interface

  • 67

    Workshop 2: Creating State Variables & Plant Inputs/Outputs

    Chapter 4:Setting Up Your ADAMS Model for Plant Export

    33. Enter the name of the .inf file (ball_test.inf).

    35. Enter 25 for the maximum number of states.

    36. Enter 3 to submit a co-simulation (discrete) analysis.

    Your AD block is now initialized.

    37. Select OK in the AD Component Data Table.

    Next, connect the AD block to the rest of the EASY5 model.

    38. Connect S2 LA (actuator input) to U1 of the AD block (S-U1)

    39. Delete the two dummy unit gain blocks.

    40. Connect Y1 of the AD block to S3 SJ.

    41. Connect Y2 of the AD block to S1 SJ2.

    The EASY5 model should now be connect properly to the AD block. Before you use EASY5 to simulate the combined controls/mechanical system, set the AD block properties.

    42. Double click the AD block

    43. Set the animation mode to interactive (ANI_MOD=1).

    44. Select OK to save.

    45. Select Build Create Executable to compile and link the model.

  • 68

    Workshop 2: Creating State Variables & Plant Inputs/Outputs

    Chapter 4:Setting Up Your ADAMS Model for Plant Export

    Next, set the simulation parameters:

    46. Set simulation parameters (Analysis Simulation Parameters):

    Title = ball_beamEnd time = 4 secondsTime increment = 0.01 secondsInt. Method = BCS Gear (stiff integrator)

    47. Create plots (Y1, Y2, etc.) by toggling Plot Results to yesand making appropriate selections in Show/Edit Plot Variables.

    48. Simulate the control system containing the ADAMS block by selecting Execute and Close.

    When the simulation is finished, the plots you created will appear automatically.

    Next, look at results in ADAMS/Controls.

    49. Open ADAMS/PPT and select File Import

    50. Select Analysis Files

    51. Choose 'ball_test.gra.

    You can now animate the mechanical system..

  • 69

    Chapter 5: Simulation Modes: Discrete vs. Continuous

    Chapter 5: Simulation Modes: Discrete vs. Continuous

    Within this chapter, you will find the following topics:

    Discrete Mode 70Continuous Mode 71Continuous vs. Discrete Mode 74Co-simulation Process 76State Repartitioning 78Output Step Size/Sampling Rate 79Workshop 3 : Discrete vs. Continuous Results 80

  • 70

    Discrete Mode (Co-simulation)

    Chapter 5: Simulation Modes: Discrete vs. Continuous

    There are two choices for the method of exchanging data between the control simulation software and ADMAS:

    1. Discrete mode2. Continuous mode

    Discrete mode (the most common) lets MATLAB integrate the Control system, ADAMS integrate the mechanical system. Controls takes a step in time, then ADAMS does the same, hence the 'discrete' label. In this mode, the integrators on both sides (CSS and ADAMS) are running in parallel. They exchange data as specified by the output step size. In this mode, the controls package, using output from ADAMS, calculates the mechanical model inputs and sends it back to ADAMS. It is the responsibility of ADAMS to integrate the mechanical system for a single time step with the specified inputs.

    Discrete mode is also known as co-simulation

  • 71

    Continuous (Function Evaluation) Mode

    Chapter 5: Simulation Modes: Discrete vs. Continuous

    Continuous mode lets the controls simulation software integrate everything. The CSS computes a big system Jacobian that includes our mechanical system. ADAMS acts as a function evaluator.

    By this, we mean that the Jacobian, which describes the mechanical system, is evaluated by ADAMS, and the values are sent to the controls package to populate the equations integrated *solely* by the controls package. Viewed from the control side, ADAMS is no different from a nonlinear block (something like General State Equation, GSE, in ADAMS). At each integration steps, ADAMS provides the necessary information, such as inputs and states to the controls packages.

  • 72

    Continuous (Function Evaluation) Mode (continued)

    Chapter 5: Simulation Modes: Discrete vs. Continuous

    Because function evaluation mode creates a large system Jacobian matrix that presents both the control scheme and the mechanical system at once, any integrator dealing with this sees an effectively 'continuous' system. This means that function evaluation mode will give results that are exact for simple systems. The downfall is that the control system integrators must be used and they are not finely tuned for solving mechanical systems, hence they have a tendency to fail for complex systems, particularly those with high frequency mechanical system effects.

    Initially a system Jacobian is formulated by ADAMS based on the initial model configuration. As the CSS requests values from ADAMS and the model position changes, there is a possibility that the system Jacobian may change (by choosing different variables which define the Jacobian).

    -

  • 73

    Continuous (Function Evaluation) Mode (continued)

    Chapter 5: Simulation Modes: Discrete vs. Continuous

    ADAMS automatically chooses new independent generalized coordinates to build a Jacobian with, based on which variables are changing most rapidly in a simulation. If the variables that ADAMS uses change, the system Jacobian changes. This is a problem, as there is currently not a way to tell MATLAB that the form of the Jacobian has changed.

    What this means is that continuous mode only works for models that are near-linear. This is a limitation of the mode, so most people use discrete mode for mechanical systems with rotating parts and movements with large displacements.

    -

  • 74

    Continuous vs. Discrete Modes

    Chapter 5: Simulation Modes: Discrete vs. Continuous

    Function Evaluation Mode Co-Simulation Mode

    ADAMS

    ADAMS writes out function and controls application does the work

    ADAMS and controls application share the work

    ControlsSoftware

    ADAMS

    ControlsSoftware

    ADAMS plant outputs(state variables)sent by ADAMS

    Jacobian partialssent by ADAMS

  • 75

    Continuous vs. Discrete Modes

    Chapter 5: Simulation Modes: Discrete vs. Continuous

    ( )( )( )

    , , ,

    , ,

    , ,

    x x x u

    x x

    y x u

    1 2

    1 2

    1 1

    20

    =

    =

    =

    f t

    f t

    h t

    ( , , )( , , )

    x xy x=

    =

    f th t

    k

    k

    UU

    PlantP

    ControllerC

    y,f(.)u,t,x PlantP

    ControllerC

    y,f(.)U,t,x

    ZOH T

    Function Evaluation Mode Cosimulation Mode

    Control App. does the work! ADAMS and Control App.share the work!

    P:

  • 76

    Co-simulation (discrete mode) Process

    Chapter 5: Simulation Modes: Discrete vs. Continuous

    Here's what happens when you run an ADAMS/Control co-simulation in discrete mode. The following steps through an ADAMS message file (.msg) output from a batch mode co-simulation.

    1. Controls tells ADAMS to start and loads up your model. Youshould see the following lines in your message file:

    OUTFOP:IN_FILENM

    ADAMS model file ..

    VERINP:END_INPUT

    Input and Input Check Phase complete.

    GTMODE:NUMB_DOF1

    The system has one kinematic degree of freedom.

    2. After the initialization tasks, the controls package and ADAMS exchange data regarding system states. The line

    GLGETL:USER_CMND

    var/1, fun=0

    in the .msg file shows the value from your controls package coming into ADAMS. At the same time the plant outputs from ADAMS are being sent to the Controls package.

  • 77

    Co-simulation (discrete mode) Process (continued)

    Chapter 5: Simulation Modes: Discrete vs. Continuous

    3.Now that ADAMS has the input values needed, the line

    DBANNR:BDF

    Begin the dynamic analysis.

    appears indicating that the dynamic analysis has begun on the ADAMS side. At this point the inputs to the plant are held fixed from the current time until the next output time step. In the above example, variable 1 is held fixed at 0.

    4.When the dynamic analysis in ADAMS has proceeded for the output time step interval the message appears:

    Simulation Time Cumulative Cumulative Integrator

    Time Step Iterations Steps Taken Order

    ___________ ___________ __________ ___________ __________

    0.00000E+00 2.50000E-04 0 0 1

    2.50000E-04 2.50000E-04 3 1 1

    5.00000E-03 2.50000E-03 13 5 2

    GLGETL:USER_CMND

    var/1, fun=0.01

    .indicating that the dynamic simulation has halted. The linevar/1, fun=0.01 indicates that another exchange between the controls package and ADAMS follows, setting variable 1 to a value of 0.01. In this manner the co-simulation proceeds. At every specified time interval the controls package and ADAMS stop, update one another with new state values. Each package then runs it's simulation independently, using the fixed values throughout the following interval.

  • 78

    State Repartitioning

    Chapter 5: Simulation Modes: Discrete vs. Continuous

    You may be performing an ADAMS/Controls simulation and get part way through when the simulation stops, with the error message: 'ADAMS State Repartitioning occurred ... The 'State Repartitioning' message means that the ADAMS integrator is having some major problems resolving an event in your mechanical system, such as a rapidly changing input force or a locking up mechanism. This message can sometimes be overlooked when using regular old ADAMS, but it is not good when using ADAMS/Controls, as it may trigger a failure in the Controls package ADAMS communication process.

    To avoid this problem with your mechanical system check things such:

    - gains in your Controls package. If they're large and they feed back rapidly changing forces you can have trouble - try decreasing these.

    - step times for forces in ADAMS. If you're using any STEP functions, try increasing the ramp-up time.

    - force magnitudes. Try decreasing your forcing function magnitudes.

    - the output step size for ADAMS (typically set in the ADAMS plant mask, or properties panel). The Controls package and ADAMS trade data only at discrete output steps. Try decreasing the output step size to have the two packages update more frequently, decreasing the discrepancies when they exchange data in periodic update process.

    Essentially the best way to avoid this is to try and 'smooth' things out by checking rapidly changing forces and/or making the output step size small so that the results from the two packages don't diverge too much.

  • 79

    Output Step Size/Sampling Rate

    Chapter 5: Simulation Modes: Discrete vs. Continuous

    The output step size is the duration at which information is exchanged between the controls package and ADAMS. This is commonly known as the sampling rate, and its greatest affects are seen in the discrete mode.In discrete mode, the controls package, using output from ADAMS, calculates the mechanical model inputs and sends it back to ADAMS. It is the responsibility of ADAMS to integrate the mechanical system for a single time step with the specified inputs.The sampling rate at which the ADAMS side receives input updates is critical - you must ensure that you're sampling the mechanical system (in MATLAB this is set as the 'output step size' variable in the ADAMS plant mask; EASY5, the Time Increment) at more than twice the highest frequency you're interested in on the mechanical side. Otherwise, you may see aliasing in your mechanical model (aliasing is the generation of a false (alias) frequency).The effect of aliasing is that high frequency noise can be converted into a lower frequency, which could change the response of your system.

    -

  • 80

    Workshop 3: Discrete vs. Continuous Results

    Chapter 5: Simulation Modes: Discrete vs. Continuous

    In this workshop, you will simulate the ball-beam model in both discrete (co-simulation) and continuous (function evaluation) modes, and compare the results.

    To work with MATLAB, follow steps 1-14.To work with EASY5, follow steps 15-47.

    MATLAB Steps

    1. Open up MATLAB and select File Open in the Simulink window and read in the .mdl for the from Workshop 2 for the ball_beam model.

    Now, look at the plant properties - we'll be modifying the solution method and noting the simulation results.

    To open the plant properties:2. Double click plant (adams_sub block in the control

    system diagram)3. Double click 'Mechanical Dynamics' block

  • 81

    Workshop 3: Discrete vs. Continuous Results

    Chapter 5: Simulation Modes: Discrete vs. Continuous

    MATLAB Steps4. Set Output files prefix to 'ball_results_discrete5. Set Simulation mode to discrete.6. Set Animation mode - batch (interactive if you like the

    animations).7. Select OK to save.8. Simulate using these parameters. The results, stored

    in the ball_results_discrete. files, will be saved for comparison to the continuous mode.

    9. Take a look at the results in the MATLAB strip charts. Use the zoom tool to take a close look at a section of the curve in the 'Position' strip chart. It should show the discrete nature of the simulation, with small steps evident in the plot.

    10. Now, change the simulation mode to continuous, the output prefix to 'ball_results_continuous.

    11. In your Simulink model, select Simulate Simulation Parameters, and change the solver to ode23s (stiff/ Mod. Rosenbrock).

    12. Select OK, and re-run the simulation

  • 82

    Workshop 3: Discrete vs. Continuous Results

    Chapter 5: Simulation Modes: Discrete vs. Continuous

    MATLAB Steps13. As in step 5 use the zoom tool and examine the

    'Position' strip chart. It should appear continuous no matter how close you zoom in.

    14. Open up the plant properties again and change back to the discrete mode. Make the output step size large -say 0.05 and resimulate. You should see the very discrete nature of the simulation and the result of undersampling the system.

    EASY5 Steps15. Edit the file ball_test.inf from Workshop 2, so that

    the fourth line is changed from ball_test to ball_test_discrete. This will change the output file names.

    16. Open the EASY5 model ball_beam.mf.# (where # = the number of your last saved model from Workshop 2)

    17. Open up the Component Data Table for the AD block and select Spawn ADAMS Interface

  • 83

    Workshop 3: Discrete vs. Continuous Results

    Chapter 5: Simulation Modes: Discrete vs. Continuous

    EASY5 Steps

    18. Enter the name of the .inf file (ball_test.inf).

    19. Enter 25 for the maximum number of states.

    20. Enter 3 to submit a co-simulation (discrete) analysis.

    Your AD block is now initialized.

    21. Select OK in the AD Component Data Table.

    Before you use EASY5 to simulate the combined controls/mechanical system, set the AD block properties.

    22. Double click the AD block

    23. Set the animation mode (ANI_MOD)to interactive.

    24. Select OK to save.

    25. Select Build Create Executable to compile and link the model.

    Next, set the simulation parameters:

    26. Set simulation parameters (Analysis Simulation Parameters):

    Title = ball_beam_discreteEnd time = 4 secondsTime increment = 0.01 secondsInt. Method = BCS Gear (stiff integrator)

  • 84

    Workshop 3: Discrete vs. Continuous Results

    Chapter 5: Simulation Modes: Discrete vs. Continuous

    EASY5 Steps

    27. Create plots (Y1, Y2, etc.) by toggling Plot Results to yes and making appropriate selections in Show/Edit Plot Variables.

    28. Simulate the control system containing the ADAMS block by selecting Execute and Close.

    When the simulation is finished, the plots you created will appear automatically.

    You can zoom in on the plots and see the discrete nature of the curve.

    Next, look at results in ADAMS/Controls.

    29. Open ADAMS/PPT and select File Import

    30. Select Analysis Files

    31. Choose 'ball_beam_discrete.res. You can now make plots from results of the simulation of your mechanical system.

    Next, perform the same simulation in continuous mode.32. Edit the file ball_test.inf from Workshop 2, so that

    the fourth line is changed from ball_test to ball_test_continuous. This will change the output file names.

  • 85

    Workshop 3: Discrete vs. Continuous Results

    Chapter 5: Simulation Modes: Discrete vs. Continuous

    EASY5 Steps

    33. Open up the Component Data Table for the AD block and select Spawn ADAMS Interface

    34. Enter the name of the .inf file (ball_test.inf).

    35. Enter 25 for the maximum number of states.

    36. Enter 1 to submit a continuous analysis with no input feed-through.

    Your AD block is now initialized.

    37. Select OK in the AD Component Data Table.

    Before you use EASY5 to simulate the combined controls/mechanical system, set the AD block properties.

    38. Double click the AD block

    39. Set the animation mode (ANI_MOD)to batch.

    40. Select OK to save.

    41. Select Build Create Executable to compile and link the model.

  • 86

    Workshop 3: Discrete vs. Continuous Results

    Chapter 5: Simulation Modes: Discrete vs. Continuous

    EASY5 Steps

    Next, set the simulation parameters:

    42. Set simulation parameters (Analysis Simulation Parameters):

    Title = ball_beam_continuousEnd time = 4 secondsTime increment = 0.01 secondsInt. Method = BCS Gear (stiff integrator)

    43. Create plots (Y1, Y2, etc.) by toggling Plot Results to yes and making appropriate selections in Show/Edit Plot Variables.

    44. Simulate the control system containing the ADAMS block by selecting Execute and Close.

    When the simulation is finished, the plots you created will appear automatically.

    You can zoom in on the plots and see that the plots are smooth, no matter how close you zoom in.

    Next, look at results in ADAMS/Controls.

    45. Open ADAMS/PPT and select File Import

    46. Select Analysis Files

    47. Choose 'ball_beam_continuous.res. You can now make plots from results of the simulation of your mechanical system.

  • 87

    Notes

    Chapter 5: Simulation Modes: Discrete vs. Continuous

  • 88

    Notes

    Chapter 5: Simulation Modes: Discrete vs. Continuous

  • 89

    Chapter 6: Preparing Simulations

    Chapter 6: Preparing Simulations

    Within this chapter, you will find the following topics:

    Licenses (or) Should View be running? 90Speeding Up Simulations 91Initialization Commands 92 Workshop 4: Initialization Commands 93

  • 90

    Licenses

    Chapter 6: Preparing Simulations

    Question: I'm about to run the cosimulation from MATLAB. Should ADAMS be running at this time?

    Answer: You do not have to have ADAMS/View running when running a co-simulation. The ADAMS/Controls scripts will launch ADAMS/View on its own when the time comes to animate the model interactively during the co-simulation. Note that ADAMS/View will only be launched if you are running an "interactive simulation. If you run a "batch" simulation, then View is not launched the job is run completely by Solver, and you will not see any graphical feedback.

    The upside to running in "batch" mode is that the simulation will take far less time.

    Beware that if you have ADAMS/View running while you try to run a co-simulation, you will then need two licenses. If you don't have two available, you will get an error (Plant communication error 109).

  • 91

    Speeding Up Simulation Times

    Chapter 6: Preparing Simulations

    There are two cosimulation modes when using ADAMS/Controls. Interactive = use View, batch = use Solver on the command line. For speed you want to do the batch cosimulation.

    Here's the results of a simple experiment using the Antenna model provided with your ADAMS distribution. To baseline things,I've first run in plain old View, then ran the Controls cosimulationfor comparison of it's operating modes.

    1. The baseline: run antenna model in View using output steps of size 0.005 and a simulation time of 1.0 seconds. Doing this yields:

    Description Computation time

    Regular View simulation 11 seconds

    View simulation - execution display off 5 seconds

    2. Test the ADAMS/Controls cosimulation: run cosimulation with MATLAB, using settings in the MATLAB plant mask:

    end time = 1 second

    dt (plant output step size) = 0.005s

    using Stiff integrator (ODE15S) in Simulation settings

    Result:

    Description Computation time

    View (interactive cosimulation) 1:26 (~20 second startup)

    Solver (batch cosimulation) 0:18 (~8 second startup)

    Summary:

    Use the interactive cosimulation to verify that you've set your model up correctly; once you're sure of that, run using 'batch' model to significantly speed things up.

  • 92

    Initialization Commands

    Chapter 6: Preparing Simulations

    You can submit commands to your ADAMS model before the co-simulation process starts by using initialization commands. Initialization commands allow you to specify a Solver or View command that will be issued to ADAMS/Solver when running ADAMS/Controls. Solver commands are used for batch mode, and view commands are used for interactive mode. These can be used to run your model until it reaches some initial state at which you want to turn on your system controller (among other things).

    To use this in MATALB, enter a single Solver command (for batchmode) such as:

    ['file/command=Starting_Commands.acf']

    in the MATLAB plant mask "Initialization Commands" field. This Solver command reads an .acf (ADAMS command file) that can exercise your model before your Control system is turned on.

    To use this in EASY5, enter a single Solver command such as:

    file/command=Starting_Commands.acf

    in the EASY5 .inf file under the line NUMBER OF COMMANDS 1. This Solver command reads an .acf (ADAMS command file) that can exercise your model before your Control system is turned on.

    Refer to the ADAMS/Solver reference guide for valid Solver command file syntax.

  • 93

    Workshop 4: Initialization Commands

    Chapter 6: Preparing Simulations

    In the following workshop, the antenna model has a motion activated on the antenna base that twists the antenna in the direction opposite to what the control system does. An .acffile runs the model for .5 seconds with this motion turned on, then uses a DEACTIVATE/MOTION, ID=1 command to turn off the motion prior to the Control system turning on and running for another .5 seconds.

    To work with MATLAB, follow steps 1-7.

    To work with EASY5, follow steps 8-18.

    MATLAB Steps

    1. Start MATLAB and change to the /Workshop4-InitCommands/ directory.

    2. Type ant_test to setup the MATLAB environment variables, then type adams_sys to bring up a Simulink window.

    3. From the Simulink window, select File Open and open antenna.mdl.

    4. Edit the adams_sub block to include the initialization command ['file/command=Starting_Commands.acf'] in the initialization field.

    5. Simulate from MATLAB.

    6. Open ADAMS/View and import antenna.cmd. Then import the ADAMS/Solver Analysis files and attach the files to the antenna model or to a new analysis that you created (right-click on the field beside model name or 'analysis name').

  • 94

    Workshop 4: Initialization Commands

    Chapter 6: Preparing Simulations

    7. Inspect the results and convince yourself that the initialization commands were performed before the co-simulation.

    EASY5 Steps

    8. With a text editor, modify ant_test.inf to include the following commands:

    F:\Program Files\ADAMS 12.0

    ant_testant_testinteractivecontinuous0.010000automaticno

    NUMBER OF COMMANDS1File/command=Starting_Commands.acfNUMBER OF INPUTS/OUTPUTS1 2INPUT VARIABLEScontrol_torque 1 1OUTPUT VARIABLESrotor_velocity 2 1azimuth_position 3 1

  • 95

    Workshop 4: Initialization Commands

    Chapter 6: Preparing Simulations

    9. Start EASY5 and open the antenna model the /Workshop4-InitCommands/ directory.

    10. Double click on the ADAMS AD block

    11. Set the animation mode to batch (ANI_MOD=0).

    12. Select Spawn ADAMS Interface.

    13. Enter ball_test.inf.

    14. Enter 25 for the number of states.

    15. Enter 3 for a co-simulation.

    16. Build the executable and simulate.

    17. Open ADAMS/View and import antenna.cmd. Then import the ADAMS/Solver Analysis files and attach the files to the antenna model or to a new analysis that you created (right-click on the field beside model name or 'analysis name').

    18. Inspect the results and convince yourself that the initialization commands were performed before the co-simulation.

  • 96

    Notes

    Chapter 6: Preparing Simulations

  • 97

    Chapter 7: Advanced Topics

    Chapter 7: Advanced Topics

    Within this chapter, you will find the following topics:

    User Libraries/Subroutines 98 Debugging Models: General Tips 100Error Messages: Plant Communication Error 101

  • 98

    User Libraries

    Chapter 7: Advanced Topics

    Unlike previous versions of ADAMS, you no longer create an entire executable for ADAMS when you want to link in a user subroutine. Instead, a library is created once and simply selected when the subroutine(s) within the library are needed. For more information on this change, see KB 9317.

    What does this mean? Well, instead of creating a controls executable (e.g., adams11 controls cr-uscontrols), you simply create a "standard" user executable (e.g., adams11 cr-user).

    So, here are the explicit steps:

    From the mdi script for UNIX, or the NT selections from the Start menu, do the following:

    1) UNIX: mdi -c cr-user

    NT: Start --> Programs --> ADAMS 11.0 --> ASolver -->

    Create Custom Solver (or just type mdi cr-user in the DOS

    prompt)

    2) answer if you want to link in debug mode, and provide the

    list of your user subroutines.

    3) provide a name for the library, such as my_sub.dll

  • 99

    User Libraries (continued)

    Chapter 7: Advanced Topics

    4) within ADAMS/View, when you use the Controls Plant Export

    dialog box to save out your input and output data, include the

    name of the user library you just created in the appropriate

    field

    5) The user executable name is now automatically written out to

    the MATLAB .m file or the MATRIXx/EASY5 information file and

    automatically picked up by the controls program as the proper

    executable. Alternatively, you can enter this explicitly in the file. For example, in MATLAB enter ADAMS_exec = '$my_path/my_sub.dll'; (where $my_path is the path to your library).

    6) Note that there is no longer a difference between a custom solver library and a custom view library if the library is used by solver. In other words, you create a library for solver, which can be used by either the view interface or solver when simulating. A view library can *only* be in view as in design-time; it makes no sense to use this with solver, and obviously cannot be used in solver.

  • 100

    Debugging Models: General Tips

    Chapter 7: Advanced Topics

    It's often difficult to understand what's happening with your ADAMS/Controls cosimulation because the Solver messages will scroll across your screen (or won't even be visible, depending on setup), then be gone, so you can't see what's causing errors in your cosimulation.

    To see the output from Solver in the cosimulation, turn on message file output by setting the MDI_ADAMS_NOMSGFILE environment variable to FALSE. This will save all of the output messages to a .msg file that you can look through for errors.

    If you're having trouble solving your equations of motion (integrator failures, long simulation times, odd results, etc.),use initialization commands to create a Solver command file (.acf file) which can change the default integrator settings, or perhaps run your model for a time without the controls inputs.

    To summarize, some of the things to watch for:

    - your inputs/outputs are in the correct order

    - your control block diagram is proper

    - you have an ADAMS license available (did you shut down ADAMS before doing the cosim?)

    - your input forces/torques are reasonable (not too large or abrupt)- the ADAMS integrator shouldn't have problems with them.

  • 101

    Error Messages: Plant Communication Error

    Chapter 7: Advanced Topics

    If you receive an ADAMS plant communication error when trying to perform the co-simulation, this could mean many things. The ADAMS plant communication error is a generic message that could unfortunately mean anything from you don't have a license available to you've referenced a variable incorrectly inthe controls simulation software. If you're trying to make your own model work and haven't tried one of the example problems found in your ADAMS installation at /ADAMS_install/controls/examples/, then run an example. It's important to ensure that you can run an example as your own model can potentially have incorrect feedback values, crossed lines, etc. You should establish that you can run an example model, which has been setup to work properly, before you start with your own model.

    If you generate an ADAMS plant communication error at some point in an ADAMS/Controls co-simulation (due to too rapid feedback, improper variable specification in MATLAB, etc.) and then fix the source of your error, but now get the plant communication error as soon as you hit 'Simulate', you may need to do some clean-up in your workspace.

    To clear things in the MATLAB ADAMS/Controls environment, use the

    clear mex

    command on the command line in MATLAB. This gets rid of anything floating around from past failures and will allow you to perform subsequent co-simulations.

    Finally, make sure there are no pipe files remaining: delete any APCInput or APCOutput files.

  • 102

    Notes

    Chapter 7: Advanced Topics