bulletphysics / bullet3

Bullet Physics SDK: real-time collision detection and multi-physics simulation for VR, games, visual effects, robotics, machine learning etc.
http://bulletphysics.org
Other
12.37k stars 2.85k forks source link

MJCF file; joints not responding properly #1772

Closed Anmol6 closed 6 years ago

Anmol6 commented 6 years ago

Hi, here's a mjcf file (which is a biped that's constrained to move along the y-z plane) that I'm loading in pybullet with the following code:

import pybullet as p;
import pybullet_data; 
p.connect(p.GUI);
p.setAdditionalSearchPath(pybullet_data.getDataPath()); 
planeID=p.loadURDF("plane.urdf");  
bid=p.loadMJCF('2dbiped.xml');
p.setGravity(0,0 ,-9.8); 
p.setRealTimeSimulation(True)

I noticed the following problems: 1) the torso always wants to stay upright if I try to rotate it 2) when the leg/knees are lifted, they slowly do move down, but not nearly as fast as they should (this can be seen by how much faster the torso falls when it is lifted high)

Any insight into this would be appreciated; thanks!

erwincoumans commented 6 years ago

No idea, we focus primarily on URDF for PyBullet (we just added a rudimentary MJCF loader for some OpenAI Gym models). Attached is a URDF you could try to use as a starting point instead. biped_pybullet_urdf_debug (1).zip

If someone wants to improve the MJCF importer, the source code is here. I don't have the time/bandwidth to work on this, but happy to accept contributions.

Anmol6 commented 6 years ago

@erwincoumans Thanks for that! However, I am not able to add a planar movement constraint using planar joints to the body (I also tried adding just one planar constraint). I get a segmentation fault when I load this file. Any ideas on how to add this constraint?

Anmol6 commented 6 years ago

It might be better if I open a new issue, actually.

erwincoumans commented 6 years ago

We start with a fixed base, then add prismatic and revolute joints. This is how we convert MuJoCo 2D models too (2D hopper and Half Cheetah etc). We don't expose/support planar constraints and spherical joints (none of our robots have them).

jkoendev commented 5 years ago

@erwincoumans i would be very interested in having URDF files of 2D hopper and half cheetah! Are these available somewhere online, or could you provide them to me? Best, Jonas

edit: i just found URDF models here but none of the two mentioned above, could you point me to the location? Thanks!

erwincoumans commented 5 years ago

2d hopper, 2d half cheetah, humanoid, ant etc are all part of PyBullet pybullet_envs and pybullet_data including their Gym environments and pre-trained policies/neural network weights.

MJCF files are here: https://github.com/bulletphysics/bullet3/tree/master/examples/pybullet/gym/pybullet_data/mjcf

pip3 install pybullet
python3 -m pybullet_envs.examples.enjoy_TF_HopperBulletEnv_v0_2017ma
python3 -m pybullet_envs.examples.enjoy_TF_AntBulletEnv_v0_2017may
python3 -m pybullet_envs.examples.enjoy_TF_HumanoidBulletEnv_v0_2017may
python3 -m pybullet_envs.examples.enjoy_TF_HumanoidFlagrunHarderBulletEnv_v1_2017jul

I quickly converted them to urdf, not tested using the mjcf2urdf.py util. 2d_hopper_cheetah.zip

mjcf2urdf.py utility: https://github.com/bulletphysics/bullet3/blob/master/examples/pybullet/gym/pybullet_utils/examples/mjcf2urdf.py

jkoendev commented 5 years ago

this is great, thanks a lot!

erwincoumans commented 5 years ago

Don't expect too much, the mjcf2urdf is a quick rudimentary hack, only covering a small subset of mjcf that was used to get the gym environments working.