PyBullet: Connect client to multiple physics servers via Shared Memory

Official Python bindings with a focus on reinforcement learning and robotics.
Yogha001
Posts: 3
Joined: Tue Jan 31, 2023 4:16 pm

PyBullet: Connect client to multiple physics servers via Shared Memory

Post by Yogha001 »

Hi there!

I'm trying to find a way to turn on/off gravity forces only for specific objects using pyBullet.

In the Quickstart Guide (page 87) it is said, that there might be a way by running a second physics server:
Question:
How to turn off gravity only for some parts of a robot (for example the arm)?

Answer:
At the moment this is not exposed, so you would need to either turn of gravity acceleration for all objects, and manually apply gravity for the objects that need it. Or you can actively compute gravity compensation forces, like happens on a real robot. Since Bullet has a full constraint system, it would be trivial to compute those anti-gravity forces: You could run a second simulation (PyBullet lets you connect to multiple physics servers) and position the robot under gravity, set joint position control to keep the position as desired, and gather those 'anti-gravity' forces. Then apply those in the main simulation.
As a first step i want to connect a client with two servers by using the SHARED_MEMORY mode.
However, I only managed it to connect my client with one server like this:

Server:

Code: Select all

p.connect(p.GUI_SERVER)
Client:

Code: Select all

p.connect(p.SHARED_MEMORY)
Now, I want to run a second server and connect to it via Shared Memory. In the documentation on page 5 it says, that I need to specify a key for each server:
in SHARED_MEMORY mode, optional shared memory key. When starting ExampleBrowser or SharedMemoryPhysics_* you can use optional command-line --shared_memory_key to set the key. This allows to run multiple servers on the same machine.
So how exactly do I have to implement this? Is there any example script which does exactly that?

I would be very grateful, if someone could point me in the right direction!

Thank you,
Christoph