AGX Dynamics 2.38.0.2
Loading...
Searching...
No Matches
CoSimulationServer.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#pragma once
18
21
22#include <agx/Thread.h>
23
24namespace agxSDK
25{
26 class Simulation;
27}
28
29namespace agxNet
30{
31
34 {
35 public:
36
37 void run();
38
40 void shutdown();
41
42
44 {
45 NO_SCRIPT=0,
46 PYTHON_SCRIPT=1,
47 };
48
51
56 CoSimulationServer( uint16_t port );
57
62 void setEnableCompression( bool flag ) { m_useCompression = flag; }
63
67 bool getEnableCompression( ) const { return m_useCompression; }
68
70
71 Header::Mode receiveInstructions( agxSDK::Simulation *simulation );
72 void setInstructionStatus( Header::Mode mode, const agx::String& message );
73
76
77 bool isShutdown();
78
79 protected:
80
81 virtual void waitForDataAndTransfer();
82 virtual bool waitForConnection();
83 void dropConnection(bool shouldShutdown) override;
84
86
87 private:
88 void handlePreloadScript();
89 void handleSetTimeStep();
90 void handleStepInput();
91 void handleInitInput();
92 void handleNop();
93
94 void sendReplyPacket();
95
96 TCPServerSocketRef m_serverSocket;
97 uint16_t m_port;
98 bool m_useCompression;
99
100 agx::Block m_hasInstructions;
101
102 Header::Mode m_currentInstruction;
103 Header::Mode m_replyInstruction;
104 agx::String m_replyMessage;
105 agx::String m_filename;
106 double m_timeStep;
107
108 agx::RealVector m_inputs;
109 agx::RealVector m_outputs;
110
111 agx::RealVector m_initInputs;
112 agx::RealVector m_initOutputs;
113 agx::Timer stepTimer;
114 ScriptMode m_scriptMode;
115
116 };
117
118}
#define AGXPHYSICS_EXPORT
Base class for multi threaded transferring simulation between a server and a client using sockets.
Class for sending serialized agxSDK::Simulation over to a client.
void setScriptMode(ScriptMode)
void shutdown()
Shutdown the communication threads, will cause this client to be non-usable any more.
bool obtainInitOutputs(agxSDK::Simulation *simulation)
void setInstructionStatus(Header::Mode mode, const agx::String &message)
void run()
This method is invoked by start.
void dropConnection(bool shouldShutdown) override
Drop the connection to the remote host and wait for a new one.
virtual bool waitForConnection()
bool applyInitInputs(agxSDK::Simulation *simulation)
Header::Mode receiveInstructions(agxSDK::Simulation *simulation)
const agx::String & getFilename()
ScriptMode getScriptMode() const
void setEnableCompression(bool flag)
Enable/disable compression of transmitted data.
CoSimulationServer(uint16_t port)
Constructor.
virtual void waitForDataAndTransfer()
Simulation is a class that bridges the collision space agxCollide::Space and the dynamic simulation s...
Definition Simulation.h:126
Basic wrapper class aroud std::thread.
Definition Thread.h:83
Block synchronization primitive.
Base class providing referencing counted objects.
Definition Referenced.h:120
The Timer class permits timing execution speed with the same refinement as the built in hardware cloc...
Definition Timer.h:75
Containins classes for sending/reading data over sockets as well as compression functionality.
Definition MacUtil.h:23
The agxSDK namespace contain classes to bridge the collision detection system and the dynamical simul...
Definition Constraint.h:31