Skip to content

Commit e7ed875

Browse files
committed
feat(node-fmu): Add new FMU node type
1 parent db372c7 commit e7ed875

5 files changed

Lines changed: 397 additions & 0 deletions

File tree

CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@ cmake_dependent_option(WITH_NODE_ULDAQ "Build with uldaq node-type"
214214
cmake_dependent_option(WITH_NODE_WEBRTC "Build with webrtc node-type" "${WITH_DEFAULTS}" "WITH_WEB; LibDataChannel_FOUND" OFF)
215215
cmake_dependent_option(WITH_NODE_WEBSOCKET "Build with websocket node-type" "${WITH_DEFAULTS}" "WITH_WEB" OFF)
216216
cmake_dependent_option(WITH_NODE_ZEROMQ "Build with zeromq node-type" "${WITH_DEFAULTS}" "LIBZMQ_FOUND; NOT WITHOUT_GPL" OFF)
217+
cmake_dependent_option(WITH_NODE_FMU "Build with fmu node-type" "${WITH_DEFAULTS}" "" OFF)
217218

218219
# Set a default for the build type
219220
if("${CMAKE_BUILD_TYPE}" STREQUAL "")
@@ -324,6 +325,7 @@ add_feature_info(NODE_ULDAQ WITH_NODE_ULDAQ "Build with
324325
add_feature_info(NODE_WEBRTC WITH_NODE_WEBRTC "Build with webrtc node-type")
325326
add_feature_info(NODE_WEBSOCKET WITH_NODE_WEBSOCKET "Build with websocket node-type")
326327
add_feature_info(NODE_ZEROMQ WITH_NODE_ZEROMQ "Build with zeromq node-type")
328+
add_feature_info(NODE_FMU WITH_NODE_FMU "Build with fmu node-type")
327329

328330
if(TOPLEVEL_PROJECT)
329331
feature_summary(WHAT ALL VAR FEATURES)

etc/examples/nodes/fmu.conf

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# SPDX-FileCopyrightText: 2014-2023 Institute for Automation of Complex Power Systems, RWTH Aachen University
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
nodes = {
5+
fmu = {
6+
type = "fmu"
7+
# Path to fmu file
8+
fmu_path = "external/fmu/ieee13bus/binaries/x86_64-linux/ieee13bus.so"
9+
# fmu token usually in xml file
10+
fmu_token = ""
11+
fmu_writefirst = false
12+
# fmu output list
13+
in = {
14+
signals = (
15+
{ref = 48, type = "float"},
16+
{ref = 49, type = "float"},
17+
{ref = 50, type = "float"},
18+
{ref = 51, type = "float"},
19+
{ref = 52, type = "float"},
20+
{ref = 53, type = "float"}
21+
)
22+
}
23+
# fmu input list
24+
out = {
25+
signals = (
26+
{ref = 99, type = "float"},
27+
{ref = 99, type = "float"},
28+
)
29+
}
30+
}
31+
32+
signal_node = {
33+
type = "signal"
34+
limit = 10
35+
signal = "mixed"
36+
values = 1
37+
rate = 2.0
38+
}
39+
}
40+
41+
paths = (
42+
{
43+
in = "signal_node"
44+
out = "fmu"
45+
hooks = ( { type = "print" } )
46+
},
47+
{
48+
in = "fmu"
49+
hooks = ( { type = "print" } )
50+
}
51+
)

include/villas/nodes/fmu.hpp

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
#pragma once
2+
3+
#include <string>
4+
#include <vector>
5+
#include <villas/node.hpp>
6+
#include <villas/format.hpp>
7+
8+
#include "fmi3FunctionTypes.h"
9+
#include "fmi3Functions.h"
10+
#include "fmi3PlatformTypes.h"
11+
12+
namespace villas {
13+
namespace node {
14+
15+
// Forward declarations
16+
struct Sample;
17+
18+
class FmuNode : public Node {
19+
protected:
20+
int parse(json_t *json) override;
21+
22+
int _read(struct Sample *smps[], unsigned cnt) override;
23+
int _write(struct Sample *smps[], unsigned cnt) override;
24+
25+
bool writingTurn;
26+
const char *path;
27+
const char *token;
28+
void *handle;
29+
30+
timespec ts;
31+
pthread_mutex_t mutex;
32+
pthread_cond_t cv;
33+
34+
fmi3Instance fmu;
35+
fmi3InstantiateCoSimulationTYPE* fmi3InstantiateCoSimulation;
36+
fmi3EnterInitializationModeTYPE* fmi3EnterInitializationMode;
37+
fmi3ExitInitializationModeTYPE* fmi3ExitInitializationMode;
38+
fmi3DoStepTYPE* fmi3DoStep;
39+
fmi3FreeInstanceTYPE* fmi3FreeInstance;
40+
41+
fmi3Float64 stoptime;
42+
fmi3Boolean stoptimedefined;
43+
44+
fmi3Float64 stepsize;
45+
fmi3Float64 currenttime;
46+
47+
fmi3Boolean eventHandlingNeeded;
48+
fmi3Boolean terminateSimulation;
49+
fmi3Boolean earlyReturn;
50+
fmi3Float64 lastSuccessfulTime;
51+
52+
fmi3GetFloat64TYPE* fmi3GetFloat64;
53+
fmi3SetFloat64TYPE* fmi3SetFloat64;
54+
55+
fmi3GetFloat32TYPE* fmi3GetFloat32;
56+
fmi3SetFloat32TYPE* fmi3SetFloat32;
57+
58+
fmi3SetInt32TYPE* fmi3SetInt32;
59+
fmi3GetInt32TYPE* fmi3GetInt32;
60+
61+
fmi3GetInt64TYPE* fmi3GetInt64;
62+
fmi3SetInt64TYPE* fmi3SetInt64;
63+
64+
fmi3GetBooleanTYPE* fmi3GetBoolean;
65+
fmi3SetBooleanTYPE* fmi3SetBoolean;
66+
67+
public:
68+
FmuNode(const uuid_t &id = {}, const std::string &name = "");
69+
70+
enum FMUDataType { fmu_float, fmu_int, fmu_bool };
71+
72+
struct fmu_signal {
73+
unsigned int ref;
74+
FMUDataType type;
75+
};
76+
77+
std::vector<fmu_signal> signal_in, signal_out;
78+
79+
int prepare() override;
80+
81+
int check() override;
82+
83+
int start() override;
84+
85+
int stop() override;
86+
87+
~FmuNode();
88+
89+
private:
90+
void parse_signal(json_t *json, bool in);
91+
int limit;
92+
int step;
93+
};
94+
95+
} // namespace node
96+
} // namespace villas

lib/nodes/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ if(WITH_WEB)
1212
list(APPEND NODE_SRC api.cpp)
1313
endif()
1414

15+
if(WITH_NODE_FMU)
16+
list(APPEND NODE_SRC fmu.cpp)
17+
endif()
18+
1519
if(LIBNL3_ROUTE_FOUND)
1620
list(APPEND LIBRARIES PkgConfig::LIBNL3_ROUTE)
1721
endif()

0 commit comments

Comments
 (0)