Part 8.3 – Getting Started With Pybullet

Pybullet is an open-source physics engine simulator for robotics. We will briefly explain how to use it.

Simple robot simulation

Please follow the installation instructions here. Let’s check that everything was installed correctly. Run this code, say hi to Pybullet and play with R2D2.

The Pybullet commands are described in the documentation. The robot’s geometry and mechanics are described in XML files and can be loaded in Pybullet. The XML file format compatible with Pybullet are:

  • URDF: the most common format. Many robots have public URDF file. URDF files are used by the ROS project (Robot Operating System), see here.
  • SDF: this file format was developed as part of the Gazebo robot simulator, see here.
  • MJCF: file format developed for the MuJoCo physics engine.

Many of these files are already included in Pybullet, see here. Let’s see another example where we import a Kuka robot. First, let’s download the Kuka urdf files from the ROS Github.

$ git clone

Then run this code:

The Pybullet – Gym interface

Ok so we know how to import robots in Pybullet. Now, how do we train them? We need a way to interact with the simulation using the Gym interface. Fortunately, Pybullet interfaces very nicely with Gym using its pybullet_envs library. For example, you can import the cart-pole environment this way:

This image has an empty alt attribute; its file name is Selection_016.png

You can also enjoy pre-trained environments here. For example, see this Kuka grasping robot following a continuous downward policy using the following command.

$ python -m pybullet_envs.baselines.enjoy_kuka_diverse_object_grasping

However, the environments found in pybullet_envs are not exactly the same as those offered by MuJoCo. Fortunately, the Pybullet-gym library has just re-implemented most MuJoCo and Roboschool environments in Pybullet and they seamlessly integrate with OpenAI Gym. For example, the MuJoCo reacher environment can be loaded using this code:

This image has an empty alt attribute; its file name is Selection_017.png