mirror of
https://github.com/huggingface/lerobot.git
synced 2026-07-25 18:56:09 +00:00
style: fix ruff SIM105/format lints in unitree_g1 scripts
Use contextlib.suppress(zmq.Again) instead of try/except/pass in the onboard state publisher and teleop client, plus ruff-format/isort autofixes across the unitree_g1 helpers and dataset_reader imports. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -137,7 +137,10 @@ class ImageServer:
|
||||
last_err = e
|
||||
logger.warning(
|
||||
"Camera %s open attempt %d/%d failed: %s",
|
||||
name, attempt, self.open_attempts, e,
|
||||
name,
|
||||
attempt,
|
||||
self.open_attempts,
|
||||
e,
|
||||
)
|
||||
with contextlib.suppress(Exception):
|
||||
camera.disconnect()
|
||||
|
||||
@@ -19,9 +19,9 @@ from collections.abc import Callable
|
||||
from concurrent.futures import ThreadPoolExecutor
|
||||
from pathlib import Path
|
||||
|
||||
import datasets
|
||||
import torch
|
||||
|
||||
import datasets
|
||||
from lerobot.configs import (
|
||||
DEFAULT_DEPTH_UNIT,
|
||||
DEPTH_METER_UNIT,
|
||||
|
||||
@@ -44,6 +44,7 @@ Examples (on the robot):
|
||||
"""
|
||||
|
||||
import argparse
|
||||
import contextlib
|
||||
import json
|
||||
import logging
|
||||
import os
|
||||
@@ -218,10 +219,8 @@ def main() -> None:
|
||||
state["groot.rpy.roll"] = float(orient[0])
|
||||
state["groot.rpy.pitch"] = float(orient[1])
|
||||
state["groot.rpy.yaw"] = float(orient[2])
|
||||
try:
|
||||
with contextlib.suppress(zmq.Again):
|
||||
state_sock.send_json(state, zmq.NOBLOCK)
|
||||
except zmq.Again:
|
||||
pass
|
||||
time.sleep(max(0.0, period - (time.time() - t0)))
|
||||
|
||||
threading.Thread(target=publish_state, daemon=True).start()
|
||||
|
||||
@@ -151,11 +151,7 @@ def parse_camera_specs(spec: str, default_width: int, default_height: int) -> di
|
||||
# a pixel format. Real device-path tail segments (e.g. "1.0-video-index0")
|
||||
# won't match these strict patterns.
|
||||
fourcc = None
|
||||
if (
|
||||
len(tokens) >= 3
|
||||
and wh_re.fullmatch(tokens[-2])
|
||||
and fourcc_re.fullmatch(tokens[-1])
|
||||
):
|
||||
if len(tokens) >= 3 and wh_re.fullmatch(tokens[-2]) and fourcc_re.fullmatch(tokens[-1]):
|
||||
fourcc = tokens.pop().upper()
|
||||
width, height = default_width, default_height
|
||||
if len(tokens) >= 2 and wh_re.fullmatch(tokens[-1]):
|
||||
|
||||
@@ -32,6 +32,7 @@ Example (on the laptop):
|
||||
"""
|
||||
|
||||
import argparse
|
||||
import contextlib
|
||||
import logging
|
||||
import time
|
||||
|
||||
@@ -106,10 +107,8 @@ def main() -> None:
|
||||
rc.lx = rc.ly = rc.rx = rc.ry = 0.0
|
||||
rc.button = [0] * 16
|
||||
action = teleop.get_action()
|
||||
try:
|
||||
with contextlib.suppress(zmq.Again):
|
||||
sock.send_json(_to_jsonable(action), zmq.NOBLOCK)
|
||||
except zmq.Again:
|
||||
pass
|
||||
n += 1
|
||||
if n % 60 == 0:
|
||||
axes = {
|
||||
|
||||
@@ -70,8 +70,22 @@ else:
|
||||
# teleoperator's RemoteController so the onboard path reads the physical Unitree remote
|
||||
# identically.
|
||||
_REMOTE_BUTTON_MAP: list[str] = [
|
||||
"RB", "LB", "start", "back", "RT", "LT", "", "",
|
||||
"A", "B", "X", "Y", "up", "right", "down", "left",
|
||||
"RB",
|
||||
"LB",
|
||||
"start",
|
||||
"back",
|
||||
"RT",
|
||||
"LT",
|
||||
"",
|
||||
"",
|
||||
"A",
|
||||
"B",
|
||||
"X",
|
||||
"Y",
|
||||
"up",
|
||||
"right",
|
||||
"down",
|
||||
"left",
|
||||
]
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
@@ -299,8 +313,7 @@ class UnitreeG1(Robot):
|
||||
actual_hz = loop_count / (time.time() - last_log_time)
|
||||
eff = {k: round(float(controller_input.get(k, 0.0)), 3) for k in REMOTE_AXES}
|
||||
logger.info(
|
||||
f"Controller {actual_hz:.1f}Hz | eff_axes={eff} "
|
||||
f"wireless={'ACTIVE' if wl else 'idle'}"
|
||||
f"Controller {actual_hz:.1f}Hz | eff_axes={eff} wireless={'ACTIVE' if wl else 'idle'}"
|
||||
)
|
||||
loop_count = 0
|
||||
last_log_time = time.time()
|
||||
|
||||
Reference in New Issue
Block a user