expose some sleep timeout pybullet.setPhysicsEngineParameter(maxNumCmdPer1ms=100) or b3PhysicsParamSetMaxNumCommandsPer1ms,
if more commands than those are processed per millisecond, a 1ms sleep will follow, to avoid other threads being stalled.
This commit is contained in:
@@ -347,6 +347,16 @@ int b3PhysicsParamSetContactBreakingThreshold(b3SharedMemoryCommandHandle comman
|
|||||||
command->m_updateFlags |= SIM_PARAM_UPDATE_CONTACT_BREAKING_THRESHOLD;
|
command->m_updateFlags |= SIM_PARAM_UPDATE_CONTACT_BREAKING_THRESHOLD;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
int b3PhysicsParamSetMaxNumCommandsPer1ms(b3SharedMemoryCommandHandle commandHandle, int maxNumCmdPer1ms)
|
||||||
|
{
|
||||||
|
struct SharedMemoryCommand* command = (struct SharedMemoryCommand*) commandHandle;
|
||||||
|
b3Assert(command->m_type == CMD_SEND_PHYSICS_SIMULATION_PARAMETERS);
|
||||||
|
|
||||||
|
command->m_physSimParamArgs.m_maxNumCmdPer1ms = maxNumCmdPer1ms;
|
||||||
|
command->m_updateFlags |= SIM_PARAM_MAX_CMD_PER_1MS;
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
int b3PhysicsParamSetNumSolverIterations(b3SharedMemoryCommandHandle commandHandle, int numSolverIterations)
|
int b3PhysicsParamSetNumSolverIterations(b3SharedMemoryCommandHandle commandHandle, int numSolverIterations)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -198,6 +198,7 @@ int b3PhysicsParamSetCollisionFilterMode(b3SharedMemoryCommandHandle commandHand
|
|||||||
int b3PhysicsParamSetUseSplitImpulse(b3SharedMemoryCommandHandle commandHandle, int useSplitImpulse);
|
int b3PhysicsParamSetUseSplitImpulse(b3SharedMemoryCommandHandle commandHandle, int useSplitImpulse);
|
||||||
int b3PhysicsParamSetSplitImpulsePenetrationThreshold(b3SharedMemoryCommandHandle commandHandle, double splitImpulsePenetrationThreshold);
|
int b3PhysicsParamSetSplitImpulsePenetrationThreshold(b3SharedMemoryCommandHandle commandHandle, double splitImpulsePenetrationThreshold);
|
||||||
int b3PhysicsParamSetContactBreakingThreshold(b3SharedMemoryCommandHandle commandHandle, double contactBreakingThreshold);
|
int b3PhysicsParamSetContactBreakingThreshold(b3SharedMemoryCommandHandle commandHandle, double contactBreakingThreshold);
|
||||||
|
int b3PhysicsParamSetMaxNumCommandsPer1ms(b3SharedMemoryCommandHandle commandHandle, int maxNumCmdPer1ms);
|
||||||
|
|
||||||
//b3PhysicsParamSetInternalSimFlags is for internal/temporary/easter-egg/experimental demo purposes
|
//b3PhysicsParamSetInternalSimFlags is for internal/temporary/easter-egg/experimental demo purposes
|
||||||
//Use at own risk: magic things may or my not happen when calling this API
|
//Use at own risk: magic things may or my not happen when calling this API
|
||||||
|
|||||||
@@ -48,6 +48,7 @@ bool gResetSimulation = 0;
|
|||||||
int gVRTrackingObjectUniqueId = -1;
|
int gVRTrackingObjectUniqueId = -1;
|
||||||
btTransform gVRTrackingObjectTr = btTransform::getIdentity();
|
btTransform gVRTrackingObjectTr = btTransform::getIdentity();
|
||||||
|
|
||||||
|
int gMaxNumCmdPer1ms = 100;//experiment: add some delay to avoid threads starving other threads
|
||||||
int gCreateObjectSimVR = -1;
|
int gCreateObjectSimVR = -1;
|
||||||
int gEnableKukaControl = 0;
|
int gEnableKukaControl = 0;
|
||||||
btVector3 gVRTeleportPos1(0,0,0);
|
btVector3 gVRTeleportPos1(0,0,0);
|
||||||
@@ -3161,6 +3162,11 @@ bool PhysicsServerCommandProcessor::processCommand(const struct SharedMemoryComm
|
|||||||
{
|
{
|
||||||
gContactBreakingThreshold = clientCmd.m_physSimParamArgs.m_contactBreakingThreshold;
|
gContactBreakingThreshold = clientCmd.m_physSimParamArgs.m_contactBreakingThreshold;
|
||||||
}
|
}
|
||||||
|
if (clientCmd.m_updateFlags&SIM_PARAM_MAX_CMD_PER_1MS)
|
||||||
|
{
|
||||||
|
gMaxNumCmdPer1ms = clientCmd.m_physSimParamArgs.m_maxNumCmdPer1ms;
|
||||||
|
}
|
||||||
|
|
||||||
if (clientCmd.m_updateFlags&SIM_PARAM_UPDATE_COLLISION_FILTER_MODE)
|
if (clientCmd.m_updateFlags&SIM_PARAM_UPDATE_COLLISION_FILTER_MODE)
|
||||||
{
|
{
|
||||||
m_data->m_broadphaseCollisionFilterCallback->m_filterMode = clientCmd.m_physSimParamArgs.m_collisionFilterMode;
|
m_data->m_broadphaseCollisionFilterCallback->m_filterMode = clientCmd.m_physSimParamArgs.m_collisionFilterMode;
|
||||||
|
|||||||
@@ -277,7 +277,7 @@ struct MotionThreadLocalStorage
|
|||||||
|
|
||||||
|
|
||||||
float clampedDeltaTime = 0.2;
|
float clampedDeltaTime = 0.2;
|
||||||
float sleepTimeThreshold = 8./1000.;
|
extern int gMaxNumCmdPer1ms;
|
||||||
|
|
||||||
|
|
||||||
void MotionThreadFunc(void* userPtr,void* lsMemory)
|
void MotionThreadFunc(void* userPtr,void* lsMemory)
|
||||||
@@ -289,6 +289,7 @@ void MotionThreadFunc(void* userPtr,void* lsMemory)
|
|||||||
//int workLeft = true;
|
//int workLeft = true;
|
||||||
b3Clock clock;
|
b3Clock clock;
|
||||||
clock.reset();
|
clock.reset();
|
||||||
|
b3Clock sleepClock;
|
||||||
bool init = true;
|
bool init = true;
|
||||||
if (init)
|
if (init)
|
||||||
{
|
{
|
||||||
@@ -299,6 +300,8 @@ void MotionThreadFunc(void* userPtr,void* lsMemory)
|
|||||||
|
|
||||||
|
|
||||||
double deltaTimeInSeconds = 0;
|
double deltaTimeInSeconds = 0;
|
||||||
|
int numCmdSinceSleep1ms = 0;
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
BT_PROFILE("loop");
|
BT_PROFILE("loop");
|
||||||
@@ -307,6 +310,19 @@ void MotionThreadFunc(void* userPtr,void* lsMemory)
|
|||||||
BT_PROFILE("usleep(0)");
|
BT_PROFILE("usleep(0)");
|
||||||
b3Clock::usleep(0);
|
b3Clock::usleep(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (numCmdSinceSleep1ms>gMaxNumCmdPer1ms)
|
||||||
|
{
|
||||||
|
BT_PROFILE("usleep(1000)");
|
||||||
|
b3Clock::usleep(1000);
|
||||||
|
numCmdSinceSleep1ms = 0;
|
||||||
|
sleepClock.reset();
|
||||||
|
}
|
||||||
|
if (sleepClock.getTimeMilliseconds()>1)
|
||||||
|
{
|
||||||
|
sleepClock.reset();
|
||||||
|
numCmdSinceSleep1ms = 0;
|
||||||
|
}
|
||||||
double dt = double(clock.getTimeMicroseconds())/1000000.;
|
double dt = double(clock.getTimeMicroseconds())/1000000.;
|
||||||
clock.reset();
|
clock.reset();
|
||||||
deltaTimeInSeconds+= dt;
|
deltaTimeInSeconds+= dt;
|
||||||
@@ -434,6 +450,7 @@ void MotionThreadFunc(void* userPtr,void* lsMemory)
|
|||||||
{
|
{
|
||||||
BT_PROFILE("processClientCommands");
|
BT_PROFILE("processClientCommands");
|
||||||
args->m_physicsServerPtr->processClientCommands();
|
args->m_physicsServerPtr->processClientCommands();
|
||||||
|
numCmdSinceSleep1ms++;
|
||||||
}
|
}
|
||||||
|
|
||||||
} while (args->m_cs->getSharedParam(0)!=eRequestTerminateMotion);
|
} while (args->m_cs->getSharedParam(0)!=eRequestTerminateMotion);
|
||||||
|
|||||||
@@ -315,6 +315,7 @@ enum EnumSimParamUpdateFlags
|
|||||||
SIM_PARAM_UPDATE_SPLIT_IMPULSE_PENETRATION_THRESHOLD = 256,
|
SIM_PARAM_UPDATE_SPLIT_IMPULSE_PENETRATION_THRESHOLD = 256,
|
||||||
SIM_PARAM_UPDATE_COLLISION_FILTER_MODE=512,
|
SIM_PARAM_UPDATE_COLLISION_FILTER_MODE=512,
|
||||||
SIM_PARAM_UPDATE_CONTACT_BREAKING_THRESHOLD = 1024,
|
SIM_PARAM_UPDATE_CONTACT_BREAKING_THRESHOLD = 1024,
|
||||||
|
SIM_PARAM_MAX_CMD_PER_1MS = 2048,
|
||||||
};
|
};
|
||||||
|
|
||||||
enum EnumLoadBunnyUpdateFlags
|
enum EnumLoadBunnyUpdateFlags
|
||||||
@@ -342,6 +343,7 @@ struct SendPhysicsSimulationParameters
|
|||||||
int m_useSplitImpulse;
|
int m_useSplitImpulse;
|
||||||
double m_splitImpulsePenetrationThreshold;
|
double m_splitImpulsePenetrationThreshold;
|
||||||
double m_contactBreakingThreshold;
|
double m_contactBreakingThreshold;
|
||||||
|
int m_maxNumCmdPer1ms;
|
||||||
int m_internalSimFlags;
|
int m_internalSimFlags;
|
||||||
double m_defaultContactERP;
|
double m_defaultContactERP;
|
||||||
int m_collisionFilterMode;
|
int m_collisionFilterMode;
|
||||||
|
|||||||
@@ -659,9 +659,11 @@ void CMainApplication::Shutdown()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (sExample)
|
||||||
|
{
|
||||||
sExample->exitPhysics();
|
sExample->exitPhysics();
|
||||||
delete sExample;
|
delete sExample;
|
||||||
|
}
|
||||||
delete m_app;
|
delete m_app;
|
||||||
m_app=0;
|
m_app=0;
|
||||||
|
|
||||||
|
|||||||
@@ -606,14 +606,14 @@ static PyObject* pybullet_setPhysicsEngineParameter(PyObject* self, PyObject* ar
|
|||||||
int numSubSteps = -1;
|
int numSubSteps = -1;
|
||||||
int collisionFilterMode = -1;
|
int collisionFilterMode = -1;
|
||||||
double contactBreakingThreshold = -1;
|
double contactBreakingThreshold = -1;
|
||||||
|
int maxNumCmdPer1ms = -1;
|
||||||
b3PhysicsClientHandle sm = 0;
|
b3PhysicsClientHandle sm = 0;
|
||||||
|
|
||||||
int physicsClientId = 0;
|
int physicsClientId = 0;
|
||||||
static char *kwlist[] = { "fixedTimeStep", "numSolverIterations","useSplitImpulse","splitImpulsePenetrationThreshold", "numSubSteps","collisionFilterMode", "contactBreakingThreshold", "physicsClientId", NULL };
|
static char *kwlist[] = { "fixedTimeStep", "numSolverIterations","useSplitImpulse","splitImpulsePenetrationThreshold", "numSubSteps","collisionFilterMode", "contactBreakingThreshold", "maxNumCmdPer1ms", "physicsClientId", NULL };
|
||||||
|
|
||||||
if (!PyArg_ParseTupleAndKeywords(args, keywds, "|diidiidi", kwlist,&fixedTimeStep,&numSolverIterations,&useSplitImpulse,&splitImpulsePenetrationThreshold,&numSubSteps,
|
if (!PyArg_ParseTupleAndKeywords(args, keywds, "|diidiidii", kwlist,&fixedTimeStep,&numSolverIterations,&useSplitImpulse,&splitImpulsePenetrationThreshold,&numSubSteps,
|
||||||
&collisionFilterMode, &contactBreakingThreshold, &physicsClientId))
|
&collisionFilterMode, &contactBreakingThreshold, &maxNumCmdPer1ms, &physicsClientId))
|
||||||
{
|
{
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@@ -658,7 +658,10 @@ static PyObject* pybullet_setPhysicsEngineParameter(PyObject* self, PyObject* ar
|
|||||||
{
|
{
|
||||||
b3PhysicsParamSetContactBreakingThreshold(command,contactBreakingThreshold);
|
b3PhysicsParamSetContactBreakingThreshold(command,contactBreakingThreshold);
|
||||||
}
|
}
|
||||||
|
if (maxNumCmdPer1ms>=0)
|
||||||
|
{
|
||||||
|
b3PhysicsParamSetMaxNumCommandsPer1ms(command,maxNumCmdPer1ms);
|
||||||
|
}
|
||||||
|
|
||||||
//ret = b3PhysicsParamSetRealTimeSimulation(command, enableRealTimeSimulation);
|
//ret = b3PhysicsParamSetRealTimeSimulation(command, enableRealTimeSimulation);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user