接入 LinuxCNC TP 运行反馈
This commit is contained in:
@@ -80,4 +80,84 @@ try {
|
||||
tp._lctp_free_string(resultPtr);
|
||||
}
|
||||
|
||||
function allocCString(mod, value) {
|
||||
const bytes = mod.lengthBytesUTF8(value) + 1;
|
||||
const ptr = mod._malloc(bytes);
|
||||
mod.stringToUTF8(value, ptr, bytes);
|
||||
return ptr;
|
||||
}
|
||||
|
||||
const timingPayload = JSON.stringify({
|
||||
cycleTime: 0.001,
|
||||
maxVelocity: 10,
|
||||
maxAcceleration: 50,
|
||||
maxJerk: 100,
|
||||
queueSize: 8,
|
||||
motion: [
|
||||
{ line: 2, type: "STRAIGHT_TRAVERSE", x: 0, y: 0, z: 0, a: 0, b: 0, c: 0, feedRate: 0 },
|
||||
{ line: 3, type: "STRAIGHT_FEED", x: 1, y: 0, z: 0, a: 0, b: 0, c: 0, feedRate: 60 },
|
||||
{ line: 4, type: "STRAIGHT_FEED", x: 1, y: 1, z: 0, a: 0, b: 0, c: 0, feedRate: 60 },
|
||||
],
|
||||
});
|
||||
const timingInputPtr = allocCString(tp, timingPayload);
|
||||
const timingResultPtr = tp._lctp_run_canonical_motion_timing(timingInputPtr);
|
||||
assert.notEqual(timingResultPtr, 0);
|
||||
try {
|
||||
const timing = JSON.parse(tp.UTF8ToString(timingResultPtr));
|
||||
assert.equal(timing.ok, true);
|
||||
assert.equal(timing.semanticBoundary, "linuxcnc_tp_queue_runtime_timing_from_canonical_motion");
|
||||
assert.equal(timing.motionCount, 3);
|
||||
assert.equal(timing.addFailures, 0);
|
||||
assert.equal(timing.emittedMotionCount, 3);
|
||||
assert.equal(timing.segments[0].zeroLength, true);
|
||||
assert.equal(timing.segments[0].durationSeconds, 0);
|
||||
assert.equal(timing.totalSeconds > 0, true);
|
||||
assert.equal(timing.tpDone, 1);
|
||||
} finally {
|
||||
tp._lctp_free_string(timingResultPtr);
|
||||
tp._free(timingInputPtr);
|
||||
}
|
||||
|
||||
const arcPayload = JSON.stringify({
|
||||
cycleTime: 0.001,
|
||||
maxVelocity: 10,
|
||||
maxAcceleration: 50,
|
||||
maxJerk: 100,
|
||||
queueSize: 8,
|
||||
motion: [
|
||||
{ line: 2, type: "STRAIGHT_TRAVERSE", x: 1, y: 0, z: 0, a: 0, b: 0, c: 0, feedRate: 0 },
|
||||
{
|
||||
line: 3,
|
||||
type: "ARC_FEED",
|
||||
x: 0,
|
||||
y: 1,
|
||||
z: 0,
|
||||
a: 0,
|
||||
b: 0,
|
||||
c: 0,
|
||||
feedRate: 60,
|
||||
plane: 170,
|
||||
centerFirst: 0,
|
||||
centerSecond: 0,
|
||||
rotation: -1,
|
||||
axisEndPoint: 0,
|
||||
},
|
||||
],
|
||||
});
|
||||
const arcInputPtr = allocCString(tp, arcPayload);
|
||||
const arcResultPtr = tp._lctp_run_canonical_motion_timing(arcInputPtr);
|
||||
assert.notEqual(arcResultPtr, 0);
|
||||
try {
|
||||
const timing = JSON.parse(tp.UTF8ToString(arcResultPtr));
|
||||
assert.equal(timing.ok, true);
|
||||
assert.equal(timing.addFailures, 0);
|
||||
assert.equal(timing.emittedMotionCount, 2);
|
||||
assert.equal(timing.segments[1].type, "ARC_FEED");
|
||||
assert.equal(timing.segments[1].durationSeconds > 1.4, true);
|
||||
assert.equal(timing.tpDone, 1);
|
||||
} finally {
|
||||
tp._lctp_free_string(arcResultPtr);
|
||||
tp._free(arcInputPtr);
|
||||
}
|
||||
|
||||
console.log("tp_wasm_node_smoke=ok");
|
||||
|
||||
Reference in New Issue
Block a user