google-deepmind / google-deepmind/dm_control

Viewer Continuous Key Callback

未关闭
#375 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
主要语言
Python
星标
4.7k
派生
764
PR 合并指标
30 天内没有已合并 PR

描述

Hello,

I am trying to control the actuators with the keyboard using the `viewer.launch` function. In order to do this, I have created the following class:

```python
class Application(viewer.application.Application):

def __init__(self, title, width, height):
super().__init__(title, width, height)

self._keyboard.on_key_hold += self._handle_key
self._input_map.bind(self._move_forward, viewer.user_input.KEY_UP)
self._input_map.bind(self._move_back, viewer.user_input.KEY_DOWN)

def _move_forward(self):
action = self._environment.action_spec()
action = np.zeros_like(action.shape)
action[0] = 1
self._runtime._time_step = self._runtime._env.step(action)
self._runtime._last_action = action
finished = self._runtime._time_step.last()
print("moving forward")
return finished or self._runtime._error_logger.errors_found

def _move_back(self):
action = self._environment.action_spec()
action = np.zeros_like(action.shape)
action[0] = -1
self._runtime._time_step = self._runtime._env.step(action)
self._runtime._last_action = action
finished = self._runtime._time_step.last()
print("moving backward")
return finished or self._runtime._error_logger.errors_found
```

This basically allows me to set the action values at each timestep given the UP or DOWN key presses. The only issue is when I am trying to continuously control the simulator such as it goes forward as I keep the UP key pressed rather than on the release.

I was looking at a way to edit the file from [dm_control/viewer/user_input.py](https://github.com/deepmind/dm_control/blob/4e1a35595124742015ae0c7a829e099a5aa100f5/dm_control/viewer/user_input.py) such that it can accept it but I cannot see a clear way to do it. Is there any suggestion on how to approach this?

Thank you!

贡献指南

打开贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。