@wandelbots/nova-js 2.1.4 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +29 -1
- package/dist/{chunk-6WCKJOFL.js → chunk-4FP7NTKS.js} +51 -1
- package/dist/chunk-4FP7NTKS.js.map +1 -0
- package/dist/{chunk-V3NJLR6P.js → chunk-DOFCSS2H.js} +1 -51
- package/dist/chunk-DOFCSS2H.js.map +1 -0
- package/dist/index.js +8 -8
- package/dist/lib/v1/index.js +6 -6
- package/dist/lib/v2/NovaCellAPIClient.d.ts +9 -11
- package/dist/lib/v2/NovaCellAPIClient.d.ts.map +1 -1
- package/dist/lib/v2/NovaClient.d.ts +0 -8
- package/dist/lib/v2/NovaClient.d.ts.map +1 -1
- package/dist/lib/v2/index.cjs +28 -771
- package/dist/lib/v2/index.cjs.map +1 -1
- package/dist/lib/v2/index.d.ts +0 -4
- package/dist/lib/v2/index.d.ts.map +1 -1
- package/dist/lib/v2/index.js +32 -764
- package/dist/lib/v2/index.js.map +1 -1
- package/dist/lib/v2/mock/MockNovaInstance.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/lib/v2/NovaCellAPIClient.ts +22 -22
- package/src/lib/v2/NovaClient.ts +0 -28
- package/src/lib/v2/index.ts +0 -4
- package/src/lib/v2/mock/MockNovaInstance.ts +9 -32
- package/dist/chunk-6WCKJOFL.js.map +0 -1
- package/dist/chunk-V3NJLR6P.js.map +0 -1
- package/dist/lib/v2/ConnectedMotionGroup.d.ts +0 -41
- package/dist/lib/v2/ConnectedMotionGroup.d.ts.map +0 -1
- package/dist/lib/v2/JoggerConnection.d.ts +0 -53
- package/dist/lib/v2/JoggerConnection.d.ts.map +0 -1
- package/dist/lib/v2/MotionStreamConnection.d.ts +0 -25
- package/dist/lib/v2/MotionStreamConnection.d.ts.map +0 -1
- package/dist/lib/v2/ProgramStateConnection.d.ts +0 -53
- package/dist/lib/v2/ProgramStateConnection.d.ts.map +0 -1
- package/dist/lib/v2/motionStateUpdate.d.ts +0 -4
- package/dist/lib/v2/motionStateUpdate.d.ts.map +0 -1
- package/src/lib/v2/ConnectedMotionGroup.ts +0 -216
- package/src/lib/v2/JoggerConnection.ts +0 -207
- package/src/lib/v2/MotionStreamConnection.ts +0 -201
- package/src/lib/v2/ProgramStateConnection.ts +0 -249
- package/src/lib/v2/motionStateUpdate.ts +0 -55
package/dist/lib/v2/index.cjs
CHANGED
|
@@ -68,525 +68,15 @@ var __async = (__this, __arguments, generator) => {
|
|
|
68
68
|
// src/lib/v2/index.ts
|
|
69
69
|
var v2_exports = {};
|
|
70
70
|
__export(v2_exports, {
|
|
71
|
-
ConnectedMotionGroup: () => ConnectedMotionGroup,
|
|
72
|
-
JoggerConnection: () => JoggerConnection,
|
|
73
|
-
MotionStreamConnection: () => MotionStreamConnection,
|
|
74
71
|
NovaCellAPIClient: () => NovaCellAPIClient,
|
|
75
|
-
NovaClient: () => NovaClient
|
|
76
|
-
ProgramState: () => ProgramState,
|
|
77
|
-
ProgramStateConnection: () => ProgramStateConnection
|
|
72
|
+
NovaClient: () => NovaClient
|
|
78
73
|
});
|
|
79
74
|
module.exports = __toCommonJS(v2_exports);
|
|
80
75
|
__reExport(v2_exports, require("@wandelbots/nova-api/v2"), module.exports);
|
|
81
76
|
|
|
82
|
-
// src/lib/v2/ConnectedMotionGroup.ts
|
|
83
|
-
var import_axios = require("axios");
|
|
84
|
-
var import_mobx = require("mobx");
|
|
85
|
-
|
|
86
|
-
// src/lib/converters.ts
|
|
87
|
-
function tryParseJson(json) {
|
|
88
|
-
try {
|
|
89
|
-
return JSON.parse(json);
|
|
90
|
-
} catch (e) {
|
|
91
|
-
return void 0;
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
// src/lib/v2/motionStateUpdate.ts
|
|
96
|
-
function jointValuesEqual(oldJointValues, newJointValues, changeDeltaThreshold) {
|
|
97
|
-
if (newJointValues.length !== oldJointValues.length) {
|
|
98
|
-
return true;
|
|
99
|
-
}
|
|
100
|
-
for (let jointIndex = 0; jointIndex < newJointValues.length; jointIndex++) {
|
|
101
|
-
if (Math.abs(newJointValues[jointIndex] - oldJointValues[jointIndex]) > changeDeltaThreshold) {
|
|
102
|
-
return false;
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
return true;
|
|
106
|
-
}
|
|
107
|
-
function tcpPoseEqual(oldTcp, newTcp, changeDeltaThreshold) {
|
|
108
|
-
if (oldTcp === void 0 && newTcp || oldTcp && newTcp === void 0) {
|
|
109
|
-
return false;
|
|
110
|
-
}
|
|
111
|
-
if (oldTcp === void 0 || newTcp === void 0) {
|
|
112
|
-
return true;
|
|
113
|
-
}
|
|
114
|
-
let changedDelta = 0;
|
|
115
|
-
changedDelta += Math.abs(oldTcp.orientation[0] - newTcp.orientation[0]);
|
|
116
|
-
changedDelta += Math.abs(oldTcp.orientation[1] - newTcp.orientation[1]);
|
|
117
|
-
changedDelta += Math.abs(oldTcp.orientation[2] - newTcp.orientation[2]);
|
|
118
|
-
changedDelta += Math.abs(oldTcp.position[0] - newTcp.position[0]);
|
|
119
|
-
changedDelta += Math.abs(oldTcp.position[1] - newTcp.position[1]);
|
|
120
|
-
changedDelta += Math.abs(oldTcp.position[2] - newTcp.position[2]);
|
|
121
|
-
if (changedDelta > changeDeltaThreshold) {
|
|
122
|
-
return false;
|
|
123
|
-
}
|
|
124
|
-
return oldTcp.coordinate_system === newTcp.coordinate_system && oldTcp.tcp === newTcp.tcp;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
// src/lib/v2/ConnectedMotionGroup.ts
|
|
128
|
-
var MOTION_DELTA_THRESHOLD = 1e-4;
|
|
129
|
-
var ConnectedMotionGroup = class _ConnectedMotionGroup {
|
|
130
|
-
constructor(nova, controller, motionGroup, initialMotionState, motionStateSocket, isVirtual, tcps, motionGroupSpecification, safetySetup) {
|
|
131
|
-
this.nova = nova;
|
|
132
|
-
this.controller = controller;
|
|
133
|
-
this.motionGroup = motionGroup;
|
|
134
|
-
this.initialMotionState = initialMotionState;
|
|
135
|
-
this.motionStateSocket = motionStateSocket;
|
|
136
|
-
this.isVirtual = isVirtual;
|
|
137
|
-
this.tcps = tcps;
|
|
138
|
-
this.motionGroupSpecification = motionGroupSpecification;
|
|
139
|
-
this.safetySetup = safetySetup;
|
|
140
|
-
this.connectedJoggingCartesianSocket = null;
|
|
141
|
-
this.connectedJoggingJointsSocket = null;
|
|
142
|
-
// tmp
|
|
143
|
-
this.joggingVelocity = 10;
|
|
144
|
-
this.rapidlyChangingMotionState = initialMotionState;
|
|
145
|
-
motionStateSocket.addEventListener("message", (event) => {
|
|
146
|
-
var _a;
|
|
147
|
-
const motionStateResponse = (_a = tryParseJson(event.data)) == null ? void 0 : _a.result;
|
|
148
|
-
if (!motionStateResponse) {
|
|
149
|
-
throw new Error(
|
|
150
|
-
`Failed to get motion state for ${this.motionGroupId}: ${event.data}`
|
|
151
|
-
);
|
|
152
|
-
}
|
|
153
|
-
if (!jointValuesEqual(
|
|
154
|
-
this.rapidlyChangingMotionState.joint_position.joints,
|
|
155
|
-
motionStateResponse.joint_position.joints,
|
|
156
|
-
MOTION_DELTA_THRESHOLD
|
|
157
|
-
)) {
|
|
158
|
-
(0, import_mobx.runInAction)(() => {
|
|
159
|
-
this.rapidlyChangingMotionState = motionStateResponse;
|
|
160
|
-
});
|
|
161
|
-
}
|
|
162
|
-
if (!tcpPoseEqual(
|
|
163
|
-
this.rapidlyChangingMotionState.tcp_pose,
|
|
164
|
-
motionStateResponse.tcp_pose,
|
|
165
|
-
MOTION_DELTA_THRESHOLD
|
|
166
|
-
)) {
|
|
167
|
-
(0, import_mobx.runInAction)(() => {
|
|
168
|
-
this.rapidlyChangingMotionState.tcp_pose = motionStateResponse.tcp_pose;
|
|
169
|
-
});
|
|
170
|
-
}
|
|
171
|
-
});
|
|
172
|
-
(0, import_mobx.makeAutoObservable)(this);
|
|
173
|
-
}
|
|
174
|
-
static connect(nova, motionGroupId, controllers) {
|
|
175
|
-
return __async(this, null, function* () {
|
|
176
|
-
var _a;
|
|
177
|
-
const [_motionGroupIndex, controllerId] = motionGroupId.split("@");
|
|
178
|
-
const controller = controllers.find((c) => c.controller === controllerId);
|
|
179
|
-
const motionGroup = controller == null ? void 0 : controller.motion_groups.find(
|
|
180
|
-
(mg) => mg.motion_group === motionGroupId
|
|
181
|
-
);
|
|
182
|
-
if (!controller || !motionGroup) {
|
|
183
|
-
throw new Error(
|
|
184
|
-
`Controller ${controllerId} or motion group ${motionGroupId} not found`
|
|
185
|
-
);
|
|
186
|
-
}
|
|
187
|
-
const motionStateSocket = nova.openReconnectingWebsocket(
|
|
188
|
-
`/motion-groups/${motionGroupId}/state-stream`
|
|
189
|
-
);
|
|
190
|
-
const firstMessage = yield motionStateSocket.firstMessage();
|
|
191
|
-
const initialMotionState = (_a = tryParseJson(firstMessage.data)) == null ? void 0 : _a.result;
|
|
192
|
-
if (!initialMotionState) {
|
|
193
|
-
throw new Error(
|
|
194
|
-
`Unable to parse initial motion state message ${firstMessage.data}`
|
|
195
|
-
);
|
|
196
|
-
}
|
|
197
|
-
console.log(
|
|
198
|
-
`Connected motion state websocket to motion group ${motionGroup.motion_group}. Initial state:
|
|
199
|
-
`,
|
|
200
|
-
initialMotionState
|
|
201
|
-
);
|
|
202
|
-
let isVirtual = false;
|
|
203
|
-
try {
|
|
204
|
-
const opMode = yield nova.api.virtualRobotMode.getOperationMode(controllerId);
|
|
205
|
-
if (opMode) isVirtual = true;
|
|
206
|
-
} catch (err) {
|
|
207
|
-
if (err instanceof import_axios.AxiosError) {
|
|
208
|
-
console.log(
|
|
209
|
-
`Received ${err.status} from getOperationMode, concluding that ${controllerId} is physical`
|
|
210
|
-
);
|
|
211
|
-
} else {
|
|
212
|
-
throw err;
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
const { tcps } = yield nova.api.motionGroupInfos.listTcps(motionGroupId);
|
|
216
|
-
const motionGroupSpecification = yield nova.api.motionGroupInfos.getMotionGroupSpecification(motionGroupId);
|
|
217
|
-
const safetySetup = yield nova.api.motionGroupInfos.getSafetySetup(motionGroupId);
|
|
218
|
-
return new _ConnectedMotionGroup(
|
|
219
|
-
nova,
|
|
220
|
-
controller,
|
|
221
|
-
motionGroup,
|
|
222
|
-
initialMotionState,
|
|
223
|
-
motionStateSocket,
|
|
224
|
-
isVirtual,
|
|
225
|
-
tcps,
|
|
226
|
-
motionGroupSpecification,
|
|
227
|
-
safetySetup
|
|
228
|
-
);
|
|
229
|
-
});
|
|
230
|
-
}
|
|
231
|
-
get motionGroupId() {
|
|
232
|
-
return this.motionGroup.motion_group;
|
|
233
|
-
}
|
|
234
|
-
get controllerId() {
|
|
235
|
-
return this.controller.controller;
|
|
236
|
-
}
|
|
237
|
-
get modelFromController() {
|
|
238
|
-
return this.motionGroup.model_from_controller;
|
|
239
|
-
}
|
|
240
|
-
get wandelscriptIdentifier() {
|
|
241
|
-
const num = this.motionGroupId.split("@")[0];
|
|
242
|
-
return `${this.controllerId.replaceAll("-", "_")}_${num}`;
|
|
243
|
-
}
|
|
244
|
-
/** Jogging velocity in radians for rotation and joint movement */
|
|
245
|
-
get joggingVelocityRads() {
|
|
246
|
-
return this.joggingVelocity * Math.PI / 180;
|
|
247
|
-
}
|
|
248
|
-
get joints() {
|
|
249
|
-
return this.initialMotionState.joint_position.joints.map((_, i) => {
|
|
250
|
-
return {
|
|
251
|
-
index: i
|
|
252
|
-
};
|
|
253
|
-
});
|
|
254
|
-
}
|
|
255
|
-
get dhParameters() {
|
|
256
|
-
return this.motionGroupSpecification.dh_parameters;
|
|
257
|
-
}
|
|
258
|
-
get safetyZones() {
|
|
259
|
-
return this.safetySetup.safety_zones;
|
|
260
|
-
}
|
|
261
|
-
dispose() {
|
|
262
|
-
this.motionStateSocket.close();
|
|
263
|
-
if (this.connectedJoggingCartesianSocket)
|
|
264
|
-
this.connectedJoggingCartesianSocket.close();
|
|
265
|
-
if (this.connectedJoggingJointsSocket)
|
|
266
|
-
this.connectedJoggingJointsSocket.close();
|
|
267
|
-
}
|
|
268
|
-
setJoggingVelocity(velocity) {
|
|
269
|
-
this.joggingVelocity = velocity;
|
|
270
|
-
}
|
|
271
|
-
};
|
|
272
|
-
|
|
273
|
-
// src/lib/v2/vectorUtils.ts
|
|
274
|
-
var THREE = __toESM(require("three"), 1);
|
|
275
|
-
function axisToIndex(axis) {
|
|
276
|
-
switch (axis) {
|
|
277
|
-
case "x":
|
|
278
|
-
return 0;
|
|
279
|
-
case "y":
|
|
280
|
-
return 1;
|
|
281
|
-
case "z":
|
|
282
|
-
return 2;
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
function vector3ToArray(vector) {
|
|
286
|
-
return [vector.x, vector.y, vector.z];
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
// src/lib/v2/JoggerConnection.ts
|
|
290
|
-
var JoggerConnection = class _JoggerConnection {
|
|
291
|
-
constructor(nova, cell, motionGroupId, motionGroupState, opts) {
|
|
292
|
-
this.nova = nova;
|
|
293
|
-
this.cell = cell;
|
|
294
|
-
this.motionGroupId = motionGroupId;
|
|
295
|
-
this.motionGroupState = motionGroupState;
|
|
296
|
-
this.opts = opts;
|
|
297
|
-
// Currently a separate websocket is needed for each mode, pester API people
|
|
298
|
-
// to merge these for simplicity
|
|
299
|
-
this.joggingWebsocket = null;
|
|
300
|
-
this.lastVelocityRequest = null;
|
|
301
|
-
this.lastResponse = null;
|
|
302
|
-
this.joggingWebsocket = nova.openReconnectingWebsocket(
|
|
303
|
-
`/cells/${cell}/execution/jogging`
|
|
304
|
-
);
|
|
305
|
-
this.joggingWebsocket.addEventListener("message", (ev) => {
|
|
306
|
-
const data = tryParseJson(ev.data);
|
|
307
|
-
if (data && "error" in data) {
|
|
308
|
-
if (this.opts.onError) {
|
|
309
|
-
this.opts.onError(ev.data);
|
|
310
|
-
} else {
|
|
311
|
-
throw new Error(ev.data);
|
|
312
|
-
}
|
|
313
|
-
}
|
|
314
|
-
});
|
|
315
|
-
this.joggingWebsocket.addEventListener("message", (ev) => {
|
|
316
|
-
const data = tryParseJson(ev.data);
|
|
317
|
-
if (data && "error" in data) {
|
|
318
|
-
if (this.opts.onError) {
|
|
319
|
-
this.opts.onError(ev.data);
|
|
320
|
-
} else {
|
|
321
|
-
throw new Error(ev.data);
|
|
322
|
-
}
|
|
323
|
-
}
|
|
324
|
-
});
|
|
325
|
-
}
|
|
326
|
-
static open(nova, cell, motionGroupId, opts) {
|
|
327
|
-
return __async(this, null, function* () {
|
|
328
|
-
const motionGroupState = yield nova.api.motionGroupInfos.getCurrentMotionGroupState(motionGroupId);
|
|
329
|
-
return new _JoggerConnection(
|
|
330
|
-
nova,
|
|
331
|
-
cell,
|
|
332
|
-
motionGroupId,
|
|
333
|
-
motionGroupState,
|
|
334
|
-
opts
|
|
335
|
-
);
|
|
336
|
-
});
|
|
337
|
-
}
|
|
338
|
-
get jointCount() {
|
|
339
|
-
var _a;
|
|
340
|
-
return (_a = this.motionGroupState.joint_current) == null ? void 0 : _a.joints.length;
|
|
341
|
-
}
|
|
342
|
-
get activeWebsocket() {
|
|
343
|
-
return this.joggingWebsocket;
|
|
344
|
-
}
|
|
345
|
-
stop() {
|
|
346
|
-
return __async(this, null, function* () {
|
|
347
|
-
var _a, _b;
|
|
348
|
-
if (!this.joggingWebsocket) {
|
|
349
|
-
return;
|
|
350
|
-
}
|
|
351
|
-
if (((_a = this.lastVelocityRequest) == null ? void 0 : _a.message_type) === "JointVelocityRequest") {
|
|
352
|
-
this.joggingWebsocket.sendJson({
|
|
353
|
-
message_type: "JointVelocityRequest",
|
|
354
|
-
velocity: {
|
|
355
|
-
joints: Array.from(new Array(this.jointCount).keys()).map(() => 0)
|
|
356
|
-
}
|
|
357
|
-
});
|
|
358
|
-
}
|
|
359
|
-
if (((_b = this.lastVelocityRequest) == null ? void 0 : _b.message_type) === "TcpVelocityRequest") {
|
|
360
|
-
this.joggingWebsocket.sendJson({
|
|
361
|
-
message_type: "TcpVelocityRequest",
|
|
362
|
-
rotation: [0, 0, 0],
|
|
363
|
-
translation: [0, 0, 0]
|
|
364
|
-
});
|
|
365
|
-
}
|
|
366
|
-
});
|
|
367
|
-
}
|
|
368
|
-
dispose() {
|
|
369
|
-
if (this.joggingWebsocket) {
|
|
370
|
-
this.joggingWebsocket.dispose();
|
|
371
|
-
}
|
|
372
|
-
}
|
|
373
|
-
/**
|
|
374
|
-
* Start rotation of a single robot joint at the specified velocity
|
|
375
|
-
*/
|
|
376
|
-
startJointRotation(_0) {
|
|
377
|
-
return __async(this, arguments, function* ({
|
|
378
|
-
joint,
|
|
379
|
-
velocityRadsPerSec
|
|
380
|
-
}) {
|
|
381
|
-
if (!this.joggingWebsocket) {
|
|
382
|
-
throw new Error(
|
|
383
|
-
"Joint jogging websocket not connected. Wait for reconnect or open new jogging connection"
|
|
384
|
-
);
|
|
385
|
-
}
|
|
386
|
-
const jointVelocities = new Array(this.jointCount).fill(0);
|
|
387
|
-
jointVelocities[joint] = velocityRadsPerSec;
|
|
388
|
-
this.joggingWebsocket.sendJson({
|
|
389
|
-
message_type: "JointVelocityRequest",
|
|
390
|
-
velocity: {
|
|
391
|
-
joints: jointVelocities
|
|
392
|
-
}
|
|
393
|
-
});
|
|
394
|
-
});
|
|
395
|
-
}
|
|
396
|
-
/**
|
|
397
|
-
* Start the TCP moving along a specified axis at a given velocity
|
|
398
|
-
*/
|
|
399
|
-
startTCPTranslation(_0) {
|
|
400
|
-
return __async(this, arguments, function* ({
|
|
401
|
-
axis,
|
|
402
|
-
velocityMmPerSec,
|
|
403
|
-
useToolCoordinateSystem
|
|
404
|
-
}) {
|
|
405
|
-
if (!this.joggingWebsocket) {
|
|
406
|
-
throw new Error(
|
|
407
|
-
"Cartesian jogging websocket not connected. Wait for reconnect or open new jogging connection"
|
|
408
|
-
);
|
|
409
|
-
}
|
|
410
|
-
const joggingVector = [0, 0, 0];
|
|
411
|
-
joggingVector[axisToIndex(axis)] = velocityMmPerSec;
|
|
412
|
-
this.joggingWebsocket.sendJson({
|
|
413
|
-
message_type: "TcpVelocityRequest",
|
|
414
|
-
translation: joggingVector,
|
|
415
|
-
rotation: [0, 0, 0],
|
|
416
|
-
use_tool_coordinate_system: useToolCoordinateSystem
|
|
417
|
-
});
|
|
418
|
-
});
|
|
419
|
-
}
|
|
420
|
-
/**
|
|
421
|
-
* Start the TCP rotating around a specified axis at a given velocity
|
|
422
|
-
*/
|
|
423
|
-
startTCPRotation(_0) {
|
|
424
|
-
return __async(this, arguments, function* ({
|
|
425
|
-
axis,
|
|
426
|
-
velocityRadsPerSec,
|
|
427
|
-
useToolCoordinateSystem
|
|
428
|
-
}) {
|
|
429
|
-
if (!this.joggingWebsocket) {
|
|
430
|
-
throw new Error(
|
|
431
|
-
"Cartesian jogging websocket not connected. Wait for reconnect or open new jogging connection"
|
|
432
|
-
);
|
|
433
|
-
}
|
|
434
|
-
const joggingVector = [0, 0, 0];
|
|
435
|
-
joggingVector[axisToIndex(axis)] = velocityRadsPerSec;
|
|
436
|
-
this.joggingWebsocket.sendJson({
|
|
437
|
-
message_type: "TcpVelocityRequest",
|
|
438
|
-
rotation: joggingVector,
|
|
439
|
-
translation: [0, 0, 0],
|
|
440
|
-
use_tool_coordinate_system: useToolCoordinateSystem
|
|
441
|
-
});
|
|
442
|
-
});
|
|
443
|
-
}
|
|
444
|
-
};
|
|
445
|
-
|
|
446
|
-
// src/lib/v2/MotionStreamConnection.ts
|
|
447
|
-
var import_mobx2 = require("mobx");
|
|
448
|
-
var THREE2 = __toESM(require("three"), 1);
|
|
449
|
-
var MOTION_DELTA_THRESHOLD2 = 1e-4;
|
|
450
|
-
function unwrapRotationVector(newRotationVectorApi, currentRotationVectorApi) {
|
|
451
|
-
const currentRotationVector = new THREE2.Vector3(
|
|
452
|
-
currentRotationVectorApi[0],
|
|
453
|
-
currentRotationVectorApi[1],
|
|
454
|
-
currentRotationVectorApi[2]
|
|
455
|
-
);
|
|
456
|
-
const newRotationVector = new THREE2.Vector3(
|
|
457
|
-
newRotationVectorApi[0],
|
|
458
|
-
newRotationVectorApi[1],
|
|
459
|
-
newRotationVectorApi[2]
|
|
460
|
-
);
|
|
461
|
-
const currentAngle = currentRotationVector.length();
|
|
462
|
-
const currentAxis = currentRotationVector.normalize();
|
|
463
|
-
let newAngle = newRotationVector.length();
|
|
464
|
-
let newAxis = newRotationVector.normalize();
|
|
465
|
-
if (newAxis.dot(currentAxis) < 0) {
|
|
466
|
-
newAngle = -newAngle;
|
|
467
|
-
newAxis = newAxis.multiplyScalar(-1);
|
|
468
|
-
}
|
|
469
|
-
let angleDifference = newAngle - currentAngle;
|
|
470
|
-
angleDifference -= 2 * Math.PI * Math.floor((angleDifference + Math.PI) / (2 * Math.PI));
|
|
471
|
-
newAngle = currentAngle + angleDifference;
|
|
472
|
-
return vector3ToArray(newAxis.multiplyScalar(newAngle));
|
|
473
|
-
}
|
|
474
|
-
var MotionStreamConnection = class _MotionStreamConnection {
|
|
475
|
-
constructor(nova, controller, motionGroup, initialMotionState, motionStateSocket) {
|
|
476
|
-
this.nova = nova;
|
|
477
|
-
this.controller = controller;
|
|
478
|
-
this.motionGroup = motionGroup;
|
|
479
|
-
this.initialMotionState = initialMotionState;
|
|
480
|
-
this.motionStateSocket = motionStateSocket;
|
|
481
|
-
this.rapidlyChangingMotionState = initialMotionState;
|
|
482
|
-
motionStateSocket.addEventListener("message", (event) => {
|
|
483
|
-
var _a;
|
|
484
|
-
const motionState = (_a = tryParseJson(event.data)) == null ? void 0 : _a.result;
|
|
485
|
-
if (!motionState) {
|
|
486
|
-
throw new Error(
|
|
487
|
-
`Failed to get motion state for ${this.motionGroupId}: ${event.data}`
|
|
488
|
-
);
|
|
489
|
-
}
|
|
490
|
-
if (!jointValuesEqual(
|
|
491
|
-
this.rapidlyChangingMotionState.joint_position.joints,
|
|
492
|
-
motionState.joint_position.joints,
|
|
493
|
-
MOTION_DELTA_THRESHOLD2
|
|
494
|
-
)) {
|
|
495
|
-
(0, import_mobx2.runInAction)(() => {
|
|
496
|
-
this.rapidlyChangingMotionState = motionState;
|
|
497
|
-
});
|
|
498
|
-
}
|
|
499
|
-
if (!tcpPoseEqual(
|
|
500
|
-
this.rapidlyChangingMotionState.tcp_pose,
|
|
501
|
-
motionState.tcp_pose,
|
|
502
|
-
MOTION_DELTA_THRESHOLD2
|
|
503
|
-
)) {
|
|
504
|
-
(0, import_mobx2.runInAction)(() => {
|
|
505
|
-
if (this.rapidlyChangingMotionState.tcp_pose == void 0) {
|
|
506
|
-
this.rapidlyChangingMotionState.tcp_pose = motionState.tcp_pose;
|
|
507
|
-
} else {
|
|
508
|
-
this.rapidlyChangingMotionState.tcp_pose = {
|
|
509
|
-
position: motionState.tcp_pose.position,
|
|
510
|
-
orientation: unwrapRotationVector(
|
|
511
|
-
motionState.tcp_pose.orientation,
|
|
512
|
-
this.rapidlyChangingMotionState.tcp_pose.orientation
|
|
513
|
-
),
|
|
514
|
-
tcp: motionState.tcp_pose.tcp,
|
|
515
|
-
coordinate_system: motionState.tcp_pose.coordinate_system
|
|
516
|
-
};
|
|
517
|
-
}
|
|
518
|
-
});
|
|
519
|
-
}
|
|
520
|
-
});
|
|
521
|
-
(0, import_mobx2.makeAutoObservable)(this);
|
|
522
|
-
}
|
|
523
|
-
static open(nova, motionGroupId) {
|
|
524
|
-
return __async(this, null, function* () {
|
|
525
|
-
var _a;
|
|
526
|
-
const { controllers } = yield nova.api.controller.listControllers();
|
|
527
|
-
const [_motionGroupIndex, controllerId] = motionGroupId.split("@");
|
|
528
|
-
const controller = controllers.find((c) => c.controller === controllerId);
|
|
529
|
-
const motionGroup = controller == null ? void 0 : controller.motion_groups.find(
|
|
530
|
-
(mg) => mg.motion_group === motionGroupId
|
|
531
|
-
);
|
|
532
|
-
if (!controller || !motionGroup) {
|
|
533
|
-
throw new Error(
|
|
534
|
-
`Controller ${controllerId} or motion group ${motionGroupId} not found`
|
|
535
|
-
);
|
|
536
|
-
}
|
|
537
|
-
const motionStateSocket = nova.openReconnectingWebsocket(
|
|
538
|
-
`/motion-groups/${motionGroupId}/state-stream`
|
|
539
|
-
);
|
|
540
|
-
const firstMessage = yield motionStateSocket.firstMessage();
|
|
541
|
-
console.log("got first message", firstMessage);
|
|
542
|
-
const initialMotionState = (_a = tryParseJson(firstMessage.data)) == null ? void 0 : _a.result;
|
|
543
|
-
if (!initialMotionState) {
|
|
544
|
-
throw new Error(
|
|
545
|
-
`Unable to parse initial motion state message ${firstMessage.data}`
|
|
546
|
-
);
|
|
547
|
-
}
|
|
548
|
-
console.log(
|
|
549
|
-
`Connected motion state websocket to motion group ${motionGroup.motion_group}. Initial state:
|
|
550
|
-
`,
|
|
551
|
-
initialMotionState
|
|
552
|
-
);
|
|
553
|
-
return new _MotionStreamConnection(
|
|
554
|
-
nova,
|
|
555
|
-
controller,
|
|
556
|
-
motionGroup,
|
|
557
|
-
initialMotionState,
|
|
558
|
-
motionStateSocket
|
|
559
|
-
);
|
|
560
|
-
});
|
|
561
|
-
}
|
|
562
|
-
get motionGroupId() {
|
|
563
|
-
return this.motionGroup.motion_group;
|
|
564
|
-
}
|
|
565
|
-
get controllerId() {
|
|
566
|
-
return this.controller.controller;
|
|
567
|
-
}
|
|
568
|
-
get modelFromController() {
|
|
569
|
-
return this.motionGroup.model_from_controller;
|
|
570
|
-
}
|
|
571
|
-
get wandelscriptIdentifier() {
|
|
572
|
-
const num = this.motionGroupId.split("@")[0];
|
|
573
|
-
return `${this.controllerId.replaceAll("-", "_")}_${num}`;
|
|
574
|
-
}
|
|
575
|
-
get joints() {
|
|
576
|
-
return this.initialMotionState.joint_position.joints.map((_, i) => {
|
|
577
|
-
return {
|
|
578
|
-
index: i
|
|
579
|
-
};
|
|
580
|
-
});
|
|
581
|
-
}
|
|
582
|
-
dispose() {
|
|
583
|
-
this.motionStateSocket.close();
|
|
584
|
-
}
|
|
585
|
-
};
|
|
586
|
-
|
|
587
77
|
// src/lib/v2/NovaCellAPIClient.ts
|
|
588
78
|
var import_v2 = require("@wandelbots/nova-api/v2");
|
|
589
|
-
var
|
|
79
|
+
var import_axios = __toESM(require("axios"), 1);
|
|
590
80
|
var NovaCellAPIClient = class {
|
|
591
81
|
constructor(cellId, opts) {
|
|
592
82
|
this.cellId = cellId;
|
|
@@ -594,27 +84,29 @@ var NovaCellAPIClient = class {
|
|
|
594
84
|
this.system = this.withUnwrappedResponsesOnly(import_v2.SystemApi);
|
|
595
85
|
this.cell = this.withUnwrappedResponsesOnly(import_v2.CellApi);
|
|
596
86
|
this.motionGroup = this.withCellId(import_v2.MotionGroupApi);
|
|
597
|
-
this.
|
|
87
|
+
this.motionGroupModels = this.withCellId(import_v2.MotionGroupModelsApi);
|
|
598
88
|
this.controller = this.withCellId(import_v2.ControllerApi);
|
|
599
|
-
this.program = this.withCellId(import_v2.ProgramApi);
|
|
600
|
-
this.programOperator = this.withCellId(import_v2.ProgramOperatorApi);
|
|
601
89
|
this.controllerIOs = this.withCellId(import_v2.ControllerInputsOutputsApi);
|
|
602
|
-
this.motionGroupKinematic = this.withCellId(import_v2.MotionGroupKinematicsApi);
|
|
603
90
|
this.trajectoryPlanning = this.withCellId(import_v2.TrajectoryPlanningApi);
|
|
604
91
|
this.trajectoryExecution = this.withCellId(import_v2.TrajectoryExecutionApi);
|
|
605
|
-
this.
|
|
92
|
+
this.trajectoryCaching = this.withCellId(import_v2.TrajectoryCachingApi);
|
|
606
93
|
this.application = this.withCellId(import_v2.ApplicationApi);
|
|
607
94
|
this.applicationGlobal = this.withUnwrappedResponsesOnly(import_v2.ApplicationApi);
|
|
608
95
|
this.jogging = this.withCellId(import_v2.JoggingApi);
|
|
609
|
-
this.
|
|
610
|
-
this.
|
|
611
|
-
this.
|
|
612
|
-
this.
|
|
96
|
+
this.kinematics = this.withCellId(import_v2.KinematicsApi);
|
|
97
|
+
this.busInputsOutputs = this.withCellId(import_v2.BUSInputsOutputsApi);
|
|
98
|
+
this.virtualController = this.withCellId(import_v2.VirtualControllerApi);
|
|
99
|
+
this.virtualControllerBehavior = this.withCellId(
|
|
100
|
+
import_v2.VirtualControllerBehaviorApi
|
|
101
|
+
);
|
|
102
|
+
this.virtualControllerIOs = this.withCellId(
|
|
103
|
+
import_v2.VirtualControllerInputsOutputsApi
|
|
104
|
+
);
|
|
613
105
|
this.storeObject = this.withCellId(import_v2.StoreObjectApi);
|
|
614
106
|
this.storeCollisionComponents = this.withCellId(
|
|
615
107
|
import_v2.StoreCollisionComponentsApi
|
|
616
108
|
);
|
|
617
|
-
this.
|
|
109
|
+
this.storeCollisionSetups = this.withCellId(import_v2.StoreCollisionSetupsApi);
|
|
618
110
|
}
|
|
619
111
|
/**
|
|
620
112
|
* Some TypeScript sorcery which alters the API class methods so you don't
|
|
@@ -630,7 +122,7 @@ var NovaCellAPIClient = class {
|
|
|
630
122
|
}
|
|
631
123
|
}),
|
|
632
124
|
(_a = this.opts.basePath) != null ? _a : "",
|
|
633
|
-
(_b = this.opts.axiosInstance) != null ? _b :
|
|
125
|
+
(_b = this.opts.axiosInstance) != null ? _b : import_axios.default.create()
|
|
634
126
|
);
|
|
635
127
|
for (const key of Reflect.ownKeys(Reflect.getPrototypeOf(apiClient))) {
|
|
636
128
|
if (key !== "constructor" && typeof apiClient[key] === "function") {
|
|
@@ -654,7 +146,7 @@ var NovaCellAPIClient = class {
|
|
|
654
146
|
}
|
|
655
147
|
}),
|
|
656
148
|
(_a = this.opts.basePath) != null ? _a : "",
|
|
657
|
-
(_b = this.opts.axiosInstance) != null ? _b :
|
|
149
|
+
(_b = this.opts.axiosInstance) != null ? _b : import_axios.default.create()
|
|
658
150
|
);
|
|
659
151
|
for (const key of Reflect.ownKeys(Reflect.getPrototypeOf(apiClient))) {
|
|
660
152
|
if (key !== "constructor" && typeof apiClient[key] === "function") {
|
|
@@ -669,7 +161,7 @@ var NovaCellAPIClient = class {
|
|
|
669
161
|
};
|
|
670
162
|
|
|
671
163
|
// src/lib/v2/NovaClient.ts
|
|
672
|
-
var
|
|
164
|
+
var import_axios3 = __toESM(require("axios"), 1);
|
|
673
165
|
var import_url_join = __toESM(require("url-join"), 1);
|
|
674
166
|
|
|
675
167
|
// src/LoginWithAuth0.ts
|
|
@@ -910,7 +402,7 @@ var AvailableStorage = class {
|
|
|
910
402
|
var availableStorage = new AvailableStorage();
|
|
911
403
|
|
|
912
404
|
// src/lib/v2/mock/MockNovaInstance.ts
|
|
913
|
-
var
|
|
405
|
+
var import_axios2 = require("axios");
|
|
914
406
|
var pathToRegexp = __toESM(require("path-to-regexp"), 1);
|
|
915
407
|
var MockNovaInstance = class {
|
|
916
408
|
constructor() {
|
|
@@ -954,7 +446,6 @@ var MockNovaInstance = class {
|
|
|
954
446
|
configuration: {
|
|
955
447
|
kind: "VirtualController",
|
|
956
448
|
manufacturer: "universalrobots",
|
|
957
|
-
position: "[0,-1.571,-1.571,-1.571,1.571,-1.571,0]",
|
|
958
449
|
type: "universalrobots-ur5e"
|
|
959
450
|
},
|
|
960
451
|
name: "mock-ur5"
|
|
@@ -1593,7 +1084,7 @@ var MockNovaInstance = class {
|
|
|
1593
1084
|
};
|
|
1594
1085
|
}
|
|
1595
1086
|
}
|
|
1596
|
-
throw new
|
|
1087
|
+
throw new import_axios2.AxiosError(
|
|
1597
1088
|
`No mock handler matched this request: ${method} ${path}`,
|
|
1598
1089
|
"404",
|
|
1599
1090
|
config
|
|
@@ -1834,6 +1325,8 @@ var defaultMotionState = {
|
|
|
1834
1325
|
result: {
|
|
1835
1326
|
motion_group: "0@universalrobots-ur5e",
|
|
1836
1327
|
controller: "universalrobots-ur5e",
|
|
1328
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1329
|
+
sequence_number: 1,
|
|
1837
1330
|
joint_position: {
|
|
1838
1331
|
joints: [
|
|
1839
1332
|
1.1699999570846558,
|
|
@@ -1844,17 +1337,17 @@ var defaultMotionState = {
|
|
|
1844
1337
|
1.2799999713897705
|
|
1845
1338
|
]
|
|
1846
1339
|
},
|
|
1847
|
-
|
|
1848
|
-
|
|
1340
|
+
joint_limit_reached: {
|
|
1341
|
+
limit_reached: [false, false, false, false, false, false]
|
|
1849
1342
|
},
|
|
1343
|
+
standstill: false,
|
|
1850
1344
|
flange_pose: {
|
|
1851
1345
|
position: [1.3300010259703043, -409.2680714682808, 531.0203477065281],
|
|
1852
1346
|
orientation: [
|
|
1853
1347
|
1.7564919306270736,
|
|
1854
1348
|
-1.7542521568325058,
|
|
1855
1349
|
0.7326972590614671
|
|
1856
|
-
]
|
|
1857
|
-
coordinate_system: ""
|
|
1350
|
+
]
|
|
1858
1351
|
},
|
|
1859
1352
|
tcp_pose: {
|
|
1860
1353
|
position: [1.3300010259703043, -409.2680714682808, 531.0203477065281],
|
|
@@ -1862,25 +1355,7 @@ var defaultMotionState = {
|
|
|
1862
1355
|
1.7564919306270736,
|
|
1863
1356
|
-1.7542521568325058,
|
|
1864
1357
|
0.7326972590614671
|
|
1865
|
-
]
|
|
1866
|
-
coordinate_system: "",
|
|
1867
|
-
tcp: "Flange"
|
|
1868
|
-
},
|
|
1869
|
-
velocity: {
|
|
1870
|
-
linear: [0, 0, 0],
|
|
1871
|
-
angular: [0, 0, 0],
|
|
1872
|
-
coordinate_system: ""
|
|
1873
|
-
},
|
|
1874
|
-
force: {
|
|
1875
|
-
force: [0, 0, 0],
|
|
1876
|
-
moment: [0, 0, 0],
|
|
1877
|
-
coordinate_system: ""
|
|
1878
|
-
},
|
|
1879
|
-
joint_limit_reached: {
|
|
1880
|
-
limit_reached: [false, false, false, false, false, false]
|
|
1881
|
-
},
|
|
1882
|
-
joint_current: {
|
|
1883
|
-
joints: [0, 0, 0, 0, 0, 0]
|
|
1358
|
+
]
|
|
1884
1359
|
}
|
|
1885
1360
|
}
|
|
1886
1361
|
};
|
|
@@ -1900,7 +1375,7 @@ var NovaClient = class {
|
|
|
1900
1375
|
if (this.config.instanceUrl === "https://mock.example.com") {
|
|
1901
1376
|
this.mock = new MockNovaInstance();
|
|
1902
1377
|
}
|
|
1903
|
-
const axiosInstance =
|
|
1378
|
+
const axiosInstance = import_axios3.default.create({
|
|
1904
1379
|
baseURL: (0, import_url_join.default)(this.config.instanceUrl, "/api/v2"),
|
|
1905
1380
|
// TODO - backend needs to set proper CORS headers for this
|
|
1906
1381
|
headers: typeof window !== "undefined" && window.location.origin.includes("localhost") ? {} : {
|
|
@@ -1923,7 +1398,7 @@ var NovaClient = class {
|
|
|
1923
1398
|
(r) => r,
|
|
1924
1399
|
(error) => __async(this, null, function* () {
|
|
1925
1400
|
var _a2, _b;
|
|
1926
|
-
if ((0,
|
|
1401
|
+
if ((0, import_axios3.isAxiosError)(error)) {
|
|
1927
1402
|
if (((_a2 = error.response) == null ? void 0 : _a2.status) === 401) {
|
|
1928
1403
|
try {
|
|
1929
1404
|
yield this.renewAuthentication();
|
|
@@ -2008,229 +1483,11 @@ var NovaClient = class {
|
|
|
2008
1483
|
mock: this.mock
|
|
2009
1484
|
});
|
|
2010
1485
|
}
|
|
2011
|
-
/**
|
|
2012
|
-
* Connect to the motion state websocket(s) for a given motion group
|
|
2013
|
-
*/
|
|
2014
|
-
connectMotionStream(motionGroupId) {
|
|
2015
|
-
return __async(this, null, function* () {
|
|
2016
|
-
return yield MotionStreamConnection.open(this, motionGroupId);
|
|
2017
|
-
});
|
|
2018
|
-
}
|
|
2019
|
-
connectMotionGroups(motionGroupIds) {
|
|
2020
|
-
return __async(this, null, function* () {
|
|
2021
|
-
const { controllers } = yield this.api.controller.listControllers();
|
|
2022
|
-
return Promise.all(
|
|
2023
|
-
motionGroupIds.map(
|
|
2024
|
-
(motionGroupId) => ConnectedMotionGroup.connect(this, motionGroupId, controllers)
|
|
2025
|
-
)
|
|
2026
|
-
);
|
|
2027
|
-
});
|
|
2028
|
-
}
|
|
2029
|
-
connectMotionGroup(motionGroupId) {
|
|
2030
|
-
return __async(this, null, function* () {
|
|
2031
|
-
const motionGroups = yield this.connectMotionGroups([motionGroupId]);
|
|
2032
|
-
return motionGroups[0];
|
|
2033
|
-
});
|
|
2034
|
-
}
|
|
2035
|
-
};
|
|
2036
|
-
|
|
2037
|
-
// src/lib/v2/ProgramStateConnection.ts
|
|
2038
|
-
var import_axios5 = require("axios");
|
|
2039
|
-
var import_mobx3 = require("mobx");
|
|
2040
|
-
var ProgramState = /* @__PURE__ */ ((ProgramState2) => {
|
|
2041
|
-
ProgramState2["NotStarted"] = "not started";
|
|
2042
|
-
ProgramState2["Running"] = "running";
|
|
2043
|
-
ProgramState2["Stopped"] = "stopped";
|
|
2044
|
-
ProgramState2["Failed"] = "failed";
|
|
2045
|
-
ProgramState2["Completed"] = "completed";
|
|
2046
|
-
return ProgramState2;
|
|
2047
|
-
})(ProgramState || {});
|
|
2048
|
-
var ProgramStateConnection = class {
|
|
2049
|
-
constructor(nova) {
|
|
2050
|
-
this.nova = nova;
|
|
2051
|
-
this.currentProgram = {};
|
|
2052
|
-
this.logs = [];
|
|
2053
|
-
this.executionState = "idle";
|
|
2054
|
-
this.currentlyExecutingProgramRunnerId = null;
|
|
2055
|
-
(0, import_mobx3.makeAutoObservable)(this, {}, { autoBind: true });
|
|
2056
|
-
this.programStateSocket = nova.openReconnectingWebsocket(`/programs/state`);
|
|
2057
|
-
this.programStateSocket.addEventListener("message", (ev) => {
|
|
2058
|
-
const msg = tryParseJson(ev.data);
|
|
2059
|
-
if (!msg) {
|
|
2060
|
-
console.error("Failed to parse program state message", ev.data);
|
|
2061
|
-
return;
|
|
2062
|
-
}
|
|
2063
|
-
if (msg.type === "update") {
|
|
2064
|
-
this.handleProgramStateMessage(msg);
|
|
2065
|
-
}
|
|
2066
|
-
});
|
|
2067
|
-
}
|
|
2068
|
-
/** Handle a program state update from the backend */
|
|
2069
|
-
handleProgramStateMessage(msg) {
|
|
2070
|
-
return __async(this, null, function* () {
|
|
2071
|
-
var _a;
|
|
2072
|
-
const { runner } = msg;
|
|
2073
|
-
if (runner.id !== this.currentlyExecutingProgramRunnerId) return;
|
|
2074
|
-
if (runner.state === "failed" /* Failed */) {
|
|
2075
|
-
try {
|
|
2076
|
-
const runnerState = yield this.nova.api.program.getProgramRun(runner.id);
|
|
2077
|
-
const stdout = runnerState.stdout;
|
|
2078
|
-
if (stdout) {
|
|
2079
|
-
this.log(stdout);
|
|
2080
|
-
}
|
|
2081
|
-
this.logError(
|
|
2082
|
-
`Program runner ${runner.id} failed with error: ${runnerState.error}
|
|
2083
|
-
${runnerState.traceback}`
|
|
2084
|
-
);
|
|
2085
|
-
} catch (err) {
|
|
2086
|
-
this.logError(
|
|
2087
|
-
`Failed to retrieve results for program ${runner.id}: ${err}`
|
|
2088
|
-
);
|
|
2089
|
-
}
|
|
2090
|
-
this.currentProgram.state = "failed" /* Failed */;
|
|
2091
|
-
this.gotoIdleState();
|
|
2092
|
-
} else if (runner.state === "stopped" /* Stopped */) {
|
|
2093
|
-
try {
|
|
2094
|
-
const runnerState = yield this.nova.api.program.getProgramRun(runner.id);
|
|
2095
|
-
const stdout = runnerState.stdout;
|
|
2096
|
-
if (stdout) {
|
|
2097
|
-
this.log(stdout);
|
|
2098
|
-
}
|
|
2099
|
-
this.currentProgram.state = "stopped" /* Stopped */;
|
|
2100
|
-
this.log(`Program runner ${runner.id} stopped`);
|
|
2101
|
-
} catch (err) {
|
|
2102
|
-
this.logError(
|
|
2103
|
-
`Failed to retrieve results for program ${runner.id}: ${err}`
|
|
2104
|
-
);
|
|
2105
|
-
}
|
|
2106
|
-
this.gotoIdleState();
|
|
2107
|
-
} else if (runner.state === "completed" /* Completed */) {
|
|
2108
|
-
try {
|
|
2109
|
-
const runnerState = yield this.nova.api.program.getProgramRun(runner.id);
|
|
2110
|
-
const stdout = runnerState.stdout;
|
|
2111
|
-
if (stdout) {
|
|
2112
|
-
this.log(stdout);
|
|
2113
|
-
}
|
|
2114
|
-
this.log(
|
|
2115
|
-
`Program runner ${runner.id} finished successfully in ${(_a = runner.execution_time) == null ? void 0 : _a.toFixed(2)} seconds`
|
|
2116
|
-
);
|
|
2117
|
-
this.currentProgram.state = "completed" /* Completed */;
|
|
2118
|
-
} catch (err) {
|
|
2119
|
-
this.logError(
|
|
2120
|
-
`Failed to retrieve results for program ${runner.id}: ${err}`
|
|
2121
|
-
);
|
|
2122
|
-
}
|
|
2123
|
-
this.gotoIdleState();
|
|
2124
|
-
} else if (runner.state === "running" /* Running */) {
|
|
2125
|
-
this.currentProgram.state = "running" /* Running */;
|
|
2126
|
-
this.log(`Program runner ${runner.id} now running`);
|
|
2127
|
-
} else if (runner.state !== "not started" /* NotStarted */) {
|
|
2128
|
-
console.error(runner);
|
|
2129
|
-
this.logError(
|
|
2130
|
-
`Program runner ${runner.id} entered unexpected state: ${runner.state}`
|
|
2131
|
-
);
|
|
2132
|
-
this.currentProgram.state = "not started" /* NotStarted */;
|
|
2133
|
-
this.gotoIdleState();
|
|
2134
|
-
}
|
|
2135
|
-
});
|
|
2136
|
-
}
|
|
2137
|
-
/** Call when a program is no longer executing */
|
|
2138
|
-
gotoIdleState() {
|
|
2139
|
-
(0, import_mobx3.runInAction)(() => {
|
|
2140
|
-
this.executionState = "idle";
|
|
2141
|
-
});
|
|
2142
|
-
this.currentlyExecutingProgramRunnerId = null;
|
|
2143
|
-
}
|
|
2144
|
-
executeProgram(wandelscript, initial_state, activeRobot) {
|
|
2145
|
-
return __async(this, null, function* () {
|
|
2146
|
-
this.currentProgram = {
|
|
2147
|
-
wandelscript,
|
|
2148
|
-
state: "not started" /* NotStarted */
|
|
2149
|
-
};
|
|
2150
|
-
const { currentProgram: openProgram } = this;
|
|
2151
|
-
if (!openProgram) return;
|
|
2152
|
-
(0, import_mobx3.runInAction)(() => {
|
|
2153
|
-
this.executionState = "starting";
|
|
2154
|
-
});
|
|
2155
|
-
const trimmedCode = openProgram.wandelscript.replaceAll(/^\s*$/gm, "");
|
|
2156
|
-
try {
|
|
2157
|
-
const programRunnerRef = yield this.nova.api.program.createProgramRun(
|
|
2158
|
-
{
|
|
2159
|
-
code: trimmedCode,
|
|
2160
|
-
initial_state,
|
|
2161
|
-
default_robot: activeRobot == null ? void 0 : activeRobot.wandelscriptIdentifier
|
|
2162
|
-
},
|
|
2163
|
-
{
|
|
2164
|
-
headers: {
|
|
2165
|
-
"Content-Type": "application/json"
|
|
2166
|
-
}
|
|
2167
|
-
}
|
|
2168
|
-
);
|
|
2169
|
-
this.log(`Created program runner ${programRunnerRef.id}"`);
|
|
2170
|
-
(0, import_mobx3.runInAction)(() => {
|
|
2171
|
-
this.executionState = "executing";
|
|
2172
|
-
});
|
|
2173
|
-
this.currentlyExecutingProgramRunnerId = programRunnerRef.id;
|
|
2174
|
-
} catch (error) {
|
|
2175
|
-
if (error instanceof import_axios5.AxiosError && error.response && error.request) {
|
|
2176
|
-
this.logError(
|
|
2177
|
-
`${error.response.status} ${error.response.statusText} from ${error.response.config.url} ${JSON.stringify(error.response.data)}`
|
|
2178
|
-
);
|
|
2179
|
-
} else {
|
|
2180
|
-
this.logError(JSON.stringify(error));
|
|
2181
|
-
}
|
|
2182
|
-
(0, import_mobx3.runInAction)(() => {
|
|
2183
|
-
this.executionState = "idle";
|
|
2184
|
-
});
|
|
2185
|
-
}
|
|
2186
|
-
});
|
|
2187
|
-
}
|
|
2188
|
-
stopProgram() {
|
|
2189
|
-
return __async(this, null, function* () {
|
|
2190
|
-
if (!this.currentlyExecutingProgramRunnerId) return;
|
|
2191
|
-
(0, import_mobx3.runInAction)(() => {
|
|
2192
|
-
this.executionState = "stopping";
|
|
2193
|
-
});
|
|
2194
|
-
try {
|
|
2195
|
-
yield this.nova.api.program.stopProgramRun(
|
|
2196
|
-
this.currentlyExecutingProgramRunnerId
|
|
2197
|
-
);
|
|
2198
|
-
} catch (err) {
|
|
2199
|
-
(0, import_mobx3.runInAction)(() => {
|
|
2200
|
-
this.executionState = "executing";
|
|
2201
|
-
});
|
|
2202
|
-
throw err;
|
|
2203
|
-
}
|
|
2204
|
-
});
|
|
2205
|
-
}
|
|
2206
|
-
reset() {
|
|
2207
|
-
this.currentProgram = {};
|
|
2208
|
-
}
|
|
2209
|
-
log(message) {
|
|
2210
|
-
console.log(message);
|
|
2211
|
-
this.logs.push({
|
|
2212
|
-
timestamp: Date.now(),
|
|
2213
|
-
message
|
|
2214
|
-
});
|
|
2215
|
-
}
|
|
2216
|
-
logError(message) {
|
|
2217
|
-
console.log(message);
|
|
2218
|
-
this.logs.push({
|
|
2219
|
-
timestamp: Date.now(),
|
|
2220
|
-
message,
|
|
2221
|
-
level: "error"
|
|
2222
|
-
});
|
|
2223
|
-
}
|
|
2224
1486
|
};
|
|
2225
1487
|
// Annotate the CommonJS export names for ESM import in node:
|
|
2226
1488
|
0 && (module.exports = {
|
|
2227
|
-
ConnectedMotionGroup,
|
|
2228
|
-
JoggerConnection,
|
|
2229
|
-
MotionStreamConnection,
|
|
2230
1489
|
NovaCellAPIClient,
|
|
2231
1490
|
NovaClient,
|
|
2232
|
-
ProgramState,
|
|
2233
|
-
ProgramStateConnection,
|
|
2234
1491
|
...require("@wandelbots/nova-api/v2")
|
|
2235
1492
|
});
|
|
2236
1493
|
//# sourceMappingURL=index.cjs.map
|