|
| 1 | +# Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | +from dataclasses import MISSING |
| 16 | + |
| 17 | +import isaaclab.envs.mdp as mdp_isaac_lab |
| 18 | +from isaaclab.managers import EventTermCfg, TerminationTermCfg |
| 19 | +from isaaclab.utils import configclass |
| 20 | + |
| 21 | +from isaac_arena.affordances.pressable import Pressable |
| 22 | +from isaac_arena.metrics.metric_base import MetricBase |
| 23 | +from isaac_arena.metrics.success_rate import SuccessRateMetric |
| 24 | +from isaac_arena.tasks.task_base import TaskBase |
| 25 | + |
| 26 | + |
| 27 | +class PressButtonTask(TaskBase): |
| 28 | + def __init__( |
| 29 | + self, |
| 30 | + pressable_object: Pressable, |
| 31 | + pressedness_threshold: float | None = None, |
| 32 | + reset_pressedness: float | None = None, |
| 33 | + ): |
| 34 | + super().__init__() |
| 35 | + assert isinstance(pressable_object, Pressable), "Pressable object must be an instance of Pressable" |
| 36 | + self.pressable_object = pressable_object |
| 37 | + self.pressedness_threshold = pressedness_threshold |
| 38 | + self.reset_pressedness = reset_pressedness |
| 39 | + |
| 40 | + def get_scene_cfg(self): |
| 41 | + pass |
| 42 | + |
| 43 | + def get_termination_cfg(self): |
| 44 | + params = {} |
| 45 | + if self.pressedness_threshold is not None: |
| 46 | + params["threshold"] = self.pressedness_threshold |
| 47 | + success = TerminationTermCfg( |
| 48 | + func=self.pressable_object.is_pressed, |
| 49 | + params=params, |
| 50 | + ) |
| 51 | + return TerminationsCfg(success=success) |
| 52 | + |
| 53 | + def get_events_cfg(self): |
| 54 | + return PressEventCfg(self.pressable_object, reset_pressedness=self.reset_pressedness) |
| 55 | + |
| 56 | + def get_prompt(self): |
| 57 | + raise NotImplementedError("Function not implemented yet.") |
| 58 | + |
| 59 | + def get_mimic_env_cfg(self, embodiment_name: str): |
| 60 | + raise NotImplementedError("Function not implemented yet.") |
| 61 | + |
| 62 | + def get_metrics(self) -> list[MetricBase]: |
| 63 | + return [ |
| 64 | + SuccessRateMetric(), |
| 65 | + ] |
| 66 | + |
| 67 | + |
| 68 | +@configclass |
| 69 | +class TerminationsCfg: |
| 70 | + """Termination terms for the MDP.""" |
| 71 | + |
| 72 | + time_out: TerminationTermCfg = TerminationTermCfg(func=mdp_isaac_lab.time_out, time_out=False) |
| 73 | + |
| 74 | + # Dependent on the openable object, so this is passed in from the task at |
| 75 | + # construction time. |
| 76 | + success: TerminationTermCfg = MISSING |
| 77 | + |
| 78 | + |
| 79 | +@configclass |
| 80 | +class PressEventCfg: |
| 81 | + """Configuration for Open Door.""" |
| 82 | + |
| 83 | + reset_button_state: EventTermCfg = MISSING |
| 84 | + |
| 85 | + def __init__(self, pressable_object: Pressable, reset_pressedness: float | None): |
| 86 | + assert isinstance(pressable_object, Pressable), "Object pose must be an instance of Pressable" |
| 87 | + params = {} |
| 88 | + if reset_pressedness is not None: |
| 89 | + params["unpressed_percentage"] = reset_pressedness |
| 90 | + self.reset_button_state = EventTermCfg( |
| 91 | + func=pressable_object.unpress, |
| 92 | + mode="reset", |
| 93 | + params=params, |
| 94 | + ) |
0 commit comments