Unverified Commit da5618bb authored by Mayank Mittal's avatar Mayank Mittal Committed by GitHub

Fixes device settings in env tutorials (#2151)

# Description

The environment examples were not setting the device properly.

## Type of change

- Bug fix (non-breaking change which fixes an issue)

## Checklist

- [x] I have run the [`pre-commit` checks](https://pre-commit.com/) with
`./isaaclab.sh --format`
- [x] I have made corresponding changes to the documentation
- [x] My changes generate no new warnings
- [ ] I have added tests that prove my fix is effective or that my
feature works
- [ ] I have updated the changelog and the corresponding version in the
extension's `config/extension.toml` file
- [x] I have added my name to the `CONTRIBUTORS.md` or my name already
exists there
Signed-off-by: 's avatarMayank Mittal <12863862+Mayankm96@users.noreply.github.com>
parent ba314082
......@@ -140,6 +140,7 @@ def main():
# parse the arguments
env_cfg = CartpoleEnvCfg()
env_cfg.scene.num_envs = args_cli.num_envs
env_cfg.sim.device = args_cli.device
# setup base environment
env = ManagerBasedEnv(cfg=env_cfg)
......
......@@ -304,6 +304,7 @@ class CubeEnvCfg(ManagerBasedEnvCfg):
self.sim.dt = 0.01
self.sim.physics_material = self.scene.terrain.physics_material
self.sim.render_interval = 2 # render interval should be a multiple of decimation
self.sim.device = args_cli.device
# viewer settings
self.viewer.eye = (5.0, 5.0, 5.0)
self.viewer.lookat = (0.0, 0.0, 2.0)
......
......@@ -194,6 +194,7 @@ class QuadrupedEnvCfg(ManagerBasedEnvCfg):
# simulation settings
self.sim.dt = 0.005 # simulation timestep -> 200 Hz physics
self.sim.physics_material = self.scene.terrain.physics_material
self.sim.device = args_cli.device
# update sensor update periods
# we tick all the sensors based on the smallest update period (physics update period)
if self.scene.height_scanner is not None:
......
......@@ -57,6 +57,8 @@ def main():
file_content = omni.client.read_file(policy_path)[2]
file = io.BytesIO(memoryview(file_content).tobytes())
policy = torch.jit.load(file)
# setup environment
env_cfg = H1RoughEnvCfg_PLAY()
env_cfg.scene.num_envs = 1
env_cfg.curriculum = None
......@@ -65,13 +67,19 @@ def main():
terrain_type="usd",
usd_path=f"{ISAAC_NUCLEUS_DIR}/Environments/Simple_Warehouse/warehouse.usd",
)
env_cfg.sim.device = "cpu"
env_cfg.sim.use_fabric = False
env_cfg.sim.device = args_cli.device
if args_cli.device == "cpu":
env_cfg.sim.use_fabric = False
# create environment
env = ManagerBasedRLEnv(cfg=env_cfg)
# run inference with the policy
obs, _ = env.reset()
while simulation_app.is_running():
action = policy(obs["policy"]) # run inference
obs, _, _, _, _ = env.step(action)
with torch.inference_mode():
while simulation_app.is_running():
action = policy(obs["policy"])
obs, _, _, _, _ = env.step(action)
if __name__ == "__main__":
......
......@@ -45,6 +45,7 @@ def main():
# create environment configuration
env_cfg = CartpoleEnvCfg()
env_cfg.scene.num_envs = args_cli.num_envs
env_cfg.sim.device = args_cli.device
# setup RL environment
env = ManagerBasedRLEnv(cfg=env_cfg)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment