google-deepmind / google-deepmind/dm_control

Viewer Continuous Key Callback

Offen
#375 1 Kommentar 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
Vorherrschende Sprache
Python
Sterne
4.7k
Forks
764
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

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!

Beitragsleitfaden

Beitragsleitfaden öffnen

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.