MCPcopy Create free account
hub / github.com/InternRobotics/UniHSI / VecTaskCPU

Class VecTaskCPU

unihsi/env/tasks/vec_task.py:68–89  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

66
67# C++ CPU Class
68class VecTaskCPU(VecTask):
69 def __init__(self, task, rl_device, sync_frame_time=False, clip_observations=5.0, clip_actions=1.0):
70 super().__init__(task, rl_device, clip_observations=clip_observations, clip_actions=clip_actions)
71 self.sync_frame_time = sync_frame_time
72
73 def step(self, actions):
74 actions = actions.cpu().numpy()
75 self.task.render(self.sync_frame_time)
76
77 obs, rewards, resets, extras = self.task.step(np.clip(actions, -self.clip_actions, self.clip_actions))
78
79 return (to_torch(np.clip(obs, -self.clip_obs, self.clip_obs), dtype=torch.float, device=self.rl_device),
80 to_torch(rewards, dtype=torch.float, device=self.rl_device),
81 to_torch(resets, dtype=torch.uint8, device=self.rl_device), [])
82
83 def reset(self):
84 actions = 0.01 * (1 - 2 * np.random.rand(self.num_envs, self.num_actions)).astype('f')
85
86 # step the simulator
87 obs, rewards, resets, extras = self.task.step(actions)
88
89 return to_torch(np.clip(obs, -self.clip_obs, self.clip_obs), dtype=torch.float, device=self.rl_device)
90
91
92# C++ GPU Class

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected