-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enable loading models with <freejoint/> attribute (#5)
* Fix set_kinematic(False) * Fix warning * Can load models with freejoints * Refactor * Refactor --------- Co-authored-by: Nikita Chernyadev <[email protected]>
- Loading branch information
Showing
11 changed files
with
127 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<mujoco model="sphere"> | ||
|
||
<worldbody> | ||
<body name="sphere"> | ||
<freejoint/> | ||
<geom type="sphere" size="0.05 0.05 0.05"/> | ||
</body> | ||
</worldbody> | ||
</mujoco> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<mujoco model="sphere_and_box"> | ||
|
||
<worldbody> | ||
<body name="sphere"> | ||
<freejoint/> | ||
<geom type="sphere" size="0.05 0.05 0.05"/> | ||
</body> | ||
<body name="cube"> | ||
<freejoint/> | ||
<geom type="box" size="0.05 0.05 0.05"/> | ||
</body> | ||
</worldbody> | ||
</mujoco> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
from pathlib import Path | ||
|
||
import pytest | ||
|
||
from mojo import Mojo | ||
from mojo.elements import Body | ||
|
||
|
||
@pytest.fixture() | ||
def mojo() -> Mojo: | ||
return Mojo(str(Path(__file__).parents[1] / "world.xml")) | ||
|
||
|
||
def load_model(mojo: Mojo, model_name: str, handle_freejoints: bool) -> Body: | ||
body = mojo.load_model( | ||
str(Path(__file__).parents[1] / "assets" / "models" / model_name), | ||
handle_freejoints=handle_freejoints, | ||
) | ||
_ = mojo.physics | ||
return body | ||
|
||
|
||
def test_load_freejoint(mojo: Mojo): | ||
load_model(mojo, "sphere.xml", True) | ||
|
||
|
||
def test_load_freejoint_raises_by_default(mojo: Mojo): | ||
with pytest.raises(ValueError): | ||
load_model(mojo, "sphere.xml", False) | ||
|
||
|
||
def test_load_freejoint_hierarchy(mojo: Mojo): | ||
sphere_and_box = load_model(mojo, "sphere_and_box.xml", True) | ||
for joint in sphere_and_box.joints: | ||
assert joint.mjcf.tag == "freejoint" | ||
assert joint.mjcf.parent.parent.tag == "worldbody" |