Co-simulation Design towards Cyber-Physical Robotic Applications - - PowerPoint PPT Presentation

co simulation design towards cyber physical robotic
SMART_READER_LITE
LIVE PREVIEW

Co-simulation Design towards Cyber-Physical Robotic Applications - - PowerPoint PPT Presentation

Co-simulation Design towards Cyber-Physical Robotic Applications Leveraging on FMI Standard and CSP Semantics Zhou Lu and Jan Broenink Robotics and Mechatronics, University of Twente 22 Aug, 2017 Introduction - Context Cyber-Physical


slide-1
SLIDE 1

Co-simulation Design towards Cyber-Physical Robotic Applications

Leveraging on FMI Standard and CSP Semantics Zhou Lu and Jan Broenink Robotics and Mechatronics, University of Twente 22 Aug, 2017

slide-2
SLIDE 2

Introduction - Context

◮ Cyber-Physical Systems towards robotic applications

◮ Combination of different engineering domains ◮ Software, control, electrical, mechanical ◮ Variety of formalisms and tools for subsystems in C-P domains ◮ Discrete-Event (cyber), Continuous-Time (physical)

2/29

slide-3
SLIDE 3

Introduction - Generic Approach

◮ Merging different subsystems involves

◮ Multi-disciplinary modelling ◮ Different formalisms and tools for subsystems ◮ Model-driven design ◮ Meta-modelling, model-to-model transformation ◮ Co-modelling and Co-simulation ◮ Couple models (simulators) via specifically defined interfaces ◮ Collaborate and coordinate simulations of subsystems

◮ Problems

◮ Application-dependent syntax and semantics ◮ Variables are different in different application domains ◮ Interfaces are defined differently in different tools ◮ Flexibility, extensibility and re-usability are limited

3/29

slide-4
SLIDE 4

Introduction - Goal

◮ Couple models in different tools in a standardized way

◮ Standard interfaces to interconnect subsystem models ◮ Functional Mock-up Interface (FMI) standard

◮ State consistency between subsystem models

◮ Data exchange and synchronization ◮ between DE controller models and CT plant models ◮ through CSP semantics

4/29

slide-5
SLIDE 5

Background - Functional Mock-up Interface

◮ Tool-independent standard: initiated by automobile industries

◮ To support the exchange, interoperation and coordination ◮ between subsystem models designed with different tools ◮ provides a set of generic APIs that can be adopted

◮ More than 100 tools claim to support FMI standard

◮ openModelica, Dymola, Adams, SimulationX, 20-sim ... ◮ Becoming the de-facto standard for co-sim in CPS co-design

5/29

slide-6
SLIDE 6

Background - Functional Mock-up Unit

◮ A model implementing FMI interface is denoted as a FMU

◮ XML model-description file ◮ describes static meta-date following FMI XML schema ◮ includes variable attributes, sim capabilities and configuration ◮ Shared library/C source files ◮ model implementation ◮ FMI API implementation

◮ Interconnected FMUs constitute a co-simulation model

◮ Can be simulated as a whole in a co-sim environment

FMU FMU FMU

A B C

A_out B_in1 B_in2 B_out C_out C_in

6/29

slide-7
SLIDE 7

Background - FMI-CS and FMI-ME

◮ FMI for Co-Simulation (FMI-CS)

◮ To couple subsystem models in a co-sim environment ◮ models are provided with their own numerical solvers

◮ FMI for Model Exchange (FMI-ME)

◮ To provide the interface to dynamic models that can be

utilized by other tools

◮ described by differential, algebraic and discrete equations ◮ solvers are provided by the simulation tool

◮ In this paper FMI-CS is used 7/29

slide-8
SLIDE 8

Background - FMI for Co-simulation

◮ Master-Slave mechanism ◮ Slaves: interconnected FMUs

◮ Communicate with the Master only ◮ Black-box components with exposed IO variables

◮ Master: orchestrates communications between slaves

◮ Performs data exchange and manages synchronization ◮ A sophisticated Master Algorithm (MA) is crucial Master

......

FMI

Slave Model Solver

FMU 1

FMI

Slave Model Solver

FMU 2

FMI

Slave Model Solver

FMU N

Co-simulation model

8/29

slide-9
SLIDE 9

Background - Tool Chain

◮ TERRA

◮ CSP based modelling tool for software architecture (DE)

◮ Two hierarchical abstraction layers

◮ Architecture layer ◮ Functional layer

9/29

slide-10
SLIDE 10

Background - Tool Chain

◮ 20-sim

