Your Own Tasks and Embodiments#
The environment on the previous page uses its own task, embodiment and
episode recorder terms. This page explains them. All three are defined in the same file,
isaaclab_arena_examples/external_environments/franka_table_environment.py.
Defining a Custom Task#
To define a task, subclass TaskBase and implement its required methods. The example task counts
every episode that runs a fixed number of steps as a success, so it only shows how a task is defined.
get_termination_cfg() sets its success check and its time limit. The factory passes the task to
IsaacLabArenaEnvironment, as Putting It All Together shows.
@register_task
class SuccessAfterNStepsTask(TaskBase):
"""Minimal task: the episode succeeds after a fixed number of steps."""
def __init__(
self, num_steps_for_success: int = 50, episode_length_s: float = 10.0, task_description: str | None = None
):
super().__init__(
episode_length_s=episode_length_s,
task_description=task_description or f"Succeed after {num_steps_for_success} steps",
)
self.num_steps_for_success = num_steps_for_success
def get_scene_cfg(self):
return None
def get_termination_cfg(self) -> TaskTerminationCfg:
return TaskTerminationCfg(
timeout_s=self.episode_length_s,
success=[
CompletionCriteria(
name="reach_step_count",
predicate_sequence=[self.has_reached_step_count],
)
],
)
def has_reached_step_count(self, env):
"""Check whether each episode has reached the requested number of steps."""
return env.episode_length_buf >= self.num_steps_for_success
def get_events_cfg(self):
return None
def get_mimic_env_cfg(self, arm_mode: ArmMode):
raise NotImplementedError
def get_viewer_cfg(self) -> ViewerCfg:
return ViewerCfg(eye=(-1.5, -1.5, 1.5), lookat=(0.0, 0.0, 0.5))
When the module is imported, @register_task adds the class to the TaskRegistry under its class
name. An environment YAML can then name it as a subtask kind, as The Same Environment in YAML
shows. The YAML passes its task description to the constructor as task_description, so a task
used from YAML must accept that argument.
Defining a Custom Embodiment#
To define an embodiment, subclass EmbodimentBase and implement its required methods. The example
keeps it simple: it subclasses FrankaIKEmbodiment and halves the joint PD gains, which makes the
arm more compliant:
@register_asset
class SoftFrankaIKEmbodiment(FrankaIKEmbodiment):
"""Franka IK embodiment with halved joint PD gains for more compliant behaviour.
The standard ``franka_ik`` uses stiffness 400 / damping 80 on its shoulder
and forearm actuator groups. This variant halves both, which is useful for
contact-rich or force-sensitive tasks.
"""
registry_name = "franka_ik_soft"
def __init__(self, **kwargs):
super().__init__(**kwargs)
for actuator_name in ("panda_shoulder", "panda_forearm"):
actuator = self.scene_config.robot.actuators[actuator_name]
actuator.stiffness = 200.0
actuator.damping = 40.0
When the module is imported, @register_asset adds the class to the AssetRegistry under its
registry_name, "franka_ik_soft". The factory then gets it by that name, like any built-in
embodiment.
Recording a Custom Value per Episode#
The example records two values for each episode with two episode recorder terms. The factory passes them
to IsaacLabArenaEnvironment as episode_recorder_terms, as Putting It All Together shows:
object_final_heightuses the functionrecord_object_final_height, which reads the object’s height when the episode ends.object_peak_speeduses Arena’sObjectPeakSpeed, anEpisodeRecorderTermclass for a value that builds up during the episode.
def record_object_final_height(env, env_id: int, object_name: str) -> float:
"""Records the height [m] of an object when the episode ends."""
return float(env.arena_world.get_pose_w(object_name)[env_id, 2])
Each episode’s line in the episode results holds both values under these names, for example
"object_final_height": 0.12, "object_peak_speed": 0.83.
Registering Your Package as an Arena Plugin#
To make your custom components available to every Arena runner and tool, declare the modules that
register them as entry points in the isaaclab_arena.plugins group of your package’s
pyproject.toml:
[project.entry-points."isaaclab_arena.plugins"]
my_package_franka_table = "my_package.isaaclab_arena_environments.franka_table_environment"
Declare the entry points before you install the package with install_package.sh, as shown in
Installing IsaacLab-Arena in Your Repository. Arena reads plugins from the metadata that the install writes, so
putting your source folder on PYTHONPATH is not enough. If you change the entry points later,
rebuild the image.
Registration decorators such as @register_asset run only when their module is imported. Arena’s
runners and tools (experiment_runner.py, policy_runner.py, environment_runner.py, and
the review GUI) never import your package on their own. Without a plugin, an environment YAML naming
franka_ik_soft fails with Unknown asset registry_name, and an Experiment cannot select an
environment that your package registers.
Arena loads every installed plugin once per process, the first time it looks up a registered component, such as an asset, task, relation, policy, or environment. It imports the plugin modules in entry-point name order, after its own built-in components. Each entry point must name a module; an entry point that names a function or another module attribute is rejected.
Keep these rules in mind when writing a plugin:
Plugins can load before Isaac Sim starts, so a plugin module must import without a running simulation app, just like Arena’s own asset modules.
If a plugin registers a name that is already taken, Arena keeps the first registration and prints a warning.
If a plugin fails to load, Arena stops with an error whose note names the plugin. To fix this, repair or uninstall the broken package.
Putting It All Together#
The factory’s build(cfg) gets the embodiment by its name, "franka_ik_soft", and ends by passing
the task and the two episode recorder terms to IsaacLabArenaEnvironment:
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}
),
},
)
@register_environment registers the factory under its name, franka_table. With your
package installed as a plugin, an Experiment selects the environment by that name, and the config
fields set its values. For example, to run it with a zero-action policy, without an Experiment file:
python isaaclab_arena/evaluation/experiment_runner.py \
runs.franka_table.environment.type=franka_table \
runs.franka_table.environment.object=tomato_soup_can \
runs.franka_table.policy.type=zero_action \
runs.franka_table.rollout_limit.num_steps=50
The Same Environment in YAML#
An environment YAML names the plugin’s components like built-in ones. This YAML,
isaaclab_arena_examples/external_environments/franka_table.yaml, describes the same scene and
task. It has no episode recorder terms, because they have no YAML form:
env_name: franka_table
embodiment:
id: robot
registry_name: franka_ik_soft
background:
id: maple_table_robolab
registry_name: maple_table_robolab
objects:
- id: pick_up_object
registry_name: cracker_box
- id: light
registry_name: light
object_references:
- id: table
parent_id: maple_table_robolab
prim_path: '{ENV_REGEX_NS}/maple_table_robolab/table'
object_type: rigid
relations:
- kind: is_anchor
subject: table
- kind: 'on'
subject: pick_up_object
reference: table
task:
composition: atomic
description: Succeed after 50 steps
subtasks:
- kind: SuccessAfterNStepsTask
params:
num_steps_for_success: 50
episode_length_s: 10.0
cli_override_specs:
- arg: object
target_node_id: pick_up_object
cli_override_specs declares an object value that replaces the object’s registry_name,
like the object field of the Python config. An Experiment selects the YAML by its path, relative
to the working directory. For a copy at my_package/franka_table.yaml:
python isaaclab_arena/evaluation/experiment_runner.py \
runs.franka_table_yaml.environment.type=my_package/franka_table.yaml \
runs.franka_table_yaml.environment.object=tomato_soup_can \
runs.franka_table_yaml.policy.type=zero_action \
runs.franka_table_yaml.rollout_limit.num_steps=50