@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.
Files changed (40) hide show
  1. package/README.md +29 -1
  2. package/dist/{chunk-6WCKJOFL.js → chunk-4FP7NTKS.js} +51 -1
  3. package/dist/chunk-4FP7NTKS.js.map +1 -0
  4. package/dist/{chunk-V3NJLR6P.js → chunk-DOFCSS2H.js} +1 -51
  5. package/dist/chunk-DOFCSS2H.js.map +1 -0
  6. package/dist/index.js +8 -8
  7. package/dist/lib/v1/index.js +6 -6
  8. package/dist/lib/v2/NovaCellAPIClient.d.ts +9 -11
  9. package/dist/lib/v2/NovaCellAPIClient.d.ts.map +1 -1
  10. package/dist/lib/v2/NovaClient.d.ts +0 -8
  11. package/dist/lib/v2/NovaClient.d.ts.map +1 -1
  12. package/dist/lib/v2/index.cjs +28 -771
  13. package/dist/lib/v2/index.cjs.map +1 -1
  14. package/dist/lib/v2/index.d.ts +0 -4
  15. package/dist/lib/v2/index.d.ts.map +1 -1
  16. package/dist/lib/v2/index.js +32 -764
  17. package/dist/lib/v2/index.js.map +1 -1
  18. package/dist/lib/v2/mock/MockNovaInstance.d.ts.map +1 -1
  19. package/package.json +2 -2
  20. package/src/lib/v2/NovaCellAPIClient.ts +22 -22
  21. package/src/lib/v2/NovaClient.ts +0 -28
  22. package/src/lib/v2/index.ts +0 -4
  23. package/src/lib/v2/mock/MockNovaInstance.ts +9 -32
  24. package/dist/chunk-6WCKJOFL.js.map +0 -1
  25. package/dist/chunk-V3NJLR6P.js.map +0 -1
  26. package/dist/lib/v2/ConnectedMotionGroup.d.ts +0 -41
  27. package/dist/lib/v2/ConnectedMotionGroup.d.ts.map +0 -1
  28. package/dist/lib/v2/JoggerConnection.d.ts +0 -53
  29. package/dist/lib/v2/JoggerConnection.d.ts.map +0 -1
  30. package/dist/lib/v2/MotionStreamConnection.d.ts +0 -25
  31. package/dist/lib/v2/MotionStreamConnection.d.ts.map +0 -1
  32. package/dist/lib/v2/ProgramStateConnection.d.ts +0 -53
  33. package/dist/lib/v2/ProgramStateConnection.d.ts.map +0 -1
  34. package/dist/lib/v2/motionStateUpdate.d.ts +0 -4
  35. package/dist/lib/v2/motionStateUpdate.d.ts.map +0 -1
  36. package/src/lib/v2/ConnectedMotionGroup.ts +0 -216
  37. package/src/lib/v2/JoggerConnection.ts +0 -207
  38. package/src/lib/v2/MotionStreamConnection.ts +0 -201
  39. package/src/lib/v2/ProgramStateConnection.ts +0 -249
  40. package/src/lib/v2/motionStateUpdate.ts +0 -55
@@ -4,532 +4,33 @@ import {
4
4
  __spreadProps,
5
5
  __spreadValues,
6
6
  availableStorage,
7
- loginWithAuth0,
8
- tryParseJson
9
- } from "../../chunk-V3NJLR6P.js";
7
+ loginWithAuth0
8
+ } from "../../chunk-DOFCSS2H.js";
10
9
 
11
10
  // src/lib/v2/index.ts
12
11
  export * from "@wandelbots/nova-api/v2";
13
12
 
