Skip to content

Adds time-based mdp (observation) functions. #2332

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
1 change: 1 addition & 0 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ Guidelines for modifications:
* Ryley McCarroll
* Shafeef Omar
* Shundo Kishi
* Stefan Van de Mosselaer
* Stephan Pleines
* Tyler Lum
* Victor Khaustov
Expand Down
2 changes: 1 addition & 1 deletion source/isaaclab/config/extension.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]

# Note: Semantic Versioning is used: https://semver.org/
version = "0.36.6"
version = "0.36.7"

# Description
title = "Isaac Lab framework for Robot Learning"
Expand Down
15 changes: 15 additions & 0 deletions source/isaaclab/docs/CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,21 @@
Changelog
---------

0.36.7 (2025-04-17)
~~~~~~~~~~~~~~~~~~~

Added
^^^^^

* Added initialization of ``episode_length_buf`` in :meth:`load_managers()` of :class:`~isaaclab.envs.ManagerBasedRLEnv`
to make it available for use in mdp functions. Note: existing initialization in :meth:`__init__` left in place in case
it is needed for other use cases.
* Added :attr:`~isaaclab.envs.ManagerBasedRLEnv.curr_episode_length` to :class:`~isaaclab.envs.ManagerBasedRLEnv` which
returns reshaped ``episode_length_buf`` so it is visible as an attribute in the documentation.
* Added time observation functions to ~isaaclab.envs.mdp.observations module,
:func:`~isaaclab.envs.mdp.observations.current_time_s` and :func:`~isaaclab.envs.mdp.observations.remaining_time_s`.


0.36.6 (2025-04-09)
~~~~~~~~~~~~~~~~~~~

Expand Down
7 changes: 5 additions & 2 deletions source/isaaclab/isaaclab/envs/manager_based_rl_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,16 @@ def __init__(self, cfg: ManagerBasedRLEnvCfg, render_mode: str | None = None, **
# -- counter for curriculum
self.common_step_counter = 0

# initialize the episode length buffer BEFORE loading the managers so it is available for use by mdp functions.
self.cfg = cfg
self.episode_length_buf = torch.zeros(self.cfg.scene.num_envs, device=self.cfg.sim.device, dtype=torch.long)

# initialize the base class to setup the scene.
super().__init__(cfg=cfg)
# store the render mode
self.render_mode = render_mode

# initialize data and constants
# -- init buffers
self.episode_length_buf = torch.zeros(self.num_envs, device=self.device, dtype=torch.long)
# -- set the framerate of the gym video recorder wrapper so that the playback speed of the produced video matches the simulation
self.metadata["render_fps"] = 1 / self.step_dt

Expand All @@ -107,6 +109,7 @@ def max_episode_length(self) -> int:
"""

def load_managers(self):

# note: this order is important since observation manager needs to know the command and action managers
# and the reward manager needs to know the termination manager
# -- command manager
Expand Down
15 changes: 15 additions & 0 deletions source/isaaclab/isaaclab/envs/mdp/observations.py
Original file line number Diff line number Diff line change
Expand Up @@ -529,3 +529,18 @@ def last_action(env: ManagerBasedEnv, action_name: str | None = None) -> torch.T
def generated_commands(env: ManagerBasedRLEnv, command_name: str) -> torch.Tensor:
"""The generated command from command term in the command manager with the given name."""
return env.command_manager.get_command(command_name)


"""
Time.
"""


def current_time_s(env: ManagerBasedRLEnv) -> torch.Tensor:
"""The current time in the episode (in seconds)."""
return env.episode_length_buf.unsqueeze(1) * env.step_dt


def remaining_time_s(env: ManagerBasedRLEnv) -> torch.Tensor:
"""The maximum time remaining in the episode (in seconds)."""
return env.max_episode_length_s - env.episode_length_buf.unsqueeze(1) * env.step_dt