From 3d130d9d669f63fc986b5ca892c97132b7cb1db5 Mon Sep 17 00:00:00 2001 From: "Erwin Coumans (Google)" Date: Thu, 27 Aug 2015 17:51:31 -0700 Subject: [PATCH] reset simulation in test/SharedMemory/test for proper cleanup, and it can restart without shutting down/restarting physics server w --- examples/SharedMemory/PhysicsClientC_API.cpp | 10 ++++++++++ examples/SharedMemory/PhysicsClientC_API.h | 2 ++ test/SharedMemory/test.c | 7 +++++++ 3 files changed, 19 insertions(+) diff --git a/examples/SharedMemory/PhysicsClientC_API.cpp b/examples/SharedMemory/PhysicsClientC_API.cpp index 8d627322a..47a977bd9 100644 --- a/examples/SharedMemory/PhysicsClientC_API.cpp +++ b/examples/SharedMemory/PhysicsClientC_API.cpp @@ -80,6 +80,16 @@ int b3InitStepSimulationCommand(struct SharedMemoryCommand* command) } +int b3InitResetSimulationCommand(struct SharedMemoryCommand* command) +{ + b3Assert(command); + command->m_type = CMD_RESET_SIMULATION; + command->m_updateFlags = 0; + + return 0; + +} + int b3JointControlCommandInit(struct SharedMemoryCommand* command, int controlMode) { diff --git a/examples/SharedMemory/PhysicsClientC_API.h b/examples/SharedMemory/PhysicsClientC_API.h index d726d2740..cc3c6d420 100644 --- a/examples/SharedMemory/PhysicsClientC_API.h +++ b/examples/SharedMemory/PhysicsClientC_API.h @@ -33,6 +33,8 @@ int b3PhysicsParamSetTimeStep(struct SharedMemoryCommand* command, double timeSt int b3InitStepSimulationCommand(struct SharedMemoryCommand* command); +int b3InitResetSimulationCommand(struct SharedMemoryCommand* command); + int b3LoadUrdfCommandInit(struct SharedMemoryCommand* command, const char* urdfFileName); ///all those commands are optional, except for the *Init int b3LoadUrdfCommandSetStartPosition(struct SharedMemoryCommand* command, double startPosX,double startPosY,double startPosZ); diff --git a/test/SharedMemory/test.c b/test/SharedMemory/test.c index ad4e7cfe4..55fd1dc70 100644 --- a/test/SharedMemory/test.c +++ b/test/SharedMemory/test.c @@ -148,8 +148,15 @@ int main(int argc, char* argv[]) status.m_sendActualStateArgs.m_jointReactionForces[6*sensorJointIndexRight+1], status.m_sendActualStateArgs.m_jointReactionForces[6*sensorJointIndexRight+2]); } + + ret = b3InitResetSimulationCommand(&command); + ret = b3SubmitClientCommand(sm, &command); + timeout = MAX_TIMEOUT; + while ((timeout-- > 0) && b3ProcessServerStatus(sm, &status)==0) {} } + + b3DisconnectSharedMemory(sm); }