14
- // src/lib/v2/ConnectedMotionGroup.ts
15
- import { AxiosError } from "axios";
16
- import { makeAutoObservable, runInAction } from "mobx";
17
-
18
- // src/lib/v2/motionStateUpdate.ts
19
- function jointValuesEqual(oldJointValues, newJointValues, changeDeltaThreshold) {
20
- if (newJointValues.length !== oldJointValues.length) {
21
- return true;
22
- }
23
- for (let jointIndex = 0; jointIndex < newJointValues.length; jointIndex++) {
24
- if (Math.abs(newJointValues[jointIndex] - oldJointValues[jointIndex]) > changeDeltaThreshold) {
25
- return false;
26
- }
27
- }
28
- return true;
29
- }
30
- function tcpPoseEqual(oldTcp, newTcp, changeDeltaThreshold) {
31
- if (oldTcp === void 0 && newTcp || oldTcp && newTcp === void 0) {
32
- return false;
33
- }
34
- if (oldTcp === void 0 || newTcp === void 0) {
35
- return true;
36
- }
37
- let changedDelta = 0;
38
- changedDelta += Math.abs(oldTcp.orientation[0] - newTcp.orientation[0]);
39
- changedDelta += Math.abs(oldTcp.orientation[1] - newTcp.orientation[1]);
40
- changedDelta += Math.abs(oldTcp.orientation[2] - newTcp.orientation[2]);
41
- changedDelta += Math.abs(oldTcp.position[0] - newTcp.position[0]);
42
- changedDelta += Math.abs(oldTcp.position[1] - newTcp.position[1]);
43
- changedDelta += Math.abs(oldTcp.position[2] - newTcp.position[2]);
44
- if (changedDelta > changeDeltaThreshold) {
45
- return false;
46
- }
47
- return oldTcp.coordinate_system === newTcp.coordinate_system && oldTcp.tcp === newTcp.tcp;
48
- }
49
-
50
- // src/lib/v2/ConnectedMotionGroup.ts
51
- var MOTION_DELTA_THRESHOLD = 1e-4;
52
- var ConnectedMotionGroup = class _ConnectedMotionGroup {
53
- constructor(nova, controller, motionGroup, initialMotionState, motionStateSocket, isVirtual, tcps, motionGroupSpecification, safetySetup) {
54
- this.nova = nova;
55
- this.controller = controller;
56
- this.motionGroup = motionGroup;
57
- this.initialMotionState = initialMotionState;
58
- this.motionStateSocket = motionStateSocket;
59
- this.isVirtual = isVirtual;
60
- this.tcps = tcps;
61
- this.motionGroupSpecification = motionGroupSpecification;
62
- this.safetySetup = safetySetup;
63
- this.connectedJoggingCartesianSocket = null;
64
- this.connectedJoggingJointsSocket = null;
65
- // tmp
66
- this.joggingVelocity = 10;
67
- this.rapidlyChangingMotionState = initialMotionState;
68
- motionStateSocket.addEventListener("message", (event) => {
69
- var _a;
70
- const motionStateResponse = (_a = tryParseJson(event.data)) == null ? void 0 : _a.result;
71
- if (!motionStateResponse) {
72
- throw new Error(
73
- `Failed to get motion state for ${this.motionGroupId}: ${event.data}`
74
- );
75
- }
76
- if (!jointValuesEqual(
77
- this.rapidlyChangingMotionState.joint_position.joints,
78
- motionStateResponse.joint_position.joints,
79
- MOTION_DELTA_THRESHOLD
80
- )) {
81
- runInAction(() => {
82
- this.rapidlyChangingMotionState = motionStateResponse;
83
- });
84
- }
85
- if (!tcpPoseEqual(
86
- this.rapidlyChangingMotionState.tcp_pose,
87
- motionStateResponse.tcp_pose,
88
- MOTION_DELTA_THRESHOLD
89
- )) {
90
- runInAction(() => {
91
- this.rapidlyChangingMotionState.tcp_pose = motionStateResponse.tcp_pose;
92
- });
93
- }
94
- });
95
- makeAutoObservable(this);
96
- }
97
- static connect(nova, motionGroupId, controllers) {
98
- return __async(this, null, function* () {
99
- var _a;
100
- const [_motionGroupIndex, controllerId] = motionGroupId.split("@");
101
- const controller = controllers.find((c) => c.controller === controllerId);
102
- const motionGroup = controller == null ? void 0 : controller.motion_groups.find(
103
- (mg) => mg.motion_group === motionGroupId
104
- );
105
- if (!controller || !motionGroup) {
106
- throw new Error(
107
- `Controller ${controllerId} or motion group ${motionGroupId} not found`
108
- );
109
- }
110
- const motionStateSocket = nova.openReconnectingWebsocket(
111
- `/motion-groups/${motionGroupId}/state-stream`
112
- );
113
- const firstMessage = yield motionStateSocket.firstMessage();
114
- const initialMotionState = (_a = tryParseJson(firstMessage.data)) == null ? void 0 : _a.result;
115
- if (!initialMotionState) {
116
- throw new Error(
117
- `Unable to parse initial motion state message ${firstMessage.data}`
118
- );
119
- }
120
- console.log(
121
- `Connected motion state websocket to motion group ${motionGroup.motion_group}. Initial state:
122
- `,
123
- initialMotionState
124
- );
125
- let isVirtual = false;
126
- try {
127
- const opMode = yield nova.api.virtualRobotMode.getOperationMode(controllerId);
128
- if (opMode) isVirtual = true;
129
- } catch (err) {
130
- if (err instanceof AxiosError) {
131
- console.log(
132
- `Received ${err.status} from getOperationMode, concluding that ${controllerId} is physical`
133
- );
134
- } else {
135
- throw err;
136
- }
137
- }
138
- const { tcps } = yield nova.api.motionGroupInfos.listTcps(motionGroupId);
139
- const motionGroupSpecification = yield nova.api.motionGroupInfos.getMotionGroupSpecification(motionGroupId);
140
- const safetySetup = yield nova.api.motionGroupInfos.getSafetySetup(motionGroupId);
141
- return new _ConnectedMotionGroup(
142
- nova,
143
- controller,
144
- motionGroup,
145
- initialMotionState,
146
- motionStateSocket,
147
- isVirtual,
148
- tcps,
149
- motionGroupSpecification,
150
- safetySetup
151
- );
152
- });
153
- }
154
- get motionGroupId() {
155
- return this.motionGroup.motion_group;
156
- }
157
- get controllerId() {
158
- return this.controller.controller;
159
- }
160
- get modelFromController() {
161
- return this.motionGroup.model_from_controller;
162
- }
163
- get wandelscriptIdentifier() {
164
- const num = this.motionGroupId.split("@")[0];
165
- return `${this.controllerId.replaceAll("-", "_")}_${num}`;
166
- }
167
- /** Jogging velocity in radians for rotation and joint movement */
168
- get joggingVelocityRads() {
169
- return this.joggingVelocity * Math.PI / 180;
170
- }
171
- get joints() {
172
- return this.initialMotionState.joint_position.joints.map((_, i) => {
173
- return {
174
- index: i
175
- };
176
- });
177
- }
178
- get dhParameters() {
179
- return this.motionGroupSpecification.dh_parameters;
180
- }
181
- get safetyZones() {
182
- return this.safetySetup.safety_zones;
183
- }
184
- dispose() {
185
- this.motionStateSocket.close();
186
- if (this.connectedJoggingCartesianSocket)
187
- this.connectedJoggingCartesianSocket.close();
188
- if (this.connectedJoggingJointsSocket)
189
- this.connectedJoggingJointsSocket.close();
190
- }
191
- setJoggingVelocity(velocity) {
192
- this.joggingVelocity = velocity;
193
- }
194
- };
195
-
196
- // src/lib/v2/vectorUtils.ts
197
- import * as THREE from "three";
198
- function axisToIndex(axis) {
199
- switch (axis) {
200
- case "x":
201
- return 0;
202
- case "y":
203
- return 1;
204
- case "z":
205
- return 2;
206
- }
207
- }
208
- function vector3ToArray(vector) {
209
- return [vector.x, vector.y, vector.z];
210
- }
211
-
212
- // src/lib/v2/JoggerConnection.ts
213
- var JoggerConnection = class _JoggerConnection {
214
- constructor(nova, cell, motionGroupId, motionGroupState, opts) {
215
- this.nova = nova;
216
- this.cell = cell;
217
- this.motionGroupId = motionGroupId;
218
- this.motionGroupState = motionGroupState;
219
- this.opts = opts;
220
- // Currently a separate websocket is needed for each mode, pester API people
221
- // to merge these for simplicity
222
- this.joggingWebsocket = null;
223
- this.lastVelocityRequest = null;
224
- this.lastResponse = null;
225
- this.joggingWebsocket = nova.openReconnectingWebsocket(
226
- `/cells/${cell}/execution/jogging`
227
- );
228
- this.joggingWebsocket.addEventListener("message", (ev) => {
229
- const data = tryParseJson(ev.data);
230
- if (data && "error" in data) {
231
- if (this.opts.onError) {
232
- this.opts.onError(ev.data);
233
- } else {
234
- throw new Error(ev.data);
235
- }
236
- }
237
- });
238
- this.joggingWebsocket.addEventListener("message", (ev) => {
239
- const data = tryParseJson(ev.data);
240
- if (data && "error" in data) {
241
- if (this.opts.onError) {
242
- this.opts.onError(ev.data);
243
- } else {
244
- throw new Error(ev.data);
245
- }
246
- }
247
- });
248
- }
249
- static open(nova, cell, motionGroupId, opts) {
250
- return __async(this, null, function* () {
251
- const motionGroupState = yield nova.api.motionGroupInfos.getCurrentMotionGroupState(motionGroupId);
252
- return new _JoggerConnection(
253
- nova,
254
- cell,
255
- motionGroupId,
256
- motionGroupState,
257
- opts
258
- );
259
- });
260
- }
261
- get jointCount() {
262
- var _a;
263
- return (_a = this.motionGroupState.joint_current) == null ? void 0 : _a.joints.length;
264
- }
265
- get activeWebsocket() {
266
- return this.joggingWebsocket;
267
- }
268
- stop() {
269
- return __async(this, null, function* () {
270
- var _a, _b;
271
- if (!this.joggingWebsocket) {
272
- return;
273
- }
274
- if (((_a = this.lastVelocityRequest) == null ? void 0 : _a.message_type) === "JointVelocityRequest") {
275
- this.joggingWebsocket.sendJson({
276
- message_type: "JointVelocityRequest",
277
- velocity: {
278
- joints: Array.from(new Array(this.jointCount).keys()).map(() => 0)
279
- }
280
- });
281
- }
282
- if (((_b = this.lastVelocityRequest) == null ? void 0 : _b.message_type) === "TcpVelocityRequest") {
283
- this.joggingWebsocket.sendJson({
284
- message_type: "TcpVelocityRequest",
285
- rotation: [0, 0, 0],
286
- translation: [0, 0, 0]
287
- });
288
- }
289
- });
290
- }
291
- dispose() {
292
- if (this.joggingWebsocket) {
293
- this.joggingWebsocket.dispose();
294
- }
295
- }
296
- /**
297
- * Start rotation of a single robot joint at the specified velocity
298
- */
299
- startJointRotation(_0) {
300
- return __async(this, arguments, function* ({
301
- joint,
302
- velocityRadsPerSec
303
- }) {
304
- if (!this.joggingWebsocket) {
305
- throw new Error(
306
- "Joint jogging websocket not connected. Wait for reconnect or open new jogging connection"
307
- );
308
- }
309
- const jointVelocities = new Array(this.jointCount).fill(0);
310
- jointVelocities[joint] = velocityRadsPerSec;
311
- this.joggingWebsocket.sendJson({
312
- message_type: "JointVelocityRequest",
313
- velocity: {
314
- joints: jointVelocities
315
- }
316
- });
317
- });
318
- }
319
- /**
320
- * Start the TCP moving along a specified axis at a given velocity
321
- */
322
- startTCPTranslation(_0) {
323
- return __async(this, arguments, function* ({
324
- axis,
325
- velocityMmPerSec,
326
- useToolCoordinateSystem
327
- }) {
328
- if (!this.joggingWebsocket) {
329
- throw new Error(
330
- "Cartesian jogging websocket not connected. Wait for reconnect or open new jogging connection"
331
- );
332
- }
333
- const joggingVector = [0, 0, 0];
334
- joggingVector[axisToIndex(axis)] = velocityMmPerSec;
335
- this.joggingWebsocket.sendJson({
336
- message_type: "TcpVelocityRequest",
337
- translation: joggingVector,
338
- rotation: [0, 0, 0],
339
- use_tool_coordinate_system: useToolCoordinateSystem
340
- });
341
- });
342
- }
343
- /**
344
- * Start the TCP rotating around a specified axis at a given velocity
345
- */
346
- startTCPRotation(_0) {
347
- return __async(this, arguments, function* ({
348
- axis,
349
- velocityRadsPerSec,
350
- useToolCoordinateSystem
351
- }) {
352
- if (!this.joggingWebsocket) {
353
- throw new Error(
354
- "Cartesian jogging websocket not connected. Wait for reconnect or open new jogging connection"
355
- );
356
- }
357
- const joggingVector = [0, 0, 0];
358
- joggingVector[axisToIndex(axis)] = velocityRadsPerSec;
359
- this.joggingWebsocket.sendJson({
360
- message_type: "TcpVelocityRequest",
361
- rotation: joggingVector,
362
- translation: [0, 0, 0],
363
- use_tool_coordinate_system: useToolCoordinateSystem
364
- });
365
- });
366
- }
367
- };
368
-
369
- // src/lib/v2/MotionStreamConnection.ts
370
- import { makeAutoObservable as makeAutoObservable2, runInAction as runInAction2 } from "mobx";
371
- import * as THREE2 from "three";
372
- var MOTION_DELTA_THRESHOLD2 = 1e-4;
373
- function unwrapRotationVector(newRotationVectorApi, currentRotationVectorApi) {
374
- const currentRotationVector = new THREE2.Vector3(
375
- currentRotationVectorApi[0],
376
- currentRotationVectorApi[1],
377
- currentRotationVectorApi[2]
378
- );
379
- const newRotationVector = new THREE2.Vector3(
380
- newRotationVectorApi[0],
381
- newRotationVectorApi[1],
382
- newRotationVectorApi[2]
383
- );
384
- const currentAngle = currentRotationVector.length();
385
- const currentAxis = currentRotationVector.normalize();
386
- let newAngle = newRotationVector.length();
387
- let newAxis = newRotationVector.normalize();
388
- if (newAxis.dot(currentAxis) < 0) {
389
- newAngle = -newAngle;
390
- newAxis = newAxis.multiplyScalar(-1);
391
- }
392
- let angleDifference = newAngle - currentAngle;
393
- angleDifference -= 2 * Math.PI * Math.floor((angleDifference + Math.PI) / (2 * Math.PI));
394
- newAngle = currentAngle + angleDifference;
395
- return vector3ToArray(newAxis.multiplyScalar(newAngle));
396
- }
397
- var MotionStreamConnection = class _MotionStreamConnection {
398
- constructor(nova, controller, motionGroup, initialMotionState, motionStateSocket) {
399
- this.nova = nova;
400
- this.controller = controller;
401
- this.motionGroup = motionGroup;
402
- this.initialMotionState = initialMotionState;
403
- this.motionStateSocket = motionStateSocket;
404
- this.rapidlyChangingMotionState = initialMotionState;
405
- motionStateSocket.addEventListener("message", (event) => {
406
- var _a;
407
- const motionState = (_a = tryParseJson(event.data)) == null ? void 0 : _a.result;
408
- if (!motionState) {
409
- throw new Error(
410
- `Failed to get motion state for ${this.motionGroupId}: ${event.data}`
411
- );
412
- }
413
- if (!jointValuesEqual(
414
- this.rapidlyChangingMotionState.joint_position.joints,
415
- motionState.joint_position.joints,
416
- MOTION_DELTA_THRESHOLD2
417
- )) {
418
- runInAction2(() => {
419
- this.rapidlyChangingMotionState = motionState;
420
- });
421
- }
422
- if (!tcpPoseEqual(
423
- this.rapidlyChangingMotionState.tcp_pose,
424
- motionState.tcp_pose,
425
- MOTION_DELTA_THRESHOLD2
426
- )) {
427
- runInAction2(() => {
428
- if (this.rapidlyChangingMotionState.tcp_pose == void 0) {
429
- this.rapidlyChangingMotionState.tcp_pose = motionState.tcp_pose;
430
- } else {
431
- this.rapidlyChangingMotionState.tcp_pose = {
432
- position: motionState.tcp_pose.position,
433
- orientation: unwrapRotationVector(
434
- motionState.tcp_pose.orientation,
435
- this.rapidlyChangingMotionState.tcp_pose.orientation
436
- ),
437
- tcp: motionState.tcp_pose.tcp,
438
- coordinate_system: motionState.tcp_pose.coordinate_system
439
- };
440
- }
441
- });
442
- }
443
- });
444
- makeAutoObservable2(this);
445
- }
446
- static open(nova, motionGroupId) {
447
- return __async(this, null, function* () {
448
- var _a;
449
- const { controllers } = yield nova.api.controller.listControllers();
450
- const [_motionGroupIndex, controllerId] = motionGroupId.split("@");
451
- const controller = controllers.find((c) => c.controller === controllerId);
452
- const motionGroup = controller == null ? void 0 : controller.motion_groups.find(
453
- (mg) => mg.motion_group === motionGroupId
454
- );
455
- if (!controller || !motionGroup) {
456
- throw new Error(
457
- `Controller ${controllerId} or motion group ${motionGroupId} not found`
458
- );
459
- }
460
- const motionStateSocket = nova.openReconnectingWebsocket(
461
- `/motion-groups/${motionGroupId}/state-stream`
462
- );
463
- const firstMessage = yield motionStateSocket.firstMessage();
464
- console.log("got first message", firstMessage);
465
- const initialMotionState = (_a = tryParseJson(firstMessage.data)) == null ? void 0 : _a.result;
466
- if (!initialMotionState) {
467
- throw new Error(
468
- `Unable to parse initial motion state message ${firstMessage.data}`
469
- );
470
- }
471
- console.log(
472
- `Connected motion state websocket to motion group ${motionGroup.motion_group}. Initial state:
473
- `,
474
- initialMotionState
475
- );
476
- return new _MotionStreamConnection(
477
- nova,
478
- controller,
479
- motionGroup,
480
- initialMotionState,
481
- motionStateSocket
482
- );
483
- });
484
- }
485
- get motionGroupId() {
486
- return this.motionGroup.motion_group;
487
- }
488
- get controllerId() {
489
- return this.controller.controller;
490
- }
491
- get modelFromController() {
492
- return this.motionGroup.model_from_controller;
493
- }
494
- get wandelscriptIdentifier() {
495
- const num = this.motionGroupId.split("@")[0];
496
- return `${this.controllerId.replaceAll("-", "_")}_${num}`;
497
- }
498
- get joints() {
499
- return this.initialMotionState.joint_position.joints.map((_, i) => {
500
- return {
501
- index: i
502
- };
503
- });
504
- }
505
- dispose() {
506
- this.motionStateSocket.close();
507
- }
508
- };
509
-
510
13
  // src/lib/v2/NovaCellAPIClient.ts
