google-deepmind / google-deepmind/dm_control

Viewer Continuous Key Callback

Abierto
#375 1 comentario 0 reacciones 0 asignados Ver en GitHub
Lenguaje dominante
Python
Estrellas
4.7k
Forks
764
Métricas de merge de PR
Sin PR fusionados en 30 d

Descripción

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!

Guía de contribución

Abrir la guía de contribución

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.