Files
Robot_Arm/ml/prep/export_kin.cjs
T

24 lines
1.2 KiB
JavaScript
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.
/* 导出运动学 + 胶囊碰撞模型给 PyTorch(ml/common/kin_torch.py 读取)
* node ml/prep/export_kin.cjs [out=ml/assets/kin.json]
* collide.json 重新拟合/重生成 pair2d 后必须重跑(指纹不符时 Python 端拒绝加载)。 */
'use strict';
const fs = require('fs'), path = require('path');
const { S } = require('../../tests/route_bench_setup.cjs')();
const OUT = process.argv[2] || path.join(__dirname, '../assets/kin.json');
const COL = JSON.parse(fs.readFileSync(path.join(__dirname, '../../docs/collide.json'), 'utf8'));
const ce = S.clusterExport();
const out = {
fp: S.modelFingerprint(),
order: S.ORDER,
P: S.ORDER.map(id => S.P[id]), D: S.ORDER.map(id => S.D[id]),
lim: S.ORDER.map(id => [S.LIM[id].lo, S.LIM[id].hi, S.LIM[id].cont ? 1 : 0]),
tcp0: S.TCP0, capm: S.CAPM,
caps: COL.caps.map(c => ({ g: c.g, a: c.a, b: c.b, r: c.r })),
clusters: ce.clusters, cpairs: ce.cpairs,
lever: S.leverBounds(20000),
generated: new Date().toISOString()
};
fs.mkdirSync(path.dirname(OUT), { recursive: true });
fs.writeFileSync(OUT, JSON.stringify(out));
console.log('wrote', OUT, 'caps', out.caps.length, 'clusters', out.clusters.length, 'cpairs', out.cpairs.length, 'fp', out.fp);