Defining Environments in Your Repository#
You can define an environment in your own package and run it with Arena’s runners, without changing Arena. Like a built-in environment, it has two classes:
A config dataclass that subclasses
ArenaEnvironmentCfg. Its fields are the values a user can set. Each environment needs its own config class.A factory class that subclasses
ArenaEnvironmentFactory[YourCfg], sets a uniquename, and builds the environment inbuild(cfg).
The example isaaclab_arena_examples/external_environments/franka_table_environment.py places one object on a
table. Copy it into your package, for example as
my_package/isaaclab_arena_environments/franka_table_environment.py. Here are its config and factory:
@dataclass
class ExternalFrankaTableEnvironmentCfg(ArenaEnvironmentCfg):
"""Configure the external Franka table environment."""
object: str = "cracker_box"
"""Registered name of the object placed on the table."""
@register_environment
class ExternalFrankaTableEnvironment(ArenaEnvironmentFactory[ExternalFrankaTableEnvironmentCfg]):
name: str = "franka_table"
def build(self, cfg: ExternalFrankaTableEnvironmentCfg) -> IsaacLabArenaEnvironment:
"""Build the environment from its config."""
from isaaclab_arena.assets.object_reference import ObjectReference
from isaaclab_arena.environments.isaaclab_arena_environment import IsaacLabArenaEnvironment
from isaaclab_arena.relations.relations import IsAnchor, On
from isaaclab_arena.scene.scene import Scene
# Grab some assets from the registry. franka_ik_soft is the custom embodiment above.
background = self.asset_registry.get_asset_by_name("maple_table_robolab")()
light = self.asset_registry.get_asset_by_name("light")()
pick_up_object = self.asset_registry.get_asset_by_name(cfg.object)()
embodiment = self.asset_registry.get_asset_by_name("franka_ik_soft")(enable_cameras=cfg.enable_cameras)
# Position the assets
table_reference = ObjectReference(
name="table",
prim_path="{ENV_REGEX_NS}/maple_table_robolab/table",
parent_asset=background,
)
table_reference.add_relation(IsAnchor())
pick_up_object.add_relation(On(table_reference))
# Build the scene and the custom task. The task counts every episode that runs 50 steps as a success,
# so replace it with your own task, or NoTask, when you copy this file.
scene = Scene(assets=[background, table_reference, pick_up_object, light])
task = SuccessAfterNStepsTask(
num_steps_for_success=50,
episode_length_s=10.0,
)
# Create the environment with the custom episode recorder terms
return IsaacLabArenaEnvironment(
name=self.name,
embodiment=embodiment,
scene=scene,
task=task,
episode_recorder_terms={
"object_final_height": EpisodeRecorderTermCfg(
func=record_object_final_height, params={"object_name": pick_up_object.name}
),
"object_peak_speed": EpisodeRecorderTermCfg(
func=ObjectPeakSpeed, params={"object_name": pick_up_object.name}
),
},
)
The factory also uses a custom task, embodiment and episode recorder terms from the same file;
Your Own Tasks and Embodiments explains them. Replace the task in your copy:
SuccessAfterNStepsTask counts every episode that runs 50 steps as a success.
To run it, pass the class path to --external_environment_class_path, then the environment name and
its config fields as flags. For example, with a zero-action policy:
python isaaclab_arena/evaluation/policy_runner.py \
--policy_type zero_action \
--num_steps 50 \
--external_environment_class_path my_package.isaaclab_arena_environments.franka_table_environment.ExternalFrankaTableEnvironment \
franka_table \
--object tomato_soup_can
The class path is the module path and the class name, joined by a dot as in a Python import. For the
class ExternalFrankaTableEnvironment in my_package/isaaclab_arena_environments/franka_table_environment.py, it
is my_package.isaaclab_arena_environments.franka_table_environment.ExternalFrankaTableEnvironment. Python must be
able to import the module, for example because your package is installed or on PYTHONPATH.
@register_environment registers the factory under its name when the module is imported. If you
install your package as an Arena plugin, every runner and Experiment finds
franka_table by name, without --external_environment_class_path.
Note
The example lives in the Arena source tree but is not a built-in environment, so it needs
--external_environment_class_path as well. --viz kit opens a viewer:
python isaaclab_arena/evaluation/policy_runner.py \
--viz kit \
--policy_type zero_action \
--num_steps 50 \
--external_environment_class_path isaaclab_arena_examples.external_environments.franka_table_environment.ExternalFrankaTableEnvironment \
franka_table \
--object tomato_soup_can
The environment looks like this: