@wandelbots/nova-js 3.13.0 → 4.0.0-pr.309.02b99fd

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 (72) hide show
  1. package/dist/{AutoReconnectingWebsocket-1K2J1NA4.d.cts → AutoReconnectingWebsocket-BSt-vnzX.d.mts} +4 -16
  2. package/dist/AutoReconnectingWebsocket-BSt-vnzX.d.mts.map +1 -0
  3. package/dist/{context-ffr5Q2dc.mjs → LoginWithAuth0-D92HnzHq.mjs} +3 -13
  4. package/dist/LoginWithAuth0-D92HnzHq.mjs.map +1 -0
  5. package/dist/{Nova--8gozkLR.d.mts → Nova-C8nDNSCa.d.mts} +2 -2
  6. package/dist/{Nova--8gozkLR.d.mts.map → Nova-C8nDNSCa.d.mts.map} +1 -1
  7. package/dist/experimental/nats/index.d.mts +1 -1
  8. package/dist/index.d.mts +2 -7
  9. package/dist/index.d.mts.map +1 -1
  10. package/dist/index.mjs +2 -3
  11. package/dist/v2/index.d.mts +2 -130
  12. package/dist/v2/index.mjs +4 -231
  13. package/dist/v2/index.mjs.map +1 -1
  14. package/package.json +13 -17
  15. package/src/index.ts +0 -2
  16. package/src/lib/AutoReconnectingWebsocket.ts +3 -4
  17. package/src/lib/LoginWithAuth0.ts +1 -1
  18. package/src/lib/context.ts +1 -1
  19. package/src/lib/errorHandling.ts +0 -7
  20. package/src/v2/index.ts +0 -3
  21. package/dist/AutoReconnectingWebsocket-1K2J1NA4.d.cts.map +0 -1
  22. package/dist/AutoReconnectingWebsocket-1K2J1NA4.d.mts +0 -69
  23. package/dist/AutoReconnectingWebsocket-1K2J1NA4.d.mts.map +0 -1
  24. package/dist/Nova-B1o5iTQ6.d.cts +0 -85
  25. package/dist/Nova-B1o5iTQ6.d.cts.map +0 -1
  26. package/dist/context-BZELA2eh.cjs +0 -348
  27. package/dist/context-BZELA2eh.cjs.map +0 -1
  28. package/dist/context-ffr5Q2dc.mjs.map +0 -1
  29. package/dist/converters-EYS27XJE.cjs +0 -146
  30. package/dist/converters-EYS27XJE.cjs.map +0 -1
  31. package/dist/experimental/nats/index.cjs +0 -158
  32. package/dist/experimental/nats/index.cjs.map +0 -1
  33. package/dist/experimental/nats/index.d.cts +0 -3235
  34. package/dist/experimental/nats/index.d.cts.map +0 -1
  35. package/dist/index.cjs +0 -24
  36. package/dist/index.d.cts +0 -110
  37. package/dist/index.d.cts.map +0 -1
  38. package/dist/v1/index.cjs +0 -201
  39. package/dist/v1/index.cjs.map +0 -1
  40. package/dist/v1/index.d.cts +0 -67
  41. package/dist/v1/index.d.cts.map +0 -1
  42. package/dist/v1/index.d.mts +0 -67
  43. package/dist/v1/index.d.mts.map +0 -1
  44. package/dist/v1/index.mjs +0 -184
  45. package/dist/v1/index.mjs.map +0 -1
  46. package/dist/v2/index.cjs +0 -1038
  47. package/dist/v2/index.cjs.map +0 -1
  48. package/dist/v2/index.d.cts +0 -131
  49. package/dist/v2/index.d.cts.map +0 -1
  50. package/dist/v2/index.d.mts.map +0 -1
  51. package/dist/wandelscriptUtils-CpUXdLVc.mjs +0 -2062
  52. package/dist/wandelscriptUtils-CpUXdLVc.mjs.map +0 -1
  53. package/dist/wandelscriptUtils-DY3WsiuB.d.cts +0 -356
  54. package/dist/wandelscriptUtils-DY3WsiuB.d.cts.map +0 -1
  55. package/dist/wandelscriptUtils-DcY1aLWu.cjs +0 -2099
  56. package/dist/wandelscriptUtils-DcY1aLWu.cjs.map +0 -1
  57. package/dist/wandelscriptUtils-YHTxn_p9.d.mts +0 -356
  58. package/dist/wandelscriptUtils-YHTxn_p9.d.mts.map +0 -1
  59. package/src/lib/deprecated/v1/ConnectedMotionGroup.ts +0 -449
  60. package/src/lib/deprecated/v1/JoggerConnection.ts +0 -491
  61. package/src/lib/deprecated/v1/MotionStreamConnection.ts +0 -215
  62. package/src/lib/deprecated/v1/NovaCellAPIClient.ts +0 -208
  63. package/src/lib/deprecated/v1/NovaClient.ts +0 -260
  64. package/src/lib/deprecated/v1/ProgramStateConnection.ts +0 -277
  65. package/src/lib/deprecated/v1/getLatestTrajectories.ts +0 -37
  66. package/src/lib/deprecated/v1/mock/MockNovaInstance.ts +0 -1303
  67. package/src/lib/deprecated/v1/motionStateUpdate.ts +0 -58
  68. package/src/lib/deprecated/v1/wandelscriptUtils.ts +0 -23
  69. package/src/lib/deprecated/v2/NovaCellAPIClient.ts +0 -215
  70. package/src/lib/deprecated/v2/NovaClient.ts +0 -218
  71. package/src/lib/deprecated/v2/wandelscriptUtils.ts +0 -28
  72. package/src/v1/index.ts +0 -14
