SharedMemoryCommands.h 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  1. #ifndef SHARED_MEMORY_COMMANDS_H
  2. #define SHARED_MEMORY_COMMANDS_H
  3. //this is a very experimental draft of commands. We will iterate on this API (commands, arguments etc)
  4. #include "SharedMemoryPublic.h"
  5. #ifdef __GNUC__
  6. #include <stdint.h>
  7. typedef int32_t smInt32_t;
  8. typedef int64_t smInt64_t;
  9. typedef uint32_t smUint32_t;
  10. typedef uint64_t smUint64_t;
  11. #elif defined(_MSC_VER)
  12. typedef __int32 smInt32_t;
  13. typedef __int64 smInt64_t;
  14. typedef unsigned __int32 smUint32_t;
  15. typedef unsigned __int64 smUint64_t;
  16. #else
  17. typedef int smInt32_t;
  18. typedef long long int smInt64_t;
  19. typedef unsigned int smUint32_t;
  20. typedef unsigned long long int smUint64_t;
  21. #endif
  22. #define SHARED_MEMORY_MAX_STREAM_CHUNK_SIZE (256*1024)
  23. #define SHARED_MEMORY_SERVER_TEST_C
  24. #define MAX_DEGREE_OF_FREEDOM 64
  25. #define MAX_NUM_SENSORS 256
  26. #define MAX_URDF_FILENAME_LENGTH 1024
  27. #define MAX_FILENAME_LENGTH MAX_URDF_FILENAME_LENGTH
  28. struct TmpFloat3
  29. {
  30. float m_x;
  31. float m_y;
  32. float m_z;
  33. };
  34. #ifdef _WIN32
  35. __inline
  36. #else
  37. inline
  38. #endif
  39. TmpFloat3 CreateTmpFloat3(float x, float y, float z)
  40. {
  41. TmpFloat3 tmp;
  42. tmp.m_x = x;
  43. tmp.m_y = y;
  44. tmp.m_z = z;
  45. return tmp;
  46. }
  47. enum EnumUrdfArgsUpdateFlags
  48. {
  49. URDF_ARGS_FILE_NAME=1,
  50. URDF_ARGS_INITIAL_POSITION=2,
  51. URDF_ARGS_INITIAL_ORIENTATION=4,
  52. URDF_ARGS_USE_MULTIBODY=8,
  53. URDF_ARGS_USE_FIXED_BASE=16,
  54. };
  55. struct UrdfArgs
  56. {
  57. char m_urdfFileName[MAX_URDF_FILENAME_LENGTH];
  58. double m_initialPosition[3];
  59. double m_initialOrientation[4];
  60. int m_useMultiBody;
  61. int m_useFixedBase;
  62. };
  63. struct BulletDataStreamArgs
  64. {
  65. char m_bulletFileName[MAX_FILENAME_LENGTH];
  66. int m_streamChunkLength;
  67. int m_bodyUniqueId;
  68. };
  69. struct SetJointFeedbackArgs
  70. {
  71. int m_bodyUniqueId;
  72. int m_linkId;
  73. int m_isEnabled;
  74. };
  75. enum EnumInitPoseFlags
  76. {
  77. INIT_POSE_HAS_INITIAL_POSITION=1,
  78. INIT_POSE_HAS_INITIAL_ORIENTATION=2,
  79. INIT_POSE_HAS_JOINT_STATE=4
  80. };
  81. ///InitPoseArgs is mainly to initialize (teleport) the robot in a particular position
  82. ///No motors or controls are needed to initialize the pose. It is similar to
  83. ///moving a robot to a starting place, while it is switched off. It is only called
  84. ///at the start of a robot control session. All velocities and control forces are cleared to zero.
  85. struct InitPoseArgs
  86. {
  87. int m_bodyUniqueId;
  88. double m_initialStateQ[MAX_DEGREE_OF_FREEDOM];
  89. };
  90. struct RequestDebugLinesArgs
  91. {
  92. int m_debugMode;
  93. int m_startingLineIndex;
  94. };
  95. struct SendDebugLinesArgs
  96. {
  97. int m_startingLineIndex;
  98. int m_numDebugLines;
  99. int m_numRemainingDebugLines;
  100. };
  101. struct PickBodyArgs
  102. {
  103. double m_rayFromWorld[3];
  104. double m_rayToWorld[3];
  105. };
  106. ///Controlling a robot involves sending the desired state to its joint motor controllers.
  107. ///The control mode determines the state variables used for motor control.
  108. struct SendDesiredStateArgs
  109. {
  110. int m_bodyUniqueId;
  111. int m_controlMode;
  112. //PD parameters in case m_controlMode == CONTROL_MODE_POSITION_VELOCITY_PD
  113. double m_Kp[MAX_DEGREE_OF_FREEDOM];//indexed by degree of freedom, 6 for base, and then the dofs for each link
  114. double m_Kd[MAX_DEGREE_OF_FREEDOM];//indexed by degree of freedom, 6 for base, and then the dofs for each link
  115. //desired state is only written by the client, read-only access by server is expected
  116. //m_desiredStateQ is indexed by position variables,
  117. //starting with 3 base position variables, 4 base orientation variables (quaternion), then link position variables
  118. double m_desiredStateQ[MAX_DEGREE_OF_FREEDOM];
  119. //m_desiredStateQdot is index by velocity degrees of freedom, 3 linear and 3 angular variables for the base and then link velocity variables
  120. double m_desiredStateQdot[MAX_DEGREE_OF_FREEDOM];
  121. //m_desiredStateForceTorque is either the actual applied force/torque (in CONTROL_MODE_TORQUE) or
  122. //or the maximum applied force/torque for the PD/motor/constraint to reach the desired velocity in CONTROL_MODE_VELOCITY and CONTROL_MODE_POSITION_VELOCITY_PD mode
  123. //indexed by degree of freedom, 6 dof base, and then dofs for each link
  124. double m_desiredStateForceTorque[MAX_DEGREE_OF_FREEDOM];
  125. };
  126. enum EnumSimParamUpdateFlags
  127. {
  128. SIM_PARAM_UPDATE_DELTA_TIME=1,
  129. SIM_PARAM_UPDATE_GRAVITY=2,
  130. SIM_PARAM_UPDATE_NUM_SOLVER_ITERATIONS=4,
  131. SIM_PARAM_UPDATE_NUM_SIMULATION_SUB_STEPS=8,
  132. };
  133. ///Controlling a robot involves sending the desired state to its joint motor controllers.
  134. ///The control mode determines the state variables used for motor control.
  135. struct SendPhysicsSimulationParameters
  136. {
  137. double m_deltaTime;
  138. double m_gravityAcceleration[3];
  139. int m_numSimulationSubSteps;
  140. int m_numSolverIterations;
  141. };
  142. struct RequestActualStateArgs
  143. {
  144. int m_bodyUniqueId;
  145. };
  146. struct SendActualStateArgs
  147. {
  148. int m_bodyUniqueId;
  149. int m_numDegreeOfFreedomQ;
  150. int m_numDegreeOfFreedomU;
  151. double m_rootLocalInertialFrame[7];
  152. //actual state is only written by the server, read-only access by client is expected
  153. double m_actualStateQ[MAX_DEGREE_OF_FREEDOM];
  154. double m_actualStateQdot[MAX_DEGREE_OF_FREEDOM];
  155. //measured 6DOF force/torque sensors: force[x,y,z] and torque[x,y,z]
  156. double m_jointReactionForces[6*MAX_DEGREE_OF_FREEDOM];
  157. };
  158. enum EnumSensorTypes
  159. {
  160. SENSOR_FORCE_TORQUE=1,
  161. SENSOR_IMU=2,
  162. };
  163. struct CreateSensorArgs
  164. {
  165. int m_bodyUniqueId;
  166. int m_numJointSensorChanges;
  167. int m_sensorType[MAX_DEGREE_OF_FREEDOM];
  168. ///todo: clean up the duplication, make sure no-one else is using those members directly (use C-API header instead)
  169. int m_jointIndex[MAX_DEGREE_OF_FREEDOM];
  170. int m_enableJointForceSensor[MAX_DEGREE_OF_FREEDOM];
  171. int m_linkIndex[MAX_DEGREE_OF_FREEDOM];
  172. int m_enableSensor[MAX_DEGREE_OF_FREEDOM];
  173. };
  174. typedef struct SharedMemoryCommand SharedMemoryCommand_t;
  175. enum EnumBoxShapeFlags
  176. {
  177. BOX_SHAPE_HAS_INITIAL_POSITION=1,
  178. BOX_SHAPE_HAS_INITIAL_ORIENTATION=2,
  179. BOX_SHAPE_HAS_HALF_EXTENTS=4,
  180. BOX_SHAPE_HAS_MASS=8,
  181. BOX_SHAPE_HAS_COLLISION_SHAPE_TYPE=16,
  182. BOX_SHAPE_HAS_COLOR=32,
  183. };
  184. ///This command will be replaced to allow arbitrary collision shape types
  185. struct CreateBoxShapeArgs
  186. {
  187. double m_halfExtentsX;
  188. double m_halfExtentsY;
  189. double m_halfExtentsZ;
  190. double m_mass;
  191. int m_collisionShapeType;//see SharedMemoryPublic.h
  192. double m_initialPosition[3];
  193. double m_initialOrientation[4];
  194. double m_colorRGBA[4];
  195. };
  196. struct SharedMemoryCommand
  197. {
  198. int m_type;
  199. smUint64_t m_timeStamp;
  200. int m_sequenceNumber;
  201. //m_updateFlags is a bit fields to tell which parameters need updating
  202. //for example m_updateFlags = SIM_PARAM_UPDATE_DELTA_TIME | SIM_PARAM_UPDATE_NUM_SOLVER_ITERATIONS;
  203. int m_updateFlags;
  204. union
  205. {
  206. struct UrdfArgs m_urdfArguments;
  207. struct InitPoseArgs m_initPoseArgs;
  208. struct SendPhysicsSimulationParameters m_physSimParamArgs;
  209. struct BulletDataStreamArgs m_dataStreamArguments;
  210. struct SendDesiredStateArgs m_sendDesiredStateCommandArgument;
  211. struct RequestActualStateArgs m_requestActualStateInformationCommandArgument;
  212. struct CreateSensorArgs m_createSensorArguments;
  213. struct CreateBoxShapeArgs m_createBoxShapeArguments;
  214. struct RequestDebugLinesArgs m_requestDebugLinesArguments;
  215. struct PickBodyArgs m_pickBodyArguments;
  216. };
  217. };
  218. struct RigidBodyCreateArgs
  219. {
  220. int m_bodyUniqueId;
  221. };
  222. struct SharedMemoryStatus
  223. {
  224. int m_type;
  225. smUint64_t m_timeStamp;
  226. int m_sequenceNumber;
  227. union
  228. {
  229. struct BulletDataStreamArgs m_dataStreamArguments;
  230. struct SendActualStateArgs m_sendActualStateArgs;
  231. struct SendDebugLinesArgs m_sendDebugLinesArgs;
  232. struct RigidBodyCreateArgs m_rigidBodyCreateArgs;
  233. };
  234. };
  235. typedef struct SharedMemoryStatus SharedMemoryStatus_t;
  236. #endif //SHARED_MEMORY_COMMANDS_H