Files
wasm-simulator/generate-linuxcnc-puma560-dh-parameters.sh
cnc 51b415a701 参考所有分组,完成尽量多的内容。禁止顺手扩功能 smoke
结论:补齐 Puma560 DH 参数生成器的可执行入口和 LinuxCNC-root 相对 HAL 源约束,锁住 puma560_dh.hal 中 genserkins DH 值到生成输出的映射,不新增 CNC 行为或 smoke 功能。
2026-06-03 20:36:09 +08:00

90 lines
2.3 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
cd "$(dirname "$0")"
# LinuxCNC source basis: Puma560 DH parameter output is generated from
# configs/sim/axis/vismach/puma/puma560_dh.hal setp genserkins.{A,ALPHA,D}-N
# values used by LinuxCNC genser/switchkins simulation configs.
linuxcnc_root=${LINUXCNC_ROOT:-../linuxcnc}
usage() {
echo "usage: $0 [linuxcnc-root-relative-puma560-dh-hal]" >&2
}
case "${1:-}" in
--help|-h)
usage
exit 0
;;
--*)
usage
echo "unknown LinuxCNC puma560 DH generator option: $1" >&2
exit 1
;;
esac
if [[ -n "${2:-}" ]]; then
usage
echo "too many LinuxCNC puma560 DH generator arguments" >&2
exit 1
fi
source_path=${1:-configs/sim/axis/vismach/puma/puma560_dh.hal}
if [[ "$source_path" = /* || "$source_path" == .. || "$source_path" == ../* || "$source_path" == */.. || "$source_path" == */../* ]]; then
echo "LinuxCNC puma560 DH HAL source path must stay LinuxCNC-root relative: $source_path" >&2
exit 1
fi
if [[ "$source_path" != *.hal ]]; then
echo "LinuxCNC puma560 DH source must be a HAL file: $source_path" >&2
exit 1
fi
source_file="$linuxcnc_root/$source_path"
if [[ ! -f "$source_file" ]]; then
echo "missing LinuxCNC puma560 DH HAL source: $source_file" >&2
exit 1
fi
awk -v source_path="$source_path" '
function fail(message) {
print message > "/dev/stderr"
exit 1
}
$1 == "setp" && $2 ~ /^genserkins\.(A|ALPHA|D)-[0-5]$/ {
split($2, qualified, ".")
split(qualified[2], name_index, "-")
name = name_index[1]
joint_index = name_index[2] + 0
values[name, joint_index] = $3
}
END {
names[0] = "A"
arrays["A"] = "a"
names[1] = "ALPHA"
arrays["ALPHA"] = "alpha"
names[2] = "D"
arrays["D"] = "d"
print "// Generated by ./generate-linuxcnc-puma560-dh-parameters.sh."
print "// Source: linuxcnc/" source_path " setp genserkins.{A,ALPHA,D}-N values."
for (n = 0; n < 3; n++) {
name = names[n]
array = arrays[name]
for (i = 0; i < 6; i++) {
key = name SUBSEP i
if (!(key in values)) {
fail("missing " name "-" i " in " source_path)
}
print " parameters." array "[" i "] = " values[key] ";"
}
if (n < 2) {
print ""
}
}
}
' "$source_file"