2023-09-19 12:04:53 +02:00
|
|
|
"""
|
|
|
|
Author: Steffen Vogel <post@steffenvogel.de>
|
|
|
|
SPDX-FileCopyrightText: 2014-2023 Institute for Automation of Complex Power Systems, RWTH Aachen University
|
|
|
|
SPDX-License-Identifier: Apache-2.0
|
|
|
|
""" # noqa: E501
|
2024-02-13 13:13:06 +00:00
|
|
|
|
2021-02-17 09:33:35 +01:00
|
|
|
import time
|
|
|
|
from villas.node.node import Node as VILLASnode
|
|
|
|
|
|
|
|
# This could be moved to the DPsim Python code later
|
2021-02-17 09:52:06 +01:00
|
|
|
|
2021-02-17 12:33:28 +01:00
|
|
|
|
2021-02-17 09:52:06 +01:00
|
|
|
def get_dpsim_shmem_interface_signals():
|
2023-09-19 12:04:53 +02:00
|
|
|
"""It would be nice if the DPsim Shmem interface could
|
|
|
|
build-up a list of actual signal descriptions
|
|
|
|
(names, units, etc..) which attributes are exported.
|
|
|
|
This would eliviate the user from manually configuring
|
|
|
|
signal mappings"""
|
2021-02-17 09:52:06 +01:00
|
|
|
signals = []
|
|
|
|
|
|
|
|
for i in range(0, 30):
|
2023-09-19 12:04:53 +02:00
|
|
|
signals.append(
|
|
|
|
{
|
|
|
|
"name": f"signal_{i}",
|
|
|
|
"type": "float",
|
|
|
|
"unit": "volts",
|
|
|
|
}
|
|
|
|
)
|
2021-02-17 12:33:28 +01:00
|
|
|
|
2021-02-17 09:52:06 +01:00
|
|
|
return signals
|
|
|
|
|
2021-02-17 12:33:28 +01:00
|
|
|
|
2021-02-17 09:33:35 +01:00
|
|
|
def get_dpsim_shmem_interface_config():
|
|
|
|
return {
|
2023-09-19 12:04:53 +02:00
|
|
|
"type": "shmem",
|
|
|
|
"in": {
|
|
|
|
"name": "/dpsim1-villas",
|
|
|
|
"hooks": [{"type": "stats"}],
|
|
|
|
"signals": get_dpsim_shmem_interface_signals(),
|
2023-09-04 19:22:56 +02:00
|
|
|
},
|
2023-09-19 12:04:53 +02:00
|
|
|
"out": {"name": "/villas-dpsim1"},
|
2023-09-04 19:22:56 +02:00
|
|
|
}
|
2021-02-17 09:33:35 +01:00
|
|
|
|
2021-02-17 12:33:28 +01:00
|
|
|
|
2021-02-17 09:33:35 +01:00
|
|
|
def get_villas_config():
|
|
|
|
return {
|
2023-09-19 12:04:53 +02:00
|
|
|
"nodes": {
|
|
|
|
"broker1": {
|
|
|
|
"type": "mqtt",
|
|
|
|
"format": "json",
|
|
|
|
"host": "172.17.0.1",
|
|
|
|
"in": {"subscribe": "/powerflow-dpsim"},
|
|
|
|
"out": {"publish": "/dpsim-powerflow"},
|
2021-02-17 09:33:35 +01:00
|
|
|
},
|
2023-09-19 12:04:53 +02:00
|
|
|
"dpsim1": get_dpsim_shmem_interface_config(),
|
2021-02-17 09:33:35 +01:00
|
|
|
},
|
2023-09-19 12:04:53 +02:00
|
|
|
"paths": [
|
2021-02-17 09:33:35 +01:00
|
|
|
{
|
2023-09-19 12:04:53 +02:00
|
|
|
"in": "dpsim1",
|
|
|
|
"out": "broker1",
|
|
|
|
"hooks": [{"type": "limit_rate", "rate": 50}],
|
2021-02-17 09:33:35 +01:00
|
|
|
}
|
2023-09-19 12:04:53 +02:00
|
|
|
],
|
2021-02-17 09:33:35 +01:00
|
|
|
}
|
|
|
|
|
2021-02-17 12:33:28 +01:00
|
|
|
|
2021-02-17 09:33:35 +01:00
|
|
|
def main():
|
2023-09-19 12:04:53 +02:00
|
|
|
node = VILLASnode(config=get_villas_config())
|
2021-02-17 09:33:35 +01:00
|
|
|
|
2021-02-17 12:33:28 +01:00
|
|
|
node.start() # VILLASnode starts running in the background from here..
|
2021-02-17 09:33:35 +01:00
|
|
|
|
|
|
|
# Some infos from the running VILLASnode instance queried via its REST API
|
2023-09-19 12:04:53 +02:00
|
|
|
print("VILLASnode running?: ", node.is_running())
|
|
|
|
print("VILLASnode status: ", node.status)
|
|
|
|
print("VILLASnode nodes: ", node.nodes)
|
|
|
|
print("VILLASnode paths: ", node.paths)
|
|
|
|
print("VILLASnode config: ", node.active_config)
|
|
|
|
print("VILLASnode version: ", node.get_version())
|
2021-02-17 09:33:35 +01:00
|
|
|
|
2021-02-17 12:33:28 +01:00
|
|
|
# Load a new config into the running
|
|
|
|
# VILLASnode instance (old config will be replaced)
|
2021-02-17 09:33:35 +01:00
|
|
|
new_config = node.active_config
|
2023-09-19 12:04:53 +02:00
|
|
|
new_config["paths"].append({"out": "dpsim1", "in": "broker1"})
|
2021-02-17 09:33:35 +01:00
|
|
|
|
|
|
|
node.load_config(new_config)
|
|
|
|
|
|
|
|
time.sleep(100)
|
|
|
|
|
|
|
|
node.stop()
|
|
|
|
|
|
|
|
|
2023-09-19 12:04:53 +02:00
|
|
|
if __name__ == "main":
|
2021-02-17 09:33:35 +01:00
|
|
|
main()
|