Skip to content

Commit

Permalink
v1.6.28; adds floor_z to MujocoScene´; adds add_dt to randomize…
Browse files Browse the repository at this point in the history
…_hz_kwargs` in `RCMG`; adds `jit` as kwarg to `ring.RING`
  • Loading branch information
simon-bachhuber committed Dec 10, 2024
1 parent 3508c48 commit c3ef7f2
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 5 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "imt-ring"
version = "1.6.27"
version = "1.6.28"
authors = [
{ name="Simon Bachhuber", email="[email protected]" },
]
Expand Down
4 changes: 4 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
# Recurrent Inertial Graph-based Estimator (RING)
<img src="https://raw.githubusercontent.com/simon-bachhuber/ring/main/docs/img/coverage_badge.svg" height="20" />

> **ℹ️ Tip:**
>
> Check out my new plug-and-play interface for inertial motion tracking (RING included) [here](https://github.com/simon-bachhuber/imt.git).
## Installation

Supports `Python=3.10/3.11/3.12` (tested).
Expand Down
5 changes: 4 additions & 1 deletion src/ring/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,10 @@ def RING(lam: list[int] | None, Ts: float | None, **kwargs) -> ml.AbstractFilter
add_Ts = True

ringnet = ml.RING(
params=params, lam=None if lam is None else tuple(lam), jit=False, name="RING"
params=params,
lam=None if lam is None else tuple(lam),
jit=config.pop("jit", False),
name="RING",
)
ringnet = ml.base.ScaleX_FilterWrapper(ringnet)
if config["use_lpf"]:
Expand Down
11 changes: 10 additions & 1 deletion src/ring/algorithms/generator/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ def __init__(
) -> None:
"Random Chain Motion Generator"

# add some default values
randomize_hz_kwargs_defaults = dict(add_dt=True)
randomize_hz_kwargs_defaults.update(randomize_hz_kwargs)
randomize_hz_kwargs = randomize_hz_kwargs_defaults

sys, config = utils.to_list(sys), utils.to_list(config)
sys_ml = sys[0] if sys_ml is None else sys_ml

Expand Down Expand Up @@ -409,7 +414,11 @@ def _gen(key: types.PRNGKey):
@jax.vmap
def _vmapped_context(key, q, sys):
x, _ = jax.vmap(kinematics.forward_kinematics_transforms, (None, 0))(sys, q)
X = {"dt": jnp.array(sys.dt)} if randomize_hz else {}
X = (
{"dt": jnp.array(sys.dt)}
if (randomize_hz and randomize_hz_kwargs["add_dt"])
else {}
)
Xy, extras = (X, {}), (key, q, x, sys)
return _finalize_fn(Xy, extras)

Expand Down
11 changes: 9 additions & 2 deletions src/ring/rendering/mujoco_render.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,18 @@

_skybox = """<texture name="skybox" type="skybox" builtin="gradient" rgb1=".4 .6 .8" rgb2="0 0 0" width="800" height="800" mark="random" markrgb="1 1 1"/>""" # noqa: E501
_skybox_white = """<texture name="skybox" type="skybox" builtin="gradient" rgb1="1 1 1" rgb2="1 1 1" width="800" height="800" mark="random" markrgb="1 1 1"/>""" # noqa: E501
_floor = """<geom name="floor" pos="0 0 -0.84" size="0 0 1" type="plane" material="matplane" mass="0"/>""" # noqa: E501


def _floor(floor_z: float) -> str:
return f"""<geom name="floor" pos="0 0 {floor_z}" size="0 0 1" type="plane" material="matplane" mass="0"/>""" # noqa: E501


def _build_model_of_geoms(
geoms: list[base.Geometry],
cameras: dict[int, Sequence[str]],
lights: dict[int, Sequence[str]],
floor: bool,
floor_z: float,
stars: bool,
debug: bool,
) -> mujoco.MjModel:
Expand Down Expand Up @@ -94,7 +98,7 @@ def _build_model_of_geoms(
<camera pos="0 -1 1" name="target" mode="targetbodycom" target="{targetbody}"/>
<camera pos="0 -3 3" name="targetfar" mode="targetbodycom" target="{targetbody}"/>
<camera pos="0 -5 5" name="targetFar" mode="targetbodycom" target="{targetbody}"/>
{_floor if floor else ''}
{_floor(floor_z) if floor else ''}
{inside_worldbody_cameras}
{inside_worldbody_lights}
{inside_worldbody}
Expand Down Expand Up @@ -171,6 +175,7 @@ def __init__(
add_lights: dict[int, str | Sequence[str]] = _default_lights,
show_stars: bool = True,
show_floor: bool = True,
floor_z: float = -0.84,
debug: bool = False,
) -> None:
self.debug = debug
Expand All @@ -185,6 +190,7 @@ def to_list(dic: dict):
self.add_cameras, self.add_lights = to_list(add_cameras), to_list(add_lights)
self.show_stars = show_stars
self.show_floor = show_floor
self.floor_z = floor_z

def init(self, geoms: list[base.Geometry]):
self._parent_ids = list(set([geom.link_idx for geom in geoms]))
Expand All @@ -193,6 +199,7 @@ def init(self, geoms: list[base.Geometry]):
self.add_cameras,
self.add_lights,
floor=self.show_floor,
floor_z=self.floor_z,
stars=self.show_stars,
debug=self.debug,
)
Expand Down

0 comments on commit c3ef7f2

Please sign in to comment.