Undesired behaviour when dropping cube

Official Python bindings with a focus on reinforcement learning and robotics.
Post Reply
robotguy
Posts: 2
Joined: Mon Feb 18, 2019 1:05 pm

Undesired behaviour when dropping cube

Post by robotguy »

Hello,

I recently started using PyBullet and want to thank you for this awesome piece of software. However, during some trials I found some weird behavior when dropping a simple cube from 100 meters: The velocity seems to stall asymptotically. This probably has to do with some stabilization of the simulation, but I could not find any information on this in the documentation. Could you give me a hint please? I attached the code and a plot.

Thank you in advance.

Best regards
Image

Code: Select all

import pybullet as p
import pybullet_data
import numpy as np
import matplotlib.pyplot as plt

timestep = 1 / 240
g = -10

physicsClient = p.connect(p.DIRECT)
p.setAdditionalSearchPath(pybullet_data.getDataPath())
p.setGravity(0, 0, g)
planeId = p.loadURDF("plane.urdf")
cubeStartPos = [0, 0, 100]
cubeStartOrientation = p.getQuaternionFromEuler([0, 0, 0])
boxId = p.loadURDF("cube.urdf", cubeStartPos, cubeStartOrientation)

p.setTimeStep(timestep)
simulated_velocity_list = []
physical_velocity_list = []
time = []
i = 0
while True:
    time.append(i * timestep)
    physical_velocity_list.append(g * i * timestep)
    simulated_velocity_list.append(p.getBaseVelocity(boxId)[0][2])
    if (p.getBasePositionAndOrientation(boxId)[0][2] <= 0.05):
        print(i * timestep)
        break
    p.stepSimulation()
    i += 1

plt.plot(time, simulated_velocity_list)
plt.plot(time, physical_velocity_list)
plt.grid()
plt.xlabel("Time [s]")
plt.ylabel("Velocity [mps]")
plt.legend(["PyBullet", "v=a t"])
plt.show()
p.disconnect()
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA
Contact:

Re: Undesired behaviour when dropping cube

Post by Erwin Coumans »

Yes, by default PyBullet adds some damping for stability. You can disable it like this:
p.changeDynamics(boxId,-1,linearDamping=0, angularDamping=0)

In addition, there is a maximum velocity of 100 units (m/s for linear velocity and radians/sec for angular velocity).
If this is an issue, you can compile PyBullet from source, and increase m_maxCoordinateVelocity in Bullet/src/BulletDynamics/Featherstone/btMultiBody.cpp
Post Reply