镜像自地址
https://github.com/MINT-SJTU/Evo-RL.git
已同步 2026-11-21 02:27:04 +00:00
feat: add cooldown for intervention toggle key to prevent rapid re-triggers
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
这个提交包含在:
@ -23,6 +23,7 @@ import select
|
|||||||
import sys
|
import sys
|
||||||
import termios
|
import termios
|
||||||
import threading
|
import threading
|
||||||
|
import time
|
||||||
import tty
|
import tty
|
||||||
from contextlib import nullcontext
|
from contextlib import nullcontext
|
||||||
from copy import copy
|
from copy import copy
|
||||||
@ -41,6 +42,9 @@ from lerobot.processor import PolicyAction, PolicyProcessorPipeline
|
|||||||
from lerobot.robots import Robot
|
from lerobot.robots import Robot
|
||||||
from lerobot.utils.recording_annotations import EPISODE_FAILURE, EPISODE_SUCCESS
|
from lerobot.utils.recording_annotations import EPISODE_FAILURE, EPISODE_SUCCESS
|
||||||
|
|
||||||
|
# Minimum interval (seconds) between consecutive intervention toggle presses.
|
||||||
|
INTERVENTION_TOGGLE_COOLDOWN_S = 0.5
|
||||||
|
|
||||||
|
|
||||||
@cache
|
@cache
|
||||||
def is_headless():
|
def is_headless():
|
||||||
@ -81,6 +85,7 @@ class TTYKeyboardListener:
|
|||||||
self._stop_event = threading.Event()
|
self._stop_event = threading.Event()
|
||||||
self._thread: threading.Thread | None = None
|
self._thread: threading.Thread | None = None
|
||||||
self._old_attrs = None
|
self._old_attrs = None
|
||||||
|
self._last_intervention_time: float = 0.0
|
||||||
|
|
||||||
def start(self):
|
def start(self):
|
||||||
self._old_attrs = termios.tcgetattr(self._fd)
|
self._old_attrs = termios.tcgetattr(self._fd)
|
||||||
@ -157,6 +162,10 @@ class TTYKeyboardListener:
|
|||||||
self.events["stop_recording"] = True
|
self.events["stop_recording"] = True
|
||||||
self.events["exit_early"] = True
|
self.events["exit_early"] = True
|
||||||
elif normalized == self.intervention_toggle_key:
|
elif normalized == self.intervention_toggle_key:
|
||||||
|
now = time.monotonic()
|
||||||
|
if now - self._last_intervention_time < INTERVENTION_TOGGLE_COOLDOWN_S:
|
||||||
|
return
|
||||||
|
self._last_intervention_time = now
|
||||||
print(f"'{self.intervention_toggle_key}' key pressed. Toggling intervention mode...")
|
print(f"'{self.intervention_toggle_key}' key pressed. Toggling intervention mode...")
|
||||||
self.events["toggle_intervention"] = True
|
self.events["toggle_intervention"] = True
|
||||||
elif self.episode_success_key and normalized == self.episode_success_key:
|
elif self.episode_success_key and normalized == self.episode_success_key:
|
||||||
@ -253,6 +262,8 @@ def init_keyboard_listener(
|
|||||||
# Only import pynput if not in a headless environment
|
# Only import pynput if not in a headless environment
|
||||||
from pynput import keyboard
|
from pynput import keyboard
|
||||||
|
|
||||||
|
last_intervention_time = [0.0]
|
||||||
|
|
||||||
def on_press(key):
|
def on_press(key):
|
||||||
try:
|
try:
|
||||||
if key == keyboard.Key.right:
|
if key == keyboard.Key.right:
|
||||||
@ -267,6 +278,10 @@ def init_keyboard_listener(
|
|||||||
events["stop_recording"] = True
|
events["stop_recording"] = True
|
||||||
events["exit_early"] = True
|
events["exit_early"] = True
|
||||||
elif hasattr(key, "char") and key.char and key.char.lower() == intervention_toggle_key.lower():
|
elif hasattr(key, "char") and key.char and key.char.lower() == intervention_toggle_key.lower():
|
||||||
|
now = time.monotonic()
|
||||||
|
if now - last_intervention_time[0] < INTERVENTION_TOGGLE_COOLDOWN_S:
|
||||||
|
return
|
||||||
|
last_intervention_time[0] = now
|
||||||
print(f"'{intervention_toggle_key}' key pressed. Toggling intervention mode...")
|
print(f"'{intervention_toggle_key}' key pressed. Toggling intervention mode...")
|
||||||
events["toggle_intervention"] = True
|
events["toggle_intervention"] = True
|
||||||
elif (
|
elif (
|
||||||
|
|||||||
在新工单中引用
屏蔽一个用户