WORKSHOP 1 CO-SIMULATION ADM711, Workshop 1, January 2013 Copyright 2013 MSC.Software Corporation ML WS1 - 1 ADM711, Workshop 1, January 2013 Copyright 2013 MSC.Software Corporation ML WS1 - 2 Getting started Start Adams/View: a. b. c. d. e. f. Click on Existing model Click on browser for specifying working directory . Select folder containing mod1_cosim relative to Adams/Controls training files on your computer. Click OK. Click on the browser for specifying the file name. In file name select spring_damper.cmd and Click OK. a c d e b ADM711, Workshop 1, January 2013 Copyright 2013 MSC.Software Corporation ML WS1 - 3 f Investigate the Model a Investigate the current model by simulating for a short time: a. Run a dynamic simulation for 2 seconds, 100 steps. b. Note that the Adams-only spring-damper system oscillates. c. The other spring damper system in the model simply falls down. d. Right-click on the springdamper element named ‘adams_spring_force’ and note the K and C values for the spring element in Adams: e. K = _________ f. C = _________ ADM711, Workshop 1, January 2013 Copyright 2013 MSC.Software Corporation c b e f ML WS1 - 4 d Create State VARIABLE, Integrate with Model To build a State Variable to be passed in from MATLAB: Create a new Variable using the menu picks: a. Click on Elements. b. Create State Variable defined by algebraic equation. c. Enter force_matlab for the Name. d. Specify 0.0 as the function value (this will be over-written during cosimulation). e. Click OK. Modify the model so that the Variable is used by the SFORCE element: f. g. Adams/Controls requires State Variables for communication with MATLAB or EASY5. The model currently lacks a State Variable representing the spring force that is to be calculated by MATLAB. b a c d e f Modify the SFORCE named ‘SFORCE_1’. Use the VARVAL() function to reference the new state VARIABLE, for example: VARVAL(force_matlab) ADM711, Workshop 1, January 2013 Copyright 2013 MSC.Software Corporation g ML WS1 - 5 Export the Plant Simulate the model again, verify that the ball simply drops since the Variable (and hence the SFORCE) has a zero-value. During co-simulation, the Variable (and hence the SFORCE) will be constantly updated, so the behavior will be different. Create files required by MATLAB for co-simulation by selecting the menu picks: a. Controls: Plant Export In the resulting dialog box, specify the following: b. File Prefix: cosim c. Input Signal(s): force_matlab d. Output Signal(s): (use Browse and select in the exact order as shown): - displ_part_2 - displ_part_3 - vel_part_2 - vel_part_3 e. Target Software: MATLAB f. Leave all other settings as default g. Click OK. a b c d Verify that files named: -cosim.m -cosim.adm -cosim.cmd have been created in the working directory of Adams/View. e f ADM711, Workshop 1, January 2013 Copyright 2013 MSC.Software Corporation ML WS1 - 6 Setup in MATLAB Start MATLAB and: a. Change the working directory of MATLAB to be where your cosim.m file exists. b. Enter cosim in the MATLAB shell to execute the cosim.m file. Create a Simulink block that represents the Adams component by : c. Enter the command, adams_sys into the MATLAB shell. The steps above create a blank ‘adams_sub’ Simulink block which represents your Adams model. At this point, a Simulink model can be built around the adams_sub block using the inputs and outputs that have been defined for the adams_sub block. Note that the inputs and outputs correspond to what was specified during the plant export process in Adams. ADM711, Workshop 1, January 2013 Copyright 2013 MSC.Software Corporation ML WS1 - 7 Load an Existing Simulink Model Rather than create a new Simulink model to interact with the Adams block, an existing model can be loaded that will make use of the adams_sub block created earlier. Load an existing Simulink model containing the spring-damper modeled in MATLAB: a. Enter the following command in the MATLAB command line: matlab_spring_start This command will open the file ‘matlab_spring_start.mdl ’ from the working directory. b. The adams_sub block can now be dragged from the initial Simulink model into the model above. ADM711, Workshop 1, January 2013 Copyright 2013 MSC.Software Corporation ML WS1 - 8 Setup and Co-simulation Before simulation, ensure that the adams_sub block has the appropriate parameters. Double-click the adams_sub block, then the Adams plant block to view the block parameters. In the Adams plant mask settings, modify the following parameters: – Communication Interval = 0.005 (default) – Output files prefix = ‘cosim_005’ (include single-quotation marks) – Leave all other settings as default, then save the Simulink model. Specify an end-time of 2 seconds for the simulation by using the menu picks: • Simulation: Configuration Parameters • Click the ‘play’ button in the MATLAB to simulate the Simulink Model. ADM711, Workshop 1, January 2013 Copyright 2013 MSC.Software Corporation ML WS1 - 9 Inspect Simulation Results Inspect the results: a. Double-click the scope blocks in MATLAB and inspect the displacement and velocity values. b. The displacement scope will plot the position of the ball for the Adams-calculated force in the model (the upper trace) and the MATLAB-calculated force in the model (the lower trace). Note how the MATLAB-calculated force does not have the same damping behavior as the Adams-calculated force. ADM711, Workshop 1, January 2013 Copyright 2013 MSC.Software Corporation ML WS1 - 10 Repeat Simulation Repeat the co-simulation with a finer sampling interval: – Communication Interval = 0.001 – Output files prefix = ‘cosim_001’ – Inspect the displacement and velocity plots. – Repeat with smaller sampling rates and investigate the effect on displacement and velocity. The effect of sampling rate is shown for two co-simulations with rates of 0.001 and 0.0001 seconds. These plots use the scope value ‘Displacement Difference’ found in the model. ADM711, Workshop 1, January 2013 Copyright 2013 MSC.Software Corporation ML WS1 - 11 Algebraic Loops, Artificial Dynamics • The current model contains an ‘Artificial Lag’ block (a Transfer Function that acts as a filter) in order to break any algebraic loops in MATLAB. MATLAB attempts to resolve algebraic loops through an iterative process; this can be seen when the inputs to Adams, as shown in the .msg file, are repeated several times. Algebraic loops in the MATLAB model will slow simulations down and possibly cause wrong answers. • Inserting a simple dynamic element (such as a filter block) into the loop will resolve the problem. Note that very few dynamic systems can be modeled as not having dynamics such as lag, so this is likely a realistic feature to build into a model. ADM711, Workshop 1, January 2013 Copyright 2013 MSC.Software Corporation ML WS1 - 12
© Copyright 2026 Paperzz