1
0
Fork 0
mirror of https://git.rwth-aachen.de/acs/public/villas/node/ synced 2025-03-09 00:00:00 +01:00
VILLASnode/python/examples/Shmem_CIGRE_MV.py

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

94 lines
2.5 KiB
Python
Raw Permalink Normal View History

"""
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
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():
"""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):
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
def get_dpsim_shmem_interface_config():
return {
"type": "shmem",
"in": {
"name": "/dpsim1-villas",
"hooks": [{"type": "stats"}],
"signals": get_dpsim_shmem_interface_signals(),
},
"out": {"name": "/villas-dpsim1"},
}
2021-02-17 12:33:28 +01:00
def get_villas_config():
return {
"nodes": {
"broker1": {
"type": "mqtt",
"format": "json",
"host": "172.17.0.1",
"in": {"subscribe": "/powerflow-dpsim"},
"out": {"publish": "/dpsim-powerflow"},
},
"dpsim1": get_dpsim_shmem_interface_config(),
},
"paths": [
{
"in": "dpsim1",
"out": "broker1",
"hooks": [{"type": "limit_rate", "rate": 50}],
}
],
}
2021-02-17 12:33:28 +01:00
def main():
node = VILLASnode(config=get_villas_config())
2021-02-17 12:33:28 +01:00
node.start() # VILLASnode starts running in the background from here..
# Some infos from the running VILLASnode instance queried via its REST API
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 12:33:28 +01:00
# Load a new config into the running
# VILLASnode instance (old config will be replaced)
new_config = node.active_config
new_config["paths"].append({"out": "dpsim1", "in": "broker1"})
node.load_config(new_config)
time.sleep(100)
node.stop()
if __name__ == "main":
main()