AGX Dynamics  2.35.0.1
CoSimulationServer.h
Go to the documentation of this file.
1 /*
2 Copyright 2007-2022. Algoryx Simulation AB.
3 
4 All AGX source code, intellectual property, documentation, sample code,
5 tutorials, scene files and technical white papers, are copyrighted, proprietary
6 and confidential material of Algoryx Simulation AB. You may not download, read,
7 store, distribute, publish, copy or otherwise disseminate, use or expose this
8 material unless having a written signed agreement with Algoryx Simulation AB, or having been
9 advised so by Algoryx Simulation AB for a time limited evaluation, or having purchased a
10 valid commercial license from Algoryx Simulation AB.
11 
12 Algoryx Simulation AB disclaims all responsibilities for loss or damage caused
13 from using this software, unless otherwise stated in written agreements with
14 Algoryx Simulation AB.
15 */
16 
17 #pragma once
18 
20 #include <agx/agx_vector_types.h>
21 
22 #include <agx/Thread.h>
23 
24 namespace agxSDK
25 {
26  class Simulation;
27 }
28 
29 namespace 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 
74  bool applyInitInputs(agxSDK::Simulation *simulation );
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.
const agx::String & getFilename()
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)
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:127
Basic wrapper class aroud std::thread.
Definition: Thread.h:82
Block synchronization primitive.
Base class providing referencing counted objects.
Definition: Referenced.h:114
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