b3RobotSimAPI.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. #ifndef B3_ROBOT_SIM_API_H
  2. #define B3_ROBOT_SIM_API_H
  3. ///todo: remove those includes from this header
  4. #include "../SharedMemory/PhysicsClientC_API.h"
  5. #include "../SharedMemory/SharedMemoryPublic.h"
  6. #include "Bullet3Common/b3Vector3.h"
  7. #include "Bullet3Common/b3Quaternion.h"
  8. #include "Bullet3Common/b3Transform.h"
  9. #include "Bullet3Common/b3AlignedObjectArray.h"
  10. #include <string>
  11. enum b3RigidSimFileType
  12. {
  13. B3_URDF_FILE=1,
  14. B3_SDF_FILE,
  15. B3_AUTO_DETECT_FILE//todo based on extension
  16. };
  17. struct b3JointStates
  18. {
  19. int m_bodyUniqueId;
  20. int m_numDegreeOfFreedomQ;
  21. int m_numDegreeOfFreedomU;
  22. b3Transform m_rootLocalInertialFrame;
  23. b3AlignedObjectArray<double> m_actualStateQ;
  24. b3AlignedObjectArray<double> m_actualStateQdot;
  25. b3AlignedObjectArray<double> m_jointReactionForces;
  26. };
  27. struct b3RobotSimLoadFileArgs
  28. {
  29. std::string m_fileName;
  30. b3Vector3 m_startPosition;
  31. b3Quaternion m_startOrientation;
  32. bool m_forceOverrideFixedBase;
  33. bool m_useMultiBody;
  34. int m_fileType;
  35. b3RobotSimLoadFileArgs(const std::string& fileName)
  36. :m_fileName(fileName),
  37. m_startPosition(b3MakeVector3(0,0,0)),
  38. m_startOrientation(b3Quaternion(0,0,0,1)),
  39. m_forceOverrideFixedBase(false),
  40. m_useMultiBody(true),
  41. m_fileType(B3_URDF_FILE)
  42. {
  43. }
  44. };
  45. struct b3RobotSimLoadFileResults
  46. {
  47. b3AlignedObjectArray<int> m_uniqueObjectIds;
  48. b3RobotSimLoadFileResults()
  49. {
  50. }
  51. };
  52. struct b3JointMotorArgs
  53. {
  54. int m_controlMode;
  55. double m_targetPosition;
  56. double m_kp;
  57. double m_targetVelocity;
  58. double m_kd;
  59. double m_maxTorqueValue;
  60. b3JointMotorArgs(int controlMode)
  61. :m_controlMode(controlMode),
  62. m_targetPosition(0),
  63. m_kp(0.1),
  64. m_targetVelocity(0),
  65. m_kd(0.9),
  66. m_maxTorqueValue(1000)
  67. {
  68. }
  69. };
  70. enum b3InverseKinematicsFlags
  71. {
  72. B3_HAS_IK_TARGET_ORIENTATION=1,
  73. B3_HAS_NULL_SPACE_VELOCITY=2,
  74. };
  75. struct b3RobotSimInverseKinematicArgs
  76. {
  77. int m_bodyUniqueId;
  78. // double* m_currentJointPositions;
  79. // int m_numPositions;
  80. double m_endEffectorTargetPosition[3];
  81. double m_endEffectorTargetOrientation[4];
  82. int m_endEffectorLinkIndex;
  83. int m_flags;
  84. int m_numDegreeOfFreedom;
  85. b3AlignedObjectArray<double> m_lowerLimits;
  86. b3AlignedObjectArray<double> m_upperLimits;
  87. b3AlignedObjectArray<double> m_jointRanges;
  88. b3AlignedObjectArray<double> m_restPoses;
  89. b3RobotSimInverseKinematicArgs()
  90. :m_bodyUniqueId(-1),
  91. m_endEffectorLinkIndex(-1),
  92. m_flags(0)
  93. {
  94. m_endEffectorTargetPosition[0]=0;
  95. m_endEffectorTargetPosition[1]=0;
  96. m_endEffectorTargetPosition[2]=0;
  97. m_endEffectorTargetOrientation[0]=0;
  98. m_endEffectorTargetOrientation[1]=0;
  99. m_endEffectorTargetOrientation[2]=0;
  100. m_endEffectorTargetOrientation[3]=1;
  101. }
  102. };
  103. struct b3RobotSimInverseKinematicsResults
  104. {
  105. int m_bodyUniqueId;
  106. b3AlignedObjectArray<double> m_calculatedJointPositions;
  107. };
  108. class b3RobotSimAPI
  109. {
  110. struct b3RobotSimAPI_InternalData* m_data;
  111. void processMultiThreadedGraphicsRequests();
  112. b3SharedMemoryStatusHandle submitClientCommandAndWaitStatusMultiThreaded(b3PhysicsClientHandle physClient, b3SharedMemoryCommandHandle commandHandle);
  113. public:
  114. b3RobotSimAPI();
  115. virtual ~b3RobotSimAPI();
  116. bool connect(struct GUIHelperInterface* guiHelper);
  117. void disconnect();
  118. bool loadFile(const struct b3RobotSimLoadFileArgs& args, b3RobotSimLoadFileResults& results);
  119. int getNumJoints(int bodyUniqueId) const;
  120. bool getJointInfo(int bodyUniqueId, int jointIndex, b3JointInfo* jointInfo);
  121. void createJoint(int parentBodyIndex, int parentJointIndex, int childBodyIndex, int childJointIndex, b3JointInfo* jointInfo);
  122. bool getJointStates(int bodyUniqueId, b3JointStates& state);
  123. void setJointMotorControl(int bodyUniqueId, int jointIndex, const struct b3JointMotorArgs& args);
  124. void stepSimulation();
  125. void setGravity(const b3Vector3& gravityAcceleration);
  126. void setNumSimulationSubSteps(int numSubSteps);
  127. bool calculateInverseKinematics(const struct b3RobotSimInverseKinematicArgs& args, struct b3RobotSimInverseKinematicsResults& results);
  128. void renderScene();
  129. void debugDraw(int debugDrawMode);
  130. void getBodyJacobian(int bodyUniqueId, int linkIndex, const double* localPosition, const double* jointPositions, const double* jointVelocities, const double* jointAccelerations, double* linearJacobian, double* angularJacobian);
  131. void getLinkState(int bodyUniqueId, int linkIndex, double* worldPosition, double* worldOrientation);
  132. };
  133. #endif //B3_ROBOT_SIM_API_H