google-deepmind / google-deepmind/dm_control

Viewer Continuous Key Callback

Đang mở
#375 1 bình luận 0 reaction 0 người được giao Xem trên GitHub
Ngôn ngữ chính
Python
Star
4.7k
Fork
764
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

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!

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.