#include #include #include #include #include "SharedMemory/PhysicsClientC_API.h" #include "Bullet3Common/b3Vector3.h" #include "Bullet3Common/b3Quaternion.h" extern const int CONTROL_RATE; const int CONTROL_RATE = 500; // Bullet globals b3PhysicsClientHandle kPhysClient = 0; const b3Scalar FIXED_TIMESTEP = 1.0/((b3Scalar)CONTROL_RATE); // temp vars used a lot b3SharedMemoryCommandHandle command; b3SharedMemoryStatusHandle statusHandle; int statusType, ret; b3JointInfo jointInfo; b3JointSensorState state; // test int twojoint; std::map< std::string, int > jointNameToId; int main(int argc, char* argv[]) { kPhysClient = b3CreateInProcessPhysicsServerAndConnect(argc, argv); if (!kPhysClient) return -1; // visualizer command = b3InitConfigureOpenGLVisualizer(kPhysClient); b3ConfigureOpenGLVisualizerSetVisualizationFlags(command, COV_ENABLE_GUI, 0); b3SubmitClientCommandAndWaitStatus(kPhysClient, command); b3ConfigureOpenGLVisualizerSetVisualizationFlags(command, COV_ENABLE_SHADOWS, 0); b3SubmitClientCommandAndWaitStatus(kPhysClient, command); b3SetTimeOut(kPhysClient, 10); //syncBodies is only needed when connecting to an existing physics server that has already some bodies command = b3InitSyncBodyInfoCommand(kPhysClient); statusHandle = b3SubmitClientCommandAndWaitStatus(kPhysClient, command); statusType = b3GetStatusType(statusHandle); // set fixed time step command = b3InitPhysicsParamCommand(kPhysClient); ret = b3PhysicsParamSetTimeStep(command, FIXED_TIMESTEP); statusHandle = b3SubmitClientCommandAndWaitStatus(kPhysClient, command); ret = b3PhysicsParamSetRealTimeSimulation(command, false); statusHandle = b3SubmitClientCommandAndWaitStatus(kPhysClient, command); b3Assert(b3GetStatusType(statusHandle) == CMD_CLIENT_COMMAND_COMPLETED); // load test command = b3LoadUrdfCommandInit(kPhysClient, "TwoJointRobot_wo_fixedJoints.urdf"); int flags = URDF_USE_INERTIA_FROM_FILE; b3LoadUrdfCommandSetFlags(command, flags); b3LoadUrdfCommandSetUseFixedBase(command, true); // q.setEulerZYX(0, 0, 0); // b3LoadUrdfCommandSetStartOrientation(command, q[0], q[1], q[2], q[3]); b3LoadUrdfCommandSetUseMultiBody(command, true); statusHandle = b3SubmitClientCommandAndWaitStatus(kPhysClient, command); statusType = b3GetStatusType(statusHandle); b3Assert(statusType == CMD_URDF_LOADING_COMPLETED); if (statusType == CMD_URDF_LOADING_COMPLETED) { twojoint = b3GetStatusBodyIndex(statusHandle); } //disable default linear/angular damping b3SharedMemoryCommandHandle command = b3InitChangeDynamicsInfo(kPhysClient); double linearDamping = 0; double angularDamping = 0; b3ChangeDynamicsInfoSetLinearDamping(command, twojoint, linearDamping); b3ChangeDynamicsInfoSetAngularDamping(command, twojoint, angularDamping); statusHandle = b3SubmitClientCommandAndWaitStatus(kPhysClient, command); int numJoints = b3GetNumJoints(kPhysClient, twojoint); printf("twojoint numjoints = %d\n", numJoints); // Loop through all joints for (int i=0; i