Visualizing multiple bullet server instances using PyBullet

Official Python bindings with a focus on reinforcement learning and robotics.
Post Reply
mkale96
Posts: 1
Joined: Mon Jun 27, 2022 12:56 pm

Visualizing multiple bullet server instances using PyBullet

Post by mkale96 »

Hi, I'd like to spawn multiple instances of the physics server, send them some geometry, start them and then combine their output in a single rendering window. Note that the geometry on "worker" servers might not be the same.
I'm trying to repurpose the existing 3D rendering infrastructure that pyBullet provides. Here's what I'm trying to do so far:

I'm currently looking into the saveBullet() and restoreState() methods to do this (spawning only 1 worker server for simplicity):

Code: Select all

import pybullet_utils.bullet_client as bc
import pybullet as p
import pybullet_data
import time
STATE_FILE = 'state.bullet'

def setupServer(handle):
    handle.setAdditionalSearchPath(pybullet_data.getDataPath())
    handle.setPhysicsEngineParameter(deterministicOverlappingPairs=1)

    startOrientation = handle.getQuaternionFromEuler([0, 0, 0])
    handle.loadURDF("r2d2.urdf", [0, 0, 1], startOrientation)
    handle.loadURDF("plane.urdf")
    handle.setGravity(0, 0, -10)

p1 = bc.BulletClient(connection_mode=p.DIRECT)
setupServer(p1)

pgui = bc.BulletClient(connection_mode=p.GUI)
#setupServer(pgui)

while 1:
    p1.stepSimulation()

    p1.saveBullet(STATE_FILE)
    pgui.restoreState(fileName=STATE_FILE)

    pgui.stepSimulation()

    time.sleep(1. / 240.)
Which gives me the error:

Code: Select all

Traceback (most recent call last):
  File "C:\Users\m84241864\Desktop\projects\bullet\python\multi_server.py", line 43, in <module>
    pgui.restoreState(fileName=STATE_FILE)
pybullet.error: Couldn't restore state.
If I load the same geometry as p1 in pgui, I don't get the error. However, I do want p1, p2... to have different geometries and pgui to render all of them. How should I do this? If this is not supported OOTB, I don't mind changing the C++ source code. Some pointers on where to start would be very helpful. Thanks!
Post Reply