注释与提示信息全面中文化:源码 66 个 .py + 脚本/配置 45 个文件
背景:现场读代码的人只读中文。此前代码里的 docstring 是英文、行内注释是中文,
一半英文一半中文反而更难看懂 —— 新手打开一个 .py 不知道这个模块为什么存在。
范围(本仓库自己的代码,厂商上游不动)
src/arm_application/** 37 个文件:servo_node / perception_node / handeye_* / dh_pgea /
yolo_detector / kalman_filter / goto_ee_plane / dual_gripper …
src/arm_interfaces/** 11 个文件:paths / manifest / loader / config_guard / errors …
src/arm_control/** 5 个文件
src/arm_bringup/** 3 个 launch
scripts/** 6 个 .py + 29 个 .sh(scripts/ 是"唯一操作入口",用户屏幕上
看到的就是这些提示,所以提示信息也一并中文化)
config/ handeye/ devices/ src/arm_*/config/ 17 个 .yaml/.xml/.xacro/.cfg
口径(写进 docs/FRAMEWORK_RULES.md 新增的 R6.5,作为长期约束)
注释、docstring、print/日志/异常里给人看的句子 = 中文;
标识符、API 名、话题名、参数名、字段名、命令名 = 保留英文原文(用 `` `` 包起来);
单位、十六进制、协议报文、CRC 值、命令示例 = 原样保留;
src/flexiv_*/ = 厂商上游代码,不许改也不许翻译(R4.4)。
翻译保原意与原有详细程度:那些"为什么不能用另一种做法""踩过什么坑"的说明
全部完整保留 —— 它们才是这份代码里最贵的部分。
新增 scripts/check_text_only.py:只改文字时的自证工具
人工 review 靠不住(115 个文件、3000 多行 diff)。这个脚本把改动前后的源码解析成
语法树,删掉 docstring、抹平字符串常量、把 f-string 只留"插值了几次 + 插值是什么",
再比对:完全相同 = 改动范围内没有逻辑变化。
留了一个口子:f-string 的插值按内容排序后再比 —— 因为中文语序常常要和英文反着来
(f"on {port} read {idx} failed" → f"在 {port} 上读 {idx} 失败"),只换显示顺序不该判失败;
但多插一个、少插一个、换掉被插入的表达式,立刻会报出来。
本次 66 个 .py 全部通过该闸门。
验收
改动的 66 个 .py:scripts/check_text_only.py 全部通过(零逻辑变化)
45 个非 .py 文件:去注释后与 HEAD 逐字节相同(零配置变化)
docstring 总数:没有一个文件减少(不存在"翻译时顺手删了说明")
单测:arm_application 233 / arm_driver_flexiv 69 / arm_interfaces 46 /
arm_kinematics 24 / arm_sim_gazebo 236 = 608 passed,与改动前一致
全部 .sh:bash -n 通过;并额外实际执行了 --help 验证(见下一个提交:
bash -n 对 CRLF 脚本会漏报,只有真跑才暴露)
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
+15
-15
@@ -1,10 +1,10 @@
|
||||
#!/usr/bin/env bash
|
||||
# Move Rizon4 to a named pose (default: home) and FORCE stop.
|
||||
# 把 Rizon4 移动到指定命名的位姿(默认:home)并强制停止。
|
||||
#
|
||||
# Critical: visual_servo.launch / servo_node must be killed first, otherwise
|
||||
# they keep streaming JointTrajectory and the arm never settles.
|
||||
# 关键:必须先杀掉 visual_servo.launch / servo_node,否则
|
||||
# 它们会一直发 JointTrajectory,机械臂永远稳定不下来。
|
||||
#
|
||||
# Usage:
|
||||
# 用法:
|
||||
# bash ~/ros2/scripts/go_home.sh
|
||||
# bash ~/ros2/scripts/go_home.sh --pose ready --speed 0.3
|
||||
|
||||
@@ -39,7 +39,7 @@ while [[ $# -gt 0 ]]; do
|
||||
--pose) POSE="${2:?}"; shift 2 ;;
|
||||
--speed) SPEED="${2:?}"; shift 2 ;;
|
||||
--keep-servo) KEEP_SERVO=1; shift ;;
|
||||
--stop-track) shift ;; # legacy
|
||||
--stop-track) shift ;; # 历史遗留
|
||||
-h|--help) usage; exit 0 ;;
|
||||
*) echo "Unknown: $1" >&2; usage >&2; exit 1 ;;
|
||||
esac
|
||||
@@ -56,10 +56,10 @@ SPEED="${SPEED:-${SITE_GO_HOME_SPEED:-0.25}}"
|
||||
|
||||
kill_streamers() {
|
||||
echo "=== killing visual-servo streamers ==="
|
||||
# Prefer disable control before kill (if node still up)
|
||||
# 能先禁用控制就禁用(如果节点还活着),再动手 kill
|
||||
ros2 param set /servo_node enable_control false >/dev/null 2>&1 || true
|
||||
|
||||
# Kill launch parent first, then executables (SIGTERM then SIGKILL)
|
||||
# 先杀 launch 父进程,再杀可执行文件(先 SIGTERM 再 SIGKILL)
|
||||
local patterns=(
|
||||
'visual_servo.launch.py'
|
||||
'/lib/arm_application/servo_node'
|
||||
@@ -115,7 +115,7 @@ n.destroy_node(); rclpy.shutdown()
|
||||
PY
|
||||
}
|
||||
|
||||
# Strong settle via controller ACTION (not topic — matches JTC reliably)
|
||||
# 用控制器的 ACTION 做强力稳定(不走话题 —— 这样能可靠地匹配 JTC)
|
||||
settle_hold_action() {
|
||||
local pose="$1"
|
||||
python3 - "$pose" <<'PY'
|
||||
@@ -160,7 +160,7 @@ def spin_until(pred, timeout=3.0):
|
||||
|
||||
spin_until(lambda: js_box[0] is not None, 3.0)
|
||||
|
||||
# Two-point: current -> target (or target hold), BOTH with zero velocity
|
||||
# 两点轨迹:当前位姿 -> 目标位姿(或保持在目标位姿),两点速度都为零
|
||||
q_now = list(target)
|
||||
if js_box[0] is not None:
|
||||
m = dict(zip(js_box[0].name, js_box[0].position))
|
||||
@@ -172,14 +172,14 @@ if js_box[0] is not None:
|
||||
def send_hold(q, T=0.40):
|
||||
traj = JointTrajectory()
|
||||
traj.joint_names = list(JOINTS)
|
||||
# start
|
||||
# 起点
|
||||
p0 = JointTrajectoryPoint()
|
||||
p0.positions = [float(v) for v in q]
|
||||
p0.velocities = [0.0] * 7
|
||||
p0.accelerations = [0.0] * 7
|
||||
p0.time_from_start.sec = 0
|
||||
p0.time_from_start.nanosec = 50_000_000
|
||||
# end same pose, still zero vel (pin)
|
||||
# 终点是同一姿势,速度仍为零(钉住)
|
||||
p1 = JointTrajectoryPoint()
|
||||
p1.positions = [float(v) for v in q]
|
||||
p1.velocities = [0.0] * 7
|
||||
@@ -203,11 +203,11 @@ def send_hold(q, T=0.40):
|
||||
spin_until(lambda: rfut.done(), T + 3.0)
|
||||
return True
|
||||
|
||||
# 1) snap toward named pose with zero end vel
|
||||
# 1) 先朝命名位姿快速靠拢,末端速度为零
|
||||
print(f" action hold → {name} (zero vel)")
|
||||
send_hold(target, T=0.60)
|
||||
time.sleep(0.4)
|
||||
# 2–4) re-pin measured pose several times (align JTC open-loop cmd to encoder)
|
||||
# 2–4) 反复把实测位姿重新钉住(让 JTC 的开环指令与编码器读数对齐)
|
||||
for i in range(3):
|
||||
spin_until(lambda: js_box[0] is not None, 1.0)
|
||||
if js_box[0] is None:
|
||||
@@ -218,7 +218,7 @@ for i in range(3):
|
||||
send_hold(q_pin, T=0.45)
|
||||
time.sleep(0.25)
|
||||
|
||||
# Wait until |qd| small
|
||||
# 等到 |qd| 足够小
|
||||
print(" waiting for joints to stop ...")
|
||||
t0 = time.monotonic()
|
||||
while time.monotonic() - t0 < 5.0:
|
||||
@@ -270,7 +270,7 @@ sleep "${WAIT_SEC}"
|
||||
echo "=== settle (action, vel=0) ==="
|
||||
settle_hold_action "${POSE}"
|
||||
|
||||
# Final check: servo must still be dead
|
||||
# 最后确认:servo 必须仍然是死的
|
||||
if pgrep -f '/lib/arm_application/servo_node' >/dev/null 2>&1; then
|
||||
echo "WARNING: servo_node came back — killing again"
|
||||
kill_streamers
|
||||
|
||||
Reference in New Issue
Block a user