3c86441fb0
Co-authored-by: Cursor <cursoragent@cursor.com>
59 lines
2.3 KiB
Bash
Executable File
59 lines
2.3 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# 针对站点机器人对 Flexiv RDK Python 做冒烟测试(不需要 ROS / 不访问 GitHub)。
|
|
set -euo pipefail
|
|
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
|
# shellcheck disable=SC1091
|
|
source "${ROOT}/scripts/lib/load_site_config.sh" 2>/dev/null || true
|
|
|
|
SN="${1:-${ROBOT_SN:-${SITE_ROBOT_SN:-}}}"
|
|
ROBOT_IP="${ROBOT_IP:-${SITE_ROBOT_IP:-192.168.100.1}}"
|
|
IFACE="${SITE_NET_IFACE:-}"
|
|
# shellcheck disable=SC1091
|
|
source "${ROOT}/scripts/lib/dev_tools.sh"
|
|
PY="$(dev_rdk_python)"
|
|
|
|
echo "Using: ${PY}"
|
|
echo "Robot SN: ${SN} IP: ${ROBOT_IP} iface: ${IFACE:-auto}"
|
|
echo "Ping ${ROBOT_IP} ..."
|
|
ping -c 1 -W 1 "${ROBOT_IP}" >/dev/null && echo " network OK" || echo " network FAIL"
|
|
|
|
"${PY}" - <<PY
|
|
import flexivrdk
|
|
sn = "${SN}"
|
|
iface = "${IFACE}"
|
|
print("Connecting...", sn, "iface", iface or "auto")
|
|
robot = None
|
|
if iface:
|
|
for args in ((sn, [iface]), (sn, [iface], True), (sn, [iface], True, False)):
|
|
try:
|
|
robot = flexivrdk.Robot(*args)
|
|
break
|
|
except TypeError:
|
|
continue
|
|
except RuntimeError as exc:
|
|
# 这个 iface 用不了(实测:enp4s0 上有 5 个 IPv4 时,RDK 的
|
|
# UDPv4Transport 会把整张白名单都过滤掉,报 "All whitelist
|
|
# interfaces were filtered out"),别再拿它试了,交给下面的
|
|
# 「不指定网卡」兜底。
|
|
#
|
|
# **这一条以前漏了**:老代码只捕获 TypeError,而真实失败是
|
|
# RuntimeError —— 于是异常直接抛出去,下面那行兜底永远走不到。
|
|
# 后果是预检报「机械臂 RDK 连不上」这个**假阻断**,
|
|
# 而真机栈其实连得上(flexiv_hardware_interface.cpp 构造
|
|
# flexiv::rdk::Robot 时只传 robot_sn、不传网卡)。
|
|
print(f" iface={iface} 不可用({str(exc)[:70]}),回退到不指定网卡")
|
|
break
|
|
if robot is None:
|
|
robot = flexivrdk.Robot(sn)
|
|
print("Connected. Clearing fault if any...")
|
|
try:
|
|
robot.ClearFault()
|
|
except Exception as e:
|
|
print("ClearFault:", e)
|
|
mode = robot.mode()
|
|
print("mode:", mode)
|
|
states = robot.states()
|
|
print("q:", list(states.q))
|
|
print("OK — RDK Python link works. Enable RDK on teach pendant if mode/fault unexpected.")
|
|
PY
|