Presentation is loading. Please wait.

Presentation is loading. Please wait.

WORKSHOP 1 CO-SIMULATION.

Similar presentations


Presentation on theme: "WORKSHOP 1 CO-SIMULATION."— Presentation transcript:

1 WORKSHOP 1 CO-SIMULATION

2

3 Getting started a c d e b f Start Adams/View: 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. b e f

4 Investigate the Model a c b e d f
Investigate the current model by simulating for a short time: Run a dynamic simulation for 2 seconds, 100 steps. Note that the Adams-only spring-damper system oscillates. The other spring damper system in the model simply falls down. Right-click on the spring-damper element named ‘adams_spring_force’ and note the K and C values for the spring element in Adams: K = _________ C = _________ d e f

5 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: Click on Elements. Create State Variable defined by algebraic equation. Enter force_matlab for the Name. Specify 0.0 as the function value (this will be over-written during co-simulation). Click OK. Modify the model so that the Variable is used by the SFORCE element: Modify the SFORCE named ‘SFORCE_1’. Use the VARVAL() function to reference the new state VARIABLE, for example: VARVAL(force_matlab) 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. a d c b e f g

6 Export the Plant a b c d e f
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: Controls: Plant Export In the resulting dialog box, specify the following: File Prefix: cosim Input Signal(s): force_matlab 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 Target Software: MATLAB Leave all other settings as default Click OK. a b c d f e Verify that files named: -cosim.m -cosim.adm -cosim.cmd have been created in the working directory of Adams/View.

7 Setup in MATLAB Start MATLAB and:
Change the working directory of MATLAB to be where your cosim.m file exists. Enter cosim in the MATLAB shell to execute the cosim.m file. Create a Simulink block that represents the Adams component by : 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.

8 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: 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. The adams_sub block can now be dragged from the initial Simulink model into the model above.

9 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 = (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.

10 Inspect Simulation Results
Inspect the results: Double-click the scope blocks in MATLAB and inspect the displacement and velocity values. 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.

11 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 and seconds. These plots use the scope value ‘Displacement Difference’ found in the model.

12 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.


Download ppt "WORKSHOP 1 CO-SIMULATION."

Similar presentations


Ads by Google