2015-07-23 01:06:05 +00:00
# ifndef PHYSICS_CLIENT_C_API_H
# define PHYSICS_CLIENT_C_API_H
2015-09-17 06:09:10 +00:00
//#include "SharedMemoryBlock.h"
# include "SharedMemoryPublic.h"
2015-07-23 01:06:05 +00:00
# define B3_DECLARE_HANDLE(name) typedef struct name##__ { int unused; } *name
B3_DECLARE_HANDLE ( b3PhysicsClientHandle ) ;
2015-09-17 06:09:10 +00:00
B3_DECLARE_HANDLE ( b3SharedMemoryCommandHandle ) ;
B3_DECLARE_HANDLE ( b3SharedMemoryStatusHandle ) ;
2015-07-23 01:06:05 +00:00
# ifdef __cplusplus
extern " C " {
# endif
2016-04-13 20:06:15 +00:00
///b3ConnectSharedMemory will connect to a physics server over shared memory, so
///make sure to start the server first.
///and a way to spawn an OpenGL 3D GUI physics server and connect (b3CreateInProcessPhysicsServerAndConnect)
2015-09-17 06:09:10 +00:00
b3PhysicsClientHandle b3ConnectSharedMemory ( int key ) ;
2015-07-23 01:06:05 +00:00
2016-04-13 20:06:15 +00:00
///b3DisconnectSharedMemory will disconnect the client from the server and cleanup memory.
2015-07-23 01:06:05 +00:00
void b3DisconnectSharedMemory ( b3PhysicsClientHandle physClient ) ;
2016-04-13 20:06:15 +00:00
///There can only be 1 outstanding command. Check if a command can be send.
2015-07-23 01:06:05 +00:00
int b3CanSubmitCommand ( b3PhysicsClientHandle physClient ) ;
2016-04-13 20:06:15 +00:00
///blocking submit command and wait for status
2015-09-17 16:37:44 +00:00
b3SharedMemoryStatusHandle b3SubmitClientCommandAndWaitStatus ( b3PhysicsClientHandle physClient , b3SharedMemoryCommandHandle commandHandle ) ;
2016-04-13 20:06:15 +00:00
///In general it is better to use b3SubmitClientCommandAndWaitStatus. b3SubmitClientCommand is a non-blocking submit
///command, which requires checking for the status manually, using b3ProcessServerStatus. Also, before sending the
///next command, make sure to check if you can send a command using 'b3CanSubmitCommand'.
2015-09-17 06:09:10 +00:00
int b3SubmitClientCommand ( b3PhysicsClientHandle physClient , b3SharedMemoryCommandHandle commandHandle ) ;
2015-07-23 01:06:05 +00:00
2015-09-17 16:37:44 +00:00
///non-blocking check status
b3SharedMemoryStatusHandle b3ProcessServerStatus ( b3PhysicsClientHandle physClient ) ;
2016-04-13 20:06:15 +00:00
/// Get the physics server return status type. See EnumSharedMemoryServerStatus in SharedMemoryPublic.h for error codes.
2015-09-17 16:37:44 +00:00
int b3GetStatusType ( b3SharedMemoryStatusHandle statusHandle ) ;
2015-10-13 18:32:25 +00:00
int b3GetStatusBodyIndex ( b3SharedMemoryStatusHandle statusHandle ) ;
2015-11-05 00:08:28 +00:00
int b3GetStatusActualState ( b3SharedMemoryStatusHandle statusHandle ,
int * bodyUniqueId ,
int * numDegreeOfFreedomQ ,
int * numDegreeOfFreedomU ,
const double * rootLocalInertialFrame [ ] ,
const double * actualStateQ [ ] ,
const double * actualStateQdot [ ] ,
const double * jointReactionForces [ ] ) ;
2016-04-13 20:06:15 +00:00
///give a unique body index (after loading the body) return the number of joints.
2015-10-13 18:32:25 +00:00
int b3GetNumJoints ( b3PhysicsClientHandle physClient , int bodyIndex ) ;
2015-07-23 01:06:05 +00:00
2016-04-13 20:06:15 +00:00
///given a body and link index, return the joint information. See b3JointInfo in SharedMemoryPublic.h
2015-10-13 18:32:25 +00:00
void b3GetJointInfo ( b3PhysicsClientHandle physClient , int bodyIndex , int linkIndex , struct b3JointInfo * info ) ;
2015-07-23 01:06:05 +00:00
2016-04-13 20:06:15 +00:00
///Request debug lines for debug visualization. The flags in debugMode are the same as used in Bullet
///See btIDebugDraw::DebugDrawModes in Bullet/src/LinearMath/btIDebugDraw.h
2015-09-17 06:09:10 +00:00
b3SharedMemoryCommandHandle b3InitRequestDebugLinesCommand ( b3PhysicsClientHandle physClient , int debugMode ) ;
2016-04-13 20:06:15 +00:00
///Get the pointers to the debug line information, after b3InitRequestDebugLinesCommand returns
///status CMD_DEBUG_LINES_COMPLETED
2015-09-17 06:09:10 +00:00
void b3GetDebugLines ( b3PhysicsClientHandle physClient , struct b3DebugLines * lines ) ;
b3SharedMemoryCommandHandle b3InitPhysicsParamCommand ( b3PhysicsClientHandle physClient ) ;
int b3PhysicsParamSetGravity ( b3SharedMemoryCommandHandle commandHandle , double gravx , double gravy , double gravz ) ;
int b3PhysicsParamSetTimeStep ( b3SharedMemoryCommandHandle commandHandle , double timeStep ) ;
2015-07-31 06:22:44 +00:00
2015-09-17 06:09:10 +00:00
b3SharedMemoryCommandHandle b3InitStepSimulationCommand ( b3PhysicsClientHandle physClient ) ;
2015-07-31 06:22:44 +00:00
2015-09-17 06:09:10 +00:00
b3SharedMemoryCommandHandle b3InitResetSimulationCommand ( b3PhysicsClientHandle physClient ) ;
2015-08-28 00:51:31 +00:00
2016-04-14 00:09:48 +00:00
///Load a robot from a URDF file. Status type will CMD_URDF_LOADING_COMPLETED.
///Access the robot from the unique body index, through b3GetStatusBodyIndex(statusHandle);
2015-09-17 06:09:10 +00:00
b3SharedMemoryCommandHandle b3LoadUrdfCommandInit ( b3PhysicsClientHandle physClient , const char * urdfFileName ) ;
2016-04-14 00:09:48 +00:00
2015-09-17 06:09:10 +00:00
int b3LoadUrdfCommandSetStartPosition ( b3SharedMemoryCommandHandle commandHandle , double startPosX , double startPosY , double startPosZ ) ;
int b3LoadUrdfCommandSetStartOrientation ( b3SharedMemoryCommandHandle commandHandle , double startOrnX , double startOrnY , double startOrnZ , double startOrnW ) ;
int b3LoadUrdfCommandSetUseMultiBody ( b3SharedMemoryCommandHandle commandHandle , int useMultiBody ) ;
int b3LoadUrdfCommandSetUseFixedBase ( b3SharedMemoryCommandHandle commandHandle , int useFixedBase ) ;
2015-07-31 06:22:44 +00:00
2015-08-02 21:00:43 +00:00
///Set joint control variables such as desired position/angle, desired velocity,
///applied joint forces, dependent on the control mode (CONTROL_MODE_VELOCITY or CONTROL_MODE_TORQUE)
2015-09-17 06:09:10 +00:00
b3SharedMemoryCommandHandle b3JointControlCommandInit ( b3PhysicsClientHandle physClient , int controlMode ) ;
///Only use when controlMode is CONTROL_MODE_POSITION_VELOCITY_PD
2015-09-25 05:42:22 +00:00
int b3JointControlSetDesiredPosition ( b3SharedMemoryCommandHandle commandHandle , int qIndex , double value ) ;
2015-09-17 06:09:10 +00:00
int b3JointControlSetKp ( b3SharedMemoryCommandHandle commandHandle , int dofIndex , double value ) ;
int b3JointControlSetKd ( b3SharedMemoryCommandHandle commandHandle , int dofIndex , double value ) ;
2015-08-02 21:00:43 +00:00
//Only use when controlMode is CONTROL_MODE_VELOCITY
2015-09-25 05:42:22 +00:00
int b3JointControlSetDesiredVelocity ( b3SharedMemoryCommandHandle commandHandle , int dofIndex , double value ) ; /* find a better name for dof/q/u indices, point to b3JointInfo */
2015-09-17 06:09:10 +00:00
int b3JointControlSetMaximumForce ( b3SharedMemoryCommandHandle commandHandle , int dofIndex , double value ) ;
2015-08-02 21:00:43 +00:00
///Only use if when controlMode is CONTROL_MODE_TORQUE,
2015-09-17 06:09:10 +00:00
int b3JointControlSetDesiredForceTorque ( b3SharedMemoryCommandHandle commandHandle , int dofIndex , double value ) ;
2015-08-02 21:00:43 +00:00
///the creation of collision shapes and rigid bodies etc is likely going to change,
///but good to have a b3CreateBoxShapeCommandInit for now
2016-04-13 20:06:15 +00:00
///create a box of size (1,1,1) at world origin (0,0,0) at orientation quat (0,0,0,1)
///after that, you can optionally adjust the initial position, orientation and size
2015-09-17 06:09:10 +00:00
b3SharedMemoryCommandHandle b3CreateBoxShapeCommandInit ( b3PhysicsClientHandle physClient ) ;
int b3CreateBoxCommandSetStartPosition ( b3SharedMemoryCommandHandle commandHandle , double startPosX , double startPosY , double startPosZ ) ;
int b3CreateBoxCommandSetStartOrientation ( b3SharedMemoryCommandHandle commandHandle , double startOrnX , double startOrnY , double startOrnZ , double startOrnW ) ;
int b3CreateBoxCommandSetHalfExtents ( b3SharedMemoryCommandHandle commandHandle , double halfExtentsX , double halfExtentsY , double halfExtentsZ ) ;
2015-10-27 21:55:46 +00:00
int b3CreateBoxCommandSetMass ( b3SharedMemoryCommandHandle commandHandle , double mass ) ;
int b3CreateBoxCommandSetCollisionShapeType ( b3SharedMemoryCommandHandle commandHandle , int collisionShapeType ) ;
2015-11-07 01:11:15 +00:00
int b3CreateBoxCommandSetColorRGBA ( b3SharedMemoryCommandHandle commandHandle , double red , double green , double blue , double alpha ) ;
2015-10-27 21:55:46 +00:00
2015-10-14 05:23:28 +00:00
2016-04-14 00:09:48 +00:00
///b3CreatePoseCommandInit will initialize (teleport) the pose of a body/robot. You can individually set the base position,
///base orientation and joint angles. This will set all velocities of base and joints to zero.
///This is not a robot control command using actuators/joint motors, but manual repositioning the robot.
2015-10-14 05:23:28 +00:00
b3SharedMemoryCommandHandle b3CreatePoseCommandInit ( b3PhysicsClientHandle physClient , int bodyIndex ) ;
int b3CreatePoseCommandSetBasePosition ( b3SharedMemoryCommandHandle commandHandle , double startPosX , double startPosY , double startPosZ ) ;
int b3CreatePoseCommandSetBaseOrientation ( b3SharedMemoryCommandHandle commandHandle , double startOrnX , double startOrnY , double startOrnZ , double startOrnW ) ;
2015-10-15 15:15:22 +00:00
int b3CreatePoseCommandSetJointPositions ( b3SharedMemoryCommandHandle commandHandle , int numJointPositions , const double * jointPositions ) ;
2015-10-14 05:23:28 +00:00
int b3CreatePoseCommandSetJointPosition ( b3PhysicsClientHandle physClient , b3SharedMemoryCommandHandle commandHandle , int jointIndex , double jointPosition ) ;
2015-08-02 21:00:43 +00:00
2016-04-14 00:09:48 +00:00
///We are currently not reading the sensor information from the URDF file, and programmatically assign sensors.
///This is rather inconsistent, to mix programmatical creation with loading from file.
2015-09-17 06:09:10 +00:00
b3SharedMemoryCommandHandle b3CreateSensorCommandInit ( b3PhysicsClientHandle physClient ) ;
2015-09-25 05:42:22 +00:00
int b3CreateSensorEnable6DofJointForceTorqueSensor ( b3SharedMemoryCommandHandle commandHandle , int jointIndex , int enable ) ;
2016-04-14 00:09:48 +00:00
///b3CreateSensorEnableIMUForLink is not implemented yet.
///For now, if the IMU is located in the root link, use the root world transform to mimic an IMU.
2015-09-17 06:09:10 +00:00
int b3CreateSensorEnableIMUForLink ( b3SharedMemoryCommandHandle commandHandle , int linkIndex , int enable ) ;
2015-08-02 21:00:43 +00:00
2015-10-27 22:46:13 +00:00
b3SharedMemoryCommandHandle b3RequestActualStateCommandInit ( b3PhysicsClientHandle physClient , int bodyUniqueId ) ;
2015-09-25 05:50:34 +00:00
void b3GetJointState ( b3PhysicsClientHandle physClient , b3SharedMemoryStatusHandle statusHandle , int jointIndex , struct b3JointSensorState * state ) ;
2015-09-25 05:42:22 +00:00
2015-11-05 00:08:28 +00:00
b3SharedMemoryCommandHandle b3PickBody ( b3PhysicsClientHandle physClient , double rayFromWorldX ,
double rayFromWorldY , double rayFromWorldZ ,
double rayToWorldX , double rayToWorldY , double rayToWorldZ ) ;
b3SharedMemoryCommandHandle b3MovePickedBody ( b3PhysicsClientHandle physClient , double rayFromWorldX ,
double rayFromWorldY , double rayFromWorldZ ,
double rayToWorldX , double rayToWorldY ,
double rayToWorldZ ) ;
b3SharedMemoryCommandHandle b3RemovePickingConstraint ( b3PhysicsClientHandle physClient ) ;
2015-07-23 01:06:05 +00:00
# ifdef __cplusplus
}
# endif
# endif //PHYSICS_CLIENT_C_API_H