expose timeout in pybullet/shared memory API

add RobotSimulator, a C++ API similar to pybullet. (work-in-progress, only part of API implemeted)
This commit is contained in:
Erwin Coumans
2017-02-24 15:34:11 -08:00
parent bb11884f89
commit a4f1e34899
34 changed files with 1654 additions and 62 deletions

View File

@@ -94,7 +94,7 @@ LINK_LIBRARIES(
)
IF (WIN32)
ADD_EXECUTABLE(App_SharedMemoryPhysics
ADD_EXECUTABLE(App_PhysicsServer_SharedMemory
${SharedMemory_SRCS}
main.cpp
../MultiThreading/b3Win32ThreadSupport.cpp
@@ -104,7 +104,7 @@ IF (WIN32)
ELSE(WIN32)
IF(APPLE)
LINK_LIBRARIES( pthread dl )
ADD_EXECUTABLE(App_SharedMemoryPhysics
ADD_EXECUTABLE(App_PhysicsServer_SharedMemory
${SharedMemory_SRCS}
../MultiThreading/b3PosixThreadSupport.cpp
../MultiThreading/b3PosixThreadSupport.h
@@ -113,7 +113,7 @@ ELSE(WIN32)
ELSE(APPLE)
LINK_LIBRARIES( pthread dl )
ADD_EXECUTABLE(App_SharedMemoryPhysics
ADD_EXECUTABLE(App_PhysicsServer_SharedMemory
${SharedMemory_SRCS}
../MultiThreading/b3PosixThreadSupport.cpp
../MultiThreading/b3PosixThreadSupport.h
@@ -126,9 +126,9 @@ ENDIF(WIN32)
IF (INTERNAL_ADD_POSTFIX_EXECUTABLE_NAMES)
SET_TARGET_PROPERTIES(App_SharedMemoryPhysics PROPERTIES DEBUG_POSTFIX "_Debug")
SET_TARGET_PROPERTIES(App_SharedMemoryPhysics PROPERTIES MINSIZEREL_POSTFIX "_MinsizeRel")
SET_TARGET_PROPERTIES(App_SharedMemoryPhysics PROPERTIES RELWITHDEBINFO_POSTFIX "_RelWithDebugInfo")
SET_TARGET_PROPERTIES(App_PhysicsServer_SharedMemory PROPERTIES DEBUG_POSTFIX "_Debug")
SET_TARGET_PROPERTIES(App_PhysicsServer_SharedMemory PROPERTIES MINSIZEREL_POSTFIX "_MinsizeRel")
SET_TARGET_PROPERTIES(App_PhysicsServer_SharedMemory PROPERTIES RELWITHDEBINFO_POSTFIX "_RelWithDebugInfo")
ENDIF(INTERNAL_ADD_POSTFIX_EXECUTABLE_NAMES)
@@ -151,7 +151,7 @@ IF (WIN32)
ADD_DEFINITIONS(-DGLEW_STATIC)
LINK_LIBRARIES( ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY} )
ADD_EXECUTABLE(App_SharedMemoryPhysics_GUI
ADD_EXECUTABLE(App_PhysicsServer_SharedMemory_GUI
${SharedMemory_SRCS}
../StandaloneMain/main_opengl_single_example.cpp
../ExampleBrowser/OpenGLGuiHelper.cpp
@@ -168,7 +168,7 @@ ELSE(WIN32)
MESSAGE(${COCOA})
LINK_LIBRARIES(${COCOA} ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY})
ADD_EXECUTABLE(App_SharedMemoryPhysics_GUI
ADD_EXECUTABLE(App_PhysicsServer_SharedMemory_GUI
${SharedMemory_SRCS}
../StandaloneMain/main_opengl_single_example.cpp
../ExampleBrowser/OpenGLGuiHelper.cpp
@@ -184,7 +184,7 @@ ELSE(WIN32)
ADD_DEFINITIONS("-DGLEW_STATIC")
ADD_DEFINITIONS("-DGLEW_DYNAMIC_LOAD_ALL_GLX_FUNCTIONS=1")
ADD_EXECUTABLE(App_SharedMemoryPhysics_GUI
ADD_EXECUTABLE(App_PhysicsServer_SharedMemory_GUI
${SharedMemory_SRCS}
../StandaloneMain/main_opengl_single_example.cpp
../ExampleBrowser/OpenGLGuiHelper.cpp
@@ -200,9 +200,9 @@ ENDIF(WIN32)
IF (INTERNAL_ADD_POSTFIX_EXECUTABLE_NAMES)
SET_TARGET_PROPERTIES(App_SharedMemoryPhysics_GUI PROPERTIES DEBUG_POSTFIX "_Debug")
SET_TARGET_PROPERTIES(App_SharedMemoryPhysics_GUI PROPERTIES MINSIZEREL_POSTFIX "_MinsizeRel")
SET_TARGET_PROPERTIES(App_SharedMemoryPhysics_GUI PROPERTIES RELWITHDEBINFO_POSTFIX "_RelWithDebugInfo")
SET_TARGET_PROPERTIES(App_PhysicsServer_SharedMemory_GUI PROPERTIES DEBUG_POSTFIX "_Debug")
SET_TARGET_PROPERTIES(App_PhysicsServer_SharedMemory_GUI PROPERTIES MINSIZEREL_POSTFIX "_MinsizeRel")
SET_TARGET_PROPERTIES(App_PhysicsServer_SharedMemory_GUI PROPERTIES RELWITHDEBINFO_POSTFIX "_RelWithDebugInfo")
ENDIF(INTERNAL_ADD_POSTFIX_EXECUTABLE_NAMES)
@@ -232,7 +232,7 @@ LINK_LIBRARIES(
ELSE(CMAKE_CL_64)
LINK_DIRECTORIES(${BULLET_PHYSICS_SOURCE_DIR}/examples/ThirdPartyLibs/openvr/lib/win32)
ENDIF(CMAKE_CL_64)
ADD_EXECUTABLE(App_SharedMemoryPhysics_VR
ADD_EXECUTABLE(App_PhysicsServer_SharedMemory_VR
${SharedMemory_SRCS}
../StandaloneMain/hellovr_opengl_main.cpp
../ExampleBrowser/OpenGLGuiHelper.cpp
@@ -257,35 +257,35 @@ LINK_LIBRARIES(
IF (NOT INTERNAL_CREATE_DISTRIBUTABLE_MSVC_PROJECTFILES)
IF (CMAKE_CL_64)
ADD_CUSTOM_COMMAND(
TARGET App_SharedMemoryPhysics_VR
TARGET App_PhysicsServer_SharedMemory_VR
POST_BUILD
COMMAND ${CMAKE_COMMAND} ARGS -E copy_if_different ${BULLET_PHYSICS_SOURCE_DIR}/examples/ThirdPartyLibs/openvr/bin/win64/openvr_api.dll ${CMAKE_CURRENT_BINARY_DIR}/openvr_api.dll
)
ELSE(CMAKE_CL_64)
ADD_CUSTOM_COMMAND(
TARGET App_SharedMemoryPhysics_VR
TARGET App_PhysicsServer_SharedMemory_VR
POST_BUILD
COMMAND ${CMAKE_COMMAND} ARGS -E copy_if_different ${BULLET_PHYSICS_SOURCE_DIR}/examples/ThirdPartyLibs/openvr/bin/win32/openvr_api.dll ${CMAKE_CURRENT_BINARY_DIR}/openvr_api.dll
)
ENDIF(CMAKE_CL_64)
ADD_CUSTOM_COMMAND(
TARGET App_SharedMemoryPhysics_VR
TARGET App_PhysicsServer_SharedMemory_VR
POST_BUILD
COMMAND ${CMAKE_COMMAND} ARGS -E copy_directory ${BULLET_PHYSICS_SOURCE_DIR}/data ${PROJECT_BINARY_DIR}/data
)
ENDIF (NOT INTERNAL_CREATE_DISTRIBUTABLE_MSVC_PROJECTFILES)
SET_TARGET_PROPERTIES(App_SharedMemoryPhysics_VR PROPERTIES COMPILE_DEFINITIONS BT_ENABLE_VR )
SET_TARGET_PROPERTIES(App_PhysicsServer_SharedMemory_VR PROPERTIES COMPILE_DEFINITIONS BT_ENABLE_VR )
IF (INTERNAL_ADD_POSTFIX_EXECUTABLE_NAMES)
SET_TARGET_PROPERTIES(App_SharedMemoryPhysics_VR PROPERTIES DEBUG_POSTFIX "_Debug")
SET_TARGET_PROPERTIES(App_SharedMemoryPhysics_VR PROPERTIES MINSIZEREL_POSTFIX "_MinsizeRel")
SET_TARGET_PROPERTIES(App_SharedMemoryPhysics_VR PROPERTIES RELWITHDEBINFO_POSTFIX "_RelWithDebugInfo")
SET_TARGET_PROPERTIES(App_PhysicsServer_SharedMemory_VR PROPERTIES DEBUG_POSTFIX "_Debug")
SET_TARGET_PROPERTIES(App_PhysicsServer_SharedMemory_VR PROPERTIES MINSIZEREL_POSTFIX "_MinsizeRel")
SET_TARGET_PROPERTIES(App_PhysicsServer_SharedMemory_VR PROPERTIES RELWITHDEBINFO_POSTFIX "_RelWithDebugInfo")
ENDIF(INTERNAL_ADD_POSTFIX_EXECUTABLE_NAMES)
ENDIF(WIN32)

View File

@@ -60,6 +60,9 @@ public:
virtual void getCachedRaycastHits(struct b3RaycastInformation* raycastHits) = 0;
virtual void setTimeOut(double timeOutInSeconds) = 0;
virtual double getTimeOut() const = 0;
};
#endif // BT_PHYSICS_CLIENT_API_H

View File

@@ -1040,13 +1040,17 @@ b3SharedMemoryStatusHandle b3SubmitClientCommandAndWaitStatus(b3PhysicsClientHan
{
b3Clock clock;
double startTime = clock.getTimeInSeconds();
double timeOutInSeconds = 10;
b3SharedMemoryStatusHandle statusHandle = 0;
b3Assert(commandHandle);
b3Assert(physClient);
if (physClient && commandHandle)
{
PhysicsClient* cl = (PhysicsClient* ) physClient;
double timeOutInSeconds = cl->getTimeOut();
b3SubmitClientCommand(physClient, commandHandle);
while ((statusHandle == 0) && (clock.getTimeInSeconds()-startTime < timeOutInSeconds))
@@ -2604,3 +2608,24 @@ void b3ConfigureOpenGLVisualizerSetViewMatrix(b3SharedMemoryCommandHandle comman
}
}
void b3SetTimeOut(b3PhysicsClientHandle physClient, double timeOutInSeconds)
{
PhysicsClient* cl = (PhysicsClient*)physClient;
b3Assert(cl);
if (cl)
{
cl->setTimeOut(timeOutInSeconds);
}
}
double b3GetTimeOut(b3PhysicsClientHandle physClient)
{
PhysicsClient* cl = (PhysicsClient*)physClient;
b3Assert(cl);
if (cl)
{
return cl->getTimeOut();
}
return -1;
}

View File

@@ -355,6 +355,10 @@ int b3StateLoggingAddLoggingObjectUniqueId(b3SharedMemoryCommandHandle commandHa
int b3GetStatusLoggingUniqueId(b3SharedMemoryStatusHandle statusHandle);
int b3StateLoggingStop(b3SharedMemoryCommandHandle commandHandle, int loggingUniqueId);
void b3SetTimeOut(b3PhysicsClientHandle physClient, double timeOutInSeconds);
double b3GetTimeOut(b3PhysicsClientHandle physClient);
#ifdef __cplusplus
}
#endif

View File

@@ -60,6 +60,7 @@ struct PhysicsClientSharedMemoryInternalData {
bool m_hasLastServerStatus;
int m_sharedMemoryKey;
bool m_verboseOutput;
double m_timeOutInSeconds;
PhysicsClientSharedMemoryInternalData()
: m_sharedMemory(0),
@@ -72,7 +73,9 @@ struct PhysicsClientSharedMemoryInternalData {
m_waitingForServer(false),
m_hasLastServerStatus(false),
m_sharedMemoryKey(SHARED_MEMORY_KEY),
m_verboseOutput(false) {}
m_verboseOutput(false),
m_timeOutInSeconds(1e30)
{}
void processServerStatus();
@@ -1208,3 +1211,11 @@ const float* PhysicsClientSharedMemory::getDebugLinesColor() const {
}
int PhysicsClientSharedMemory::getNumDebugLines() const { return m_data->m_debugLinesFrom.size(); }
void PhysicsClientSharedMemory::setTimeOut(double timeOutInSeconds)
{
m_data->m_timeOutInSeconds = timeOutInSeconds;
}
double PhysicsClientSharedMemory::getTimeOut() const
{
return m_data->m_timeOutInSeconds;
}

View File

@@ -69,6 +69,9 @@ public:
virtual void getCachedRaycastHits(struct b3RaycastInformation* raycastHits);
virtual void setTimeOut(double timeOutInSeconds);
virtual double getTimeOut() const;
};
#endif // BT_PHYSICS_CLIENT_API_H

View File

@@ -47,11 +47,13 @@ struct TcpNetworkedInternalData
int m_port;
b3AlignedObjectArray<unsigned char> m_tempBuffer;
double m_timeOutInSeconds;
TcpNetworkedInternalData()
:
m_isConnected(false),
m_hasCommand(false)
m_hasCommand(false),
m_timeOutInSeconds(60)
{
}
@@ -66,8 +68,8 @@ struct TcpNetworkedInternalData
m_isConnected = m_tcpSocket.Open(m_hostName.c_str(),m_port);
if (m_isConnected)
{
m_tcpSocket.SetSendTimeout(5,0);
m_tcpSocket.SetReceiveTimeout(5,0);
m_tcpSocket.SetSendTimeout(m_timeOutInSeconds,0);
m_tcpSocket.SetReceiveTimeout(m_timeOutInSeconds,0);
}
int key = SHARED_MEMORY_MAGIC_NUMBER;
m_tcpSocket.Send((uint8*)&key,4);
@@ -257,7 +259,10 @@ void TcpNetworkedPhysicsProcessor::disconnect()
}
void TcpNetworkedPhysicsProcessor::setTimeOut(double timeOutInSeconds)
{
m_data->m_timeOutInSeconds = timeOutInSeconds;
}

View File

@@ -30,6 +30,8 @@ public:
virtual void setGuiHelper(struct GUIHelperInterface* guiHelper);
virtual void setTimeOut(double timeOutInSeconds);
};

View File

@@ -80,6 +80,7 @@ struct UdpNetworkedInternalData
std::string m_hostName;
int m_port;
double m_timeOutInSeconds;
UdpNetworkedInternalData()
:m_client(0),
@@ -87,7 +88,8 @@ struct UdpNetworkedInternalData
m_isConnected(false),
m_threadSupport(0),
m_hasCommand(false),
m_hasStatus(false)
m_hasStatus(false),
m_timeOutInSeconds(60)
{
}
@@ -467,7 +469,7 @@ bool UdpNetworkedPhysicsProcessor::processCommand(const struct SharedMemoryComma
b3Clock clock;
double startTime = clock.getTimeInSeconds();
double timeOutInSeconds = 10;
double timeOutInSeconds = m_data->m_timeOutInSeconds;
m_data->m_cs->lock();
m_data->m_clientCmd = clientCmd;
@@ -486,7 +488,7 @@ bool UdpNetworkedPhysicsProcessor::processCommand(const struct SharedMemoryComma
b3Clock clock;
double startTime = clock.getTimeInSeconds();
double timeOutInSeconds = 10;
double timeOutInSeconds = m_data->m_timeOutInSeconds;
const SharedMemoryStatus* stat = 0;
while ((!hasStatus) && (clock.getTimeInSeconds() - startTime < timeOutInSeconds))
@@ -621,7 +623,7 @@ void UdpNetworkedPhysicsProcessor::disconnect()
}
void UdpNetworkedPhysicsProcessor::setTimeOut(double timeOutInSeconds)
{
m_data->m_timeOutInSeconds = timeOutInSeconds;
}

View File

@@ -30,6 +30,7 @@ public:
virtual void setGuiHelper(struct GUIHelperInterface* guiHelper);
virtual void setTimeOut(double timeOutInSeconds);
};

View File

@@ -20,7 +20,7 @@ public:
virtual void renderScene() = 0;
virtual void physicsDebugDraw(int debugDrawFlags) = 0;
virtual void setGuiHelper(struct GUIHelperInterface* guiHelper) = 0;
virtual void setTimeOut(double timeOutInSeconds) = 0;
};

View File

@@ -56,11 +56,13 @@ struct PhysicsDirectInternalData
PhysicsCommandProcessorInterface* m_commandProcessor;
bool m_ownsCommandProcessor;
double m_timeOutInSeconds;
PhysicsDirectInternalData()
:m_hasStatus(false),
m_verboseOutput(false),
m_ownsCommandProcessor(false)
m_ownsCommandProcessor(false),
m_timeOutInSeconds(1e30)
{
}
};
@@ -230,7 +232,7 @@ bool PhysicsDirect::processDebugLines(const struct SharedMemoryCommand& orgComma
b3Clock clock;
double startTime = clock.getTimeInSeconds();
double timeOutInSeconds = 10;
double timeOutInSeconds = m_data->m_timeOutInSeconds;
while ((!hasStatus) && (clock.getTimeInSeconds()-startTime < timeOutInSeconds))
{
@@ -315,7 +317,7 @@ bool PhysicsDirect::processVisualShapeData(const struct SharedMemoryCommand& org
b3Clock clock;
double startTime = clock.getTimeInSeconds();
double timeOutInSeconds = 10;
double timeOutInSeconds = m_data->m_timeOutInSeconds;
while ((!hasStatus) && (clock.getTimeInSeconds()-startTime < timeOutInSeconds))
{
@@ -369,7 +371,7 @@ bool PhysicsDirect::processOverlappingObjects(const struct SharedMemoryCommand&
b3Clock clock;
double startTime = clock.getTimeInSeconds();
double timeOutInSeconds = 10;
double timeOutInSeconds = m_data->m_timeOutInSeconds;
while ((!hasStatus) && (clock.getTimeInSeconds()-startTime < timeOutInSeconds))
{
@@ -427,7 +429,7 @@ bool PhysicsDirect::processContactPointData(const struct SharedMemoryCommand& or
b3Clock clock;
double startTime = clock.getTimeInSeconds();
double timeOutInSeconds = 10;
double timeOutInSeconds = m_data->m_timeOutInSeconds;
while ((!hasStatus) && (clock.getTimeInSeconds()-startTime < timeOutInSeconds))
{
@@ -491,7 +493,7 @@ bool PhysicsDirect::processCamera(const struct SharedMemoryCommand& orgCommand)
b3Clock clock;
double startTime = clock.getTimeInSeconds();
double timeOutInSeconds = 10;
double timeOutInSeconds = m_data->m_timeOutInSeconds;
while ((!hasStatus) && (clock.getTimeInSeconds()-startTime < timeOutInSeconds))
{
@@ -754,7 +756,7 @@ void PhysicsDirect::postProcessStatus(const struct SharedMemoryStatus& serverCmd
b3Clock clock;
double startTime = clock.getTimeInSeconds();
double timeOutInSeconds = 10;
double timeOutInSeconds = m_data->m_timeOutInSeconds;
while ((!hasStatus) && (clock.getTimeInSeconds()-startTime < timeOutInSeconds))
{
@@ -781,7 +783,7 @@ void PhysicsDirect::postProcessStatus(const struct SharedMemoryStatus& serverCmd
b3Clock clock;
double startTime = clock.getTimeInSeconds();
double timeOutInSeconds = 10;
double timeOutInSeconds = m_data->m_timeOutInSeconds;
while ((!hasStatus) && (clock.getTimeInSeconds()-startTime < timeOutInSeconds))
{
@@ -1034,3 +1036,13 @@ void PhysicsDirect::getCachedRaycastHits(struct b3RaycastInformation* raycastHit
raycastHits->m_numRayHits = m_data->m_raycastHits.size();
raycastHits->m_rayHits = raycastHits->m_numRayHits? &m_data->m_raycastHits[0] : 0;
}
void PhysicsDirect::setTimeOut(double timeOutInSeconds)
{
m_data->m_timeOutInSeconds = timeOutInSeconds;
}
double PhysicsDirect::getTimeOut() const
{
return m_data->m_timeOutInSeconds;
}

View File

@@ -95,6 +95,8 @@ public:
virtual void renderScene();
virtual void debugDraw(int debugDrawMode);
virtual void setTimeOut(double timeOutInSeconds);
virtual double getTimeOut() const;
};
#endif //PHYSICS_DIRECT_H

View File

@@ -169,3 +169,13 @@ void PhysicsLoopBack::getCachedRaycastHits(struct b3RaycastInformation* raycastH
{
return m_data->m_physicsClient->getCachedRaycastHits(raycastHits);
}
void PhysicsLoopBack::setTimeOut(double timeOutInSeconds)
{
m_data->m_physicsClient->setTimeOut(timeOutInSeconds);
}
double PhysicsLoopBack::getTimeOut() const
{
return m_data->m_physicsClient->getTimeOut();
}

View File

@@ -74,6 +74,8 @@ public:
virtual void getCachedRaycastHits(struct b3RaycastInformation* raycastHits);
virtual void setTimeOut(double timeOutInSeconds);
virtual double getTimeOut() const;
};
#endif //PHYSICS_LOOP_BACK_H

View File

@@ -5713,3 +5713,7 @@ void PhysicsServerCommandProcessor::createDefaultRobotAssets()
}
}
void PhysicsServerCommandProcessor::setTimeOut(double /*timeOutInSeconds*/)
{
}

View File

@@ -99,6 +99,8 @@ public:
void stepSimulationRealTime(double dtInSec, const struct b3VRControllerEvent* vrEvents, int numVREvents);
void enableRealTimeSimulation(bool enableRealTimeSim);
void applyJointDamping(int bodyUniqueId);
virtual void setTimeOut(double timeOutInSeconds);
};
#endif //PHYSICS_SERVER_COMMAND_PROCESSOR_H

View File

@@ -212,4 +212,6 @@ void SharedMemoryCommandProcessor::setSharedMemoryKey(int key)
m_data->m_sharedMemoryKey = key;
}
void SharedMemoryCommandProcessor::setTimeOut(double /*timeOutInSeconds*/)
{
}

View File

@@ -29,7 +29,7 @@ public:
void setSharedMemoryInterface(class SharedMemoryInterface* sharedMem);
void setSharedMemoryKey(int key);
virtual void setTimeOut(double timeOutInSeconds);
};

View File

@@ -310,7 +310,7 @@ enum
CONTACT_QUERY_MODE_COMPUTE_CLOSEST_POINTS = 1,
};
enum
enum b3StateLoggingType
{
STATE_LOGGING_MINITAUR = 0,
STATE_LOGGING_GENERIC_ROBOT = 1,
@@ -403,10 +403,19 @@ enum EnumRenderer
//ER_FIRE_RAYS=(1<<18),
};
enum EnumConfigureOpenGLVisualizer
enum b3ConfigureDebugVisualizerEnum
{
COV_ENABLE_GUI=1,
COV_ENABLE_SHADOWS,
COV_ENABLE_WIREFRAME,
};
enum eCONNECT_METHOD {
eCONNECT_GUI = 1,
eCONNECT_DIRECT = 2,
eCONNECT_SHARED_MEMORY = 3,
eCONNECT_UDP = 4,
eCONNECT_TCP = 5,
};
#endif//SHARED_MEMORY_PUBLIC_H

View File

@@ -1,5 +1,5 @@
project "App_SharedMemoryPhysics"
project "App_PhysicsServer_SharedMemory"
if _OPTIONS["ios"] then
kind "WindowedApp"
@@ -141,7 +141,7 @@ files {
end
project "App_SharedMemoryPhysics_GUI"
project "App_PhysicsServer_SharedMemory_GUI"
if _OPTIONS["ios"] then
kind "WindowedApp"
@@ -240,8 +240,10 @@ if os.is("MacOSX") then
--defines {"__MACOSX_CORE__"}
end
if os.is("Windows") then
project "App_SharedMemoryPhysics_VR"
project "App_PhysicsServer_SharedMemory_VR"
--for now, only enable VR under Windows, until compilation issues are resolved on Mac/Linux
defines {"B3_USE_STANDALONE_EXAMPLE","BT_ENABLE_VR"}