add hand.py/hand.ino used to create this VR glove, using MuJoCo Haptix MPL hand (Apache 2 license)
https://www.youtube.com/watch?v=VMJyZtHQL50 added b3InitSyncBodyInfoCommand, to retrieve body info, when connecting to a server with existing bodies pybullet will call this b3InitSyncBodyInfoCommand automatically after connecting Avoid overriding the py.setVRCameraState setting in VR
This commit is contained in:
@@ -535,7 +535,7 @@ b3SharedMemoryCommandHandle b3RequestActualStateCommandInit(b3PhysicsClientHandl
|
||||
return (b3SharedMemoryCommandHandle) command;
|
||||
}
|
||||
|
||||
void b3GetJointState(b3PhysicsClientHandle physClient, b3SharedMemoryStatusHandle statusHandle, int jointIndex, b3JointSensorState *state)
|
||||
int b3GetJointState(b3PhysicsClientHandle physClient, b3SharedMemoryStatusHandle statusHandle, int jointIndex, b3JointSensorState *state)
|
||||
{
|
||||
const SharedMemoryStatus* status = (const SharedMemoryStatus* ) statusHandle;
|
||||
b3Assert(status);
|
||||
@@ -544,23 +544,32 @@ void b3GetJointState(b3PhysicsClientHandle physClient, b3SharedMemoryStatusHandl
|
||||
if (bodyIndex>=0)
|
||||
{
|
||||
b3JointInfo info;
|
||||
b3GetJointInfo(physClient, bodyIndex,jointIndex, &info);
|
||||
state->m_jointPosition = status->m_sendActualStateArgs.m_actualStateQ[info.m_qIndex];
|
||||
state->m_jointVelocity = status->m_sendActualStateArgs.m_actualStateQdot[info.m_uIndex];
|
||||
for (int ii(0); ii < 6; ++ii) {
|
||||
state->m_jointForceTorque[ii] = status->m_sendActualStateArgs.m_jointReactionForces[6 * jointIndex + ii];
|
||||
bool result = b3GetJointInfo(physClient, bodyIndex,jointIndex, &info);
|
||||
if (result)
|
||||
{
|
||||
state->m_jointPosition = status->m_sendActualStateArgs.m_actualStateQ[info.m_qIndex];
|
||||
state->m_jointVelocity = status->m_sendActualStateArgs.m_actualStateQdot[info.m_uIndex];
|
||||
for (int ii(0); ii < 6; ++ii) {
|
||||
state->m_jointForceTorque[ii] = status->m_sendActualStateArgs.m_jointReactionForces[6 * jointIndex + ii];
|
||||
}
|
||||
state->m_jointMotorTorque = status->m_sendActualStateArgs.m_jointMotorForce[jointIndex];
|
||||
return 1;
|
||||
}
|
||||
state->m_jointMotorTorque = status->m_sendActualStateArgs.m_jointMotorForce[jointIndex];
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void b3GetLinkState(b3PhysicsClientHandle physClient, b3SharedMemoryStatusHandle statusHandle, int linkIndex, b3LinkState *state)
|
||||
int b3GetLinkState(b3PhysicsClientHandle physClient, b3SharedMemoryStatusHandle statusHandle, int linkIndex, b3LinkState *state)
|
||||
{
|
||||
const SharedMemoryStatus* status = (const SharedMemoryStatus* ) statusHandle;
|
||||
b3Assert(status);
|
||||
int bodyIndex = status->m_sendActualStateArgs.m_bodyUniqueId;
|
||||
b3Assert(bodyIndex>=0);
|
||||
if (bodyIndex>=0)
|
||||
b3Assert(linkIndex >= 0);
|
||||
int numJoints = b3GetNumJoints(physClient,bodyIndex);
|
||||
b3Assert(linkIndex < numJoints);
|
||||
|
||||
if ((bodyIndex>=0) && (linkIndex >= 0) && linkIndex < numJoints)
|
||||
{
|
||||
b3Transform wlf,com,inertial;
|
||||
|
||||
@@ -590,7 +599,9 @@ void b3GetLinkState(b3PhysicsClientHandle physClient, b3SharedMemoryStatusHandle
|
||||
{
|
||||
state->m_worldLinkFrameOrientation[i] = wlfOrn[i];
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
b3SharedMemoryCommandHandle b3CreateBoxShapeCommandInit(b3PhysicsClientHandle physClient)
|
||||
@@ -1259,6 +1270,18 @@ void b3GetRaycastInformation(b3PhysicsClientHandle physClient, struct b3RaycastI
|
||||
}
|
||||
|
||||
|
||||
///If you re-connected to an existing server, or server changed otherwise, sync the body info
|
||||
b3SharedMemoryCommandHandle b3InitSyncBodyInfoCommand(b3PhysicsClientHandle physClient)
|
||||
{
|
||||
PhysicsClient* cl = (PhysicsClient* ) physClient;
|
||||
b3Assert(cl);
|
||||
b3Assert(cl->canSubmitCommand());
|
||||
struct SharedMemoryCommand* command = cl->getAvailableSharedMemoryCommand();
|
||||
b3Assert(command);
|
||||
|
||||
command->m_type =CMD_SYNC_BODY_INFO;
|
||||
return (b3SharedMemoryCommandHandle) command;
|
||||
}
|
||||
|
||||
b3SharedMemoryCommandHandle b3InitRequestDebugLinesCommand(b3PhysicsClientHandle physClient, int debugMode)
|
||||
{
|
||||
|
||||
@@ -57,6 +57,9 @@ int b3GetStatusActualState(b3SharedMemoryStatusHandle statusHandle,
|
||||
const double* actualStateQdot[],
|
||||
const double* jointReactionForces[]);
|
||||
|
||||
///If you re-connected to an existing server, or server changed otherwise, sync the body info
|
||||
b3SharedMemoryCommandHandle b3InitSyncBodyInfoCommand(b3PhysicsClientHandle physClient);
|
||||
|
||||
///return the total number of bodies in the simulation
|
||||
int b3GetNumBodies(b3PhysicsClientHandle physClient);
|
||||
|
||||
@@ -293,8 +296,8 @@ int b3CreateSensorEnable6DofJointForceTorqueSensor(b3SharedMemoryCommandHandle c
|
||||
int b3CreateSensorEnableIMUForLink(b3SharedMemoryCommandHandle commandHandle, int linkIndex, int enable);
|
||||
|
||||
b3SharedMemoryCommandHandle b3RequestActualStateCommandInit(b3PhysicsClientHandle physClient,int bodyUniqueId);
|
||||
void b3GetJointState(b3PhysicsClientHandle physClient, b3SharedMemoryStatusHandle statusHandle, int jointIndex, struct b3JointSensorState *state);
|
||||
void b3GetLinkState(b3PhysicsClientHandle physClient, b3SharedMemoryStatusHandle statusHandle, int linkIndex, struct b3LinkState *state);
|
||||
int b3GetJointState(b3PhysicsClientHandle physClient, b3SharedMemoryStatusHandle statusHandle, int jointIndex, struct b3JointSensorState *state);
|
||||
int b3GetLinkState(b3PhysicsClientHandle physClient, b3SharedMemoryStatusHandle statusHandle, int linkIndex, struct b3LinkState *state);
|
||||
|
||||
b3SharedMemoryCommandHandle b3PickBody(b3PhysicsClientHandle physClient, double rayFromWorldX,
|
||||
double rayFromWorldY, double rayFromWorldZ,
|
||||
|
||||
@@ -811,6 +811,15 @@ const SharedMemoryStatus* PhysicsClientSharedMemory::processServerStatus() {
|
||||
b3Warning("createConstraint failed");
|
||||
break;
|
||||
}
|
||||
case CMD_ACTUAL_STATE_UPDATE_FAILED:
|
||||
{
|
||||
b3Warning("request actual state failed");
|
||||
break;
|
||||
}
|
||||
case CMD_SYNC_BODY_INFO_COMPLETED:
|
||||
{
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
b3Error("Unknown server status %d\n", serverCmd.m_type);
|
||||
btAssert(0);
|
||||
@@ -830,7 +839,7 @@ const SharedMemoryStatus* PhysicsClientSharedMemory::processServerStatus() {
|
||||
}
|
||||
|
||||
|
||||
if ((serverCmd.m_type == CMD_SDF_LOADING_COMPLETED) || (serverCmd.m_type == CMD_MJCF_LOADING_COMPLETED))
|
||||
if ((serverCmd.m_type == CMD_SDF_LOADING_COMPLETED) || (serverCmd.m_type == CMD_MJCF_LOADING_COMPLETED) || (serverCmd.m_type == CMD_SYNC_BODY_INFO_COMPLETED))
|
||||
{
|
||||
int numBodies = serverCmd.m_sdfLoadedArgs.m_numBodies;
|
||||
if (numBodies>0)
|
||||
|
||||
@@ -670,6 +670,7 @@ void PhysicsDirect::postProcessStatus(const struct SharedMemoryStatus& serverCmd
|
||||
break;
|
||||
}
|
||||
|
||||
case CMD_SYNC_BODY_INFO_COMPLETED:
|
||||
case CMD_MJCF_LOADING_COMPLETED:
|
||||
case CMD_SDF_LOADING_COMPLETED:
|
||||
{
|
||||
|
||||
@@ -423,6 +423,12 @@ struct PhysicsServerCommandProcessorInternalData
|
||||
btAlignedObjectArray<InternalBodyHandle> m_bodyHandles;
|
||||
int m_numUsedHandles; // number of active handles
|
||||
int m_firstFreeHandle; // free handles list
|
||||
|
||||
int getNumHandles() const
|
||||
{
|
||||
return m_bodyHandles.size();
|
||||
}
|
||||
|
||||
InternalBodyHandle* getHandle(int handle)
|
||||
{
|
||||
btAssert(handle>=0);
|
||||
@@ -1741,6 +1747,23 @@ bool PhysicsServerCommandProcessor::processCommand(const struct SharedMemoryComm
|
||||
break;
|
||||
}
|
||||
|
||||
case CMD_SYNC_BODY_INFO:
|
||||
{
|
||||
int numHandles = m_data->getNumHandles();
|
||||
int actualNumBodies = 0;
|
||||
for (int i=0;i<numHandles;i++)
|
||||
{
|
||||
InteralBodyData* body = m_data->getHandle(i);
|
||||
if (body && (body->m_multiBody || body->m_rigidBody))
|
||||
{
|
||||
serverStatusOut.m_sdfLoadedArgs.m_bodyUniqueIds[actualNumBodies++] = i;
|
||||
}
|
||||
}
|
||||
serverStatusOut.m_sdfLoadedArgs.m_numBodies = actualNumBodies;
|
||||
serverStatusOut.m_type = CMD_SYNC_BODY_INFO_COMPLETED;
|
||||
hasStatus = true;
|
||||
break;
|
||||
}
|
||||
case CMD_REQUEST_BODY_INFO:
|
||||
{
|
||||
const SdfRequestInfoArgs& sdfInfoArgs = clientCmd.m_sdfRequestInfoArgs;
|
||||
@@ -3672,7 +3695,7 @@ bool PhysicsServerCommandProcessor::processCommand(const struct SharedMemoryComm
|
||||
}
|
||||
if (userConstraintPtr->m_rbConstraint)
|
||||
{
|
||||
|
||||
//todo
|
||||
}
|
||||
serverCmd.m_userConstraintResultArgs.m_userConstraintUniqueId = -1;
|
||||
serverCmd.m_type = CMD_USER_CONSTRAINT_COMPLETED;
|
||||
@@ -4367,7 +4390,7 @@ void PhysicsServerCommandProcessor::replayFromLogFile(const char* fileName)
|
||||
}
|
||||
|
||||
|
||||
btVector3 gVRGripperPos(0.6, 0.4, 0.7);
|
||||
btVector3 gVRGripperPos(0.7, 0.3, 0.7);
|
||||
btQuaternion gVRGripperOrn(0,0,0,1);
|
||||
btVector3 gVRController2Pos(0,0,0.2);
|
||||
btQuaternion gVRController2Orn(0,0,0,1);
|
||||
@@ -4764,7 +4787,7 @@ void PhysicsServerCommandProcessor::createDefaultRobotAssets()
|
||||
loadUrdf("husky/husky.urdf", btVector3(2, -5, 1), btQuaternion(0, 0, 0, 1), true, false, &bodyId, &gBufferServerToClient[0], gBufferServerToClient.size());
|
||||
m_data->m_huskyId = bodyId;
|
||||
|
||||
m_data->m_dynamicsWorld->setGravity(btVector3(0, 0, -10));
|
||||
m_data->m_dynamicsWorld->setGravity(btVector3(0, 0, 0));
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -1671,8 +1671,8 @@ void PhysicsServerExample::drawUserDebugLines()
|
||||
void PhysicsServerExample::renderScene()
|
||||
{
|
||||
btTransform vrTrans;
|
||||
gVRTeleportPos1 = gVRTeleportPosLocal;
|
||||
gVRTeleportOrn = gVRTeleportOrnLocal;
|
||||
//gVRTeleportPos1 = gVRTeleportPosLocal;
|
||||
//gVRTeleportOrn = gVRTeleportOrnLocal;
|
||||
|
||||
///little VR test to follow/drive Husky vehicle
|
||||
if (gVRTrackingObjectUniqueId >= 0)
|
||||
|
||||
@@ -33,7 +33,7 @@
|
||||
#define MAX_SDF_FILENAME_LENGTH 1024
|
||||
#define MAX_FILENAME_LENGTH MAX_URDF_FILENAME_LENGTH
|
||||
#define MAX_NUM_LINKS MAX_DEGREE_OF_FREEDOM
|
||||
#define MAX_SDF_BODIES 500
|
||||
#define MAX_SDF_BODIES 512
|
||||
|
||||
struct TmpFloat3
|
||||
{
|
||||
|
||||
@@ -47,7 +47,7 @@ enum EnumSharedMemoryClientCommand
|
||||
CMD_USER_DEBUG_DRAW,
|
||||
CMD_REQUEST_VR_EVENTS_DATA,
|
||||
CMD_SET_VR_CAMERA_STATE,
|
||||
|
||||
CMD_SYNC_BODY_INFO,
|
||||
//don't go beyond this command!
|
||||
CMD_MAX_CLIENT_COMMANDS,
|
||||
|
||||
@@ -115,6 +115,8 @@ enum EnumSharedMemoryServerStatus
|
||||
CMD_USER_CONSTRAINT_FAILED,
|
||||
CMD_REQUEST_VR_EVENTS_DATA_COMPLETED,
|
||||
CMD_REQUEST_RAY_CAST_INTERSECTIONS_COMPLETED,
|
||||
CMD_SYNC_BODY_INFO_COMPLETED,
|
||||
CMD_SYNC_BODY_INFO_FAILED,
|
||||
//don't go beyond 'CMD_MAX_SERVER_COMMANDS!
|
||||
CMD_MAX_SERVER_COMMANDS
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user