| |
| |
| |
| |
|
|
| import math |
|
|
| import isaaclab.sim as sim_utils |
| from isaaclab.assets import ArticulationCfg, AssetBaseCfg |
| from isaaclab.envs import ManagerBasedRLEnvCfg |
| from isaaclab.managers import EventTermCfg as EventTerm |
| from isaaclab.managers import ObservationGroupCfg as ObsGroup |
| from isaaclab.managers import ObservationTermCfg as ObsTerm |
| from isaaclab.managers import RewardTermCfg as RewTerm |
| from isaaclab.managers import SceneEntityCfg |
| from isaaclab.managers import TerminationTermCfg as DoneTerm |
| from isaaclab.scene import InteractiveSceneCfg |
| from isaaclab.utils import configclass |
|
|
| from . import mdp |
|
|
| |
| |
| |
|
|
| from isaaclab_assets.robots.cartpole import CARTPOLE_CFG |
|
|
|
|
| |
| |
| |
|
|
|
|
| @configclass |
| class {{ task.classname }}SceneCfg(InteractiveSceneCfg): |
| """Configuration for a cart-pole scene.""" |
|
|
| |
| ground = AssetBaseCfg( |
| prim_path="/World/ground", |
| spawn=sim_utils.GroundPlaneCfg(size=(100.0, 100.0)), |
| ) |
|
|
| |
| robot: ArticulationCfg = CARTPOLE_CFG.replace(prim_path="{ENV_REGEX_NS}/Robot") |
|
|
| |
| dome_light = AssetBaseCfg( |
| prim_path="/World/DomeLight", |
| spawn=sim_utils.DomeLightCfg(color=(0.9, 0.9, 0.9), intensity=500.0), |
| ) |
|
|
|
|
| |
| |
| |
|
|
|
|
| @configclass |
| class ActionsCfg: |
| """Action specifications for the MDP.""" |
|
|
| joint_effort = mdp.JointEffortActionCfg(asset_name="robot", joint_names=["slider_to_cart"], scale=100.0) |
|
|
|
|
| @configclass |
| class ObservationsCfg: |
| """Observation specifications for the MDP.""" |
|
|
| @configclass |
| class PolicyCfg(ObsGroup): |
| """Observations for policy group.""" |
|
|
| |
| joint_pos_rel = ObsTerm(func=mdp.joint_pos_rel) |
| joint_vel_rel = ObsTerm(func=mdp.joint_vel_rel) |
|
|
| def __post_init__(self) -> None: |
| self.enable_corruption = False |
| self.concatenate_terms = True |
|
|
| |
| policy: PolicyCfg = PolicyCfg() |
|
|
|
|
| @configclass |
| class EventCfg: |
| """Configuration for events.""" |
|
|
| |
| reset_cart_position = EventTerm( |
| func=mdp.reset_joints_by_offset, |
| mode="reset", |
| params={ |
| "asset_cfg": SceneEntityCfg("robot", joint_names=["slider_to_cart"]), |
| "position_range": (-1.0, 1.0), |
| "velocity_range": (-0.5, 0.5), |
| }, |
| ) |
|
|
| reset_pole_position = EventTerm( |
| func=mdp.reset_joints_by_offset, |
| mode="reset", |
| params={ |
| "asset_cfg": SceneEntityCfg("robot", joint_names=["cart_to_pole"]), |
| "position_range": (-0.25 * math.pi, 0.25 * math.pi), |
| "velocity_range": (-0.25 * math.pi, 0.25 * math.pi), |
| }, |
| ) |
|
|
|
|
| @configclass |
| class RewardsCfg: |
| """Reward terms for the MDP.""" |
|
|
| |
| alive = RewTerm(func=mdp.is_alive, weight=1.0) |
| |
| terminating = RewTerm(func=mdp.is_terminated, weight=-2.0) |
| |
| pole_pos = RewTerm( |
| func=mdp.joint_pos_target_l2, |
| weight=-1.0, |
| params={"asset_cfg": SceneEntityCfg("robot", joint_names=["cart_to_pole"]), "target": 0.0}, |
| ) |
| |
| cart_vel = RewTerm( |
| func=mdp.joint_vel_l1, |
| weight=-0.01, |
| params={"asset_cfg": SceneEntityCfg("robot", joint_names=["slider_to_cart"])}, |
| ) |
| |
| pole_vel = RewTerm( |
| func=mdp.joint_vel_l1, |
| weight=-0.005, |
| params={"asset_cfg": SceneEntityCfg("robot", joint_names=["cart_to_pole"])}, |
| ) |
|
|
|
|
| @configclass |
| class TerminationsCfg: |
| """Termination terms for the MDP.""" |
|
|
| |
| time_out = DoneTerm(func=mdp.time_out, time_out=True) |
| |
| cart_out_of_bounds = DoneTerm( |
| func=mdp.joint_pos_out_of_manual_limit, |
| params={"asset_cfg": SceneEntityCfg("robot", joint_names=["slider_to_cart"]), "bounds": (-3.0, 3.0)}, |
| ) |
|
|
|
|
| |
| |
| |
|
|
|
|
| @configclass |
| class {{ task.classname }}EnvCfg(ManagerBasedRLEnvCfg): |
| |
| scene: {{ task.classname }}SceneCfg = {{ task.classname }}SceneCfg(num_envs=4096, env_spacing=4.0) |
| |
| observations: ObservationsCfg = ObservationsCfg() |
| actions: ActionsCfg = ActionsCfg() |
| events: EventCfg = EventCfg() |
| |
| rewards: RewardsCfg = RewardsCfg() |
| terminations: TerminationsCfg = TerminationsCfg() |
|
|
| |
| def __post_init__(self) -> None: |
| """Post initialization.""" |
| |
| self.decimation = 2 |
| self.episode_length_s = 5 |
| |
| self.viewer.eye = (8.0, 0.0, 5.0) |
| |
| self.sim.dt = 1 / 120 |
| self.sim.render_interval = self.decimation |
|
|