511
14
  import {
512
15
  ApplicationApi,
16
+ BUSInputsOutputsApi,
513
17
  CellApi,
514
18
  ControllerApi,
515
19
  ControllerInputsOutputsApi,
516
- CoordinateSystemsApi,
517
20
  JoggingApi,
21
+ KinematicsApi,
518
22
  MotionGroupApi,
519
- MotionGroupInfoApi,
520
- MotionGroupKinematicsApi,
521
- ProgramApi,
522
- ProgramOperatorApi,
23
+ MotionGroupModelsApi,
523
24
  StoreCollisionComponentsApi,
524
- StoreCollisionScenesApi,
25
+ StoreCollisionSetupsApi,
525
26
  StoreObjectApi,
526
27
  SystemApi,
28
+ TrajectoryCachingApi,
527
29
  TrajectoryExecutionApi,
528
30
  TrajectoryPlanningApi,
529
- VirtualRobotApi,
530
- VirtualRobotBehaviorApi,
531
- VirtualRobotModeApi,
532
- VirtualRobotSetupApi
31
+ VirtualControllerApi,
32
+ VirtualControllerBehaviorApi,
33
+ VirtualControllerInputsOutputsApi
533
34
  } from "@wandelbots/nova-api/v2";
534
35
  import axios from "axios";
