更新了一下文档

This commit is contained in:
mzx committed 2026-11-24 19:23:26 +08:00
1 parent 56f4b3adb0
commit 72f407c110
7 files changed
+319 -13

No files matched your search

+75 -1
View File
@@ -6,6 +6,7 @@ import math
import os
from pathlib import Path
import re
import shlex
import shutil
import signal
import subprocess
@@ -20,6 +21,12 @@ _KNOWN_BINARIES = ('self_filter', 'nav_client', 'patrol', 'odom_tf', 'cmd_vel_re
_GZ_CANDIDATES = ('/usr/bin/gz', '/usr/local/bin/gz', '/opt/gz/bin/gz')
_GZ_VERSION_TIMEOUT = 5
_FIELD_PACKAGE = Path('src/guodong_sentry_sim')
# 无界面 Gazebo 的 OGRE2 走 EGL。混合显卡笔记本上 glvnd 默认挑 Mesa,
# gpu_lidar 于是退化成 llvmpipe 软件光栅(实测单核 84%,CPU 射线只要 30%)。
# 把 EGL vendor 指向 NVIDIA 的 json,OGRE2 才能真正用上显卡。
_EGL_NVIDIA_JSON = Path('/usr/share/glvnd/egl_vendor.d/10_nvidia.json')
_NVIDIA_DEVICE_NODE = Path('/dev/nvidiactl')
_GPU_EGL_MODES = ('auto', 'nvidia', 'off')
class ProbeError(RuntimeError):
@@ -197,6 +204,66 @@ def wait_gz_clock(gz, gazebo_pid=None):
f'{os.environ.get("GZ_PARTITION") or "sentry"}')
def egl_vendor_json():
"""NVIDIA 的 EGL vendor 描述文件。
`SENTRY_EGL_VENDOR_JSON` 可覆盖 —— 发行版把 glvnd 配置放别处时用。
"""
override = os.environ.get('SENTRY_EGL_VENDOR_JSON')
return Path(override) if override else _EGL_NVIDIA_JSON
def gpu_env():
"""Return the EGL environment that makes OGRE2 (and gpu_lidar) use the dGPU.
`SENTRY_GPU_EGL` selects the behaviour:
auto enable only when an NVIDIA device node and the vendor json exist
nvidia always enable; missing vendor json is an error
off never touch the environment
`SENTRY_EGL_PLATFORM` additionally exports `EGL_PLATFORM` when set (some
hosts only reach the surfaceless platform that way).
An empty dict means "leave the environment alone" so callers can splat it
unconditionally.
"""
mode = (os.environ.get('SENTRY_GPU_EGL') or 'auto').strip().lower()
if mode not in _GPU_EGL_MODES:
raise ProbeError(
f'SENTRY_GPU_EGL 只能是 {"|".join(_GPU_EGL_MODES)},当前为 {mode!r}')
if mode == 'off':
return {}
vendor = egl_vendor_json()
if mode == 'nvidia' and not vendor.is_file():
raise ProbeError(f'SENTRY_GPU_EGL=nvidia 但找不到 {vendor}')
if mode == 'auto' and not (_NVIDIA_DEVICE_NODE.exists() and vendor.is_file()):
return {}
env = {
'__EGL_VENDOR_LIBRARY_FILENAMES': str(vendor),
'NVIDIA_DRIVER_CAPABILITIES':
os.environ.get('NVIDIA_DRIVER_CAPABILITIES') or 'all',
}
if platform := os.environ.get('SENTRY_EGL_PLATFORM'):
env['EGL_PLATFORM'] = platform
return env
def describe_gpu_env():
"""One-line human summary of what `gpu_env()` decided and why."""
mode = (os.environ.get('SENTRY_GPU_EGL') or 'auto').strip().lower()
env = gpu_env()
if env:
return 'nvidia → ' + ' '.join(f'{k}={v}' for k, v in env.items())
if mode == 'off':
return 'off(SENTRY_GPU_EGL=off,不改环境)'
reasons = []
if not _NVIDIA_DEVICE_NODE.exists():
reasons.append(f'{_NVIDIA_DEVICE_NODE} 不存在')
vendor = egl_vendor_json()
if not vendor.is_file():
reasons.append(f'{vendor} 不存在')
return 'off(' + ';'.join(reasons or ['未找到可用显卡']) + ')'
def find_field_root(ws=WORKSPACE, *, explicit=None):
if explicit:
return require_directory(explicit, 'field_root')
@@ -244,13 +311,15 @@ def report(ws):
print(f' gz 版本参数 : {versions or "<无>"}')
print(f' FIELD_ROOT : {field_root}')
print(f' MAP_YAML : {map_yaml}')
print(f' GPU EGL : {describe_gpu_env()}')
def main(argv=None):
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument('workspace', type=Path, nargs='?', default=WORKSPACE)
queries = parser.add_mutually_exclusive_group()
for query in ('bin-dir', 'field', 'map', 'gz', 'gz-version-args', 'ros-setup'):
for query in ('bin-dir', 'field', 'map', 'gz', 'gz-version-args', 'ros-setup',
'gpu', 'gpu-shell'):
queries.add_argument(f'--{query}', dest='query', action='store_const', const=query)
for query in ('gz-version-args-lines', 'wait-gz-clock'):
queries.add_argument(f'--{query}', dest='query', action='store_const', const=query,
@@ -283,6 +352,11 @@ def main(argv=None):
print()
case 'ros-setup':
print(find_ros_setup() or '')
case 'gpu':
print(describe_gpu_env())
case 'gpu-shell':
for name, value in gpu_env().items():
print(f'export {name}={shlex.quote(value)}')
case 'wait-gz-clock':
wait_gz_clock(find_gz_bin(), args.gazebo_pid)
case None: