Make machine configuration authoritative and restore native checkpoints exactly
This commit is contained in:
@@ -6,7 +6,7 @@ export class WasmNativeHoming {
|
||||
constructor(core, configuration, kinematics) {
|
||||
this.core = core;
|
||||
this.kinematics = kinematics;
|
||||
this.jointCount = 5;
|
||||
this.jointCount = configuration.home_limits.joint_count;
|
||||
this.size = core._sim_native_home_size();
|
||||
this.pointer = core._malloc(this.size);
|
||||
this.buffer = core._malloc(12 * 8);
|
||||
@@ -17,7 +17,7 @@ export class WasmNativeHoming {
|
||||
if (typeof value !== "string") throw new Error(`home_ini_missing:${path}`);
|
||||
return value;
|
||||
} } });
|
||||
this.parameters = Array.from({ length: 5 }, (_, j) => {
|
||||
this.parameters = Array.from({ length: this.jointCount }, (_, j) => {
|
||||
const section = parsed.sections[`JOINT_${j}`] ?? {};
|
||||
const n = (key, fallback) => section[key] === undefined ? fallback : Number(section[key]);
|
||||
const flags = [["HOME_IGNORE_LIMITS", 1], ["HOME_USE_INDEX", 2], ["HOME_IS_SHARED", 4], ["LOCKING_INDEXER", 8], ["HOME_INDEX_NO_ENCODER_RESET", 128]].reduce((mask, [key, bit]) => mask | (n(key, 0) ? bit : 0), 0);
|
||||
@@ -25,7 +25,7 @@ export class WasmNativeHoming {
|
||||
if (![0, 1, 2].includes(encoder)) throw new Error("native_home_absolute_encoder_invalid");
|
||||
return [n("HOME_OFFSET", 0), n("HOME", 0), n("HOME_FINAL_VEL", -1), n("HOME_SEARCH_VEL", 0), n("HOME_LATCH_VEL", 0), flags | (encoder ? 16 | 32 | (encoder === 2 ? 64 : 0) : 0), n("HOME_SEQUENCE", 999), n("VOLATILE_HOME", 0), n("MIN_LIMIT", -1e9), n("MAX_LIMIT", 1e9), n("MAX_VELOCITY", 1), n("MAX_ACCELERATION", 1)];
|
||||
});
|
||||
this.period = Number(parsed.sections.EMCMOT?.SERVO_PERIOD ?? 1000000) / 1e9;
|
||||
this.period = configuration.kinematics.servo_cycle_time;
|
||||
this.reset();
|
||||
}
|
||||
invoke(name, ...args) {
|
||||
@@ -41,13 +41,13 @@ export class WasmNativeHoming {
|
||||
step() { this.invoke("step"); return this.read(); }
|
||||
cancel(volatile = false) { this.invoke("cancel", Number(volatile)); return this.read(); }
|
||||
reset() {
|
||||
this.invoke("init", 5, this.period);
|
||||
this.invoke("init", this.jointCount, this.period);
|
||||
this.parameters.forEach((p, j) => { this.core.HEAPF64.set(p, this.buffer / 8); this.invoke("config", j, this.buffer); });
|
||||
return this.read();
|
||||
}
|
||||
check(joints) { if (!this.active) this.sync(joints); return this.read(); }
|
||||
read() {
|
||||
const joint = Array.from({ length: 5 }, (_, j) => ({
|
||||
const joint = Array.from({ length: this.jointCount }, (_, j) => ({
|
||||
joint: j, homing: Boolean(this.get(j, 4)), homed: Boolean(this.get(j, 5)),
|
||||
home_state: this.get(j, 6), home_state_name: `HOME_${STATES[this.get(j, 6)]}`,
|
||||
position: this.get(j, 7), motor_position: this.get(j, 8), motor_offset: this.get(j, 9),
|
||||
@@ -56,7 +56,7 @@ export class WasmNativeHoming {
|
||||
const joints = joint.map((j) => j.position);
|
||||
const result = this.kinematics.forward(joints);
|
||||
return { status: result.status, ...(result.code ? { code: result.code } : {}), state: {
|
||||
schema: "sim_home_limit_state.v1", source: "linuxcnc-homing.c", joint_count: 5,
|
||||
schema: "sim_home_limit_state.v1", source: "linuxcnc-homing.c", joint_count: this.jointCount,
|
||||
homed: joint.every((j) => j.homed), homed_mask: joint.reduce((mask, j) => mask | (j.homed ? 1 << j.joint : 0), 0),
|
||||
homing: this.active, motion_mode: this.mode, joint, joints, pose: result.pose ?? null,
|
||||
home_sequence: this.get(0, 3), tick: this.get(0, 2), last_error: result.result ?? 0, limit_error: result.result === -702 ? -702 : 0, kinematics_error: result.result ?? 0,
|
||||
|
||||
Reference in New Issue
Block a user