AGX Dynamics 2.38.0.2
Loading...
Searching...
No Matches
Master.h
Go to the documentation of this file.
1/*
2Copyright 2007-2024. Algoryx Simulation AB.
3
4All AGX source code, intellectual property, documentation, sample code,
5tutorials, scene files and technical white papers, are copyrighted, proprietary
6and confidential material of Algoryx Simulation AB. You may not download, read,
7store, distribute, publish, copy or otherwise disseminate, use or expose this
8material unless having a written signed agreement with Algoryx Simulation AB, or having been
9advised so by Algoryx Simulation AB for a time limited evaluation, or having purchased a
10valid commercial license from Algoryx Simulation AB.
11
12Algoryx Simulation AB disclaims all responsibilities for loss or damage caused
13from using this software, unless otherwise stated in written agreements with
14Algoryx Simulation AB.
15*/
16
17#ifndef AGXFMI2_IMPORT_MASTER_H
18#define AGXFMI2_IMPORT_MASTER_H
19
20#include <agx/config/AGX_USE_FMI.h>
21#include <agx/config/AGX_USE_WEBPLOT.h>
22
23#if AGX_USE_FMI()
24
26
27#include <agx/Component.h>
28#include <agxSDK/Simulation.h>
29#include <agx/RealTimeTrigger.h>
30
31#if AGX_USE_WEBSOCKETS()
32#include <agxNet/WebSocket.h>
33#endif
34
35#include <agx/PushDisableWarnings.h> // Disabling warnings. Include agx/PopDisableWarnings.h below!
36
37extern "C"
38{
39 #include <JM/jm_callbacks.h>
40}
41
42#include <agx/PopDisableWarnings.h> // End of disabled warnings.
43
44namespace agxOSG
45{
46 class ExampleApplication;
47}
48
49
50namespace agxFMI2
51{
52 namespace Import
53 {
55
59 class AGXFMI_EXPORT Master : public agx::Component
60 {
61 public:
62 Master(Module::LogLevel logLevel = Module::LOG_LEVEL_INFO);
63 Master(agxSDK::Simulation *simulation, Module::LogLevel logLevel = Module::LOG_LEVEL_INFO);
64
65 void enableDirectApplicationControl(agxOSG::ExampleApplication *app);
66
67 agxSDK::Simulation *getSimulation();
68 const agxSDK::Simulation *getSimulation() const;
69
70 void load(const agx::String& xmlPath);
71 Module *loadModule(const agx::String& path);
72
73 const agx::String& getDiskRootPath() const;
74
75 Module *getModule(const agx::Name& name);
76
77 void setTimeStep(agx::Real dt);
78
79 void init(agx::Real tStart, agx::Real tEnd, bool stopTimeDefined = true);
80
81 void bind(Variable *input, Variable *output);
82
83 void execute();
84 void terminate();
85
86
87 agx::Real getStartTime() const;
88 agx::Real getEndTime() const;
89 agx::Real getTimeStep() const;
90
91 void setControlChannelFrequency(agx::Real frequency);
92
93 void setDebug(bool flag);
94 bool getDebug() const;
95
96
97 protected:
98 virtual ~Master();
99
100 private:
103
104 Variable *getVariable(const agx::String& path);
105 void preTickCallback(agx::Clock *clock);
106 void stepForward();
107
108#if AGX_USE_WEBSOCKETS()
109 void ccGetModules(agxNet::WebSocket::ControlChannel *, agxNet::WebSocket *socket, agxNet::StructuredMessage *message);
110 void ccGetModuleDescription(agxNet::WebSocket::ControlChannel *, agxNet::WebSocket *socket, agxNet::StructuredMessage *message);
111 void ccGetInitialState(agxNet::WebSocket::ControlChannel *, agxNet::WebSocket *socket, agxNet::StructuredMessage *message);
112 void ccSetParameter(agxNet::WebSocket::ControlChannel *, agxNet::WebSocket *socket, agxNet::StructuredMessage *message);
113 void ccGetParameter(agxNet::WebSocket::ControlChannel *, agxNet::WebSocket *socket, agxNet::StructuredMessage *message);
114#endif
115
116 private:
117 agxSDK::SimulationRef m_simulation;
118 agx::Clock::TickEvent::CallbackType m_preTickCallback;
119
120 agx::String m_diskRootPath;
121 jm_callbacks m_jmCallbacks;
122
123 ModuleRefVector m_modules;
124 BindingRefVector m_bindings;
125 agx::Real m_startTime;
126 agx::Real m_endTime;
127 agx::Real m_timeStep;
128 agx::Real m_currentTime;
129 agx::RealTimeTrigger m_rtTrigger;
130 bool m_debug;
131 Module::LogLevel m_logLevel;
132#if AGX_USE_WEBSOCKETS()
133 agxNet::WebSocket::ControlChannelRef m_controlChannel;
134#endif
135 };
136
137#ifndef SWIG
138/* To-do: remove the necessity of this conditional using cleaner declaration
139
140 Reason: SWIG's primitive parser gets confused as this decl appears twice
141 in the AST SWIG produces, making it impossible ignore _properly_. */
142
143 class Master::Binding : public agx::Referenced
144 {
145 public:
146 Binding(Variable *input, Variable *output);
147
148 Variable *getInput();
149 Variable *getOutput();
150
151 void transferData();
152
153 protected:
154 virtual ~Binding();
155
156 private:
157 VariableRef m_input;
158 VariableRef m_output;
159 };
160#endif
161 }
162}
163
164#endif /* AGX_USE_FMI */
165
166#endif /* AGX_IMPORT_MASTER_H */
#define AGX_DECLARE_POINTER_TYPES(type)
Definition Referenced.h:254
#define AGXFMI_EXPORT
#define AGX_DECLARE_VECTOR_TYPES(type)
Definition agx/Vector.h:34
Class that encapsulates rendering and simulation using OpenSceneGraph.
Simulation is a class that bridges the collision space agxCollide::Space and the dynamic simulation s...
Definition Simulation.h:126
Clock class keeps representation of virtual/simulated time.
Definition Clock.h:38
A component is an object containing other objects, enabling hierarchical structuring.
Definition Component.h:39
T CallbackType
Definition Event.h:37
Representation of a name string.
Definition Name.h:33
Base class providing referencing counted objects.
Definition Referenced.h:120
This namespace contains functionality for using AGX together with version 2 of the Functional Mockup ...
The agxOSG namespace provides functionality for visualizing AGX simulations with OpenSceneGraph.
double Real
Definition Real.h:42
void AGXPHYSICS_EXPORT init()
Initialize AGX Dynamics API including thread resources and must be executed before using the AGX API.