INTO-CPS

Co-Simulation using FMI

INTO-CPS

Go to our GitHub Profile

Follow @IntoCps

Simulation Example

To perform a simulation we need the following:

  1. A collection of FMU’s
  2. A COE configuration listing:
    • the path to all FMU’s
    • their connections
    • any parameters
    • the step size configuration
  3. The COE
  4. A suitable tool and language for assisting in calling the COE (we use Shell and curl)

Fetch FMUs

These FMU’s are cross compiles to all supported platforms:

Also fetch the COE, see the download page.

File structure

This is just a proposed file structure, chose what you like.

Make the configuration

Create a file named config.json with the following content:

{
	"fmus":{
		"{fmu1}":"../fmus/tankcontroller.fmu",
		"{fmu2}":"../fmus/tank.fmu"
	},
	"connections":{
		"{fmu1}.controller.valve":
		    ["{fmu2}.tank.valve"],
		"{fmu2}.tank.level":
		    ["{fmu1}.controller.level"]
	},
	"parameters":{
		"{fmu1}.controller.maxLevel":8,
		"{fmu1}.controller.minLevel":2
	},
	"algorithm":{
		"type":"fixed-step",
		"size":0.1
	}
}

Note that the connections is Output to Inputs i.e. a map from String -> Set of String. So here "a":["b","c"] means that input b and c is provided by a.

Perform the simulation

  1. Start the COE:
cd coe
java -jar coe.jar 
  1. (New terminal, or use &) Create a session to use for the simulation
sessionIdJson=$(curl -s http://localhost:8082/createSession)
  1. Find the session id in the response
sessionId=`echo $sessionIdJson | cut -d ":" -f 2- | cut -d "}" -f 1`
  1. Initialize the simulation
curl -s -H "Content-Type: application/json" --data @config.json http://localhost:8082/initialize/$sessionId
  1. Start the simulation
endTime=4
curl -s -H "Content-Type: application/json" --data '{"startTime":0.0, "endTime":'$endTime'}' http://localhost:8082/simulate/$sessionId

note that the above json string must be expressed as follows on windows platforms:

--data "{\"startTime\":0.0, \"endTime\":%endTime%}" 
  1. Fetch the result
curl -s http://localhost:8082/result/$sessionId