mirror of
https://github.com/bulletphysics/bullet3.git
synced 2026-10-03 15:35:22 +00:00
Merge pull request #2679 from erwincoumans/master
Embed TCP remote graphics server in PyBullet (enable WFH), fixes for compilation on Visual C++ for Python 9.0
This commit is contained in:
15
examples/pybullet/examples/graphicsClient.py
Normal file
15
examples/pybullet/examples/graphicsClient.py
Normal file
@@ -0,0 +1,15 @@
|
||||
import pybullet as p
|
||||
import time
|
||||
|
||||
p.connect(p.GRAPHICS_SERVER_TCP)
|
||||
import pybullet_data as pd
|
||||
p.setAdditionalSearchPath(pd.getDataPath())
|
||||
|
||||
p.loadURDF("plane.urdf")
|
||||
p.loadURDF("r2d2.urdf", [0,0,3])
|
||||
p.setGravity(0,0,-10)
|
||||
gravId = p.addUserDebugParameter("gravity",0,10,0)
|
||||
while p.isConnected():
|
||||
p.stepSimulation()
|
||||
|
||||
|
||||
8
examples/pybullet/examples/graphicsServer.py
Normal file
8
examples/pybullet/examples/graphicsServer.py
Normal file
@@ -0,0 +1,8 @@
|
||||
import pybullet as p
|
||||
import time
|
||||
|
||||
p.connect(p.GRAPHICS_SERVER)
|
||||
#p.connect(p.GRAPHICS_SERVER_MAIN_THREAD)
|
||||
while p.isConnected():
|
||||
p.stepSimulation()
|
||||
time.sleep(1./240.)
|
||||
@@ -0,0 +1 @@
|
||||
|
||||
1
examples/pybullet/gym/pybullet_robots/xarm/__init__.py
Normal file
1
examples/pybullet/gym/pybullet_robots/xarm/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
|
||||
13
examples/pybullet/gym/pybullet_utils/graphicsClient.py
Normal file
13
examples/pybullet/gym/pybullet_utils/graphicsClient.py
Normal file
@@ -0,0 +1,13 @@
|
||||
import pybullet as p
|
||||
import time
|
||||
|
||||
p.connect(p.GRAPHICS_SERVER_TCP)
|
||||
import pybullet_data as pd
|
||||
p.setAdditionalSearchPath(pd.getDataPath())
|
||||
|
||||
p.loadURDF("plane.urdf")
|
||||
p.loadURDF("r2d2.urdf", [0,0,3])
|
||||
p.setGravity(0,0,-10)
|
||||
while p.isConnected():
|
||||
p.stepSimulation()
|
||||
|
||||
7
examples/pybullet/gym/pybullet_utils/graphicsServer.py
Normal file
7
examples/pybullet/gym/pybullet_utils/graphicsServer.py
Normal file
@@ -0,0 +1,7 @@
|
||||
import pybullet as p
|
||||
import time
|
||||
|
||||
p.connect(p.GRAPHICS_SERVER)
|
||||
print("started graphics server")
|
||||
while p.isConnected():
|
||||
time.sleep(1./240.)
|
||||
@@ -124,14 +124,15 @@ if not _OPTIONS["no-enet"] then
|
||||
"../../examples/SharedMemory/PhysicsServerExample.cpp",
|
||||
"../../examples/SharedMemory/PhysicsServerExampleBullet2.cpp",
|
||||
"../SharedMemory/GraphicsClientExample.cpp",
|
||||
"../SharedMemory/GraphicsClientExample.h",
|
||||
"../SharedMemory/GraphicsServerExample.cpp",
|
||||
"../SharedMemory/GraphicsServerExample.h",
|
||||
"../SharedMemory/GraphicsSharedMemoryBlock.h",
|
||||
"../SharedMemory/GraphicsSharedMemoryCommands.h",
|
||||
"../SharedMemory/GraphicsSharedMemoryPublic.h",
|
||||
"../SharedMemory/RemoteGUIHelper.cpp",
|
||||
"../SharedMemory/RemoteGUIHelper.h",
|
||||
"../SharedMemory/GraphicsClientExample.h",
|
||||
"../SharedMemory/GraphicsServerExample.cpp",
|
||||
"../SharedMemory/GraphicsServerExample.h",
|
||||
"../SharedMemory/GraphicsSharedMemoryBlock.h",
|
||||
"../SharedMemory/GraphicsSharedMemoryCommands.h",
|
||||
"../SharedMemory/GraphicsSharedMemoryPublic.h",
|
||||
"../SharedMemory/RemoteGUIHelper.cpp",
|
||||
"../SharedMemory/RemoteGUIHelperTCP.cpp",
|
||||
"../SharedMemory/RemoteGUIHelper.h",
|
||||
"../../examples/SharedMemory/SharedMemoryInProcessPhysicsC_API.cpp",
|
||||
"../../examples/SharedMemory/PhysicsServerSharedMemory.cpp",
|
||||
"../../examples/SharedMemory/PhysicsServerSharedMemory.h",
|
||||
|
||||
@@ -438,6 +438,7 @@ static PyObject* pybullet_connectPhysicsServer(PyObject* self, PyObject* args, P
|
||||
}
|
||||
switch (method)
|
||||
{
|
||||
|
||||
case eCONNECT_GUI:
|
||||
{
|
||||
#ifdef __APPLE__
|
||||
@@ -458,6 +459,20 @@ static PyObject* pybullet_connectPhysicsServer(PyObject* self, PyObject* args, P
|
||||
sm = b3CreateInProcessPhysicsServerAndConnectMainThreadSharedMemory(argc, argv);
|
||||
#else
|
||||
sm = b3CreateInProcessPhysicsServerAndConnectSharedMemory(argc, argv);
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
case eCONNECT_GRAPHICS_SERVER_MAIN_THREAD:
|
||||
{
|
||||
sm = b3CreateInProcessGraphicsServerAndConnectMainThreadSharedMemory(tcpPort);
|
||||
break;
|
||||
}
|
||||
case eCONNECT_GRAPHICS_SERVER:
|
||||
{
|
||||
#ifdef __APPLE__
|
||||
sm = b3CreateInProcessGraphicsServerAndConnectMainThreadSharedMemory(tcpPort);
|
||||
#else
|
||||
sm = b3CreateInProcessGraphicsServerAndConnectSharedMemory(tcpPort);
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
@@ -473,6 +488,17 @@ static PyObject* pybullet_connectPhysicsServer(PyObject* self, PyObject* args, P
|
||||
break;
|
||||
}
|
||||
|
||||
case eCONNECT_GRAPHICS_SERVER_TCP:
|
||||
{
|
||||
#ifdef BT_ENABLE_CLSOCKET
|
||||
sm = b3CreateInProcessPhysicsServerFromExistingExampleBrowserAndConnectTCP(hostName, tcpPort);
|
||||
#else
|
||||
PyErr_SetString(SpamError, "TCP is not enabled in this pybullet build");
|
||||
return NULL;
|
||||
#endif//BT_ENABLE_CLSOCKET
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
case eCONNECT_DIRECT:
|
||||
{
|
||||
@@ -576,34 +602,37 @@ static PyObject* pybullet_connectPhysicsServer(PyObject* self, PyObject* args, P
|
||||
sPhysicsClientsGUI[freeIndex] = method;
|
||||
sNumPhysicsClients++;
|
||||
|
||||
command = b3InitSyncBodyInfoCommand(sm);
|
||||
statusHandle = b3SubmitClientCommandAndWaitStatus(sm, command);
|
||||
statusType = b3GetStatusType(statusHandle);
|
||||
|
||||
if (statusType != CMD_SYNC_BODY_INFO_COMPLETED)
|
||||
if (method != eCONNECT_GRAPHICS_SERVER && method != eCONNECT_GRAPHICS_SERVER_MAIN_THREAD)
|
||||
{
|
||||
printf("Connection terminated, couldn't get body info\n");
|
||||
b3DisconnectSharedMemory(sm);
|
||||
sm = 0;
|
||||
sPhysicsClients1[freeIndex] = 0;
|
||||
sPhysicsClientsGUI[freeIndex] = 0;
|
||||
sNumPhysicsClients++;
|
||||
return PyInt_FromLong(-1);
|
||||
}
|
||||
command = b3InitSyncBodyInfoCommand(sm);
|
||||
statusHandle = b3SubmitClientCommandAndWaitStatus(sm, command);
|
||||
statusType = b3GetStatusType(statusHandle);
|
||||
|
||||
command = b3InitSyncUserDataCommand(sm);
|
||||
statusHandle = b3SubmitClientCommandAndWaitStatus(sm, command);
|
||||
statusType = b3GetStatusType(statusHandle);
|
||||
if (statusType != CMD_SYNC_BODY_INFO_COMPLETED)
|
||||
{
|
||||
printf("Connection terminated, couldn't get body info\n");
|
||||
b3DisconnectSharedMemory(sm);
|
||||
sm = 0;
|
||||
sPhysicsClients1[freeIndex] = 0;
|
||||
sPhysicsClientsGUI[freeIndex] = 0;
|
||||
sNumPhysicsClients++;
|
||||
return PyInt_FromLong(-1);
|
||||
}
|
||||
|
||||
if (statusType != CMD_SYNC_USER_DATA_COMPLETED)
|
||||
{
|
||||
printf("Connection terminated, couldn't get user data\n");
|
||||
b3DisconnectSharedMemory(sm);
|
||||
sm = 0;
|
||||
sPhysicsClients1[freeIndex] = 0;
|
||||
sPhysicsClientsGUI[freeIndex] = 0;
|
||||
sNumPhysicsClients++;
|
||||
return PyInt_FromLong(-1);
|
||||
command = b3InitSyncUserDataCommand(sm);
|
||||
statusHandle = b3SubmitClientCommandAndWaitStatus(sm, command);
|
||||
statusType = b3GetStatusType(statusHandle);
|
||||
|
||||
if (statusType != CMD_SYNC_USER_DATA_COMPLETED)
|
||||
{
|
||||
printf("Connection terminated, couldn't get user data\n");
|
||||
b3DisconnectSharedMemory(sm);
|
||||
sm = 0;
|
||||
sPhysicsClients1[freeIndex] = 0;
|
||||
sPhysicsClientsGUI[freeIndex] = 0;
|
||||
sNumPhysicsClients++;
|
||||
return PyInt_FromLong(-1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -12568,6 +12597,12 @@ initpybullet(void)
|
||||
PyModule_AddIntConstant(m, "GUI_MAIN_THREAD", eCONNECT_GUI_MAIN_THREAD); // user read
|
||||
PyModule_AddIntConstant(m, "SHARED_MEMORY_SERVER", eCONNECT_SHARED_MEMORY_SERVER); // user read
|
||||
PyModule_AddIntConstant(m, "SHARED_MEMORY_GUI", eCONNECT_SHARED_MEMORY_GUI); // user read
|
||||
PyModule_AddIntConstant(m, "GRAPHICS_CLIENT", eCONNECT_SHARED_MEMORY_GUI); // user read
|
||||
PyModule_AddIntConstant(m, "GRAPHICS_SERVER", eCONNECT_GRAPHICS_SERVER); // user read
|
||||
PyModule_AddIntConstant(m, "GRAPHICS_SERVER_TCP", eCONNECT_GRAPHICS_SERVER_TCP); // user read
|
||||
PyModule_AddIntConstant(m, "GRAPHICS_SERVER_MAIN_THREAD", eCONNECT_GRAPHICS_SERVER_MAIN_THREAD); // user read
|
||||
|
||||
|
||||
|
||||
|
||||
#ifdef BT_ENABLE_DART
|
||||
|
||||
Reference in New Issue
Block a user