@wandelbots/nova-js 3.2.0 → 3.3.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 (104) hide show
  1. package/README.md +32 -136
  2. package/dist/AutoReconnectingWebsocket-Qcrbm3Kb.d.cts +69 -0
  3. package/dist/AutoReconnectingWebsocket-Qcrbm3Kb.d.cts.map +1 -0
  4. package/dist/AutoReconnectingWebsocket-dHe-kceU.d.mts +69 -0
  5. package/dist/AutoReconnectingWebsocket-dHe-kceU.d.mts.map +1 -0
  6. package/dist/LoginWithAuth0-CBD9BXXz.cjs +264 -0
  7. package/dist/LoginWithAuth0-CBD9BXXz.cjs.map +1 -0
  8. package/dist/LoginWithAuth0-wQB-Sol1.mjs +217 -0
  9. package/dist/LoginWithAuth0-wQB-Sol1.mjs.map +1 -0
  10. package/dist/NovaClient-B8XM3OPO.mjs +2057 -0
  11. package/dist/NovaClient-B8XM3OPO.mjs.map +1 -0
  12. package/dist/NovaClient-CV7ooIkD.d.cts +349 -0
  13. package/dist/NovaClient-CV7ooIkD.d.cts.map +1 -0
  14. package/dist/NovaClient-D2EItmiH.cjs +2137 -0
  15. package/dist/NovaClient-D2EItmiH.cjs.map +1 -0
  16. package/dist/NovaClient-qJnHcx2s.d.mts +349 -0
  17. package/dist/NovaClient-qJnHcx2s.d.mts.map +1 -0
  18. package/dist/index.cjs +42 -386
  19. package/dist/index.cjs.map +1 -1
  20. package/dist/index.d.cts +73 -0
  21. package/dist/index.d.cts.map +1 -0
  22. package/dist/index.d.mts +73 -0
  23. package/dist/index.d.mts.map +1 -0
  24. package/dist/index.mjs +36 -0
  25. package/dist/index.mjs.map +1 -0
  26. package/dist/lib/v1/index.cjs +190 -2940
  27. package/dist/lib/v1/index.cjs.map +1 -1
  28. package/dist/lib/v1/index.d.cts +62 -0
  29. package/dist/lib/v1/index.d.cts.map +1 -0
  30. package/dist/lib/v1/index.d.mts +62 -0
  31. package/dist/lib/v1/index.d.mts.map +1 -0
  32. package/dist/lib/v1/index.mjs +182 -0
  33. package/dist/lib/v1/index.mjs.map +1 -0
  34. package/dist/lib/v2/index.cjs +1821 -1468
  35. package/dist/lib/v2/index.cjs.map +1 -1
  36. package/dist/lib/v2/index.d.cts +118 -0
  37. package/dist/lib/v2/index.d.cts.map +1 -0
  38. package/dist/lib/v2/index.d.mts +118 -0
  39. package/dist/lib/v2/index.d.mts.map +1 -0
  40. package/dist/lib/v2/index.mjs +1822 -0
  41. package/dist/lib/v2/index.mjs.map +1 -0
  42. package/package.json +21 -19
  43. package/src/LoginWithAuth0.ts +12 -12
  44. package/src/index.ts +2 -0
  45. package/src/lib/converters.ts +5 -23
  46. package/src/lib/v1/MotionStreamConnection.ts +0 -1
  47. package/src/lib/v1/NovaClient.ts +18 -0
  48. package/src/lib/v1/index.ts +6 -0
  49. package/src/lib/v1/mock/MockNovaInstance.ts +0 -1
  50. package/src/lib/v1/wandelscriptUtils.ts +22 -0
  51. package/src/lib/v2/NovaClient.ts +14 -7
  52. package/src/lib/v2/index.ts +1 -0
  53. package/src/lib/v2/mock/MockNovaInstance.ts +411 -21
  54. package/src/lib/v2/wandelscriptUtils.ts +27 -0
  55. package/dist/LoginWithAuth0.d.ts +0 -7
  56. package/dist/LoginWithAuth0.d.ts.map +0 -1
  57. package/dist/chunk-B2C22PTK.js +0 -53
  58. package/dist/chunk-B2C22PTK.js.map +0 -1
  59. package/dist/chunk-I3PUV6ZD.js +0 -286
  60. package/dist/chunk-I3PUV6ZD.js.map +0 -1
  61. package/dist/index.d.ts +0 -6
  62. package/dist/index.d.ts.map +0 -1
  63. package/dist/index.js +0 -60
  64. package/dist/index.js.map +0 -1
  65. package/dist/lib/AutoReconnectingWebsocket.d.ts +0 -43
  66. package/dist/lib/AutoReconnectingWebsocket.d.ts.map +0 -1
  67. package/dist/lib/availableStorage.d.ts +0 -15
  68. package/dist/lib/availableStorage.d.ts.map +0 -1
  69. package/dist/lib/converters.d.ts +0 -26
  70. package/dist/lib/converters.d.ts.map +0 -1
  71. package/dist/lib/errorHandling.d.ts +0 -15
  72. package/dist/lib/errorHandling.d.ts.map +0 -1
  73. package/dist/lib/v1/ConnectedMotionGroup.d.ts +0 -77
  74. package/dist/lib/v1/ConnectedMotionGroup.d.ts.map +0 -1
  75. package/dist/lib/v1/JoggerConnection.d.ts +0 -94
  76. package/dist/lib/v1/JoggerConnection.d.ts.map +0 -1
  77. package/dist/lib/v1/MotionStreamConnection.d.ts +0 -26
  78. package/dist/lib/v1/MotionStreamConnection.d.ts.map +0 -1
  79. package/dist/lib/v1/NovaCellAPIClient.d.ts +0 -68
  80. package/dist/lib/v1/NovaCellAPIClient.d.ts.map +0 -1
  81. package/dist/lib/v1/NovaClient.d.ts +0 -67
  82. package/dist/lib/v1/NovaClient.d.ts.map +0 -1
  83. package/dist/lib/v1/ProgramStateConnection.d.ts +0 -57
  84. package/dist/lib/v1/ProgramStateConnection.d.ts.map +0 -1
  85. package/dist/lib/v1/getLatestTrajectories.d.ts +0 -4
  86. package/dist/lib/v1/getLatestTrajectories.d.ts.map +0 -1
  87. package/dist/lib/v1/index.d.ts +0 -9
  88. package/dist/lib/v1/index.d.ts.map +0 -1
  89. package/dist/lib/v1/index.js +0 -2653
  90. package/dist/lib/v1/index.js.map +0 -1
  91. package/dist/lib/v1/mock/MockNovaInstance.d.ts +0 -13
  92. package/dist/lib/v1/mock/MockNovaInstance.d.ts.map +0 -1
  93. package/dist/lib/v1/motionStateUpdate.d.ts +0 -4
  94. package/dist/lib/v1/motionStateUpdate.d.ts.map +0 -1
  95. package/dist/lib/v2/NovaCellAPIClient.d.ts +0 -62
  96. package/dist/lib/v2/NovaCellAPIClient.d.ts.map +0 -1
  97. package/dist/lib/v2/NovaClient.d.ts +0 -60
  98. package/dist/lib/v2/NovaClient.d.ts.map +0 -1
  99. package/dist/lib/v2/index.d.ts +0 -4
  100. package/dist/lib/v2/index.d.ts.map +0 -1
  101. package/dist/lib/v2/index.js +0 -1196
  102. package/dist/lib/v2/index.js.map +0 -1
  103. package/dist/lib/v2/mock/MockNovaInstance.d.ts +0 -13
  104. package/dist/lib/v2/mock/MockNovaInstance.d.ts.map +0 -1
