From 0b08881ab83c3a51f1561b0cbcf35f69be3ba1bc Mon Sep 17 00:00:00 2001 From: erwincoumans Date: Sat, 15 Sep 2018 14:22:31 -0700 Subject: [PATCH 1/4] wait until a frame is rendered, when using the COV_ENABLE_SINGLE_STEP_RENDERING command (Windows and Linux only) --- .../ExampleBrowser/OpenGLExampleBrowser.cpp | 12 +++++- .../SharedMemory/PhysicsServerExample.cpp | 37 +++++++++++++++++-- 2 files changed, 43 insertions(+), 6 deletions(-) diff --git a/examples/ExampleBrowser/OpenGLExampleBrowser.cpp b/examples/ExampleBrowser/OpenGLExampleBrowser.cpp index 1d78d8215..871e4c9b1 100644 --- a/examples/ExampleBrowser/OpenGLExampleBrowser.cpp +++ b/examples/ExampleBrowser/OpenGLExampleBrowser.cpp @@ -393,7 +393,15 @@ void OpenGLExampleBrowserVisualizerFlagCallback(int flag, bool enable) if (flag == COV_ENABLE_SINGLE_STEP_RENDERING) { - singleStepSimulation = true; + if (enable) + { + gEnableRenderLoop = false; + singleStepSimulation = true; + } else + { + gEnableRenderLoop = true; + singleStepSimulation = false; + } } @@ -1235,7 +1243,7 @@ void OpenGLExampleBrowser::update(float deltaTime) { b3ChromeUtilsEnableProfiling(); - if (!gEnableRenderLoop) + if (!gEnableRenderLoop && !singleStepSimulation) { sCurrentDemo->updateGraphics(); return; diff --git a/examples/SharedMemory/PhysicsServerExample.cpp b/examples/SharedMemory/PhysicsServerExample.cpp index b9405371f..2d52ba03c 100644 --- a/examples/SharedMemory/PhysicsServerExample.cpp +++ b/examples/SharedMemory/PhysicsServerExample.cpp @@ -137,6 +137,7 @@ enum MultiThreadedGUIHelperCommunicationEnums eGUIHelperGetShapeIndexFromInstance, eGUIHelperChangeTexture, eGUIHelperRemoveTexture, + eGUIHelperSetVisualizerFlagCheckRenderedFrame, }; @@ -940,7 +941,9 @@ public: int m_visualizerFlag; int m_visualizerEnable; - void setVisualizerFlag(int flag, int enable) + int m_renderedFrames; + + void setVisualizerFlag(int flag, int enable) { m_visualizerFlag = flag; m_visualizerEnable = enable; @@ -1358,6 +1361,7 @@ class PhysicsServerExample : public SharedMemoryCommon int m_canvasRGBIndex; int m_canvasDepthIndex; int m_canvasSegMaskIndex; + // int m_options; @@ -1365,6 +1369,8 @@ class PhysicsServerExample : public SharedMemoryCommon TinyVRGui* m_tinyVrGui; #endif + int m_renderedFrames; + public: PhysicsServerExample(MultiThreadedOpenGLGuiHelper* helper, CommandProcessorCreationInterface* commandProcessorCreator, SharedMemoryInterface* sharedMem=0, int options=0); @@ -1723,6 +1729,7 @@ m_canvasSegMaskIndex(-1) #ifdef BT_ENABLE_VR ,m_tinyVrGui(0) #endif +,m_renderedFrames(0) { m_multiThreadedHelper = helper; @@ -2066,11 +2073,29 @@ void PhysicsServerExample::updateGraphics() gEnableDefaultMousePicking = (enable!=0); } + m_multiThreadedHelper->m_renderedFrames = m_renderedFrames; + m_multiThreadedHelper->m_childGuiHelper->setVisualizerFlag(m_multiThreadedHelper->m_visualizerFlag,m_multiThreadedHelper->m_visualizerEnable); - m_multiThreadedHelper->mainThreadRelease(); + + //postpone the release until an actual frame is rendered + if (flag == COV_ENABLE_SINGLE_STEP_RENDERING) + { + m_multiThreadedHelper->getCriticalSection()->setSharedParam(1,eGUIHelperSetVisualizerFlagCheckRenderedFrame); + } else + { + m_multiThreadedHelper->mainThreadRelease(); + } break; } - + + case eGUIHelperSetVisualizerFlagCheckRenderedFrame: + { + if (m_renderedFrames!=m_multiThreadedHelper->m_renderedFrames) + { + m_multiThreadedHelper->mainThreadRelease(); + } + break; + } case eGUIHelperRegisterGraphicsInstance: { @@ -2732,6 +2757,8 @@ void PhysicsServerExample::drawUserDebugLines() void PhysicsServerExample::renderScene() { + m_renderedFrames++; + btTransform vrTrans; @@ -2893,12 +2920,14 @@ void PhysicsServerExample::renderScene() drawUserDebugLines(); - + //m_args[0].m_cs->unlock(); } void PhysicsServerExample::physicsDebugDraw(int debugDrawFlags) { + m_renderedFrames++; + if (gEnableSyncPhysicsRendering) { m_physicsServer.syncPhysicsToGraphics(); From 3de295ca41a2df09d9229b412c558f593ffd4498 Mon Sep 17 00:00:00 2001 From: bla Date: Wed, 19 Sep 2018 08:43:55 -0700 Subject: [PATCH 2/4] add missing files to MANIFEST.in for pybullet pip version --- MANIFEST.in | 7 +------ setup.py | 2 +- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/MANIFEST.in b/MANIFEST.in index 1c978abbd..fdff76d10 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -7,11 +7,6 @@ recursive-include src *.h recursive-include src *.hpp recursive-include examples/pybullet/gym *.* include examples/ThirdPartyLibs/enet/unix.c -include examples/OpenGLWindow/X11OpenGLWindow.cpp +include examples/OpenGLWindow/*.cpp recursive-include examples/ThirdPartyLibs/glad *.* include examples/ThirdPartyLibs/enet/win32.c -include examples/OpenGLWindow/Win32Window.cpp -include examples/OpenGLWindow/Win32OpenGLWindow.cpp -include examples/ThirdPartyLibs/Glew/glew.c -include examples/OpenGLWindow/MacOpenGLWindow.cpp -include examples/OpenGLWindow/MacOpenGLWindowObjC.m diff --git a/setup.py b/setup.py index 204e369a6..ae7e7b4bf 100644 --- a/setup.py +++ b/setup.py @@ -545,7 +545,7 @@ eglRender = Extension("eglRenderer", setup( name = 'pybullet', - version='2.1.6', + version='2.1.9', description='Official Python Interface for the Bullet Physics SDK specialized for Robotics Simulation and Reinforcement Learning', long_description='pybullet is an easy to use Python module for physics simulation, robotics and deep reinforcement learning based on the Bullet Physics SDK. With pybullet you can load articulated bodies from URDF, SDF and other file formats. pybullet provides forward dynamics simulation, inverse dynamics computation, forward and inverse kinematics and collision detection and ray intersection queries. Aside from physics simulation, pybullet supports to rendering, with a CPU renderer and OpenGL visualization and support for virtual reality headsets.', url='https://github.com/bulletphysics/bullet3', From 0de99f224a9ce0d532036f3da538787f22af5045 Mon Sep 17 00:00:00 2001 From: Erwin Coumans Date: Wed, 19 Sep 2018 16:18:06 -0700 Subject: [PATCH 3/4] fix compilation on ARM (Ubuntu 18.04, NVIDIA Xavier) --- examples/ThirdPartyLibs/Gwen/Renderers/FontData.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/ThirdPartyLibs/Gwen/Renderers/FontData.h b/examples/ThirdPartyLibs/Gwen/Renderers/FontData.h index 4a2792109..90a1d9f55 100644 --- a/examples/ThirdPartyLibs/Gwen/Renderers/FontData.h +++ b/examples/ThirdPartyLibs/Gwen/Renderers/FontData.h @@ -259,7 +259,7 @@ unsigned char sGwenFontData[] = 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }; -static const char sGwenDebugFontSpacing[]= +static const signed char sGwenDebugFontSpacing[]= { 0,0,0,0,0,0,0,0,0,12,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3,3,4,6,6,9,8,3,4,4,4,6,3,7,3,3,6,6,6,6,6,6,6,6,6,6,3,3,6,5,6,6,11,7,7,8,8,7,6,8,8,3,5,7,6,9,8,8,7,8,7,7,5,8,7,9,7,7,7,3,3,3,6,6,3,5,6,5,6,5,4,6,6,2,2,5,2,8,6,6,6,6,4,5,4,5,6,8,6,5,5,3,3,3,7,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3,3,6,6,5,6,3,6,3,9,4,6,7,4,9,3,4,6,3,3,3,5,6,3,3,3,4,6,9,9,9,6,7,7,7,7,7,7,10,8,7,7,7,7,3,3,3,3,8,8,8,8,8,8,8,6,8,8,8,8,8,7,7,5,5,5,5,5,5,5,8,5,5,5,5,5,2,2,2,2,6,5,6,6,6,6,6,6,6,5,5,5,5,5,6,5,116,112,61,0,0,0,0,-96,-48,96,80,-64,0,64,-96,16,0,0,0,98,99,0,16,0,-96,-48,96,80,-64,0,-16,-128,16,98,99,0,-80,32,16,-16,16,112,-64,-64,-32,-16,-48,16,-48,0,64,-128,-64,32,-48,-64,-48,-16,96,32,64,96,96,32,32,-96,-64,-96,80,64,-80,16,-48,16,-80,-16,48,112,80,-80,-16,64,80,-112,-48,16,80,48,96,16,16,16,-112,-16,-16,0,96,48,48,-112,112,-80,-32,-48,-96,-112,16,80,80,48,-64,-80,-112,96,80,64,96,48,80,73,65,32,84,82,84,0,92,103,32,101,120,92,114,102,105,108,117,32,92,105,117,120,108,0,115,114,32,114,114,116,101,110,0,92,103,32,101,120,92,114,102,105,108,117,32,92,105,117,108,0,92,103,32,101,120,92,114,102,105,108,117,32,92,105,117,120,101,110,105,114,101,0,100,84,60,115,116,95,116,97,60,115,119,58,116,115,97,42,114,32,58,115,108,32,110,111,111,58,101,44,115,116,97,99,114,97,71,58,110,108,66,32,48,58,110,105,97,58,101,111,61,83,100,32,32,114,101,110,105,114,101,44,0,112,116,101,111,105,109,105,0,115,110,116,101,111,117,100,97,0,115,111,64,80,-112,34,32,114,101,0,100,105,99,115,101,67,114,58,115,44,115,116,97,99,114,97,71,58,110,108,66,32,62,67,116,101,111,62,112,116,42,83,100,32,32,114,101,117,102,110,44,0,115,116,116,110,100,102,110,108,0,100,105,99,115,101,67,114,58,115,44,115,116,97,99,114,97,71,58,110,108,66,32,62,67,116,101,111,62,112,116,43,0,115,116,116,110,105,101,116,101,60,108,0,112,116,97,105,97,32,115,32,103,0,100,105,99,115,101,67,114,58,115,44,115,116,97,99,114,97,71,58,110,108,66,32,62,67,116,101,111,62,67,97,108,32,114,114,110,112,98,0,100,84,60,115,116,95,116,97,60,115,119,58,116,115,97,42,114,32,58,115,108,32,110,111,111,58,101,44,115,116,97,99,114,97,71,58,110,108,66,32,48,58,110,105,97,58,101,0,112,116,101,111,111,101,109,97,0,100,84,60,115,116,95,116,97,60,115,119,58,116,115,97,42,114,32,58,115,108,32,110,111,111,58,101,44,115,116,97,99,114,97,71,58,110,108,66,32,48,58,110,105,97,58,110,0,112,116,101,111,111,110,109,97,0,118,100,101,111,16,-26,100,105,99,115,101,67,114,58,115,44,115,116,97,99,114,97,71,58,110,108,66,32,62,67,116,101,111,62,112,116,45,0,115,116,116,110,100,101,116,101,97,111,0,0,0,0,97,111,48,48,-96,-112,-48,16,-64,0,-16,-128,16,0,-103,97,111,58,110,105,33,-128,32,-64,-16,16,112,-64,-64,-32,-16,-48,16,-48,0,64,-128,-64,32,-48,-64,-48,-16,96,32,112,96,96,32,-96,-96,-64,-96,80,64,-80,16,-48,16,-80,-16,48,112,80,-80,-16,64,80,-112,-48,16,80,48,96,16,16,16,-112,32,-16,0,96,48,48,-112,112,-80,-32,-48,-96,-112,16,80,80,48,-64,-124,-96,-112,64,-110,-128,0,80,112,0,100,84,60,115,116,95,112,97,60,115,116,98,99,114,60,97,44,117,115,58,114,97,60,97,62,97,115,58,111,111,99,95,62,97,71,58,101,58,108,42,114,32,58,115,108,32,58,115,115,110,99,95,116,116,100,104,116,116,99,95,99,115,100,108,97,60,97,62,62,97,115,58,111,111,116,116,100,97,99,115,100,97,95,105,119,114,115,99,116,99,95,105,119,114,44,115,116,97,99,114,104,116,32,115,99,115,101,69,116,97,114,32,62,58,115,116,116,58,114,114,0,100,84,60,115,116,95,112,97,60,115,116,98,99,114,60,97,44,117,115,58,114,97,60,97,62,97,115,58,111,111,99,95,62,97,71,58,101,58,108,42,114,32,58,115,108,32,58,115,115,110,99,95,116,116,100,104,116,116,99,95,99,115,100,108,97,60,97,62,62,97,115,58,111,111,116,116,100,97,99,115,100,97,95,105,119,114,115,99,116,99,95,105,119,114,44,115,116,97,99,114,104,116,32,115,99,115,101,69,116,97,114,32,62,58,115,116,116,58,114,114,0,112,116,101,111,111,101,101,99,101,100,84,60,115,116,95,112,97,60,115,116,98,99,114,60,97,44,117,115,58,114,97,60,97,62,97,115,58,111,111,99,95,62,97,71,58,101,58,108,42,114,32,58,115,108,32,58,115,115,110,99,95,116,116,100,104,116,116,99,95,99,115,100,108,97,60,97,62,62,97,115,58,111,111,116,116,100,97,99,115,100,97,95,105,119,114,115,99,116,99,95,105,119,114,44,115,116,97,99,114,104,116,32,115,99,115,101,69,116,97,114,32,62,58,115,116,116,58,99,92,103,32,101,120,92,114,102,105,108,117,32,92,105,117,97,114,109,100,105,99,115,101,67,114,58,115,44,115,116,97,99,114,97,71,58,110,108,66,32,62,73,97,60,58,101,100,101,111,115,110,111,97,0,116,45,97,99,97,114,97,34,41,100,105,99,115,101,67,114,58,115,44,115,116,97,99,114,97,71,58,110,108,66,32,62,67,116,101,111,62,112,116,42,100,105,99,115,101,67,114,58,115,44,115,116,97,99,114,97,71,58,110,108,66,32,62,67,116,101,111,62,112,116,43,0,100,105,99,115,101,67,114,58,115,44,115,116,97,99,114,97,71,58,110,108,66,32,62,67,116,101,111,62,67,97,98,99,98,99,98,99,-113,67,32,83,116,0,100,105,99,115,101,72,58,115,111,44,115,116,97,99,114,97,71,58,111,66,72,32,62,67,116,101,111,62,112,116,42,100,105,99,115,101,72,58,115,111,44,115,116,97,99,114,97,71,58,111,66,72,32,62,67,116,101,111,62,112,116,43,0,100,105,99,115,101,72,58,115,111,44,115,116,97,99,114,97,71,58,111,66,72,32,62,67,116,101,111,62,67,97,98,99,-92,-96,64,-128,112,116,115,32,114,114,116,101,110,0,100,84,60,115,116,95,112,97,60,115,119,58,116,115,97,42,97,115,58,116,97,71,58,105,65,97,110,99,115,100,108,97,60,115,119,58,109,110,116,32,62,114,32,58,115,108,32,110,111,111,58,101,44,115,116,97,99,114,114,32,58,105,108,32,110,111,111,58,101,99,116,97,115,58,116,97,71,58,105,65,97,110,99,115,100,108,97,60,115,119,58,109,110,116,32,62,62,32,99,116,101,111,111,97,32,0,100,105,99,115,101,65,58,105,105,42,97,115,58,111,111,108,32,110,110,58,109,111,62,58,110,105,97,60,58,114,114,0,100,105,99,115,101,65,58,105,105,42,97,115,58,111,111,108,32,110,110,58,109,111,62,58,110,105,97,60,58,114,114,0,100,84,60,115,116,95,112,97,60,115,119,58,116,115,97,42,97,115,58,116,97,71,58,105,65,97,110,99,115,100,108,97,60,115,119,58,109,110,116,32,62,114,32,58,115,108,32,110,111,111,58,101,44,115,116,97,99,114,114,32,58,105,108,32,110,111,111,58,101,99,116,97,115,58,116,97,71,58,105,65,97,110,99,115,100,108,97,60,115,119,58,109,110,116,32,62,62,32,99,116,101,111,111,97,32,0,100,84,60,115,116,95,112,97,60,115,119,58,116,115,97,42,97,115,58,116,97,71,58,105,65,97,110,99,115,100,108,97,60,115,119,58,109,110,116,32,62,114,32,58,115,108,32,110,111,111,58,101,44,115,116,97,99,114,114,32,58,105,108,32,110,111,111,58,101,99,116,97,115,58,116,97,71,58,105,65,97,110,99,115,100,108,97,60,115,119,58,109,110,116,32,62,62,32,99,116,101,111,95,0,100,105,99,115,101,65,58,105,105,42,97,115,58,111,111,108,32,110,110,58,109,111,62,58,110,105,97,60,58,109,0,100,84,60,115,116,95,112,97,60,115,119,58,116,115,97,42,97,115,58,116,97,71,58,105,65,97,110,99,115,100,108,97,60,115,119,58,109,110,116,32 }; From 616192f80adae9b2e7ae80afed9fecb89082a831 Mon Sep 17 00:00:00 2001 From: erwincoumans Date: Thu, 20 Sep 2018 09:07:47 -0700 Subject: [PATCH 4/4] use grpc port -1 by default in PyBullet. add grpcClient.py and grpcServer.py --- examples/SharedMemory/PhysicsClientGRPC.cpp | 6 ++++- examples/SharedMemory/grpc/main.cpp | 6 ++++- examples/pybullet/examples/grpcClient.py | 19 ++++++++++++++ examples/pybullet/examples/grpcServer.py | 29 +++++++++++++++++++++ examples/pybullet/pybullet.c | 4 ++- 5 files changed, 61 insertions(+), 3 deletions(-) create mode 100644 examples/pybullet/examples/grpcClient.py create mode 100644 examples/pybullet/examples/grpcServer.py diff --git a/examples/SharedMemory/PhysicsClientGRPC.cpp b/examples/SharedMemory/PhysicsClientGRPC.cpp index fe32bd5d1..5b788ecbb 100644 --- a/examples/SharedMemory/PhysicsClientGRPC.cpp +++ b/examples/SharedMemory/PhysicsClientGRPC.cpp @@ -67,7 +67,11 @@ struct GRPCNetworkedInternalData { if (m_isConnected) return true; - std::string hostport = m_hostName + ':' + std::to_string(m_port); + std::string hostport = m_hostName; + if (m_port >= 0) + { + hostport += ':' + std::to_string(m_port); + } m_grpcChannel = grpc::CreateChannel( hostport, grpc::InsecureChannelCredentials()); diff --git a/examples/SharedMemory/grpc/main.cpp b/examples/SharedMemory/grpc/main.cpp index 5560abd55..da9bc2d30 100644 --- a/examples/SharedMemory/grpc/main.cpp +++ b/examples/SharedMemory/grpc/main.cpp @@ -255,7 +255,11 @@ int main(int argc, char** argv) int port = 6667; parseArgs.GetCmdLineArgument("port", port); std::string hostName = "localhost"; - std::string hostNamePort = hostName + ":" + std::to_string(port); + std::string hostNamePort = hostName; + if (port>=0) + { + hostNamePort += ":" + std::to_string(port); + } gVerboseNetworkMessagesServer = parseArgs.CheckCmdLineFlag("verbose"); diff --git a/examples/pybullet/examples/grpcClient.py b/examples/pybullet/examples/grpcClient.py new file mode 100644 index 000000000..cc44d06f1 --- /dev/null +++ b/examples/pybullet/examples/grpcClient.py @@ -0,0 +1,19 @@ + +import pybullet as p + +usePort = True + +if (usePort): + id = p.connect(p.GRPC,"localhost:12345") +else: + id = p.connect(p.GRPC,"localhost") +print("id=",id) + +if (id<0): + print("Cannot connect to GRPC server") + exit(0) + +print ("Connected to GRPC") +r2d2 = p.loadURDF("r2d2.urdf") +print("numJoints = ", p.getNumJoints(r2d2)) + diff --git a/examples/pybullet/examples/grpcServer.py b/examples/pybullet/examples/grpcServer.py new file mode 100644 index 000000000..a1960714f --- /dev/null +++ b/examples/pybullet/examples/grpcServer.py @@ -0,0 +1,29 @@ +import pybullet as p +import time + +useDirect = False +usePort = True + +p.connect(p.GUI) +id = p.loadPlugin("grpcPlugin") +#dynamically loading the plugin +#id = p.loadPlugin("E:/develop/bullet3/bin/pybullet_grpcPlugin_vs2010_x64_debug.dll", postFix="_grpcPlugin") + +#start the GRPC server at hostname, port +if (id<0): + print("Cannot load grpcPlugin") + exit(0) + +if usePort: + p.executePluginCommand(id, "localhost:12345") +else: + p.executePluginCommand(id, "localhost") + +while p.isConnected(): + if (useDirect): + #Only in DIRECT mode, since there is no 'ping' you need to manually call to handle RCPs: + numRPC = 10 + p.executePluginCommand(id, intArgs=[numRPC]) + else: + dt = 1./240. + time.sleep(dt) diff --git a/examples/pybullet/pybullet.c b/examples/pybullet/pybullet.c index 5a500c4ee..d3ca5fb96 100644 --- a/examples/pybullet/pybullet.c +++ b/examples/pybullet/pybullet.c @@ -330,6 +330,7 @@ static PyObject* pybullet_connectPhysicsServer(PyObject* self, PyObject* args, P int key = SHARED_MEMORY_KEY; int udpPort = 1234; int tcpPort = 6667; + int grpcPort = -1; int argc = 0; char** argv=0; @@ -352,6 +353,7 @@ static PyObject* pybullet_connectPhysicsServer(PyObject* self, PyObject* args, P { udpPort = port; tcpPort = port; + grpcPort = port; } } } @@ -437,7 +439,7 @@ static PyObject* pybullet_connectPhysicsServer(PyObject* self, PyObject* args, P case eCONNECT_GRPC: { #ifdef BT_ENABLE_GRPC - sm = b3ConnectPhysicsGRPC(hostName, tcpPort); + sm = b3ConnectPhysicsGRPC(hostName, grpcPort); #else PyErr_SetString(SpamError, "GRPC is not enabled in this pybullet build"); #endif