◮ Plant modelling using bond graphs (CT) ◮ Control laws modelling using iconic diagrams with dynamic

queations

◮ Supports exporting FMUs specified by FMI-CS

10/29

slide-11
SLIDE 11

Design - Co-sim Design Flow

◮ Co-simulation design flow using our approach and tools

◮ 5 steps towards co-simulation using TERRA and 20-sim ◮ This paper mainly contributes to Step 3 and Step 4

Contol Laws Plant 20-sim model FMU FMU .xml and .so

TERRA

CPP-coded Master Algorithm LUNA

Execution Framework

libLUNA.a Compile/Link Executable Co-simulation

1 2 4 5

Simulation Results

3

11/29

slide-12
SLIDE 12

Design - Co-sim Design Flow

◮ Co-simulation design flow using our approach and tools

◮ Step 1: architecture design in TERRA ◮ Step 2: functional design in 20-sim and FMU generation

Contol Laws Plant 20-sim model FMU FMU .xml and .so

TERRA

CPP-coded Master Algorithm LUNA

Execution Framework

libLUNA.a Compile/Link Executable Co-simulation

1 2 4 5

Simulation Results

3

12/29

slide-13
SLIDE 13

Design - Co-sim Design Flow

◮ Co-simulation design flow using our approach and tools

◮ Step 3: coupling different FMUs in TERRA ◮ Step 4: generating CSP-based C++ code implementing MA

Contol Laws Plant 20-sim model FMU FMU .xml and .so

TERRA

CPP-coded Master Algorithm LUNA

Execution Framework

libLUNA.a Compile/Link Executable Co-simulation

1 2 4 5

Simulation Results

3

13/29

slide-14
SLIDE 14

Design - Co-sim Design Flow

◮ Co-simulation design flow using our approach and tools

◮ Step 5: compiling code and performing co-simulation ◮ Simulation results are stored in csv files

Contol Laws Plant 20-sim model FMU FMU .xml and .so

TERRA

CPP-coded Master Algorithm LUNA

Execution Framework

libLUNA.a Compile/Link Executable Co-simulation

1 2 4 5

Simulation Results

3

14/29

slide-15
SLIDE 15

Design - Coupling Models

◮ Coupling different domain models using MDD

◮ Generated FMI XML schema meta-model ◮ fmiModelDescription, CoSimulation, DefaultExperiment ◮ ScalarVariable ◮ Existing TERRA CSP meta-model ◮ CSPModel process with FMU interface configuration ◮ CSPReader, CSPWriter, Port, Variable

15/29

slide-16
SLIDE 16

Design - Coupling Models

◮ Epsilon languages and tools: work out of the box with EMF

◮ Epsilon Object Language: ETL(Transformation)

EGL (Generation), EVL (Validation)

◮ Transformation rules: parser for FMI model description file

16/29

slide-17
SLIDE 17

Design - Coupling Models

◮ Example: a 20-sim plant model to a TERRA CSP model

◮ Fluid level control system: plant model in 20-sim ◮ With 2 exposed IO variables: control and height ◮ Transformed to a TERRA CSP model ◮ CSPReader: variable v control ◮ CSPWriter: variable v height ◮ CSPModel process: with FMU interface configuration

17/29

slide-18
SLIDE 18

Design : Master Algorithm

◮ Master behaves as an orchestrator for co-simulation

◮ FMI only specifies the API that FMUs must implement ◮ Does not specify how the Master should preform the co-sim

18/29

slide-19
SLIDE 19

Design : Master Algorithm

◮ Master behaves as an orchestrator for co-simulation

◮ FMI only specifies the API that FMUs must implement ◮ Does not specify how the Master should preform the co-sim

◮ FMI API calling sequence from Master to Slaves is important

◮ Must be performed correctly on each FMU ◮ Instantiation and Initialisation phase ◮ fmi2Instantiate, fmi2SetupExperiment,

fmi2EnterInitializationMode, fmi2ExitInitializationMode

◮ Simulation phase ◮ fmi2DoStep ◮ currentCommunicationPoint: current Master time ◮ communicationStepSize: proposed communication step size ◮ Termination phase ◮ fmi2Terminate, fmi2FreeInstance

18/29

slide-20
SLIDE 20

Design : Master Algorithm

◮ FMU interface meta-model

◮ FMIModel inherits from the CPPCodeBlockConfiguration ◮ Interfacing to the FMU is abstracted as a C++ code block in

the form of a CSPModel process

19/29

slide-21
SLIDE 21

Design : Master Algorithm

◮ Utilize C++ code generation feature in TERRA