@@ -0,0 +1,1822 @@
1
+ import { n as availableStorage, r as AutoReconnectingWebsocket, t as loginWithAuth0 } from "../../LoginWithAuth0-wQB-Sol1.mjs";
2
+ import axios, { AxiosError, isAxiosError } from "axios";
3
+ import urlJoin from "url-join";
4
+ import * as pathToRegexp from "path-to-regexp";
5
+ import { ApplicationApi, BUSInputsOutputsApi, CellApi, ControllerApi, ControllerInputsOutputsApi, JoggingApi, KinematicsApi, MotionGroupApi, MotionGroupModelsApi, StoreCollisionComponentsApi, StoreCollisionSetupsApi, StoreObjectApi, SystemApi, TrajectoryCachingApi, TrajectoryExecutionApi, TrajectoryPlanningApi, VirtualControllerApi, VirtualControllerBehaviorApi, VirtualControllerInputsOutputsApi } from "@wandelbots/nova-api/v2";
6
+
7
+ export * from "@wandelbots/nova-api/v2"
8
+
9
+ //#region src/lib/v2/NovaCellAPIClient.ts
10
+ /**
11
+ * API client providing type-safe access to all the Nova API REST endpoints
12
+ * associated with a specific cell id.
13
+ */
14
+ var NovaCellAPIClient = class {
15
+ constructor(cellId, opts) {
16
+ this.cellId = cellId;
17
+ this.opts = opts;
18
+ this.system = this.withUnwrappedResponsesOnly(SystemApi);
19
+ this.cell = this.withUnwrappedResponsesOnly(CellApi);
20
+ this.motionGroup = this.withCellId(MotionGroupApi);
21
+ this.motionGroupModels = this.withCellId(MotionGroupModelsApi);
22
+ this.controller = this.withCellId(ControllerApi);
23
+ this.controllerIOs = this.withCellId(ControllerInputsOutputsApi);
24
+ this.trajectoryPlanning = this.withCellId(TrajectoryPlanningApi);
25
+ this.trajectoryExecution = this.withCellId(TrajectoryExecutionApi);
26
+ this.trajectoryCaching = this.withCellId(TrajectoryCachingApi);
27
+ this.application = this.withCellId(ApplicationApi);
28
+ this.applicationGlobal = this.withUnwrappedResponsesOnly(ApplicationApi);
29
+ this.jogging = this.withCellId(JoggingApi);
30
+ this.kinematics = this.withCellId(KinematicsApi);
31
+ this.busInputsOutputs = this.withCellId(BUSInputsOutputsApi);
32
+ this.virtualController = this.withCellId(VirtualControllerApi);
33
+ this.virtualControllerBehavior = this.withCellId(VirtualControllerBehaviorApi);
34
+ this.virtualControllerIOs = this.withCellId(VirtualControllerInputsOutputsApi);
35
+ this.storeObject = this.withCellId(StoreObjectApi);
36
+ this.storeCollisionComponents = this.withCellId(StoreCollisionComponentsApi);
37
+ this.storeCollisionSetups = this.withCellId(StoreCollisionSetupsApi);
38
+ }
39
+ /**
40
+ * Some TypeScript sorcery which alters the API class methods so you don't
41
+ * have to pass the cell id to every single one, and de-encapsulates the
42
+ * response data
43
+ */
44
+ withCellId(ApiConstructor) {
45
+ const apiClient = new ApiConstructor({
46
+ ...this.opts,
47
+ isJsonMime: (mime) => {
48
+ return mime === "application/json";
49
+ }
50
+ }, this.opts.basePath ?? "", this.opts.axiosInstance ?? axios.create());
51
+ for (const key of Reflect.ownKeys(Reflect.getPrototypeOf(apiClient))) if (key !== "constructor" && typeof apiClient[key] === "function") {
52
+ const originalFunction = apiClient[key];
53
+ apiClient[key] = (...args) => {
54
+ return originalFunction.apply(apiClient, [this.cellId, ...args]).then((res) => res.data);
55
+ };
56
+ }
57
+ return apiClient;
58
+ }
59
+ /**
60
+ * As withCellId, but only does the response unwrapping
61
+ */
62
+ withUnwrappedResponsesOnly(ApiConstructor) {
63
+ const apiClient = new ApiConstructor({
64
+ ...this.opts,
65
+ isJsonMime: (mime) => {
66
+ return mime === "application/json";
67
+ }
68
+ }, this.opts.basePath ?? "", this.opts.axiosInstance ?? axios.create());
69
+ for (const key of Reflect.ownKeys(Reflect.getPrototypeOf(apiClient))) if (key !== "constructor" && typeof apiClient[key] === "function") {
70
+ const originalFunction = apiClient[key];
71
+ apiClient[key] = (...args) => {
72
+ return originalFunction.apply(apiClient, args).then((res) => res.data);
73
+ };
74
+ }
75
+ return apiClient;
76
+ }
77
+ };
78
+
79
+ //#endregion
80
+ //#region src/lib/v2/mock/MockNovaInstance.ts
81
+ /**
82
+ * Ultra-simplified mock Nova server for testing stuff
83
+ */
84
+ var MockNovaInstance = class {
85
+ constructor() {
86
+ this.connections = [];
87
+ }
88
+ async handleAPIRequest(config) {
89
+ const apiHandlers = [
90
+ {
91
+ method: "GET",
92
+ path: "/cells/:cellId/controllers/:controllerId/state",
93
+ handle() {
94
+ return {
95
+ mode: "MODE_CONTROL",
96
+ last_error: [],
97
+ timestamp: "2025-10-16T09:19:26.634534092Z",
98
+ sequence_number: 1054764,
99
+ controller: "mock-ur5e",
100
+ operation_mode: "OPERATION_MODE_AUTO",
101
+ safety_state: "SAFETY_STATE_NORMAL",
102
+ velocity_override: 100,
103
+ motion_groups: [{
104
+ timestamp: "2025-10-16T09:19:26.634534092Z",
105
+ sequence_number: 1054764,
106
+ motion_group: "0@mock-ur5e",
107
+ controller: "mock-ur5e",
108
+ joint_position: [
109
+ 1.487959623336792,
110
+ -1.8501918315887451,
111
+ 1.8003005981445312,
112
+ 6.034560203552246,
113
+ 1.4921919107437134,
114
+ 1.593459963798523
115
+ ],
116
+ joint_limit_reached: { limit_reached: [
117
+ false,
118
+ false,
119
+ false,
120
+ false,
121
+ false,
122
+ false
123
+ ] },
124
+ joint_torque: [],
125
+ joint_current: [
126
+ 0,
127
+ 0,
128
+ 0,
129
+ 0,
130
+ 0,
131
+ 0
132
+ ],
133
+ flange_pose: {
134
+ position: [
135
+ 107.6452433732927,
136
+ -409.0402987746852,
137
+ 524.2402132330305
138
+ ],
139
+ orientation: [
140
+ .9874434028353319,
141
+ -.986571714997442,
142
+ 1.3336589451098142
143
+ ]
144
+ },
145
+ tcp: "Flange",
146
+ tcp_pose: {
147
+ position: [
148
+ 107.6452433732927,
149
+ -409.0402987746852,
150
+ 524.2402132330305
151
+ ],
152
+ orientation: [
153
+ .9874434028353319,
154
+ -.986571714997442,
155
+ 1.3336589451098142
156
+ ]
157
+ },
158
+ payload: "",
159
+ coordinate_system: "",
160
+ standstill: true
161
+ }]
162
+ };
163
+ }
164
+ },
165
+ {
166
+ method: "GET",
167
+ path: "/cells/:cellId/controllers/:controllerId/coordinate-systems",
168
+ handle() {
169
+ return [{
170
+ coordinate_system: "",
171
+ name: "world",
172
+ reference_coordinate_system: "",
173
+ position: [
174
+ 0,
175
+ 0,
176
+ 0
177
+ ],
178
+ orientation: [
179
+ 0,
180
+ 0,
181
+ 0
182
+ ],
183
+ orientation_type: "ROTATION_VECTOR"
184
+ }, {
185
+ coordinate_system: "CS-0",
186
+ name: "Default-CS",
187
+ reference_coordinate_system: "",
188
+ position: [
189
+ 0,
190
+ 0,
191
+ 0
192
+ ],
193
+ orientation: [
194
+ 0,
195
+ 0,
196
+ 0
197
+ ],
198
+ orientation_type: "ROTATION_VECTOR"
199
+ }];
200
+ }
201
+ },
202
+ {
203
+ method: "GET",
204
+ path: "/cells/:cellId/controllers/:controllerId/motion-groups/:motionGroupId/description",
205
+ handle() {
206
+ return {
207
+ motion_group_model: "UniversalRobots_UR5e",
208
+ mounting: {
209
+ position: [
210
+ 0,
211
+ 0,
212
+ 0
213
+ ],
214
+ orientation: [
215
+ 0,
216
+ 0,
217
+ 0
218
+ ]
219
+ },
220
+ tcps: {
221
+ Flange: {
222
+ name: "Default-Flange",
223
+ pose: {
224
+ position: [
225
+ 0,
226
+ 0,
227
+ 0
228
+ ],
229
+ orientation: [
230
+ 0,
231
+ 0,
232
+ 0
233
+ ]
234
+ }
235
+ },
236
+ "complex-tcp-position": {
237
+ name: "Complex TCP Position",
238
+ pose: {
239
+ position: [
240
+ -200,
241
+ 300,
242
+ 150
243
+ ],
244
+ orientation: [
245
+ -.12139440409113832,
246
+ -.06356210998212003,
247
+ -.2023240068185639
248
+ ]
249
+ }
250
+ },
251
+ "offset-150mm-xy": {
252
+ name: "-150mm XY Offset",
253
+ pose: {
254
+ position: [
255
+ -150,
256
+ -150,
257
+ 0
258
+ ],
259
+ orientation: [
260
+ 0,
261
+ 0,
262
+ 0
263
+ ]
264
+ }
265
+ },
266
+ "rotated-90deg-z": {
267
+ name: "90° Z Axis Rotation",
268
+ pose: {
269
+ position: [
270
+ 0,
271
+ 0,
272
+ 0
273
+ ],
274
+ orientation: [
275
+ 0,
276
+ 0,
277
+ 1.5708
278
+ ]
279
+ }
280
+ }
281
+ },
282
+ payloads: { "FPay-0": {
283
+ name: "FPay-0",
284
+ payload: 0,
285
+ center_of_mass: [
286
+ 0,
287
+ 0,
288
+ 0
289
+ ],
290
+ moment_of_inertia: [
291
+ 0,
292
+ 0,
293
+ 0
294
+ ]
295
+ } },
296
+ cycle_time: 8,
297
+ dh_parameters: [
298
+ {
299
+ alpha: 1.5707963267948966,
300
+ d: 162.25
301
+ },
302
+ { a: -425 },
303
+ { a: -392.2 },
304
+ {
305
+ alpha: 1.5707963267948966,
306
+ d: 133.3
307
+ },
308
+ {
309
+ alpha: -1.5707963267948966,
310
+ d: 99.7
311
+ },
312
+ { d: 99.6 }
313
+ ],
314
+ operation_limits: {
315
+ auto_limits: {
316
+ joints: [
317
+ {
318
+ position: {
319
+ lower_limit: -6.283185307179586,
320
+ upper_limit: 6.283185307179586
321
+ },
322
+ velocity: 3.34159255027771,
323
+ acceleration: 40,
324
+ torque: 150
325
+ },
326
+ {
327
+ position: {
328
+ lower_limit: -6.283185307179586,
329
+ upper_limit: 6.283185307179586
330
+ },
331
+ velocity: 3.34159255027771,
332
+ acceleration: 40,
333
+ torque: 150
334
+ },
335
+ {
336
+ position: {
337
+ lower_limit: -6.283185307179586,
338
+ upper_limit: 6.283185307179586
339
+ },
340
+ velocity: 3.34159255027771,
341
+ acceleration: 40,
342
+ torque: 150
343
+ },
344
+ {
345
+ position: {
346
+ lower_limit: -6.283185307179586,
347
+ upper_limit: 6.283185307179586
348
+ },
349
+ velocity: 3.34159255027771,
350
+ acceleration: 40,
351
+ torque: 28
352
+ },
353
+ {
354
+ position: {
355
+ lower_limit: -6.283185307179586,
356
+ upper_limit: 6.283185307179586
357
+ },
358
+ velocity: 3.34159255027771,
359
+ acceleration: 40,
360
+ torque: 28
361
+ },
362
+ {
363
+ position: {
364
+ lower_limit: -6.283185307179586,
365
+ upper_limit: 6.283185307179586
366
+ },
367
+ velocity: 3.34159255027771,
368
+ acceleration: 40,
369
+ torque: 28
370
+ }
371
+ ],
372
+ tcp: { velocity: 5e3 },
373
+ elbow: { velocity: 5e3 },
374
+ flange: { velocity: 5e3 }
375
+ },
376
+ manual_limits: {
377
+ joints: [
378
+ {
379
+ position: {
380
+ lower_limit: -6.283185307179586,
381
+ upper_limit: 6.283185307179586
382
+ },
383
+ velocity: 3.34159255027771,
384
+ acceleration: 40,
385
+ torque: 150
386
+ },
387
+ {
388
+ position: {
389
+ lower_limit: -6.283185307179586,
390
+ upper_limit: 6.283185307179586
391
+ },
392
+ velocity: 3.34159255027771,
393
+ acceleration: 40,
394
+ torque: 150
395
+ },
396
+ {
397
+ position: {
398
+ lower_limit: -6.283185307179586,
399
+ upper_limit: 6.283185307179586
400
+ },
401
+ velocity: 3.34159255027771,
402
+ acceleration: 40,
403
+ torque: 150
404
+ },
405
+ {
406
+ position: {
407
+ lower_limit: -6.283185307179586,
408
+ upper_limit: 6.283185307179586
409
+ },
410
+ velocity: 3.34159255027771,
411
+ acceleration: 40,
412
+ torque: 28
413
+ },
414
+ {
415
+ position: {
416
+ lower_limit: -6.283185307179586,
417
+ upper_limit: 6.283185307179586
418
+ },
419
+ velocity: 3.34159255027771,
420
+ acceleration: 40,
421
+ torque: 28
422
+ },
423
+ {
424
+ position: {
425
+ lower_limit: -6.283185307179586,
426
+ upper_limit: 6.283185307179586
427
+ },
428
+ velocity: 3.34159255027771,
429
+ acceleration: 40,
430
+ torque: 28
431
+ }
432
+ ],
433
+ tcp: { velocity: 5e3 }
434
+ },
435
+ manual_t1_limits: {
436
+ joints: [
437
+ {
438
+ position: {
439
+ lower_limit: -6.283185307179586,
440
+ upper_limit: 6.283185307179586
441
+ },
442
+ velocity: 3.34159255027771,
443
+ acceleration: 40,
444
+ torque: 150
445
+ },
446
+ {
447
+ position: {
448
+ lower_limit: -6.283185307179586,
449
+ upper_limit: 6.283185307179586
450
+ },
451
+ velocity: 3.34159255027771,
452
+ acceleration: 40,
453
+ torque: 150
454
+ },
455
+ {
456
+ position: {
457
+ lower_limit: -6.283185307179586,
458
+ upper_limit: 6.283185307179586
459
+ },
460
+ velocity: 3.34159255027771,
461
+ acceleration: 40,
462
+ torque: 150
463
+ },
464
+ {
465
+ position: {
466
+ lower_limit: -6.283185307179586,
467
+ upper_limit: 6.283185307179586
468
+ },
469
+ velocity: 3.34159255027771,
470
+ acceleration: 40,
471
+ torque: 28
472
+ },
473
+ {
474
+ position: {
475
+ lower_limit: -6.283185307179586,
476
+ upper_limit: 6.283185307179586
477
+ },
478
+ velocity: 3.34159255027771,
479
+ acceleration: 40,
480
+ torque: 28
481
+ },
482
+ {
483
+ position: {
484
+ lower_limit: -6.283185307179586,
485
+ upper_limit: 6.283185307179586
486
+ },
487
+ velocity: 3.34159255027771,
488
+ acceleration: 40,
489
+ torque: 28
490
+ }
491
+ ],
492
+ tcp: { velocity: 5e3 }
493
+ },
494
+ manual_t2_limits: {
495
+ joints: [
496
+ {
497
+ position: {
498
+ lower_limit: -6.283185307179586,
499
+ upper_limit: 6.283185307179586
500
+ },
501
+ velocity: 3.34159255027771,
502
+ acceleration: 40,
503
+ torque: 150
504
+ },
505
+ {
506
+ position: {
507
+ lower_limit: -6.283185307179586,
508
+ upper_limit: 6.283185307179586
509
+ },
510
+ velocity: 3.34159255027771,
511
+ acceleration: 40,
512
+ torque: 150
513
+ },
514
+ {
515
+ position: {
516
+ lower_limit: -6.283185307179586,
517
+ upper_limit: 6.283185307179586
518
+ },
519
+ velocity: 3.34159255027771,
520
+ acceleration: 40,
521
+ torque: 150
522
+ },
523
+ {
524
+ position: {
525
+ lower_limit: -6.283185307179586,
526
+ upper_limit: 6.283185307179586
527
+ },
528
+ velocity: 3.34159255027771,
529
+ acceleration: 40,
530
+ torque: 28
531
+ },
532
+ {
533
+ position: {
534
+ lower_limit: -6.283185307179586,
535
+ upper_limit: 6.283185307179586
536
+ },
537
+ velocity: 3.34159255027771,
538
+ acceleration: 40,
539
+ torque: 28
540
+ },
541
+ {
542
+ position: {
543
+ lower_limit: -6.283185307179586,
544
+ upper_limit: 6.283185307179586
545
+ },
546
+ velocity: 3.34159255027771,
547
+ acceleration: 40,
548
+ torque: 28
549
+ }
550
+ ],
551
+ tcp: { velocity: 5e3 }
552
+ }
553
+ },
554
+ serial_number: "WBVirtualRobot"
555
+ };
556
+ }
557
+ },
558
+ {
559
+ method: "GET",
560
+ path: "/cells/:cellId/controllers",
561
+ handle() {
562
+ return { controllers: [{
563
+ controller: "mock-ur5e",
564
+ model_name: "UniversalRobots::Controller",
565
+ host: "mock-ur5e",
566
+ allow_software_install_on_controller: true,
567
+ motion_groups: [{
568
+ motion_group: "0@mock-ur5e",
569
+ name_from_controller: "UR5e",
570
+ active: false,
571
+ model_from_controller: "UniversalRobots_UR5e"
572
+ }],
573
+ has_error: false,
574
+ error_details: ""
575
+ }] };
576
+ }
577
+ },
578
+ {
579
+ method: "GET",
580
+ path: "/cells/:cellId/controllers/:controllerId",
581
+ handle() {
582
+ return {
583
+ configuration: {
584
+ kind: "VirtualController",
585
+ manufacturer: "universalrobots",
586
+ type: "universalrobots-ur5e"
587
+ },
588
+ name: "mock-ur5"
589
+ };
590
+ }
591
+ },
592
+ {
593
+ method: "GET",
594
+ path: "/cells/:cellId/motion-groups/:motionGroupId/specification",
595
+ handle() {
596
+ return {
597
+ dh_parameters: [
598
+ {
599
+ alpha: 1.5707963267948966,
600
+ theta: 0,
601
+ a: 0,
602
+ d: 162.25,
603
+ reverse_rotation_direction: false
604
+ },
605
+ {
606
+ alpha: 0,
607
+ theta: 0,
608
+ a: -425,
609
+ d: 0,
610
+ reverse_rotation_direction: false
611
+ },
612
+ {
613
+ alpha: 0,
614
+ theta: 0,
615
+ a: -392.2,
616
+ d: 0,
617
+ reverse_rotation_direction: false
618
+ },
619
+ {
620
+ alpha: 1.5707963267948966,
621
+ theta: 0,
622
+ a: 0,
623
+ d: 133.3,
624
+ reverse_rotation_direction: false
625
+ },
626
+ {
627
+ alpha: -1.5707963267948966,
628
+ theta: 0,
629
+ a: 0,
630
+ d: 99.7,
631
+ reverse_rotation_direction: false
632
+ },
633
+ {
634
+ alpha: 0,
635
+ theta: 0,
636
+ a: 0,
637
+ d: 99.6,
638
+ reverse_rotation_direction: false
639
+ }
640
+ ],
641
+ mechanical_joint_limits: [
642
+ {
643
+ joint: "JOINTNAME_AXIS_1",
644
+ lower_limit: -6.335545063018799,
645
+ upper_limit: 6.335545063018799,
646
+ unlimited: false
647
+ },
648
+ {
649
+ joint: "JOINTNAME_AXIS_2",
650
+ lower_limit: -6.335545063018799,
651
+ upper_limit: 6.335545063018799,
652
+ unlimited: false
653
+ },
654
+ {
655
+ joint: "JOINTNAME_AXIS_3",
656
+ lower_limit: -6.335545063018799,
657
+ upper_limit: 6.335545063018799,
658
+ unlimited: false
659
+ },
660
+ {
661
+ joint: "JOINTNAME_AXIS_4",
662
+ lower_limit: -6.335545063018799,
663
+ upper_limit: 6.335545063018799,
664
+ unlimited: false
665
+ },
666
+ {
667
+ joint: "JOINTNAME_AXIS_5",
668
+ lower_limit: -6.335545063018799,
669
+ upper_limit: 6.335545063018799,
670
+ unlimited: false
671
+ },
672
+ {
673
+ joint: "JOINTNAME_AXIS_6",
674
+ lower_limit: -6.335545063018799,
675
+ upper_limit: 6.335545063018799,
676
+ unlimited: false
677
+ }
678
+ ]
679
+ };
680
+ }
681
+ },
682
+ {
683
+ method: "GET",
684
+ path: "/cells/:cellId/motion-groups/:motionGroupId/safety-setup",
685
+ handle() {
686
+ return {
687
+ safety_settings: [{
688
+ safety_state: "SAFETY_NORMAL",
689
+ settings: {
690
+ joint_position_limits: [
691
+ {
692
+ joint: "JOINTNAME_AXIS_1",
693
+ lower_limit: -2.96705961227417,
694
+ upper_limit: 2.96705961227417,
695
+ unlimited: false
696
+ },
697
+ {
698
+ joint: "JOINTNAME_AXIS_2",
699
+ lower_limit: -1.7453292608261108,
700
+ upper_limit: 2.7925267219543457,
701
+ unlimited: false
702
+ },
703
+ {
704
+ joint: "JOINTNAME_AXIS_3",
705
+ lower_limit: -3.3161256313323975,
706
+ upper_limit: .40142571926116943,
707
+ unlimited: false
708
+ },
709
+ {
710
+ joint: "JOINTNAME_AXIS_4",
711
+ lower_limit: -3.4906585216522217,
712
+ upper_limit: 3.4906585216522217,
713
+ unlimited: false
714
+ },
715
+ {
716
+ joint: "JOINTNAME_AXIS_5",
717
+ lower_limit: -2.4434609413146973,
718
+ upper_limit: 2.4434609413146973,
719
+ unlimited: false
720
+ },
721
+ {
722
+ joint: "JOINTNAME_AXIS_6",
723
+ lower_limit: -4.71238899230957,
724
+ upper_limit: 4.71238899230957,
725
+ unlimited: false
726
+ }
727
+ ],
728
+ joint_velocity_limits: [
729
+ {
730
+ joint: "JOINTNAME_AXIS_1",
731
+ limit: 3.1415927410125732
732
+ },
733
+ {
734
+ joint: "JOINTNAME_AXIS_2",
735
+ limit: 3.1415927410125732
736
+ },
737
+ {
738
+ joint: "JOINTNAME_AXIS_3",
739
+ limit: 3.4906585216522217
740
+ },
741
+ {
742
+ joint: "JOINTNAME_AXIS_4",
743
+ limit: 6.108652591705322
744
+ },
745
+ {
746
+ joint: "JOINTNAME_AXIS_5",
747
+ limit: 6.108652591705322
748
+ },
749
+ {
750
+ joint: "JOINTNAME_AXIS_6",
751
+ limit: 6.981317043304443
752
+ }
753
+ ],
754
+ joint_acceleration_limits: [],
755
+ joint_torque_limits: [],
756
+ tcp_velocity_limit: 1800
757
+ }
758
+ }],
759
+ safety_zones: [
760
+ {
761
+ id: 1,
762
+ priority: 0,
763
+ geometry: {
764
+ compound: { child_geometries: [
765
+ {
766
+ convex_hull: { vertices: [
767
+ { vertex: [
768
+ -800,
769
+ -1330,
770
+ -1820
771
+ ] },
772
+ { vertex: [
773
+ 1650,
774
+ -1330,
775
+ -1820
776
+ ] },
777
+ { vertex: [
778
+ 1650,
779
+ 1330,
780
+ -1820
781
+ ] },
782
+ { vertex: [
783
+ -800,
784
+ 1330,
785
+ -1820
786
+ ] }
787
+ ] },
788
+ init_pose: {
789
+ position: [
790
+ 0,
791
+ 0,
792
+ 0
793
+ ],
794
+ orientation: [
795
+ 0,
796
+ 0,
797
+ 0,
798
+ 1
799
+ ]
800
+ },
801
+ id: "box"
802
+ },
803
+ {
804
+ convex_hull: { vertices: [
805
+ { vertex: [
806
+ -800,
807
+ -1330,
808
+ -1820
809
+ ] },
810
+ { vertex: [
811
+ 1650,
812
+ -1330,
813
+ -1820
814
+ ] },
815
+ { vertex: [
816
+ 1650,
817
+ -1330,
818
+ 1500
819
+ ] },
820
+ { vertex: [
821
+ -800,
822
+ -1330,
823
+ 1500
824
+ ] }
825
+ ] },
826
+ init_pose: {
827
+ position: [
828
+ 0,
829
+ 0,
830
+ 0
831
+ ],
832
+ orientation: [
833
+ 0,
834
+ 0,
835
+ 0,
836
+ 1
837
+ ]
838
+ },
839
+ id: "box"
840
+ },
841
+ {
842
+ convex_hull: { vertices: [
843
+ { vertex: [
844
+ -800,
845
+ -1330,
846
+ -1820
847
+ ] },
848
+ { vertex: [
849
+ -800,
850
+ 1330,
851
+ -1820
852
+ ] },
853
+ { vertex: [
854
+ -800,
855
+ 1330,
856
+ 1500
857
+ ] },
858
+ { vertex: [
859
+ -800,
860
+ -1330,
861
+ 1500
862
+ ] }
863
+ ] },
864
+ init_pose: {
865
+ position: [
866
+ 0,
867
+ 0,
868
+ 0
869
+ ],
870
+ orientation: [
871
+ 0,
872
+ 0,
873
+ 0,
874
+ 1
875
+ ]
876
+ },
877
+ id: "box"
878
+ },
879
+ {
880
+ convex_hull: { vertices: [
881
+ { vertex: [
882
+ 1650,
883
+ 1330,
884
+ 1500
885
+ ] },
886
+ { vertex: [
887
+ -800,
888
+ 1330,
889
+ 1500
890
+ ] },
891
+ { vertex: [
892
+ -800,
893
+ -1330,
894
+ 1500
895
+ ] },
896
+ { vertex: [
897
+ 1650,
898
+ -1330,
899
+ 1500
900
+ ] }
901
+ ] },
902
+ init_pose: {
903
+ position: [
904
+ 0,
905
+ 0,
906
+ 0
907
+ ],
908
+ orientation: [
909
+ 0,
910
+ 0,
911
+ 0,
912
+ 1
913
+ ]
914
+ },
915
+ id: "box"
916
+ },
917
+ {
918
+ convex_hull: { vertices: [
919
+ { vertex: [
920
+ 1650,
921
+ 1330,
922
+ 1500
923
+ ] },
924
+ { vertex: [
925
+ -800,
926
+ 1330,
927
+ 1500
928
+ ] },
929
+ { vertex: [
930
+ -800,
931
+ 1330,
932
+ -1820
933
+ ] },
934
+ { vertex: [
935
+ 1650,
936
+ 1330,
937
+ -1820
938
+ ] }
939
+ ] },
940
+ init_pose: {
941
+ position: [
942
+ 0,
943
+ 0,
944
+ 0
945
+ ],
946
+ orientation: [
947
+ 0,
948
+ 0,
949
+ 0,
950
+ 1
951
+ ]
952
+ },
953
+ id: "box"
954
+ },
955
+ {
956
+ convex_hull: { vertices: [
957
+ { vertex: [
958
+ 1650,
959
+ 1330,
960
+ 1500
961
+ ] },
962
+ { vertex: [
963
+ 1650,
964
+ -1330,
965
+ 1500
966
+ ] },
967
+ { vertex: [
968
+ 1650,
969
+ -1330,
970
+ -1820
971
+ ] },
972
+ { vertex: [
973
+ 1650,
974
+ 1330,
975
+ -1820
976
+ ] }
977
+ ] },
978
+ init_pose: {
979
+ position: [
980
+ 0,
981
+ 0,
982
+ 0
983
+ ],
984
+ orientation: [
985
+ 0,
986
+ 0,
987
+ 0,
988
+ 1
989
+ ]
990
+ },
991
+ id: "box"
992
+ }
993
+ ] },
994
+ init_pose: {
995
+ position: [
996
+ 0,
997
+ 0,
998
+ 0
999
+ ],
1000
+ orientation: [
1001
+ 0,
1002
+ 0,
1003
+ 0,
1004
+ 1
1005
+ ]
1006
+ },
1007
+ id: "Cell workzone"
1008
+ },
1009
+ motion_group_uid: 1
1010
+ },
1011
+ {
1012
+ id: 2,
1013
+ priority: 0,
1014
+ geometry: {
1015
+ convex_hull: { vertices: [
1016
+ { vertex: [
1017
+ 1650,
1018
+ 1330,
1019
+ -1850
1020
+ ] },
1021
+ { vertex: [
1022
+ 865,
1023
+ 1330,
1024
+ -1850
1025
+ ] },
1026
+ { vertex: [
1027
+ 865,
1028
+ -720,
1029
+ -1850
1030
+ ] },
1031
+ { vertex: [
1032
+ 1650,
1033
+ -720,
1034
+ -1850
1035
+ ] },
1036
+ { vertex: [
1037
+ 1650,
1038
+ 1330,
1039
+ -920
1040
+ ] },
1041
+ { vertex: [
1042
+ 865,
1043
+ 1330,
1044
+ -920
1045
+ ] },
1046
+ { vertex: [
1047
+ 865,
1048
+ -720,
1049
+ -920
1050
+ ] },
1051
+ { vertex: [
1052
+ 1650,
1053
+ -720,
1054
+ -920
1055
+ ] }
1056
+ ] },
1057
+ init_pose: {
1058
+ position: [
1059
+ 0,
1060
+ 0,
1061
+ 0
1062
+ ],
1063
+ orientation: [
1064
+ 0,
1065
+ 0,
1066
+ 0,
1067
+ 1
1068
+ ]
1069
+ },
1070
+ id: "Transport"
1071
+ },
1072
+ motion_group_uid: 1
1073
+ },
1074
+ {
1075
+ id: 3,
1076
+ priority: 0,
1077
+ geometry: {
1078
+ convex_hull: { vertices: [
1079
+ { vertex: [
1080
+ 1650,
1081
+ 1330,
1082
+ -600
1083
+ ] },
1084
+ { vertex: [
1085
+ 865,
1086
+ 1330,
1087
+ -600
1088
+ ] },
1089
+ { vertex: [
1090
+ 865,
1091
+ 430,
1092
+ -600
1093
+ ] },
1094
+ { vertex: [
1095
+ 1650,
1096
+ 430,
1097
+ -600
1098
+ ] },
1099
+ { vertex: [
1100
+ 1650,
1101
+ 1330,
1102
+ -1250
1103
+ ] },
1104
+ { vertex: [
1105
+ 865,
1106
+ 1330,
1107
+ -1250
1108
+ ] },
1109
+ { vertex: [
1110
+ 865,
1111
+ 430,
1112
+ -1250
1113
+ ] },
1114
+ { vertex: [
1115
+ 1650,
1116
+ 430,
1117
+ -1250
1118
+ ] }
1119
+ ] },
1120
+ init_pose: {
1121
+ position: [
1122
+ 0,
1123
+ 0,
1124
+ 0
1125
+ ],
1126
+ orientation: [
1127
+ 0,
1128
+ 0,
1129
+ 0,
1130
+ 1
1131
+ ]
1132
+ },
1133
+ id: "Tunel"
1134
+ },
1135
+ motion_group_uid: 1
1136
+ },
1137
+ {
1138
+ id: 4,
1139
+ priority: 0,
1140
+ geometry: {
1141
+ convex_hull: { vertices: [
1142
+ { vertex: [
1143
+ 1650,
1144
+ -760,
1145
+ -440
1146
+ ] },
1147
+ { vertex: [
1148
+ 900,
1149
+ -760,
1150
+ -440
1151
+ ] },
1152
+ { vertex: [
1153
+ 900,
1154
+ -1330,
1155
+ -440
1156
+ ] },
1157
+ { vertex: [
1158
+ 1650,
1159
+ -1330,
1160
+ -440
1161
+ ] },
1162
+ { vertex: [
1163
+ 1650,
1164
+ -760,
1165
+ -1800
1166
+ ] },
1167
+ { vertex: [
1168
+ 900,
1169
+ -760,
1170
+ -1800
1171
+ ] },
1172
+ { vertex: [
1173
+ 900,
1174
+ -1330,
1175
+ -1800
1176
+ ] },
1177
+ { vertex: [
1178
+ 1650,
1179
+ -1330,
1180
+ -1800
1181
+ ] }
1182
+ ] },
1183
+ init_pose: {
1184
+ position: [
1185
+ 0,
1186
+ 0,
1187
+ 0
1188
+ ],
1189
+ orientation: [
1190
+ 0,
1191
+ 0,
1192
+ 0,
1193
+ 1
1194
+ ]
1195
+ },
1196
+ id: "Fanuc controller"
1197
+ },
1198
+ motion_group_uid: 1
1199
+ },
1200
+ {
1201
+ id: 6,
1202
+ priority: 0,
1203
+ geometry: {
1204
+ convex_hull: { vertices: [
1205
+ { vertex: [
1206
+ -200,
1207
+ -200,
1208
+ -1900
1209
+ ] },
1210
+ { vertex: [
1211
+ 200,
1212
+ -200,
1213
+ -1900
1214
+ ] },
1215
+ { vertex: [
1216
+ 200,
1217
+ 200,
1218
+ -1900
1219
+ ] },
1220
+ { vertex: [
1221
+ -200,
1222
+ 200,
1223
+ -1900
1224
+ ] },
1225
+ { vertex: [
1226
+ -200,
1227
+ -200,
1228
+ -350
1229
+ ] },
1230
+ { vertex: [
1231
+ 200,
1232
+ -200,
1233
+ -350
1234
+ ] },
1235
+ { vertex: [
1236
+ 200,
1237
+ 200,
1238
+ -350
1239
+ ] },
1240
+ { vertex: [
1241
+ -200,
1242
+ 200,
1243
+ -350
1244
+ ] }
1245
+ ] },
1246
+ init_pose: {
1247
+ position: [
1248
+ 0,
1249
+ 0,
1250
+ 0
1251
+ ],
1252
+ orientation: [
1253
+ 0,
1254
+ 0,
1255
+ 0,
1256
+ 1
1257
+ ]
1258
+ },
1259
+ id: "Robot base"
1260
+ },
1261
+ motion_group_uid: 1
1262
+ }
1263
+ ],
1264
+ robot_model_geometries: [
1265
+ {
1266
+ link_index: 1,
1267
+ geometry: {
1268
+ sphere: { radius: 270 },
1269
+ init_pose: {
1270
+ position: [
1271
+ -70,
1272
+ -70,
1273
+ -50
1274
+ ],
1275
+ orientation: [
1276
+ 0,
1277
+ 0,
1278
+ 0,
1279
+ 1
1280
+ ]
1281
+ },
1282
+ id: "link1_sphere"
1283
+ }
1284
+ },
1285
+ {
1286
+ link_index: 2,
1287
+ geometry: {
1288
+ capsule: {
1289
+ radius: 160,
1290
+ cylinder_height: 800
1291
+ },
1292
+ init_pose: {
1293
+ position: [
1294
+ -450,
1295
+ 40,
1296
+ 170
1297
+ ],
1298
+ orientation: [
1299
+ 0,
1300
+ -Math.SQRT1_2,
1301
+ 0,
1302
+ Math.SQRT1_2
1303
+ ]
1304
+ },
1305
+ id: "link2_capsule"
1306
+ }
1307
+ },
1308
+ {
1309
+ link_index: 3,
1310
+ geometry: {
1311
+ sphere: { radius: 270 },
1312
+ init_pose: {
1313
+ position: [
1314
+ -110,
1315
+ 10,
1316
+ -100
1317
+ ],
1318
+ orientation: [
1319
+ 0,
1320
+ 0,
1321
+ 0,
1322
+ 1
1323
+ ]
1324
+ },
1325
+ id: "link3_sphere"
1326
+ }
1327
+ },
1328
+ {
1329
+ link_index: 4,
1330
+ geometry: {
1331
+ capsule: {
1332
+ radius: 110,
1333
+ cylinder_height: 600
1334
+ },
1335
+ init_pose: {
1336
+ position: [
1337
+ 0,
1338
+ 300,
1339
+ 40
1340
+ ],
1341
+ orientation: [
1342
+ -Math.SQRT1_2,
1343
+ 0,
1344
+ 0,
1345
+ Math.SQRT1_2
1346
+ ]
1347
+ },
1348
+ id: "link4_capsule"
1349
+ }
1350
+ },
1351
+ {
1352
+ link_index: 5,
1353
+ geometry: {
1354
+ sphere: { radius: 75 },
1355
+ init_pose: {
1356
+ position: [
1357
+ 0,
1358
+ 0,
1359
+ -50
1360
+ ],
1361
+ orientation: [
1362
+ 0,
1363
+ 0,
1364
+ 0,
1365
+ 1
1366
+ ]
1367
+ },
1368
+ id: "link5_sphere"
1369
+ }
1370
+ }
1371
+ ],
1372
+ tool_geometries: []
1373
+ };
1374
+ }
1375
+ },
1376
+ {
1377
+ method: "GET",
1378
+ path: "/cells/:cellId/motion-groups/:motionGroupId/tcps",
1379
+ handle() {
1380
+ return { tcps: [{
1381
+ id: "Flange",
1382
+ readable_name: "Default-Flange",
1383
+ position: [
1384
+ 0,
1385
+ 0,
1386
+ 0
1387
+ ],
1388
+ rotation: {
1389
+ angles: [
1390
+ 0,
1391
+ 0,
1392
+ 0,
1393
+ 0
1394
+ ],
1395
+ type: "ROTATION_VECTOR"
1396
+ }
1397
+ }, {
1398
+ id: "complex-tcp-position",
1399
+ readable_name: "Complex TCP Position",
1400
+ position: [
1401
+ -200,
1402
+ 300,
1403
+ 150
1404
+ ],
1405
+ rotation: {
1406
+ angles: [
1407
+ -.12139440409113832,
1408
+ -.06356210998212003,
1409
+ -.2023240068185639,
1410
+ 0
1411
+ ],
1412
+ type: "ROTATION_VECTOR"
1413
+ }
1414
+ }] };
1415
+ }
1416
+ }
1417
+ ];
1418
+ const method = config.method?.toUpperCase() || "GET";
1419
+ const path = `/cells${config.url?.split("/cells")[1]?.split("?")[0]}`;
1420
+ for (const handler of apiHandlers) {
1421
+ const match = pathToRegexp.match(handler.path)(path || "");
1422
+ if (method === handler.method && match) {
1423
+ const json = handler.handle();
1424
+ return {
1425
+ status: 200,
1426
+ statusText: "Success",
1427
+ data: JSON.stringify(json),
1428
+ headers: {},
1429
+ config,
1430
+ request: { responseURL: config.url }
1431
+ };
1432
+ }
1433
+ }
1434
+ throw new AxiosError(`No mock handler matched this request: ${method} ${path}`, "404", config);
1435
+ }
1436
+ handleWebsocketConnection(socket) {
1437
+ this.connections.push(socket);
1438
+ setTimeout(() => {
1439
+ socket.dispatchEvent(new Event("open"));
1440
+ console.log("Websocket connection opened from", socket.url);
1441
+ if (socket.url.includes("/state-stream")) socket.dispatchEvent(new MessageEvent("message", { data: JSON.stringify(defaultMotionState) }));
1442
+ if (socket.url.includes("/move-joint")) socket.dispatchEvent(new MessageEvent("message", { data: JSON.stringify({ result: {
1443
+ motion_group: "0@ur",
1444
+ state: {
1445
+ controller: "ur",
1446
+ operation_mode: "OPERATION_MODE_AUTO",
1447
+ safety_state: "SAFETY_STATE_NORMAL",
1448
+ timestamp: "2024-09-18T12:48:26.096266444Z",
1449
+ velocity_override: 100,
1450
+ motion_groups: [{
1451
+ motion_group: "0@ur",
1452
+ controller: "ur",
1453
+ joint_position: [
1454
+ 1.3492152690887451,
1455
+ -1.5659207105636597,
1456
+ 1.6653711795806885,
1457
+ -1.0991662740707397,
1458
+ -1.829018235206604,
1459
+ 1.264623761177063
1460
+ ],
1461
+ joint_velocity: { joints: [
1462
+ 0,
1463
+ 0,
1464
+ 0,
1465
+ 0,
1466
+ 0,
1467
+ 0
1468
+ ] },
1469
+ flange_pose: {
1470
+ position: [
1471
+ 6.437331889439328,
1472
+ -628.4123774830913,
1473
+ 577.0569957147832
1474
+ ],
1475
+ orientation: {
1476
+ x: -1.683333649797158,
1477
+ y: -1.9783363827298732,
1478
+ z: -.4928031860165713
1479
+ },
1480
+ coordinate_system: ""
1481
+ },
1482
+ tcp_pose: {
1483
+ position: [
1484
+ 6.437331889439328,
1485
+ -628.4123774830913,
1486
+ 577.0569957147832
1487
+ ],
1488
+ orientation: {
1489
+ x: -1.683333649797158,
1490
+ y: -1.9783363827298732,
1491
+ z: -.4928031860165713
1492
+ },
1493
+ coordinate_system: "",
1494
+ tcp: "Flange"
1495
+ },
1496
+ velocity: {
1497
+ linear: {
1498
+ x: 0,
1499
+ y: 0,
1500
+ z: 0
1501
+ },
1502
+ angular: {
1503
+ x: -0,
1504
+ y: 0,
1505
+ z: 0
1506
+ },
1507
+ coordinate_system: ""
1508
+ },
1509
+ force: {
1510
+ force: {
1511
+ x: 0,
1512
+ y: 0,
1513
+ z: 0
1514
+ },
1515
+ moment: {
1516
+ x: 0,
1517
+ y: 0,
1518
+ z: 0
1519
+ },
1520
+ coordinate_system: ""
1521
+ },
1522
+ joint_limit_reached: { limit_reached: [
1523
+ false,
1524
+ false,
1525
+ false,
1526
+ false,
1527
+ false,
1528
+ false
1529
+ ] },
1530
+ joint_current: { joints: [
1531
+ 0,
1532
+ 0,
1533
+ 0,
1534
+ 0,
1535
+ 0,
1536
+ 0
1537
+ ] },
1538
+ sequence_number: "671259"
1539
+ }],
1540
+ sequence_number: "671259"
1541
+ },
1542
+ movement_state: "MOVEMENT_STATE_MOVING"
1543
+ } }) }));
1544
+ if (socket.url.includes("/move-tcp")) socket.dispatchEvent(new MessageEvent("message", { data: JSON.stringify({ result: {
1545
+ motion_group: "0@ur",
1546
+ state: {
1547
+ controller: "ur",
1548
+ operation_mode: "OPERATION_MODE_AUTO",
1549
+ safety_state: "SAFETY_STATE_NORMAL",
1550
+ timestamp: "2024-09-18T12:43:12.188335774Z",
1551
+ velocity_override: 100,
1552
+ motion_groups: [{
1553
+ motion_group: "0@ur",
1554
+ controller: "ur",
1555
+ joint_position: { joints: [
1556
+ 1.3352527618408203,
1557
+ -1.5659207105636597,
1558
+ 1.6653711795806885,
1559
+ -1.110615611076355,
1560
+ -1.829018235206604,
1561
+ 1.264623761177063
1562
+ ] },
1563
+ joint_velocity: { joints: [
1564
+ 0,
1565
+ 0,
1566
+ 0,
1567
+ 0,
1568
+ 0,
1569
+ 0
1570
+ ] },
1571
+ flange_pose: {
1572
+ position: [
1573
+ -2.763015284002938,
1574
+ -630.2151479701106,
1575
+ 577.524509114342
1576
+ ],
1577
+ orientation: {
1578
+ x: -1.704794877102097,
1579
+ y: -1.9722372952861567,
1580
+ z: -.4852079204210754
1581
+ },
1582
+ coordinate_system: ""
1583
+ },
1584
+ tcp_pose: {
1585
+ position: [
1586
+ -2.763015284002938,
1587
+ -630.2151479701106,
1588
+ 577.524509114342
1589
+ ],
1590
+ orientation: {
1591
+ x: -1.704794877102097,
1592
+ y: -1.9722372952861567,
1593
+ z: -.4852079204210754
1594
+ },
1595
+ coordinate_system: "",
1596
+ tcp: "Flange"
1597
+ },
1598
+ velocity: {
1599
+ linear: {
1600
+ x: 0,
1601
+ y: 0,
1602
+ z: 0
1603
+ },
1604
+ angular: {
1605
+ x: -0,
1606
+ y: 0,
1607
+ z: 0
1608
+ },
1609
+ coordinate_system: ""
1610
+ },
1611
+ force: {
1612
+ force: {
1613
+ x: 0,
1614
+ y: 0,
1615
+ z: 0
1616
+ },
1617
+ moment: {
1618
+ x: 0,
1619
+ y: 0,
1620
+ z: 0
1621
+ },
1622
+ coordinate_system: ""
1623
+ },
1624
+ joint_limit_reached: { limit_reached: [
1625
+ false,
1626
+ false,
1627
+ false,
1628
+ false,
1629
+ false,
1630
+ false
1631
+ ] },
1632
+ joint_current: { joints: [
1633
+ 0,
1634
+ 0,
1635
+ 0,
1636
+ 0,
1637
+ 0,
1638
+ 0
1639
+ ] },
1640
+ sequence_number: "627897"
1641
+ }],
1642
+ sequence_number: "627897"
1643
+ },
1644
+ movement_state: "MOVEMENT_STATE_MOVING"
1645
+ } }) }));
1646
+ }, 10);
1647
+ }
1648
+ handleWebsocketMessage(socket, message) {
1649
+ console.log(`Received message on ${socket.url}`, message);
1650
+ }
1651
+ };
1652
+ const defaultMotionState = { result: {
1653
+ motion_group: "0@universalrobots-ur5e",
1654
+ controller: "universalrobots-ur5e",
1655
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
1656
+ sequence_number: 1,
1657
+ joint_position: [
1658
+ 1.1699999570846558,
1659
+ -1.5700000524520874,
1660
+ 1.3600000143051147,
1661
+ 1.0299999713897705,
1662
+ 1.2899999618530273,
1663
+ 1.2799999713897705
1664
+ ],
1665
+ joint_limit_reached: { limit_reached: [
1666
+ false,
1667
+ false,
1668
+ false,
1669
+ false,
1670
+ false,
1671
+ false
1672
+ ] },
1673
+ standstill: false,
1674
+ flange_pose: {
1675
+ position: [
1676
+ 1.3300010259703043,
1677
+ -409.2680714682808,
1678
+ 531.0203477065281
1679
+ ],
1680
+ orientation: [
1681
+ 1.7564919306270736,
1682
+ -1.7542521568325058,
1683
+ .7326972590614671
1684
+ ]
1685
+ },
1686
+ tcp_pose: {
1687
+ position: [
1688
+ 1.3300010259703043,
1689
+ -409.2680714682808,
1690
+ 531.0203477065281
1691
+ ],
1692
+ orientation: [
1693
+ 1.7564919306270736,
1694
+ -1.7542521568325058,
1695
+ .7326972590614671
1696
+ ]
1697
+ }
1698
+ } };
1699
+
1700
+ //#endregion
1701
+ //#region src/lib/v2/NovaClient.ts
1702
+ function permissiveInstanceUrlParse(url) {
1703
+ if (!url.startsWith("http")) url = `http://${url}`;
1704
+ return new URL(url).toString();
1705
+ }
1706
+ /**
1707
+ *
1708
+ * Client for connecting to a Nova instance and controlling robots.
1709
+ */
1710
+ var NovaClient = class {
1711
+ constructor(config) {
1712
+ this.authPromise = null;
1713
+ this.accessToken = null;
1714
+ const cellId = config.cellId ?? "cell";
1715
+ this.config = {
1716
+ cellId,
1717
+ ...config
1718
+ };
1719
+ this.accessToken = config.accessToken || availableStorage.getString("wbjs.access_token") || null;
1720
+ if (this.config.instanceUrl === "https://mock.example.com") this.mock = new MockNovaInstance();
1721
+ else this.config.instanceUrl = permissiveInstanceUrlParse(this.config.instanceUrl);
1722
+ const axiosInstance = axios.create({
1723
+ baseURL: urlJoin(this.config.instanceUrl, "/api/v2"),
1724
+ headers: typeof window !== "undefined" && window.location.origin.includes("localhost") ? {} : { "X-Wandelbots-Client": "Wandelbots-Nova-JS-SDK" }
1725
+ });
1726
+ axiosInstance.interceptors.request.use(async (request) => {
1727
+ if (!request.headers.Authorization) {
1728
+ if (this.accessToken) request.headers.Authorization = `Bearer ${this.accessToken}`;
1729
+ else if (this.config.username && this.config.password) request.headers.Authorization = `Basic ${btoa(`${config.username}:${config.password}`)}`;
1730
+ }
1731
+ return request;
1732
+ });
1733
+ if (typeof window !== "undefined") axiosInstance.interceptors.response.use((r) => r, async (error) => {
1734
+ if (isAxiosError(error)) {
1735
+ if (error.response?.status === 401) try {
1736
+ await this.renewAuthentication();
1737
+ if (error.config) {
1738
+ if (this.accessToken) error.config.headers.Authorization = `Bearer ${this.accessToken}`;
1739
+ else delete error.config.headers.Authorization;
1740
+ return axiosInstance.request(error.config);
1741
+ }
1742
+ } catch (err) {
1743
+ return Promise.reject(err);
1744
+ }
1745
+ else if (error.response?.status === 503) {
1746
+ if ((await fetch(window.location.href)).status === 503) window.location.reload();
1747
+ }
1748
+ }
1749
+ return Promise.reject(error);
1750
+ });
1751
+ this.api = new NovaCellAPIClient(cellId, {
1752
+ ...config,
1753
+ basePath: urlJoin(this.config.instanceUrl, "/api/v2"),
1754
+ isJsonMime: (mime) => {
1755
+ return mime === "application/json";
1756
+ },
1757
+ baseOptions: {
1758
+ ...this.mock ? { adapter: (config$1) => {
1759
+ return this.mock.handleAPIRequest(config$1);
1760
+ } } : {},
1761
+ ...config.baseOptions
1762
+ },
1763
+ axiosInstance
1764
+ });
1765
+ }
1766
+ async renewAuthentication() {
1767
+ if (this.authPromise) return;
1768
+ this.authPromise = loginWithAuth0(this.config.instanceUrl);
1769
+ try {
1770
+ this.accessToken = await this.authPromise;
1771
+ if (this.accessToken) availableStorage.setString("wbjs.access_token", this.accessToken);
1772
+ else availableStorage.delete("wbjs.access_token");
1773
+ } finally {
1774
+ this.authPromise = null;
1775
+ }
1776
+ }
1777
+ makeWebsocketURL(path) {
1778
+ const url = new URL(urlJoin(this.config.instanceUrl, `/api/v2/cells/${this.config.cellId}`, path));
1779
+ url.protocol = url.protocol.replace("http", "ws");
1780
+ url.protocol = url.protocol.replace("https", "wss");
1781
+ if (this.accessToken) url.searchParams.append("token", this.accessToken);
1782
+ else if (this.config.username && this.config.password) {
1783
+ url.username = this.config.username;
1784
+ url.password = this.config.password;
1785
+ }
1786
+ return url.toString();
1787
+ }
1788
+ /**
1789
+ * Retrieve an AutoReconnectingWebsocket to the given path on the Nova instance.
1790
+ * If you explicitly want to reconnect an existing websocket, call `reconnect`
1791
+ * on the returned object.
1792
+ */
1793
+ openReconnectingWebsocket(path) {
1794
+ return new AutoReconnectingWebsocket(this.makeWebsocketURL(path), { mock: this.mock });
1795
+ }
1796
+ };
1797
+
1798
+ //#endregion
1799
+ //#region src/lib/v2/wandelscriptUtils.ts
1800
+ /**
1801
+ * Convert a Pose object representing a motion group position
1802
+ * into a string which represents that pose in Wandelscript.
1803
+ */
1804
+ function poseToWandelscriptString(pose) {
1805
+ const position = [
1806
+ pose.position?.[0] ?? 0,
1807
+ pose.position?.[1] ?? 0,
1808
+ pose.position?.[2] ?? 0
1809
+ ];
1810
+ const orientation = [
1811
+ pose.orientation?.[0] ?? 0,
1812
+ pose.orientation?.[1] ?? 0,
1813
+ pose.orientation?.[2] ?? 0
1814
+ ];
1815
+ const positionValues = position.map((v) => v.toFixed(1));
1816
+ const rotationValues = orientation.map((v) => v.toFixed(4));
1817
+ return `(${positionValues.concat(rotationValues).join(", ")})`;
1818
+ }
1819
+
1820
+ //#endregion
1821
+ export { NovaCellAPIClient, NovaClient, poseToWandelscriptString };
1822
+ //# sourceMappingURL=index.mjs.map