From 19dcbc19f1780ca333a956c239828a1e365ac008 Mon Sep 17 00:00:00 2001 From: Steven Palma Date: Thu, 23 Jul 2026 18:21:48 +0200 Subject: [PATCH] fix(gamepad): Gamepad on macos often does not need fallback (#4125) * gamepad does often work on macos * review comments * fix(gamepad): expose hidapi fallback in config --------- Co-authored-by: Maxim Bonnaerens --- .../teleoperators/gamepad/configuration_gamepad.py | 2 ++ .../teleoperators/gamepad/teleop_gamepad.py | 14 +++++++++++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/lerobot/teleoperators/gamepad/configuration_gamepad.py b/src/lerobot/teleoperators/gamepad/configuration_gamepad.py index b3a565c07..9a220deb7 100644 --- a/src/lerobot/teleoperators/gamepad/configuration_gamepad.py +++ b/src/lerobot/teleoperators/gamepad/configuration_gamepad.py @@ -23,3 +23,5 @@ from ..config import TeleoperatorConfig @dataclass class GamepadTeleopConfig(TeleoperatorConfig): use_gripper: bool = True + # Use hidapi instead of pygame for controllers that pygame cannot detect reliably. + hidapi_fallback: bool = False diff --git a/src/lerobot/teleoperators/gamepad/teleop_gamepad.py b/src/lerobot/teleoperators/gamepad/teleop_gamepad.py index 8c1796e45..d86d4f486 100644 --- a/src/lerobot/teleoperators/gamepad/teleop_gamepad.py +++ b/src/lerobot/teleoperators/gamepad/teleop_gamepad.py @@ -14,6 +14,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +import logging import sys from enum import IntEnum from typing import Any @@ -27,6 +28,8 @@ from ..teleoperator import Teleoperator from ..utils import TeleopEvents from .configuration_gamepad import GamepadTeleopConfig +logger = logging.getLogger(__name__) + class GripperAction(IntEnum): CLOSE = 0 @@ -56,6 +59,13 @@ class GamepadTeleop(Teleoperator): self.gamepad = None + self.hidapi_fallback = config.hidapi_fallback + if sys.platform == "darwin" and not self.hidapi_fallback: + logger.warning( + "On macOS, pygame may not reliably detect input from some controllers. " + "If you experience issues, set `hidapi_fallback=true`." + ) + @property def action_features(self) -> dict: if self.config.use_gripper: @@ -76,9 +86,7 @@ class GamepadTeleop(Teleoperator): return {} def connect(self) -> None: - # use HidApi for macos - if sys.platform == "darwin": - # NOTE: On macOS, pygame doesn’t reliably detect input from some controllers so we fall back to hidapi + if self.hidapi_fallback: from .gamepad_utils import GamepadControllerHID as Gamepad else: from .gamepad_utils import GamepadController as Gamepad