◮ Re-use code generation facilities towards CSP components ◮ EGL templates for FMU interfacing C++ code block

◮ Mapping between class functions and FMI-CS phases

FMU Interfacing Model: FMI Co-simulation FMI API Functions Generated C++ Class Functions Phases To Be Invoked FMI FMUName(IO parameter,...) Instantiation and fmi2Instantiate (constructor) (partial) Initialisation fmi2SetupExperiment fmi2EnterInitializationMode execute() (partial) Initialisation fmi2ExitInitializationMode (at the first iteration) (synchronize init values only) execute() Simulation fmi2DoStep (execute iteratively) execute() Terminate fmi2Terminate if stopTime (final time) is reached fmi2FreeInstance

20/29

slide-22
SLIDE 22

Design : Master Algorithm

◮ Co-simulation model: TERRA arch model and CSP model

◮ Connections between FMUs are defined by CSPChannels ◮ Data exchange is in a waiting-rendezvous manner ◮ MA determinism can be ensured ◮ The results of different co-simulation runs do not depend on

any arbitrary order in which the FMUs might be chosen

21/29

slide-23
SLIDE 23

Design : Master Algorithm

◮ Artificial delay in loop control

◮ IO-SEQ pattern results in a deadlock ◮ Deadlock free modification using PARALLEL composition ◮ Communication events happen in an interleaving manner ◮ Artificial delay, wrong simulation results

22/29

slide-24
SLIDE 24

Design : Master Algorithm

◮ Algorithm to compensate for the artificial delay 23/29

slide-25
SLIDE 25

Experiments

◮ Fluid level control

◮ Plant (CT domain): two tanks coupled through a pipe ◮ Fluid input in tank 1 ◮ Leaking valve in tank 2 ◮ Controller (DE domain): a proportional controller ◮ Keep the fluid level in tank 2 at desired level ◮ Desired level changes at time step 10.0s

◮ Two types of experiments

◮ On functionality and accuracy of the co-simulation ◮ On performance with/without timing compensation

24/29

slide-26
SLIDE 26

Experiments

◮ On functionality and accuracy of the co-simulation

◮ With communication step size of 0.001s ◮ Does not cause a too much deviation from correct results

25/29

slide-27
SLIDE 27

Experiments

◮ On functionality and accuracy of the co-simulation

◮ With communication step size of 0.3s ◮ Without compensation, control rise time is 2.5s longer

26/29

slide-28
SLIDE 28

Experiments

◮ On performance with/without timing compensation

◮ At smaller communication step size ◮ Execution time is obviously longer ◮ Extra work to compensate delay has a relatively larger cost ◮ At larger communication step size ◮ Execution time differences are smaller ◮ Timing compensation should be prioritized

Co-simulation performance

0.2 0.4 0.6 0.8 1 1.2 1.4 0.2 0.4 0.6 0.8 1 1.2 1.4 0.001 0.01 0.03 0.1 0.2 0.3 0.5 1.3068472 0.2141264 0.0949332 0.0350384 0.0217286 0.0151728 0.012022 0.9604756 0.1533282 0.067546 0.0238606 0.01482 0.010206 0.0066436 step size with timing compensation without timing compensation

execution time (s) co-sim communication step size

27/29

slide-29
SLIDE 29

Conclusions and Future Work

◮ Conclusions

◮ A FMI-CS compliant co-simulation approach is introduced ◮ Using Model-Driven features to couple DE/CT models ◮ CSP-based C++ code skeleton are automatically generated

implementing the Master Algorithm

◮ The Master orchestrates the co-simulation between different

FMUs benefiting from CSP semantics

◮ An optimized algorithm is developed to compensate for the

artificial delay in loop control

◮ A fluid level control system was co-simulated using the

proposed approach

◮ The fluid level was controlled properly ◮ The one-step artificial delay was handled correctly ◮ Co-simulation performance was discussed by measuring

execution time with different communication step sizes

◮ At large step size, timing compensation should be prioritized

28/29

slide-30
SLIDE 30

Conclusions and Future Work

◮ Future Work

◮ To further develop Master Algorithms that can handle arbitrary

state events

◮ After FMI-ME is supported by 20-sim (work in progress by

Controllab Products B.V.)

◮ Coupling of simulation tools, i.e. TERRA and 20-sim ◮ To support more sophisticated co-modelling and more

advanced co-simulation calculations

29/29

slide-31
SLIDE 31

Thanks! Information and source are available on www.ram.ewi.utwente.nl/ECSSoftware/

29/29