@@ -1,449 +0,0 @@
1
- import type {
2
- ControllerInstance,
3
- MotionGroupPhysical,
4
- MotionGroupSpecification,
5
- MotionGroupStateResponse,
6
- Mounting,
7
- RobotControllerState,
8
- RobotControllerStateOperationModeEnum,
9
- RobotControllerStateSafetyStateEnum,
10
- RobotTcp,
11
- SafetySetup,
12
- } from "@wandelbots/nova-api/v1"
13
- import { makeAutoObservable, runInAction } from "mobx"
14
- import * as THREE from "three"
15
- import type { AutoReconnectingWebsocket } from "../../AutoReconnectingWebsocket.ts"
16
- import { tryParseJson } from "../../converters.ts"
17
- import { jointValuesEqual, tcpPoseEqual } from "./motionStateUpdate.ts"
18
- import type { NovaClient } from "./NovaClient.ts"
19
-
20
- const MOTION_DELTA_THRESHOLD = 0.0001
21
-
22
- /** @deprecated */
23
- export type MotionGroupOption = {
24
- selectionId: string
25
- } & MotionGroupPhysical
26
-
27
- /**
28
- * Store representing the current state of a connected motion group.
29
- * @deprecated
30
- */
31
- export class ConnectedMotionGroup {
32
- static async connect(
33
- nova: NovaClient,
34
- motionGroupId: string,
35
- controllers: ControllerInstance[],
36
- ) {
37
- const [_motionGroupIndex, controllerId] = motionGroupId.split("@") as [
38
- string,
39
- string,
40
- ]
41
- const controller = controllers.find((c) => c.controller === controllerId)
42
- const motionGroup = controller?.physical_motion_groups.find(
43
- (mg) => mg.motion_group === motionGroupId,
44
- )
45
- if (!controller || !motionGroup) {
46
- throw new Error(
47
- `Controller ${controllerId} or motion group ${motionGroupId} not found`,
48
- )
49
- }
50
-
51
- const motionStateSocket = nova.openReconnectingWebsocket(
52
- `/motion-groups/${motionGroupId}/state-stream`,
53
- )
54
-
55
- // Wait for the first message to get the initial state
56
- const firstMessage = await motionStateSocket.firstMessage()
57
- const initialMotionState = tryParseJson(firstMessage.data)
58
- ?.result as MotionGroupStateResponse
59
-
60
- if (!initialMotionState) {
61
- throw new Error(
62
- `Unable to parse initial motion state message ${firstMessage.data}`,
63
- )
64
- }
65
-
66
- console.log(
67
- `Connected motion state websocket to motion group ${motionGroup.motion_group}. Initial state:\n `,
68
- initialMotionState,
69
- )
70
-
71
- // Check if robot is virtual or physical
72
- const config = await nova.api.controller.getRobotController(
73
- controller.controller,
74
- )
75
- const isVirtual = config.configuration.kind === "VirtualController"
76
-
77
- // If there's a configured mounting, we need it to show the right
78
- // position of the robot model
79
- const mounting = await (async () => {
80
- try {
81
- const mounting = await nova.api.motionGroupInfos.getMounting(
82
- motionGroup.motion_group,
83
- )
84
- return mounting
85
- } catch (err) {
86
- console.error(
87
- `Error fetching mounting for ${motionGroup.motion_group}`,
88
- err,
89
- )
90
- return null
91
- }
92
- })()
93
-
94
- // Open the websocket to monitor controller state for e.g. e-stop
95
- const controllerStateSocket = nova.openReconnectingWebsocket(
96
- `/controllers/${controller.controller}/state-stream?response_rate=1000`,
97
- )
98
-
99
- // Wait for the first message to get the initial state
100
- const firstControllerMessage = await controllerStateSocket.firstMessage()
101
- const initialControllerState = tryParseJson(firstControllerMessage.data)
102
- ?.result as RobotControllerState
103
-
104
- if (!initialControllerState) {
105
- throw new Error(
106
- `Unable to parse initial controller state message ${firstControllerMessage.data}`,
107
- )
108
- }
109
-
110
- console.log(
111
- `Connected controller state websocket to controller ${controller.controller}. Initial state:\n `,
112
- initialControllerState,
113
- )
114
-
115
- // Find out what TCPs this motion group has (we need it for jogging)
116
- const { tcps } = await nova.api.motionGroupInfos.listTcps(motionGroupId)
117
-
118
- const motionGroupSpecification =
119
- await nova.api.motionGroupInfos.getMotionGroupSpecification(motionGroupId)
120
-
121
- const safetySetup =
122
- await nova.api.motionGroupInfos.getSafetySetup(motionGroupId)
123
-
124
- return new ConnectedMotionGroup(
125
- nova,
126
- controller,
127
- motionGroup,
128
- initialMotionState,
129
- motionStateSocket,
130
- isVirtual,
131
- // biome-ignore lint/style/noNonNullAssertion: legacy code
132
- tcps!,
133
- motionGroupSpecification,
134
- safetySetup,
135
- mounting,
136
- initialControllerState,
137
- controllerStateSocket,
138
- )
139
- }
140
-
141
- connectedJoggingCartesianSocket: WebSocket | null = null
142
- connectedJoggingJointsSocket: WebSocket | null = null
143
- // biome-ignore lint/suspicious/noExplicitAny: legacy code
144
- planData: any | null // tmp
145
- joggingVelocity: number = 10
146
-
147
- // Not mobx-observable as this changes very fast; should be observed
148
- // using animation frames
149
- rapidlyChangingMotionState: MotionGroupStateResponse
150
-
151
- // Response rate on the websocket should be a bit slower on this one since
152
- // we don't use the motion data
153
- controllerState: RobotControllerState
154
-
155
- /**
156
- * Reflects activation state of the motion group / robot servos. The
157
- * movement controls in the UI should only be enabled in the "active" state
158
- */
159
- activationState: "inactive" | "activating" | "deactivating" | "active" =
160
- "inactive"
161
-
162
- readonly nova: NovaClient
163
- readonly controller: ControllerInstance
164
- readonly motionGroup: MotionGroupPhysical
165
- readonly initialMotionState: MotionGroupStateResponse
166
- readonly motionStateSocket: AutoReconnectingWebsocket
167
- readonly isVirtual: boolean
168
- readonly tcps: RobotTcp[]
169
- readonly motionGroupSpecification: MotionGroupSpecification
170
- readonly safetySetup: SafetySetup
171
- readonly mounting: Mounting | null
172
- readonly initialControllerState: RobotControllerState
173
- readonly controllerStateSocket: AutoReconnectingWebsocket
174
-
175
- constructor(
176
- nova: NovaClient,
177
- controller: ControllerInstance,
178
- motionGroup: MotionGroupPhysical,
179
- initialMotionState: MotionGroupStateResponse,
180
- motionStateSocket: AutoReconnectingWebsocket,
181
- isVirtual: boolean,
182
- tcps: RobotTcp[],
183
- motionGroupSpecification: MotionGroupSpecification,
184
- safetySetup: SafetySetup,
185
- mounting: Mounting | null,
186
- initialControllerState: RobotControllerState,
187
- controllerStateSocket: AutoReconnectingWebsocket,
188
- ) {
189
- this.nova = nova
190
- this.controller = controller
191
- this.motionGroup = motionGroup
192
- this.initialMotionState = initialMotionState
193
- this.motionStateSocket = motionStateSocket
194
- this.isVirtual = isVirtual
195
- this.tcps = tcps
196
- this.motionGroupSpecification = motionGroupSpecification
197
- this.safetySetup = safetySetup
198
- this.mounting = mounting
199
- this.initialControllerState = initialControllerState
200
- this.controllerStateSocket = controllerStateSocket
201
-
202
- this.rapidlyChangingMotionState = initialMotionState
203
- this.controllerState = initialControllerState
204
-
205
- // Track controller state updates (e.g. safety state and operation mode)
206
- controllerStateSocket.addEventListener("message", (event) => {
207
- const data = tryParseJson(event.data)?.result
208
-
209
- if (!data) {
210
- return
211
- }
212
-
213
- runInAction(() => {
214
- this.controllerState = data
215
- })
216
- })
217
-
218
- motionStateSocket.addEventListener("message", (event) => {
219
- const motionStateResponse = tryParseJson(event.data)?.result as
220
- | MotionGroupStateResponse
221
- | undefined
222
-
223
- if (!motionStateResponse) {
224
- throw new Error(
225
- `Failed to get motion state for ${this.motionGroupId}: ${event.data}`,
226
- )
227
- }
228
-
229
- // handle motionState message
230
- if (
231
- !jointValuesEqual(
232
- this.rapidlyChangingMotionState.state.joint_position.joints,
233
- motionStateResponse.state.joint_position.joints,
234
- MOTION_DELTA_THRESHOLD,
235
- )
236
- ) {
237
- runInAction(() => {
238
- this.rapidlyChangingMotionState.state = motionStateResponse.state
239
- })
240
- }
241
-
242
- // handle tcpPose message
243
- if (
244
- !tcpPoseEqual(
245
- this.rapidlyChangingMotionState.tcp_pose,
246
- motionStateResponse.tcp_pose,
247
- MOTION_DELTA_THRESHOLD,
248
- )
249
- ) {
250
- runInAction(() => {
251
- this.rapidlyChangingMotionState.tcp_pose =
252
- motionStateResponse.tcp_pose
253
- })
254
- }
255
- })
256
- makeAutoObservable(this)
257
- }
258
-
259
- get motionGroupId() {
260
- return this.motionGroup.motion_group
261
- }
262
-
263
- get controllerId() {
264
- return this.controller.controller
265
- }
266
-
267
- get modelFromController() {
268
- return this.motionGroup.model_from_controller
269
- }
270
-
271
- get wandelscriptIdentifier() {
272
- const num = this.motionGroupId.split("@")[0]
273
- return `${this.controllerId.replaceAll("-", "_")}_${num}`
274
- }
275
-
276
- /** Jogging velocity in radians for rotation and joint movement */
277
- get joggingVelocityRads() {
278
- return (this.joggingVelocity * Math.PI) / 180
279
- }
280
-
281
- get joints() {
282
- return this.initialMotionState.state.joint_position.joints.map((_, i) => {
283
- return {
284
- index: i,
285
- }
286
- })
287
- }
288
-
289
- get dhParameters() {
290
- return this.motionGroupSpecification.dh_parameters
291
- }
292
-
293
- get safetyZones() {
294
- return this.safetySetup.safety_zones
295
- }
296
-
297
- /** Gets the robot mounting position offset in 3D viz coordinates */
298
- get mountingPosition(): [number, number, number] {
299
- if (!this.mounting) {
300
- return [0, 0, 0]
301
- }
302
-
303
- return [
304
- this.mounting.pose.position.x / 1000,
305
- this.mounting.pose.position.y / 1000,
306
- this.mounting.pose.position.z / 1000,
307
- ]
308
- }
309
-
310
- /** Gets the robot mounting position rotation in 3D viz coordinates */
311
- get mountingQuaternion() {
312
- const rotationVector = new THREE.Vector3(
313
- this.mounting?.pose.orientation?.x || 0,
314
- this.mounting?.pose.orientation?.y || 0,
315
- this.mounting?.pose.orientation?.z || 0,
316
- )
317
-
318
- const magnitude = rotationVector.length()
319
- const axis = rotationVector.normalize()
320
-
321
- return new THREE.Quaternion().setFromAxisAngle(axis, magnitude)
322
- }
323
-
324
- /**
325
- * Whether the controller is currently in a safety state
326
- * corresponding to an emergency stop
327
- */
328
- get isEstopActive() {
329
- const estopStates: RobotControllerStateSafetyStateEnum[] = [
330
- "SAFETY_STATE_ROBOT_EMERGENCY_STOP",
331
- "SAFETY_STATE_DEVICE_EMERGENCY_STOP",
332
- ]
333
-
334
- return estopStates.includes(this.controllerState.safety_state)
335
- }
336
-
337
- /**
338
- * Whether the controller is in a safety state
339
- * that may be non-functional for robot pad purposes
340
- */
341
- get isMoveableSafetyState() {
342
- const goodSafetyStates: RobotControllerStateSafetyStateEnum[] = [
343
- "SAFETY_STATE_NORMAL",
344
- "SAFETY_STATE_REDUCED",
345
- ]
346
-
347
- return goodSafetyStates.includes(this.controllerState.safety_state)
348
- }
349
-
350
- /**
351
- * Whether the controller is in an operation mode that allows movement
352
- */
353
- get isMoveableOperationMode() {
354
- const goodOperationModes: RobotControllerStateOperationModeEnum[] = [
355
- "OPERATION_MODE_AUTO",
356
- "OPERATION_MODE_MANUAL",
357
- "OPERATION_MODE_MANUAL_T1",
358
- "OPERATION_MODE_MANUAL_T2",
359
- ]
360
-
361
- return goodOperationModes.includes(this.controllerState.operation_mode)
362
- }
363
-
364
- /**
365
- * Whether the robot is currently active and can be moved, based on the
366
- * safety state, operation mode and servo toggle activation state.
367
- */
368
- get canBeMoved() {
369
- return (
370
- this.isMoveableSafetyState &&
371
- this.isMoveableOperationMode &&
372
- this.activationState === "active"
373
- )
374
- }
375
-
376
- async deactivate() {
377
- if (this.activationState !== "active") {
378
- console.error("Tried to deactivate while already deactivating")
379
- return
380
- }
381
-
382
- runInAction(() => {
383
- this.activationState = "deactivating"
384
- })
385
-
386
- try {
387
- await this.nova.api.controller.setDefaultMode(
388
- this.controllerId,
389
- "MODE_MONITOR",
390
- )
391
-
392
- runInAction(() => {
393
- this.activationState = "inactive"
394
- })
395
- } catch (err) {
396
- runInAction(() => {
397
- this.activationState = "active"
398
- })
399
- throw err
400
- }
401
- }
402
-
403
- async activate() {
404
- if (this.activationState !== "inactive") {
405
- console.error("Tried to activate while already activating")
406
- return
407
- }
408
-
409
- runInAction(() => {
410
- this.activationState = "activating"
411
- })
412
-
413
- try {
414
- await this.nova.api.controller.setDefaultMode(
415
- this.controllerId,
416
- "MODE_CONTROL",
417
- )
418
-
419
- runInAction(() => {
420
- this.activationState = "active"
421
- })
422
- } catch (err) {
423
- runInAction(() => {
424
- this.activationState = "inactive"
425
- })
426
- throw err
427
- }
428
- }
429
-
430
- toggleActivation() {
431
- if (this.activationState === "inactive") {
432
- this.activate()
433
- } else if (this.activationState === "active") {
434
- this.deactivate()
435
- }
436
- }
437
-
438
- dispose() {
439
- this.motionStateSocket.close()
440
- if (this.connectedJoggingCartesianSocket)
441
- this.connectedJoggingCartesianSocket.close()
442
- if (this.connectedJoggingJointsSocket)
443
- this.connectedJoggingJointsSocket.close()
444
- }
445
-
446
- setJoggingVelocity(velocity: number) {
447
- this.joggingVelocity = velocity
448
- }
449
- }