535
36
  var NovaCellAPIClient = class {
@@ -539,27 +40,29 @@ var NovaCellAPIClient = class {
539
40
  this.system = this.withUnwrappedResponsesOnly(SystemApi);
540
41
  this.cell = this.withUnwrappedResponsesOnly(CellApi);
541
42
  this.motionGroup = this.withCellId(MotionGroupApi);
542
- this.motionGroupInfos = this.withCellId(MotionGroupInfoApi);
43
+ this.motionGroupModels = this.withCellId(MotionGroupModelsApi);
543
44
  this.controller = this.withCellId(ControllerApi);
544
- this.program = this.withCellId(ProgramApi);
545
- this.programOperator = this.withCellId(ProgramOperatorApi);
546
45
  this.controllerIOs = this.withCellId(ControllerInputsOutputsApi);
547
- this.motionGroupKinematic = this.withCellId(MotionGroupKinematicsApi);
548
46
  this.trajectoryPlanning = this.withCellId(TrajectoryPlanningApi);
549
47
  this.trajectoryExecution = this.withCellId(TrajectoryExecutionApi);
550
- this.coordinateSystems = this.withCellId(CoordinateSystemsApi);
48
+ this.trajectoryCaching = this.withCellId(TrajectoryCachingApi);
551
49
  this.application = this.withCellId(ApplicationApi);
552
50
  this.applicationGlobal = this.withUnwrappedResponsesOnly(ApplicationApi);
553
51
  this.jogging = this.withCellId(JoggingApi);
554
- this.virtualRobot = this.withCellId(VirtualRobotApi);
555
- this.virtualRobotSetup = this.withCellId(VirtualRobotSetupApi);
556
- this.virtualRobotMode = this.withCellId(VirtualRobotModeApi);
557
- this.virtualRobotBehavior = this.withCellId(VirtualRobotBehaviorApi);
52
+ this.kinematics = this.withCellId(KinematicsApi);
53
+ this.busInputsOutputs = this.withCellId(BUSInputsOutputsApi);
54
+ this.virtualController = this.withCellId(VirtualControllerApi);
55
+ this.virtualControllerBehavior = this.withCellId(
56
+ VirtualControllerBehaviorApi
57
+ );
58
+ this.virtualControllerIOs = this.withCellId(
59
+ VirtualControllerInputsOutputsApi
60
+ );
558
61
  this.storeObject = this.withCellId(StoreObjectApi);
559
62
  this.storeCollisionComponents = this.withCellId(
560
63
  StoreCollisionComponentsApi
561
64
  );
562
- this.storeCollisionScenes = this.withCellId(StoreCollisionScenesApi);
65
+ this.storeCollisionSetups = this.withCellId(StoreCollisionSetupsApi);
563
66
  }
564
67
  /**
565
68
  * Some TypeScript sorcery which alters the API class methods so you don't
@@ -618,7 +121,7 @@ import axios2, { isAxiosError } from "axios";
618
121
  import urlJoin from "url-join";
619
122
 
620
123
  // src/lib/v2/mock/MockNovaInstance.ts
621
- import { AxiosError as AxiosError2 } from "axios";
124
+ import { AxiosError } from "axios";
622
125
  import * as pathToRegexp from "path-to-regexp";
623
126
  var MockNovaInstance = class {
624
127
  constructor() {
@@ -662,7 +165,6 @@ var MockNovaInstance = class {
662
165
  configuration: {
663
166
  kind: "VirtualController",
664
167
  manufacturer: "universalrobots",
665
- position: "[0,-1.571,-1.571,-1.571,1.571,-1.571,0]",
666
168
  type: "universalrobots-ur5e"
667
169
  },
668
170
  name: "mock-ur5"
@@ -1301,7 +803,7 @@ var MockNovaInstance = class {
1301
803
  };
1302
804
  }
1303
805
  }
1304
- throw new AxiosError2(
806
+ throw new AxiosError(
1305
807
  `No mock handler matched this request: ${method} ${path}`,
1306
808
  "404",
1307
809
  config
@@ -1542,6 +1044,8 @@ var defaultMotionState = {
1542
1044
  result: {
1543
1045
  motion_group: "0@universalrobots-ur5e",
1544
1046
  controller: "universalrobots-ur5e",
1047
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
1048
+ sequence_number: 1,
1545
1049
  joint_position: {
1546
1050
  joints: [
1547
1051
  1.1699999570846558,
@@ -1552,17 +1056,17 @@ var defaultMotionState = {
1552
1056
  1.2799999713897705
1553
1057
  ]
1554
1058
  },
1555
- joint_velocity: {
1556
- joints: [0, 0, 0, 0, 0, 0]
1059
+ joint_limit_reached: {
1060
+ limit_reached: [false, false, false, false, false, false]
1557
1061
  },
1062
+ standstill: false,
1558
1063
  flange_pose: {
1559
1064
  position: [1.3300010259703043, -409.2680714682808, 531.0203477065281],
1560
1065
  orientation: [
1561
1066
  1.7564919306270736,
1562
1067
  -1.7542521568325058,
1563
1068
  0.7326972590614671
1564
- ],
1565
- coordinate_system: ""
1069
+ ]
1566
1070
  },
1567
1071
  tcp_pose: {
1568
1072
  position: [1.3300010259703043, -409.2680714682808, 531.0203477065281],
@@ -1570,25 +1074,7 @@ var defaultMotionState = {
1570
1074
  1.7564919306270736,
1571
1075
  -1.7542521568325058,
1572
1076
  0.7326972590614671
1573
- ],
1574
- coordinate_system: "",
1575
- tcp: "Flange"
1576
- },
1577
- velocity: {
1578
- linear: [0, 0, 0],
1579
- angular: [0, 0, 0],
1580
- coordinate_system: ""
1581
- },
1582
- force: {
1583
- force: [0, 0, 0],
1584
- moment: [0, 0, 0],
1585
- coordinate_system: ""
1586
- },
1587
- joint_limit_reached: {
1588
- limit_reached: [false, false, false, false, false, false]
1589
- },
1590
- joint_current: {
1591
- joints: [0, 0, 0, 0, 0, 0]
1077
+ ]
1592
1078
  }
1593
1079
  }
1594
1080
  };
@@ -1716,227 +1202,9 @@ var NovaClient = class {
1716
1202
  mock: this.mock
1717
1203
  });
1718
1204
  }
1719
- /**
1720
- * Connect to the motion state websocket(s) for a given motion group
1721
- */
1722
- connectMotionStream(motionGroupId) {
1723
- return __async(this, null, function* () {
1724
- return yield MotionStreamConnection.open(this, motionGroupId);
1725
- });
1726
- }
1727
- connectMotionGroups(motionGroupIds) {
1728
- return __async(this, null, function* () {
1729
- const { controllers } = yield this.api.controller.listControllers();
1730
- return Promise.all(
1731
- motionGroupIds.map(
1732
- (motionGroupId) => ConnectedMotionGroup.connect(this, motionGroupId, controllers)
1733
- )
1734
- );
1735
- });
1736
- }
1737
- connectMotionGroup(motionGroupId) {
1738
- return __async(this, null, function* () {
1739
- const motionGroups = yield this.connectMotionGroups([motionGroupId]);
1740
- return motionGroups[0];
1741
- });
1742
- }
1743
- };
1744
-
1745
- // src/lib/v2/ProgramStateConnection.ts
1746
- import { AxiosError as AxiosError3 } from "axios";
1747
- import { makeAutoObservable as makeAutoObservable3, runInAction as runInAction3 } from "mobx";
1748
- var ProgramState = /* @__PURE__ */ ((ProgramState2) => {
1749
- ProgramState2["NotStarted"] = "not started";
1750
- ProgramState2["Running"] = "running";
1751
- ProgramState2["Stopped"] = "stopped";
1752
- ProgramState2["Failed"] = "failed";
1753
- ProgramState2["Completed"] = "completed";
1754
- return ProgramState2;
1755
- })(ProgramState || {});
1756
- var ProgramStateConnection = class {
1757
- constructor(nova) {
1758
- this.nova = nova;
1759
- this.currentProgram = {};
1760
- this.logs = [];
1761
- this.executionState = "idle";
1762
- this.currentlyExecutingProgramRunnerId = null;
1763
- makeAutoObservable3(this, {}, { autoBind: true });
1764
- this.programStateSocket = nova.openReconnectingWebsocket(`/programs/state`);
1765
- this.programStateSocket.addEventListener("message", (ev) => {
1766
- const msg = tryParseJson(ev.data);
1767
- if (!msg) {
1768
- console.error("Failed to parse program state message", ev.data);
1769
- return;
1770
- }
1771
- if (msg.type === "update") {
1772
- this.handleProgramStateMessage(msg);
1773
- }
1774
- });
1775
- }
1776
- /** Handle a program state update from the backend */
1777
- handleProgramStateMessage(msg) {
1778
- return __async(this, null, function* () {
1779
- var _a;
1780
- const { runner } = msg;
1781
- if (runner.id !== this.currentlyExecutingProgramRunnerId) return;
1782
- if (runner.state === "failed" /* Failed */) {
1783
- try {
1784
- const runnerState = yield this.nova.api.program.getProgramRun(runner.id);
1785
- const stdout = runnerState.stdout;
1786
- if (stdout) {
1787
- this.log(stdout);
1788
- }
1789
- this.logError(
1790
- `Program runner ${runner.id} failed with error: ${runnerState.error}
1791
- ${runnerState.traceback}`
1792
- );
1793
- } catch (err) {
1794
- this.logError(
1795
- `Failed to retrieve results for program ${runner.id}: ${err}`
1796
- );
1797
- }
1798
- this.currentProgram.state = "failed" /* Failed */;
1799
- this.gotoIdleState();
1800
- } else if (runner.state === "stopped" /* Stopped */) {
1801
- try {
1802
- const runnerState = yield this.nova.api.program.getProgramRun(runner.id);
1803
- const stdout = runnerState.stdout;
1804
- if (stdout) {
1805
- this.log(stdout);
1806
- }
1807
- this.currentProgram.state = "stopped" /* Stopped */;
1808
- this.log(`Program runner ${runner.id} stopped`);
1809
- } catch (err) {
1810
- this.logError(
1811
- `Failed to retrieve results for program ${runner.id}: ${err}`
1812
- );
1813
- }
1814
- this.gotoIdleState();
1815
- } else if (runner.state === "completed" /* Completed */) {
1816
- try {
1817
- const runnerState = yield this.nova.api.program.getProgramRun(runner.id);
1818
- const stdout = runnerState.stdout;
1819
- if (stdout) {
1820
- this.log(stdout);
1821
- }
1822
- this.log(
1823
- `Program runner ${runner.id} finished successfully in ${(_a = runner.execution_time) == null ? void 0 : _a.toFixed(2)} seconds`
1824
- );
1825
- this.currentProgram.state = "completed" /* Completed */;
1826
- } catch (err) {
1827
- this.logError(
1828
- `Failed to retrieve results for program ${runner.id}: ${err}`
1829
- );
1830
- }
1831
- this.gotoIdleState();
1832
- } else if (runner.state === "running" /* Running */) {
1833
- this.currentProgram.state = "running" /* Running */;
1834
- this.log(`Program runner ${runner.id} now running`);
1835
- } else if (runner.state !== "not started" /* NotStarted */) {
1836
- console.error(runner);
1837
- this.logError(
1838
- `Program runner ${runner.id} entered unexpected state: ${runner.state}`
1839
- );
1840
- this.currentProgram.state = "not started" /* NotStarted */;
1841
- this.gotoIdleState();
1842
- }
1843
- });
1844
- }
1845
- /** Call when a program is no longer executing */
1846
- gotoIdleState() {
1847
- runInAction3(() => {
1848
- this.executionState = "idle";
1849
- });
1850
- this.currentlyExecutingProgramRunnerId = null;
1851
- }
1852
- executeProgram(wandelscript, initial_state, activeRobot) {
1853
- return __async(this, null, function* () {
1854
- this.currentProgram = {
1855
- wandelscript,
1856
- state: "not started" /* NotStarted */
1857
- };
1858
- const { currentProgram: openProgram } = this;
1859
- if (!openProgram) return;
1860
- runInAction3(() => {
1861
- this.executionState = "starting";
1862
- });
1863
- const trimmedCode = openProgram.wandelscript.replaceAll(/^\s*$/gm, "");
1864
- try {
1865
- const programRunnerRef = yield this.nova.api.program.createProgramRun(
1866
- {
1867
- code: trimmedCode,
1868
- initial_state,
1869
- default_robot: activeRobot == null ? void 0 : activeRobot.wandelscriptIdentifier
1870
- },
1871
- {
1872
- headers: {
1873
- "Content-Type": "application/json"
1874
- }
1875
- }
1876
- );
1877
- this.log(`Created program runner ${programRunnerRef.id}"`);
1878
- runInAction3(() => {
1879
- this.executionState = "executing";
1880
- });
1881
- this.currentlyExecutingProgramRunnerId = programRunnerRef.id;
1882
- } catch (error) {
1883
- if (error instanceof AxiosError3 && error.response && error.request) {
1884
- this.logError(
1885
- `${error.response.status} ${error.response.statusText} from ${error.response.config.url} ${JSON.stringify(error.response.data)}`
1886
- );
1887
- } else {
1888
- this.logError(JSON.stringify(error));
1889
- }
1890
- runInAction3(() => {
1891
- this.executionState = "idle";
1892
- });
1893
- }
1894
- });
1895
- }
1896
- stopProgram() {
1897
- return __async(this, null, function* () {
1898
- if (!this.currentlyExecutingProgramRunnerId) return;
1899
- runInAction3(() => {
1900
- this.executionState = "stopping";
1901
- });
1902
- try {
1903
- yield this.nova.api.program.stopProgramRun(
1904
- this.currentlyExecutingProgramRunnerId
1905
- );
1906
- } catch (err) {
1907
- runInAction3(() => {
1908
- this.executionState = "executing";
1909
- });
1910
- throw err;
1911
- }
1912
- });
1913
- }
1914
- reset() {
1915
- this.currentProgram = {};
1916
- }
1917
- log(message) {
1918
- console.log(message);
1919
- this.logs.push({
1920
- timestamp: Date.now(),
1921
- message
1922
- });
1923
- }
1924
- logError(message) {
1925
- console.log(message);
1926
- this.logs.push({
1927
- timestamp: Date.now(),
1928
- message,
1929
- level: "error"
1930
- });
1931
- }
1932
1205
  };
1933
1206
  export {
1934
- ConnectedMotionGroup,
1935
- JoggerConnection,
1936
- MotionStreamConnection,
1937
1207
  NovaCellAPIClient,
1938
- NovaClient,
1939
- ProgramState,
1940
- ProgramStateConnection
1208
+ NovaClient
1941
1209
  };
1942
1210
  //# sourceMappingURL=index.js.map