Files
ros_contorl/scripts/fix_robot_lan.sh
T
arm_dev 6edb8d39ab chore: 框架科学优化前的完整基线
在开始'设备契约层 + 目录重构 + 通止规装配'改造之前,先钉住当前可运行状态,
使后续任何删除/重构都可回退。

本基线包含:
- 现有 ROS 2 工作区全部源码(arm_application / arm_control / arm_bringup 等)
- 官方 flexiv_ros2 栈(含 flexiv_hardware / flexiv_controllers 等符号链接)
- 设备契约层 src/arm_interfaces(新增,46 项单测通过)
- devices/ 设备选型与品牌清单(新增)
- scripts/gen_site_example.py 与由它生成的 config/site.example.yaml

按 .gitignore 排除:build/ / install/ / log/ / config/site.yaml / 模型权重二进制。
2026-09-23 10:53:06 +08:00

147 lines
3.5 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env bash
# 工控机 User1(enp4s0)↔ 交换机 ↔ 两台 Flexiv
#
# 本机 192.168.2.10/24(User1)。两台臂:063989=192.168.2.101 063991=192.168.2.100
#
# bash ~/ros2/scripts/fix_robot_lan.sh
# bash ~/ros2/scripts/fix_robot_lan.sh --only # 不要办公网 DHCP(独立交换机)
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
PC_IP_PRIMARY="${SITE_PC_IP:-192.168.2.10}"
PC_ADDRS=("192.168.2.10/24" "192.168.100.10/24")
ROBOT_IPS=("${SITE_ROBOT_IP:-192.168.2.100}")
# Catalog extras (second arm)
if [[ -n "${SITE_ROBOT_CATALOG:-}" ]]; then
:
fi
MODE=secondary
while [[ $# -gt 0 ]]; do
case "$1" in
--only) MODE=only; shift ;;
--secondary) MODE=secondary; shift ;;
-h|--help)
sed -n '2,12p' "$0"
exit 0
;;
*) echo "Unknown: $1" >&2; exit 1 ;;
esac
done
pick_iface() {
if [[ -n "${IFACE:-}" ]]; then
echo "$IFACE"
return
fi
if [[ -n "${SITE_NET_IFACE:-}" && -d "/sys/class/net/${SITE_NET_IFACE}" ]]; then
echo "${SITE_NET_IFACE}"
return
fi
for d in enp4s0 enp5s0 eth0; do
[[ -d /sys/class/net/$d ]] || continue
echo "$d"
return
done
return 1
}
IFACE="$(pick_iface)" || {
echo "ERROR: 找不到 User1 有线网卡" >&2
ip -br link
exit 1
}
ADDR_CSV="$(IFS=,; echo "${PC_ADDRS[*]}")"
echo "=== User1 / ${IFACE} 模式=${MODE} ==="
echo "本机副 IP: ${ADDR_CSV}"
echo "当前臂: SN=${SITE_ROBOT_SN:-?} IP=${SITE_ROBOT_IP:-?} catalog=${SITE_ROBOT_CATALOG:-}"
ip -4 -br addr
echo
if ! command -v nmcli >/dev/null; then
echo "ERROR: 需要 nmcli" >&2
exit 1
fi
CON="$(nmcli -t -f NAME,DEVICE connection show --active | awk -F: -v d="$IFACE" '$2==d{print $1; exit}')"
if [[ -z "$CON" ]]; then
CON="$(nmcli -t -f NAME,DEVICE connection show | awk -F: -v d="$IFACE" '$2==d{print $1; exit}')"
fi
if [[ -z "$CON" ]]; then
echo "ERROR: NetworkManager 没有绑定 $IFACE" >&2
nmcli device status
exit 1
fi
echo "NM 连接: $CON"
nmcli_mod() {
if nmcli connection modify "$CON" "$@"; then
return 0
fi
sudo nmcli connection modify "$CON" "$@"
}
nmcli_up() {
if nmcli connection up "$CON"; then
return 0
fi
sudo nmcli connection up "$CON"
}
if [[ "$MODE" == only ]]; then
nmcli_mod \
ipv4.method manual \
ipv4.addresses "${PC_IP_PRIMARY}/24" \
ipv4.gateway "" \
ipv4.dns "" \
ipv4.ignore-auto-dns yes \
ipv4.never-default yes
else
nmcli_mod \
ipv4.method auto \
ipv4.addresses "${ADDR_CSV}" \
ipv4.never-default no
fi
nmcli_up
echo
echo "=== 修复后 ==="
ip -4 -br addr show "$IFACE"
echo
ping_one() {
local ip="$1"
if ping -c 2 -W 1 "$ip" >/dev/null 2>&1; then
echo " UP $ip"
return 0
fi
echo " down $ip"
return 1
}
echo "=== ping 机器人网段 ==="
ok=0
for ip in 192.168.2.100 192.168.101.1 192.168.2.101 "${SITE_ROBOT_IP:-}"; do
[[ -z "$ip" ]] && continue
ping_one "$ip" && ok=1 || true
done
# unique
echo
if ping -c 1 -W 1 "${SITE_ROBOT_IP:-192.168.2.100}" >/dev/null 2>&1; then
echo "OK — 当前臂 ${SITE_ROBOT_SN:-} @ ${SITE_ROBOT_IP} 可达。RDK 用 SN 连接。"
echo " 063989 @ 192.168.2.101;063991 @ 192.168.2.100。"
else
echo "当前臂 ${SITE_ROBOT_IP:-192.168.2.100} 仍不通。检查:"
echo " 1) User1 网线 ↔ 交换机 ↔ 控制柜网口(灯亮)"
echo " 2) 示教器 About 里的 IPv4(出厂多为 192.168.2.100)"
echo " 3) Remote / Ethernet RDK 已开"
exit 2
fi