@wandelbots/nova-js 1.17.1-pr.feat-added-v2-client.64.9ac2247
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/README.md +202 -0
- package/dist/LoginWithAuth0.d.ts +7 -0
- package/dist/LoginWithAuth0.d.ts.map +1 -0
- package/dist/chunk-V3NJLR6P.js +336 -0
- package/dist/chunk-V3NJLR6P.js.map +1 -0
- package/dist/index.cjs +390 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +54 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/AutoReconnectingWebsocket.d.ts +43 -0
- package/dist/lib/AutoReconnectingWebsocket.d.ts.map +1 -0
- package/dist/lib/availableStorage.d.ts +15 -0
- package/dist/lib/availableStorage.d.ts.map +1 -0
- package/dist/lib/converters.d.ts +26 -0
- package/dist/lib/converters.d.ts.map +1 -0
- package/dist/lib/errorHandling.d.ts +4 -0
- package/dist/lib/errorHandling.d.ts.map +1 -0
- package/dist/lib/v1/ConnectedMotionGroup.d.ts +77 -0
- package/dist/lib/v1/ConnectedMotionGroup.d.ts.map +1 -0
- package/dist/lib/v1/JoggerConnection.d.ts +94 -0
- package/dist/lib/v1/JoggerConnection.d.ts.map +1 -0
- package/dist/lib/v1/MotionStreamConnection.d.ts +25 -0
- package/dist/lib/v1/MotionStreamConnection.d.ts.map +1 -0
- package/dist/lib/v1/NovaCellAPIClient.d.ts +66 -0
- package/dist/lib/v1/NovaCellAPIClient.d.ts.map +1 -0
- package/dist/lib/v1/NovaClient.d.ts +67 -0
- package/dist/lib/v1/NovaClient.d.ts.map +1 -0
- package/dist/lib/v1/ProgramStateConnection.d.ts +53 -0
- package/dist/lib/v1/ProgramStateConnection.d.ts.map +1 -0
- package/dist/lib/v1/getLatestTrajectories.d.ts +4 -0
- package/dist/lib/v1/getLatestTrajectories.d.ts.map +1 -0
- package/dist/lib/v1/index.cjs +3957 -0
- package/dist/lib/v1/index.cjs.map +1 -0
- package/dist/lib/v1/index.d.ts +9 -0
- package/dist/lib/v1/index.d.ts.map +1 -0
- package/dist/lib/v1/index.js +3662 -0
- package/dist/lib/v1/index.js.map +1 -0
- package/dist/lib/v1/mock/MockNovaInstance.d.ts +13 -0
- package/dist/lib/v1/mock/MockNovaInstance.d.ts.map +1 -0
- package/dist/lib/v1/motionStateUpdate.d.ts +4 -0
- package/dist/lib/v1/motionStateUpdate.d.ts.map +1 -0
- package/dist/lib/v2/ConnectedMotionGroup.d.ts +41 -0
- package/dist/lib/v2/ConnectedMotionGroup.d.ts.map +1 -0
- package/dist/lib/v2/JoggerConnection.d.ts +53 -0
- package/dist/lib/v2/JoggerConnection.d.ts.map +1 -0
- package/dist/lib/v2/MotionStreamConnection.d.ts +25 -0
- package/dist/lib/v2/MotionStreamConnection.d.ts.map +1 -0
- package/dist/lib/v2/NovaCellAPIClient.d.ts +64 -0
- package/dist/lib/v2/NovaCellAPIClient.d.ts.map +1 -0
- package/dist/lib/v2/NovaClient.d.ts +67 -0
- package/dist/lib/v2/NovaClient.d.ts.map +1 -0
- package/dist/lib/v2/ProgramStateConnection.d.ts +53 -0
- package/dist/lib/v2/ProgramStateConnection.d.ts.map +1 -0
- package/dist/lib/v2/index.cjs +2239 -0
- package/dist/lib/v2/index.cjs.map +1 -0
- package/dist/lib/v2/index.d.ts +8 -0
- package/dist/lib/v2/index.d.ts.map +1 -0
- package/dist/lib/v2/index.js +1947 -0
- package/dist/lib/v2/index.js.map +1 -0
- package/dist/lib/v2/mock/MockNovaInstance.d.ts +13 -0
- package/dist/lib/v2/mock/MockNovaInstance.d.ts.map +1 -0
- package/dist/lib/v2/motionStateUpdate.d.ts +4 -0
- package/dist/lib/v2/motionStateUpdate.d.ts.map +1 -0
- package/dist/lib/v2/vectorUtils.d.ts +7 -0
- package/dist/lib/v2/vectorUtils.d.ts.map +1 -0
- package/package.json +67 -0
- package/src/LoginWithAuth0.ts +90 -0
- package/src/index.ts +5 -0
- package/src/lib/AutoReconnectingWebsocket.ts +163 -0
- package/src/lib/availableStorage.ts +46 -0
- package/src/lib/converters.ts +74 -0
- package/src/lib/errorHandling.ts +26 -0
- package/src/lib/v1/ConnectedMotionGroup.ts +419 -0
- package/src/lib/v1/JoggerConnection.ts +480 -0
- package/src/lib/v1/MotionStreamConnection.ts +202 -0
- package/src/lib/v1/NovaCellAPIClient.ts +180 -0
- package/src/lib/v1/NovaClient.ts +232 -0
- package/src/lib/v1/ProgramStateConnection.ts +267 -0
- package/src/lib/v1/getLatestTrajectories.ts +36 -0
- package/src/lib/v1/index.ts +8 -0
- package/src/lib/v1/mock/MockNovaInstance.ts +1302 -0
- package/src/lib/v1/motionStateUpdate.ts +55 -0
- package/src/lib/v2/ConnectedMotionGroup.ts +216 -0
- package/src/lib/v2/JoggerConnection.ts +207 -0
- package/src/lib/v2/MotionStreamConnection.ts +201 -0
- package/src/lib/v2/NovaCellAPIClient.ts +174 -0
- package/src/lib/v2/NovaClient.ts +230 -0
- package/src/lib/v2/ProgramStateConnection.ts +255 -0
- package/src/lib/v2/index.ts +7 -0
- package/src/lib/v2/mock/MockNovaInstance.ts +982 -0
- package/src/lib/v2/motionStateUpdate.ts +55 -0
- package/src/lib/v2/vectorUtils.ts +36 -0
|
@@ -0,0 +1,1947 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AutoReconnectingWebsocket,
|
|
3
|
+
__async,
|
|
4
|
+
__spreadProps,
|
|
5
|
+
__spreadValues,
|
|
6
|
+
availableStorage,
|
|
7
|
+
loginWithAuth0,
|
|
8
|
+
tryParseJson
|
|
9
|
+
} from "../../chunk-V3NJLR6P.js";
|
|
10
|
+
|
|
11
|
+
// src/lib/v2/index.ts
|
|
12
|
+
export * from "@wandelbots/nova-api/v2";
|
|
13
|
+
|
|
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
|
+
// src/lib/v2/NovaCellAPIClient.ts
|
|
511
|
+
import {
|
|
512
|
+
ApplicationApi,
|
|
513
|
+
CellApi,
|
|
514
|
+
ControllerApi,
|
|
515
|
+
ControllerInputsOutputsApi,
|
|
516
|
+
CoordinateSystemsApi,
|
|
517
|
+
JoggingApi,
|
|
518
|
+
MotionGroupApi,
|
|
519
|
+
MotionGroupInfoApi,
|
|
520
|
+
MotionGroupKinematicsApi,
|
|
521
|
+
ProgramApi,
|
|
522
|
+
ProgramLibraryApi,
|
|
523
|
+
ProgramLibraryMetadataApi,
|
|
524
|
+
ProgramOperatorApi,
|
|
525
|
+
StoreCollisionComponentsApi,
|
|
526
|
+
StoreCollisionScenesApi,
|
|
527
|
+
StoreObjectApi,
|
|
528
|
+
SystemApi,
|
|
529
|
+
TrajectoryExecutionApi,
|
|
530
|
+
TrajectoryPlanningApi,
|
|
531
|
+
VirtualRobotApi,
|
|
532
|
+
VirtualRobotBehaviorApi,
|
|
533
|
+
VirtualRobotModeApi,
|
|
534
|
+
VirtualRobotSetupApi
|
|
535
|
+
} from "@wandelbots/nova-api/v2";
|
|
536
|
+
import axios from "axios";
|
|
537
|
+
var NovaCellAPIClient = class {
|
|
538
|
+
constructor(cellId, opts) {
|
|
539
|
+
this.cellId = cellId;
|
|
540
|
+
this.opts = opts;
|
|
541
|
+
this.system = this.withUnwrappedResponsesOnly(SystemApi);
|
|
542
|
+
this.cell = this.withUnwrappedResponsesOnly(CellApi);
|
|
543
|
+
this.motionGroup = this.withCellId(MotionGroupApi);
|
|
544
|
+
this.motionGroupInfos = this.withCellId(MotionGroupInfoApi);
|
|
545
|
+
this.controller = this.withCellId(ControllerApi);
|
|
546
|
+
this.program = this.withCellId(ProgramApi);
|
|
547
|
+
this.programOperator = this.withCellId(ProgramOperatorApi);
|
|
548
|
+
this.programLibraryMetadata = this.withCellId(ProgramLibraryMetadataApi);
|
|
549
|
+
this.programLibrary = this.withCellId(ProgramLibraryApi);
|
|
550
|
+
this.controllerIOs = this.withCellId(ControllerInputsOutputsApi);
|
|
551
|
+
this.motionGroupKinematic = this.withCellId(MotionGroupKinematicsApi);
|
|
552
|
+
this.trajectoryPlanning = this.withCellId(TrajectoryPlanningApi);
|
|
553
|
+
this.trajectoryExecution = this.withCellId(TrajectoryExecutionApi);
|
|
554
|
+
this.coordinateSystems = this.withCellId(CoordinateSystemsApi);
|
|
555
|
+
this.application = this.withCellId(ApplicationApi);
|
|
556
|
+
this.applicationGlobal = this.withUnwrappedResponsesOnly(ApplicationApi);
|
|
557
|
+
this.jogging = this.withCellId(JoggingApi);
|
|
558
|
+
this.virtualRobot = this.withCellId(VirtualRobotApi);
|
|
559
|
+
this.virtualRobotSetup = this.withCellId(VirtualRobotSetupApi);
|
|
560
|
+
this.virtualRobotMode = this.withCellId(VirtualRobotModeApi);
|
|
561
|
+
this.virtualRobotBehavior = this.withCellId(VirtualRobotBehaviorApi);
|
|
562
|
+
this.storeObject = this.withCellId(StoreObjectApi);
|
|
563
|
+
this.storeCollisionComponents = this.withCellId(
|
|
564
|
+
StoreCollisionComponentsApi
|
|
565
|
+
);
|
|
566
|
+
this.storeCollisionScenes = this.withCellId(StoreCollisionScenesApi);
|
|
567
|
+
}
|
|
568
|
+
/**
|
|
569
|
+
* Some TypeScript sorcery which alters the API class methods so you don't
|
|
570
|
+
* have to pass the cell id to every single one, and de-encapsulates the
|
|
571
|
+
* response data
|
|
572
|
+
*/
|
|
573
|
+
withCellId(ApiConstructor) {
|
|
574
|
+
var _a, _b;
|
|
575
|
+
const apiClient = new ApiConstructor(
|
|
576
|
+
__spreadProps(__spreadValues({}, this.opts), {
|
|
577
|
+
isJsonMime: (mime) => {
|
|
578
|
+
return mime === "application/json";
|
|
579
|
+
}
|
|
580
|
+
}),
|
|
581
|
+
(_a = this.opts.basePath) != null ? _a : "",
|
|
582
|
+
(_b = this.opts.axiosInstance) != null ? _b : axios.create()
|
|
583
|
+
);
|
|
584
|
+
for (const key of Reflect.ownKeys(Reflect.getPrototypeOf(apiClient))) {
|
|
585
|
+
if (key !== "constructor" && typeof apiClient[key] === "function") {
|
|
586
|
+
const originalFunction = apiClient[key];
|
|
587
|
+
apiClient[key] = (...args) => {
|
|
588
|
+
return originalFunction.apply(apiClient, [this.cellId, ...args]).then((res) => res.data);
|
|
589
|
+
};
|
|
590
|
+
}
|
|
591
|
+
}
|
|
592
|
+
return apiClient;
|
|
593
|
+
}
|
|
594
|
+
/**
|
|
595
|
+
* As withCellId, but only does the response unwrapping
|
|
596
|
+
*/
|
|
597
|
+
withUnwrappedResponsesOnly(ApiConstructor) {
|
|
598
|
+
var _a, _b;
|
|
599
|
+
const apiClient = new ApiConstructor(
|
|
600
|
+
__spreadProps(__spreadValues({}, this.opts), {
|
|
601
|
+
isJsonMime: (mime) => {
|
|
602
|
+
return mime === "application/json";
|
|
603
|
+
}
|
|
604
|
+
}),
|
|
605
|
+
(_a = this.opts.basePath) != null ? _a : "",
|
|
606
|
+
(_b = this.opts.axiosInstance) != null ? _b : axios.create()
|
|
607
|
+
);
|
|
608
|
+
for (const key of Reflect.ownKeys(Reflect.getPrototypeOf(apiClient))) {
|
|
609
|
+
if (key !== "constructor" && typeof apiClient[key] === "function") {
|
|
610
|
+
const originalFunction = apiClient[key];
|
|
611
|
+
apiClient[key] = (...args) => {
|
|
612
|
+
return originalFunction.apply(apiClient, args).then((res) => res.data);
|
|
613
|
+
};
|
|
614
|
+
}
|
|
615
|
+
}
|
|
616
|
+
return apiClient;
|
|
617
|
+
}
|
|
618
|
+
};
|
|
619
|
+
|
|
620
|
+
// src/lib/v2/NovaClient.ts
|
|
621
|
+
import axios2, { isAxiosError } from "axios";
|
|
622
|
+
import urlJoin from "url-join";
|
|
623
|
+
|
|
624
|
+
// src/lib/v2/mock/MockNovaInstance.ts
|
|
625
|
+
import { AxiosError as AxiosError2 } from "axios";
|
|
626
|
+
import * as pathToRegexp from "path-to-regexp";
|
|
627
|
+
var MockNovaInstance = class {
|
|
628
|
+
constructor() {
|
|
629
|
+
this.connections = [];
|
|
630
|
+
}
|
|
631
|
+
handleAPIRequest(config) {
|
|
632
|
+
return __async(this, null, function* () {
|
|
633
|
+
var _a, _b, _c;
|
|
634
|
+
const apiHandlers = [
|
|
635
|
+
{
|
|
636
|
+
method: "GET",
|
|
637
|
+
path: "/cells/:cellId/controllers",
|
|
638
|
+
handle() {
|
|
639
|
+
return {
|
|
640
|
+
controllers: [
|
|
641
|
+
{
|
|
642
|
+
controller: "mock-ur5e",
|
|
643
|
+
model_name: "UniversalRobots::Controller",
|
|
644
|
+
host: "mock-ur5e",
|
|
645
|
+
allow_software_install_on_controller: true,
|
|
646
|
+
motion_groups: [
|
|
647
|
+
{
|
|
648
|
+
motion_group: "0@mock-ur5e",
|
|
649
|
+
name_from_controller: "UR5e",
|
|
650
|
+
active: false,
|
|
651
|
+
model_from_controller: "UniversalRobots_UR5e"
|
|
652
|
+
}
|
|
653
|
+
],
|
|
654
|
+
has_error: false,
|
|
655
|
+
error_details: ""
|
|
656
|
+
}
|
|
657
|
+
]
|
|
658
|
+
};
|
|
659
|
+
}
|
|
660
|
+
},
|
|
661
|
+
{
|
|
662
|
+
method: "GET",
|
|
663
|
+
path: "/cells/:cellId/controllers/:controllerId",
|
|
664
|
+
handle() {
|
|
665
|
+
return {
|
|
666
|
+
configuration: {
|
|
667
|
+
kind: "VirtualController",
|
|
668
|
+
manufacturer: "universalrobots",
|
|
669
|
+
position: "[0,-1.571,-1.571,-1.571,1.571,-1.571,0]",
|
|
670
|
+
type: "universalrobots-ur5e"
|
|
671
|
+
},
|
|
672
|
+
name: "mock-ur5"
|
|
673
|
+
};
|
|
674
|
+
}
|
|
675
|
+
},
|
|
676
|
+
{
|
|
677
|
+
method: "GET",
|
|
678
|
+
path: "/cells/:cellId/motion-groups/:motionGroupId/specification",
|
|
679
|
+
handle() {
|
|
680
|
+
return {
|
|
681
|
+
dh_parameters: [
|
|
682
|
+
{
|
|
683
|
+
alpha: 1.5707963267948966,
|
|
684
|
+
theta: 0,
|
|
685
|
+
a: 0,
|
|
686
|
+
d: 162.25,
|
|
687
|
+
reverse_rotation_direction: false
|
|
688
|
+
},
|
|
689
|
+
{
|
|
690
|
+
alpha: 0,
|
|
691
|
+
theta: 0,
|
|
692
|
+
a: -425,
|
|
693
|
+
d: 0,
|
|
694
|
+
reverse_rotation_direction: false
|
|
695
|
+
},
|
|
696
|
+
{
|
|
697
|
+
alpha: 0,
|
|
698
|
+
theta: 0,
|
|
699
|
+
a: -392.2,
|
|
700
|
+
d: 0,
|
|
701
|
+
reverse_rotation_direction: false
|
|
702
|
+
},
|
|
703
|
+
{
|
|
704
|
+
alpha: 1.5707963267948966,
|
|
705
|
+
theta: 0,
|
|
706
|
+
a: 0,
|
|
707
|
+
d: 133.3,
|
|
708
|
+
reverse_rotation_direction: false
|
|
709
|
+
},
|
|
710
|
+
{
|
|
711
|
+
alpha: -1.5707963267948966,
|
|
712
|
+
theta: 0,
|
|
713
|
+
a: 0,
|
|
714
|
+
d: 99.7,
|
|
715
|
+
reverse_rotation_direction: false
|
|
716
|
+
},
|
|
717
|
+
{
|
|
718
|
+
alpha: 0,
|
|
719
|
+
theta: 0,
|
|
720
|
+
a: 0,
|
|
721
|
+
d: 99.6,
|
|
722
|
+
reverse_rotation_direction: false
|
|
723
|
+
}
|
|
724
|
+
],
|
|
725
|
+
mechanical_joint_limits: [
|
|
726
|
+
{
|
|
727
|
+
joint: "JOINTNAME_AXIS_1",
|
|
728
|
+
lower_limit: -6.335545063018799,
|
|
729
|
+
upper_limit: 6.335545063018799,
|
|
730
|
+
unlimited: false
|
|
731
|
+
},
|
|
732
|
+
{
|
|
733
|
+
joint: "JOINTNAME_AXIS_2",
|
|
734
|
+
lower_limit: -6.335545063018799,
|
|
735
|
+
upper_limit: 6.335545063018799,
|
|
736
|
+
unlimited: false
|
|
737
|
+
},
|
|
738
|
+
{
|
|
739
|
+
joint: "JOINTNAME_AXIS_3",
|
|
740
|
+
lower_limit: -6.335545063018799,
|
|
741
|
+
upper_limit: 6.335545063018799,
|
|
742
|
+
unlimited: false
|
|
743
|
+
},
|
|
744
|
+
{
|
|
745
|
+
joint: "JOINTNAME_AXIS_4",
|
|
746
|
+
lower_limit: -6.335545063018799,
|
|
747
|
+
upper_limit: 6.335545063018799,
|
|
748
|
+
unlimited: false
|
|
749
|
+
},
|
|
750
|
+
{
|
|
751
|
+
joint: "JOINTNAME_AXIS_5",
|
|
752
|
+
lower_limit: -6.335545063018799,
|
|
753
|
+
upper_limit: 6.335545063018799,
|
|
754
|
+
unlimited: false
|
|
755
|
+
},
|
|
756
|
+
{
|
|
757
|
+
joint: "JOINTNAME_AXIS_6",
|
|
758
|
+
lower_limit: -6.335545063018799,
|
|
759
|
+
upper_limit: 6.335545063018799,
|
|
760
|
+
unlimited: false
|
|
761
|
+
}
|
|
762
|
+
]
|
|
763
|
+
};
|
|
764
|
+
}
|
|
765
|
+
},
|
|
766
|
+
{
|
|
767
|
+
method: "GET",
|
|
768
|
+
path: "/cells/:cellId/motion-groups/:motionGroupId/safety-setup",
|
|
769
|
+
handle() {
|
|
770
|
+
return {
|
|
771
|
+
safety_settings: [
|
|
772
|
+
{
|
|
773
|
+
safety_state: "SAFETY_NORMAL",
|
|
774
|
+
settings: {
|
|
775
|
+
joint_position_limits: [
|
|
776
|
+
{
|
|
777
|
+
joint: "JOINTNAME_AXIS_1",
|
|
778
|
+
lower_limit: -2.96705961227417,
|
|
779
|
+
upper_limit: 2.96705961227417,
|
|
780
|
+
unlimited: false
|
|
781
|
+
},
|
|
782
|
+
{
|
|
783
|
+
joint: "JOINTNAME_AXIS_2",
|
|
784
|
+
lower_limit: -1.7453292608261108,
|
|
785
|
+
upper_limit: 2.7925267219543457,
|
|
786
|
+
unlimited: false
|
|
787
|
+
},
|
|
788
|
+
{
|
|
789
|
+
joint: "JOINTNAME_AXIS_3",
|
|
790
|
+
lower_limit: -3.3161256313323975,
|
|
791
|
+
upper_limit: 0.40142571926116943,
|
|
792
|
+
unlimited: false
|
|
793
|
+
},
|
|
794
|
+
{
|
|
795
|
+
joint: "JOINTNAME_AXIS_4",
|
|
796
|
+
lower_limit: -3.4906585216522217,
|
|
797
|
+
upper_limit: 3.4906585216522217,
|
|
798
|
+
unlimited: false
|
|
799
|
+
},
|
|
800
|
+
{
|
|
801
|
+
joint: "JOINTNAME_AXIS_5",
|
|
802
|
+
lower_limit: -2.4434609413146973,
|
|
803
|
+
upper_limit: 2.4434609413146973,
|
|
804
|
+
unlimited: false
|
|
805
|
+
},
|
|
806
|
+
{
|
|
807
|
+
joint: "JOINTNAME_AXIS_6",
|
|
808
|
+
lower_limit: -4.71238899230957,
|
|
809
|
+
upper_limit: 4.71238899230957,
|
|
810
|
+
unlimited: false
|
|
811
|
+
}
|
|
812
|
+
],
|
|
813
|
+
joint_velocity_limits: [
|
|
814
|
+
{
|
|
815
|
+
joint: "JOINTNAME_AXIS_1",
|
|
816
|
+
limit: 3.1415927410125732
|
|
817
|
+
},
|
|
818
|
+
{
|
|
819
|
+
joint: "JOINTNAME_AXIS_2",
|
|
820
|
+
limit: 3.1415927410125732
|
|
821
|
+
},
|
|
822
|
+
{
|
|
823
|
+
joint: "JOINTNAME_AXIS_3",
|
|
824
|
+
limit: 3.4906585216522217
|
|
825
|
+
},
|
|
826
|
+
{
|
|
827
|
+
joint: "JOINTNAME_AXIS_4",
|
|
828
|
+
limit: 6.108652591705322
|
|
829
|
+
},
|
|
830
|
+
{
|
|
831
|
+
joint: "JOINTNAME_AXIS_5",
|
|
832
|
+
limit: 6.108652591705322
|
|
833
|
+
},
|
|
834
|
+
{
|
|
835
|
+
joint: "JOINTNAME_AXIS_6",
|
|
836
|
+
limit: 6.981317043304443
|
|
837
|
+
}
|
|
838
|
+
],
|
|
839
|
+
joint_acceleration_limits: [],
|
|
840
|
+
joint_torque_limits: [],
|
|
841
|
+
tcp_velocity_limit: 1800
|
|
842
|
+
}
|
|
843
|
+
}
|
|
844
|
+
],
|
|
845
|
+
safety_zones: [
|
|
846
|
+
{
|
|
847
|
+
id: 1,
|
|
848
|
+
priority: 0,
|
|
849
|
+
geometry: {
|
|
850
|
+
compound: {
|
|
851
|
+
child_geometries: [
|
|
852
|
+
{
|
|
853
|
+
convex_hull: {
|
|
854
|
+
vertices: [
|
|
855
|
+
{ vertex: [-800, -1330, -1820] },
|
|
856
|
+
{ vertex: [1650, -1330, -1820] },
|
|
857
|
+
{ vertex: [1650, 1330, -1820] },
|
|
858
|
+
{ vertex: [-800, 1330, -1820] }
|
|
859
|
+
]
|
|
860
|
+
},
|
|
861
|
+
init_pose: {
|
|
862
|
+
position: [0, 0, 0],
|
|
863
|
+
orientation: [0, 0, 0, 1]
|
|
864
|
+
},
|
|
865
|
+
id: "box"
|
|
866
|
+
},
|
|
867
|
+
{
|
|
868
|
+
convex_hull: {
|
|
869
|
+
vertices: [
|
|
870
|
+
{
|
|
871
|
+
vertex: [-800, -1330, -1820]
|
|
872
|
+
},
|
|
873
|
+
{
|
|
874
|
+
vertex: [1650, -1330, -1820]
|
|
875
|
+
},
|
|
876
|
+
{
|
|
877
|
+
vertex: [1650, -1330, 1500]
|
|
878
|
+
},
|
|
879
|
+
{
|
|
880
|
+
vertex: [-800, -1330, 1500]
|
|
881
|
+
}
|
|
882
|
+
]
|
|
883
|
+
},
|
|
884
|
+
init_pose: {
|
|
885
|
+
position: [0, 0, 0],
|
|
886
|
+
orientation: [0, 0, 0, 1]
|
|
887
|
+
},
|
|
888
|
+
id: "box"
|
|
889
|
+
},
|
|
890
|
+
{
|
|
891
|
+
convex_hull: {
|
|
892
|
+
vertices: [
|
|
893
|
+
{
|
|
894
|
+
vertex: [-800, -1330, -1820]
|
|
895
|
+
},
|
|
896
|
+
{
|
|
897
|
+
vertex: [-800, 1330, -1820]
|
|
898
|
+
},
|
|
899
|
+
{
|
|
900
|
+
vertex: [-800, 1330, 1500]
|
|
901
|
+
},
|
|
902
|
+
{
|
|
903
|
+
vertex: [-800, -1330, 1500]
|
|
904
|
+
}
|
|
905
|
+
]
|
|
906
|
+
},
|
|
907
|
+
init_pose: {
|
|
908
|
+
position: [0, 0, 0],
|
|
909
|
+
orientation: [0, 0, 0, 1]
|
|
910
|
+
},
|
|
911
|
+
id: "box"
|
|
912
|
+
},
|
|
913
|
+
{
|
|
914
|
+
convex_hull: {
|
|
915
|
+
vertices: [
|
|
916
|
+
{
|
|
917
|
+
vertex: [1650, 1330, 1500]
|
|
918
|
+
},
|
|
919
|
+
{
|
|
920
|
+
vertex: [-800, 1330, 1500]
|
|
921
|
+
},
|
|
922
|
+
{
|
|
923
|
+
vertex: [-800, -1330, 1500]
|
|
924
|
+
},
|
|
925
|
+
{
|
|
926
|
+
vertex: [1650, -1330, 1500]
|
|
927
|
+
}
|
|
928
|
+
]
|
|
929
|
+
},
|
|
930
|
+
init_pose: {
|
|
931
|
+
position: [0, 0, 0],
|
|
932
|
+
orientation: [0, 0, 0, 1]
|
|
933
|
+
},
|
|
934
|
+
id: "box"
|
|
935
|
+
},
|
|
936
|
+
{
|
|
937
|
+
convex_hull: {
|
|
938
|
+
vertices: [
|
|
939
|
+
{
|
|
940
|
+
vertex: [1650, 1330, 1500]
|
|
941
|
+
},
|
|
942
|
+
{
|
|
943
|
+
vertex: [-800, 1330, 1500]
|
|
944
|
+
},
|
|
945
|
+
{
|
|
946
|
+
vertex: [-800, 1330, -1820]
|
|
947
|
+
},
|
|
948
|
+
{
|
|
949
|
+
vertex: [1650, 1330, -1820]
|
|
950
|
+
}
|
|
951
|
+
]
|
|
952
|
+
},
|
|
953
|
+
init_pose: {
|
|
954
|
+
position: [0, 0, 0],
|
|
955
|
+
orientation: [0, 0, 0, 1]
|
|
956
|
+
},
|
|
957
|
+
id: "box"
|
|
958
|
+
},
|
|
959
|
+
{
|
|
960
|
+
convex_hull: {
|
|
961
|
+
vertices: [
|
|
962
|
+
{
|
|
963
|
+
vertex: [1650, 1330, 1500]
|
|
964
|
+
},
|
|
965
|
+
{
|
|
966
|
+
vertex: [1650, -1330, 1500]
|
|
967
|
+
},
|
|
968
|
+
{
|
|
969
|
+
vertex: [1650, -1330, -1820]
|
|
970
|
+
},
|
|
971
|
+
{
|
|
972
|
+
vertex: [1650, 1330, -1820]
|
|
973
|
+
}
|
|
974
|
+
]
|
|
975
|
+
},
|
|
976
|
+
init_pose: {
|
|
977
|
+
position: [0, 0, 0],
|
|
978
|
+
orientation: [0, 0, 0, 1]
|
|
979
|
+
},
|
|
980
|
+
id: "box"
|
|
981
|
+
}
|
|
982
|
+
]
|
|
983
|
+
},
|
|
984
|
+
init_pose: {
|
|
985
|
+
position: [0, 0, 0],
|
|
986
|
+
orientation: [0, 0, 0, 1]
|
|
987
|
+
},
|
|
988
|
+
id: "Cell workzone"
|
|
989
|
+
},
|
|
990
|
+
motion_group_uid: 1
|
|
991
|
+
},
|
|
992
|
+
{
|
|
993
|
+
id: 2,
|
|
994
|
+
priority: 0,
|
|
995
|
+
geometry: {
|
|
996
|
+
convex_hull: {
|
|
997
|
+
vertices: [
|
|
998
|
+
{
|
|
999
|
+
vertex: [1650, 1330, -1850]
|
|
1000
|
+
},
|
|
1001
|
+
{
|
|
1002
|
+
vertex: [865, 1330, -1850]
|
|
1003
|
+
},
|
|
1004
|
+
{
|
|
1005
|
+
vertex: [865, -720, -1850]
|
|
1006
|
+
},
|
|
1007
|
+
{
|
|
1008
|
+
vertex: [1650, -720, -1850]
|
|
1009
|
+
},
|
|
1010
|
+
{
|
|
1011
|
+
vertex: [1650, 1330, -920]
|
|
1012
|
+
},
|
|
1013
|
+
{
|
|
1014
|
+
vertex: [865, 1330, -920]
|
|
1015
|
+
},
|
|
1016
|
+
{
|
|
1017
|
+
vertex: [865, -720, -920]
|
|
1018
|
+
},
|
|
1019
|
+
{
|
|
1020
|
+
vertex: [1650, -720, -920]
|
|
1021
|
+
}
|
|
1022
|
+
]
|
|
1023
|
+
},
|
|
1024
|
+
init_pose: {
|
|
1025
|
+
position: [0, 0, 0],
|
|
1026
|
+
orientation: [0, 0, 0, 1]
|
|
1027
|
+
},
|
|
1028
|
+
id: "Transport"
|
|
1029
|
+
},
|
|
1030
|
+
motion_group_uid: 1
|
|
1031
|
+
},
|
|
1032
|
+
{
|
|
1033
|
+
id: 3,
|
|
1034
|
+
priority: 0,
|
|
1035
|
+
geometry: {
|
|
1036
|
+
convex_hull: {
|
|
1037
|
+
vertices: [
|
|
1038
|
+
{
|
|
1039
|
+
vertex: [1650, 1330, -600]
|
|
1040
|
+
},
|
|
1041
|
+
{
|
|
1042
|
+
vertex: [865, 1330, -600]
|
|
1043
|
+
},
|
|
1044
|
+
{
|
|
1045
|
+
vertex: [865, 430, -600]
|
|
1046
|
+
},
|
|
1047
|
+
{
|
|
1048
|
+
vertex: [1650, 430, -600]
|
|
1049
|
+
},
|
|
1050
|
+
{
|
|
1051
|
+
vertex: [1650, 1330, -1250]
|
|
1052
|
+
},
|
|
1053
|
+
{
|
|
1054
|
+
vertex: [865, 1330, -1250]
|
|
1055
|
+
},
|
|
1056
|
+
{
|
|
1057
|
+
vertex: [865, 430, -1250]
|
|
1058
|
+
},
|
|
1059
|
+
{
|
|
1060
|
+
vertex: [1650, 430, -1250]
|
|
1061
|
+
}
|
|
1062
|
+
]
|
|
1063
|
+
},
|
|
1064
|
+
init_pose: {
|
|
1065
|
+
position: [0, 0, 0],
|
|
1066
|
+
orientation: [0, 0, 0, 1]
|
|
1067
|
+
},
|
|
1068
|
+
id: "Tunel"
|
|
1069
|
+
},
|
|
1070
|
+
motion_group_uid: 1
|
|
1071
|
+
},
|
|
1072
|
+
{
|
|
1073
|
+
id: 4,
|
|
1074
|
+
priority: 0,
|
|
1075
|
+
geometry: {
|
|
1076
|
+
convex_hull: {
|
|
1077
|
+
vertices: [
|
|
1078
|
+
{
|
|
1079
|
+
vertex: [1650, -760, -440]
|
|
1080
|
+
},
|
|
1081
|
+
{
|
|
1082
|
+
vertex: [900, -760, -440]
|
|
1083
|
+
},
|
|
1084
|
+
{
|
|
1085
|
+
vertex: [900, -1330, -440]
|
|
1086
|
+
},
|
|
1087
|
+
{
|
|
1088
|
+
vertex: [1650, -1330, -440]
|
|
1089
|
+
},
|
|
1090
|
+
{
|
|
1091
|
+
vertex: [1650, -760, -1800]
|
|
1092
|
+
},
|
|
1093
|
+
{
|
|
1094
|
+
vertex: [900, -760, -1800]
|
|
1095
|
+
},
|
|
1096
|
+
{
|
|
1097
|
+
vertex: [900, -1330, -1800]
|
|
1098
|
+
},
|
|
1099
|
+
{
|
|
1100
|
+
vertex: [1650, -1330, -1800]
|
|
1101
|
+
}
|
|
1102
|
+
]
|
|
1103
|
+
},
|
|
1104
|
+
init_pose: {
|
|
1105
|
+
position: [0, 0, 0],
|
|
1106
|
+
orientation: [0, 0, 0, 1]
|
|
1107
|
+
},
|
|
1108
|
+
id: "Fanuc controller"
|
|
1109
|
+
},
|
|
1110
|
+
motion_group_uid: 1
|
|
1111
|
+
},
|
|
1112
|
+
{
|
|
1113
|
+
id: 6,
|
|
1114
|
+
priority: 0,
|
|
1115
|
+
geometry: {
|
|
1116
|
+
convex_hull: {
|
|
1117
|
+
vertices: [
|
|
1118
|
+
{
|
|
1119
|
+
vertex: [-200, -200, -1900]
|
|
1120
|
+
},
|
|
1121
|
+
{
|
|
1122
|
+
vertex: [200, -200, -1900]
|
|
1123
|
+
},
|
|
1124
|
+
{
|
|
1125
|
+
vertex: [200, 200, -1900]
|
|
1126
|
+
},
|
|
1127
|
+
{
|
|
1128
|
+
vertex: [-200, 200, -1900]
|
|
1129
|
+
},
|
|
1130
|
+
{
|
|
1131
|
+
vertex: [-200, -200, -350]
|
|
1132
|
+
},
|
|
1133
|
+
{
|
|
1134
|
+
vertex: [200, -200, -350]
|
|
1135
|
+
},
|
|
1136
|
+
{
|
|
1137
|
+
vertex: [200, 200, -350]
|
|
1138
|
+
},
|
|
1139
|
+
{
|
|
1140
|
+
vertex: [-200, 200, -350]
|
|
1141
|
+
}
|
|
1142
|
+
]
|
|
1143
|
+
},
|
|
1144
|
+
init_pose: {
|
|
1145
|
+
position: [0, 0, 0],
|
|
1146
|
+
orientation: [0, 0, 0, 1]
|
|
1147
|
+
},
|
|
1148
|
+
id: "Robot base"
|
|
1149
|
+
},
|
|
1150
|
+
motion_group_uid: 1
|
|
1151
|
+
}
|
|
1152
|
+
],
|
|
1153
|
+
robot_model_geometries: [
|
|
1154
|
+
{
|
|
1155
|
+
link_index: 1,
|
|
1156
|
+
geometry: {
|
|
1157
|
+
sphere: {
|
|
1158
|
+
radius: 270
|
|
1159
|
+
},
|
|
1160
|
+
init_pose: {
|
|
1161
|
+
position: [-70, -70, -50],
|
|
1162
|
+
orientation: [0, 0, 0, 1]
|
|
1163
|
+
},
|
|
1164
|
+
id: "link1_sphere"
|
|
1165
|
+
}
|
|
1166
|
+
},
|
|
1167
|
+
{
|
|
1168
|
+
link_index: 2,
|
|
1169
|
+
geometry: {
|
|
1170
|
+
capsule: {
|
|
1171
|
+
radius: 160,
|
|
1172
|
+
cylinder_height: 800
|
|
1173
|
+
},
|
|
1174
|
+
init_pose: {
|
|
1175
|
+
position: [-450, 40, 170],
|
|
1176
|
+
orientation: [
|
|
1177
|
+
0,
|
|
1178
|
+
-0.7071067811865475,
|
|
1179
|
+
0,
|
|
1180
|
+
0.7071067811865476
|
|
1181
|
+
]
|
|
1182
|
+
},
|
|
1183
|
+
id: "link2_capsule"
|
|
1184
|
+
}
|
|
1185
|
+
},
|
|
1186
|
+
{
|
|
1187
|
+
link_index: 3,
|
|
1188
|
+
geometry: {
|
|
1189
|
+
sphere: {
|
|
1190
|
+
radius: 270
|
|
1191
|
+
},
|
|
1192
|
+
init_pose: {
|
|
1193
|
+
position: [-110, 10, -100],
|
|
1194
|
+
orientation: [0, 0, 0, 1]
|
|
1195
|
+
},
|
|
1196
|
+
id: "link3_sphere"
|
|
1197
|
+
}
|
|
1198
|
+
},
|
|
1199
|
+
{
|
|
1200
|
+
link_index: 4,
|
|
1201
|
+
geometry: {
|
|
1202
|
+
capsule: {
|
|
1203
|
+
radius: 110,
|
|
1204
|
+
cylinder_height: 600
|
|
1205
|
+
},
|
|
1206
|
+
init_pose: {
|
|
1207
|
+
position: [0, 300, 40],
|
|
1208
|
+
orientation: [
|
|
1209
|
+
-0.7071067811865475,
|
|
1210
|
+
0,
|
|
1211
|
+
0,
|
|
1212
|
+
0.7071067811865476
|
|
1213
|
+
]
|
|
1214
|
+
},
|
|
1215
|
+
id: "link4_capsule"
|
|
1216
|
+
}
|
|
1217
|
+
},
|
|
1218
|
+
{
|
|
1219
|
+
link_index: 5,
|
|
1220
|
+
geometry: {
|
|
1221
|
+
sphere: {
|
|
1222
|
+
radius: 75
|
|
1223
|
+
},
|
|
1224
|
+
init_pose: {
|
|
1225
|
+
position: [0, 0, -50],
|
|
1226
|
+
orientation: [0, 0, 0, 1]
|
|
1227
|
+
},
|
|
1228
|
+
id: "link5_sphere"
|
|
1229
|
+
}
|
|
1230
|
+
}
|
|
1231
|
+
],
|
|
1232
|
+
tool_geometries: []
|
|
1233
|
+
};
|
|
1234
|
+
}
|
|
1235
|
+
},
|
|
1236
|
+
{
|
|
1237
|
+
method: "GET",
|
|
1238
|
+
path: "/cells/:cellId/coordinate-systems",
|
|
1239
|
+
handle() {
|
|
1240
|
+
return {
|
|
1241
|
+
coordinatesystems: [
|
|
1242
|
+
{
|
|
1243
|
+
coordinate_system: "",
|
|
1244
|
+
name: "world",
|
|
1245
|
+
reference_uid: "",
|
|
1246
|
+
position: [0, 0, 0],
|
|
1247
|
+
rotation: {
|
|
1248
|
+
angles: [0, 0, 0],
|
|
1249
|
+
type: "ROTATION_VECTOR"
|
|
1250
|
+
}
|
|
1251
|
+
}
|
|
1252
|
+
]
|
|
1253
|
+
};
|
|
1254
|
+
}
|
|
1255
|
+
},
|
|
1256
|
+
{
|
|
1257
|
+
method: "GET",
|
|
1258
|
+
path: "/cells/:cellId/motion-groups/:motionGroupId/tcps",
|
|
1259
|
+
handle() {
|
|
1260
|
+
return {
|
|
1261
|
+
tcps: [
|
|
1262
|
+
{
|
|
1263
|
+
id: "Flange",
|
|
1264
|
+
readable_name: "Default-Flange",
|
|
1265
|
+
position: [0, 0, 0],
|
|
1266
|
+
rotation: {
|
|
1267
|
+
angles: [0, 0, 0, 0],
|
|
1268
|
+
type: "ROTATION_VECTOR"
|
|
1269
|
+
}
|
|
1270
|
+
},
|
|
1271
|
+
{
|
|
1272
|
+
id: "complex-tcp-position",
|
|
1273
|
+
readable_name: "Complex TCP Position",
|
|
1274
|
+
position: [-200, 300, 150],
|
|
1275
|
+
rotation: {
|
|
1276
|
+
angles: [
|
|
1277
|
+
-0.12139440409113832,
|
|
1278
|
+
-0.06356210998212003,
|
|
1279
|
+
-0.2023240068185639,
|
|
1280
|
+
0
|
|
1281
|
+
],
|
|
1282
|
+
type: "ROTATION_VECTOR"
|
|
1283
|
+
}
|
|
1284
|
+
}
|
|
1285
|
+
]
|
|
1286
|
+
};
|
|
1287
|
+
}
|
|
1288
|
+
}
|
|
1289
|
+
];
|
|
1290
|
+
const method = ((_a = config.method) == null ? void 0 : _a.toUpperCase()) || "GET";
|
|
1291
|
+
const path = "/cells" + ((_c = (_b = config.url) == null ? void 0 : _b.split("/cells")[1]) == null ? void 0 : _c.split("?")[0]);
|
|
1292
|
+
for (const handler of apiHandlers) {
|
|
1293
|
+
const match2 = pathToRegexp.match(handler.path)(path || "");
|
|
1294
|
+
if (method === handler.method && match2) {
|
|
1295
|
+
const json = handler.handle();
|
|
1296
|
+
return {
|
|
1297
|
+
status: 200,
|
|
1298
|
+
statusText: "Success",
|
|
1299
|
+
data: JSON.stringify(json),
|
|
1300
|
+
headers: {},
|
|
1301
|
+
config,
|
|
1302
|
+
request: {
|
|
1303
|
+
responseURL: config.url
|
|
1304
|
+
}
|
|
1305
|
+
};
|
|
1306
|
+
}
|
|
1307
|
+
}
|
|
1308
|
+
throw new AxiosError2(
|
|
1309
|
+
`No mock handler matched this request: ${method} ${path}`,
|
|
1310
|
+
"404",
|
|
1311
|
+
config
|
|
1312
|
+
);
|
|
1313
|
+
});
|
|
1314
|
+
}
|
|
1315
|
+
handleWebsocketConnection(socket) {
|
|
1316
|
+
this.connections.push(socket);
|
|
1317
|
+
setTimeout(() => {
|
|
1318
|
+
socket.dispatchEvent(new Event("open"));
|
|
1319
|
+
console.log("Websocket connection opened from", socket.url);
|
|
1320
|
+
if (socket.url.includes("/state-stream")) {
|
|
1321
|
+
socket.dispatchEvent(
|
|
1322
|
+
new MessageEvent("message", {
|
|
1323
|
+
data: JSON.stringify(defaultMotionState)
|
|
1324
|
+
})
|
|
1325
|
+
);
|
|
1326
|
+
}
|
|
1327
|
+
if (socket.url.includes("/move-joint")) {
|
|
1328
|
+
socket.dispatchEvent(
|
|
1329
|
+
new MessageEvent("message", {
|
|
1330
|
+
data: JSON.stringify({
|
|
1331
|
+
result: {
|
|
1332
|
+
motion_group: "0@ur",
|
|
1333
|
+
state: {
|
|
1334
|
+
controller: "ur",
|
|
1335
|
+
operation_mode: "OPERATION_MODE_AUTO",
|
|
1336
|
+
safety_state: "SAFETY_STATE_NORMAL",
|
|
1337
|
+
timestamp: "2024-09-18T12:48:26.096266444Z",
|
|
1338
|
+
velocity_override: 100,
|
|
1339
|
+
motion_groups: [
|
|
1340
|
+
{
|
|
1341
|
+
motion_group: "0@ur",
|
|
1342
|
+
controller: "ur",
|
|
1343
|
+
joint_position: {
|
|
1344
|
+
joints: [
|
|
1345
|
+
1.3492152690887451,
|
|
1346
|
+
-1.5659207105636597,
|
|
1347
|
+
1.6653711795806885,
|
|
1348
|
+
-1.0991662740707397,
|
|
1349
|
+
-1.829018235206604,
|
|
1350
|
+
1.264623761177063
|
|
1351
|
+
]
|
|
1352
|
+
},
|
|
1353
|
+
joint_velocity: {
|
|
1354
|
+
joints: [0, 0, 0, 0, 0, 0]
|
|
1355
|
+
},
|
|
1356
|
+
flange_pose: {
|
|
1357
|
+
position: [
|
|
1358
|
+
6.437331889439328,
|
|
1359
|
+
-628.4123774830913,
|
|
1360
|
+
577.0569957147832
|
|
1361
|
+
],
|
|
1362
|
+
orientation: {
|
|
1363
|
+
x: -1.683333649797158,
|
|
1364
|
+
y: -1.9783363827298732,
|
|
1365
|
+
z: -0.4928031860165713
|
|
1366
|
+
},
|
|
1367
|
+
coordinate_system: ""
|
|
1368
|
+
},
|
|
1369
|
+
tcp_pose: {
|
|
1370
|
+
position: [
|
|
1371
|
+
6.437331889439328,
|
|
1372
|
+
-628.4123774830913,
|
|
1373
|
+
577.0569957147832
|
|
1374
|
+
],
|
|
1375
|
+
orientation: {
|
|
1376
|
+
x: -1.683333649797158,
|
|
1377
|
+
y: -1.9783363827298732,
|
|
1378
|
+
z: -0.4928031860165713
|
|
1379
|
+
},
|
|
1380
|
+
coordinate_system: "",
|
|
1381
|
+
tcp: "Flange"
|
|
1382
|
+
},
|
|
1383
|
+
velocity: {
|
|
1384
|
+
linear: {
|
|
1385
|
+
x: 0,
|
|
1386
|
+
y: 0,
|
|
1387
|
+
z: 0
|
|
1388
|
+
},
|
|
1389
|
+
angular: {
|
|
1390
|
+
x: -0,
|
|
1391
|
+
y: 0,
|
|
1392
|
+
z: 0
|
|
1393
|
+
},
|
|
1394
|
+
coordinate_system: ""
|
|
1395
|
+
},
|
|
1396
|
+
force: {
|
|
1397
|
+
force: {
|
|
1398
|
+
x: 0,
|
|
1399
|
+
y: 0,
|
|
1400
|
+
z: 0
|
|
1401
|
+
},
|
|
1402
|
+
moment: {
|
|
1403
|
+
x: 0,
|
|
1404
|
+
y: 0,
|
|
1405
|
+
z: 0
|
|
1406
|
+
},
|
|
1407
|
+
coordinate_system: ""
|
|
1408
|
+
},
|
|
1409
|
+
joint_limit_reached: {
|
|
1410
|
+
limit_reached: [
|
|
1411
|
+
false,
|
|
1412
|
+
false,
|
|
1413
|
+
false,
|
|
1414
|
+
false,
|
|
1415
|
+
false,
|
|
1416
|
+
false
|
|
1417
|
+
]
|
|
1418
|
+
},
|
|
1419
|
+
joint_current: {
|
|
1420
|
+
joints: [0, 0, 0, 0, 0, 0]
|
|
1421
|
+
},
|
|
1422
|
+
sequence_number: "671259"
|
|
1423
|
+
}
|
|
1424
|
+
],
|
|
1425
|
+
sequence_number: "671259"
|
|
1426
|
+
},
|
|
1427
|
+
movement_state: "MOVEMENT_STATE_MOVING"
|
|
1428
|
+
}
|
|
1429
|
+
})
|
|
1430
|
+
})
|
|
1431
|
+
);
|
|
1432
|
+
}
|
|
1433
|
+
if (socket.url.includes("/move-tcp")) {
|
|
1434
|
+
socket.dispatchEvent(
|
|
1435
|
+
new MessageEvent("message", {
|
|
1436
|
+
data: JSON.stringify({
|
|
1437
|
+
result: {
|
|
1438
|
+
motion_group: "0@ur",
|
|
1439
|
+
state: {
|
|
1440
|
+
controller: "ur",
|
|
1441
|
+
operation_mode: "OPERATION_MODE_AUTO",
|
|
1442
|
+
safety_state: "SAFETY_STATE_NORMAL",
|
|
1443
|
+
timestamp: "2024-09-18T12:43:12.188335774Z",
|
|
1444
|
+
velocity_override: 100,
|
|
1445
|
+
motion_groups: [
|
|
1446
|
+
{
|
|
1447
|
+
motion_group: "0@ur",
|
|
1448
|
+
controller: "ur",
|
|
1449
|
+
joint_position: {
|
|
1450
|
+
joints: [
|
|
1451
|
+
1.3352527618408203,
|
|
1452
|
+
-1.5659207105636597,
|
|
1453
|
+
1.6653711795806885,
|
|
1454
|
+
-1.110615611076355,
|
|
1455
|
+
-1.829018235206604,
|
|
1456
|
+
1.264623761177063
|
|
1457
|
+
]
|
|
1458
|
+
},
|
|
1459
|
+
joint_velocity: {
|
|
1460
|
+
joints: [0, 0, 0, 0, 0, 0]
|
|
1461
|
+
},
|
|
1462
|
+
flange_pose: {
|
|
1463
|
+
position: [
|
|
1464
|
+
-2.763015284002938,
|
|
1465
|
+
-630.2151479701106,
|
|
1466
|
+
577.524509114342
|
|
1467
|
+
],
|
|
1468
|
+
orientation: {
|
|
1469
|
+
x: -1.704794877102097,
|
|
1470
|
+
y: -1.9722372952861567,
|
|
1471
|
+
z: -0.4852079204210754
|
|
1472
|
+
},
|
|
1473
|
+
coordinate_system: ""
|
|
1474
|
+
},
|
|
1475
|
+
tcp_pose: {
|
|
1476
|
+
position: [
|
|
1477
|
+
-2.763015284002938,
|
|
1478
|
+
-630.2151479701106,
|
|
1479
|
+
577.524509114342
|
|
1480
|
+
],
|
|
1481
|
+
orientation: {
|
|
1482
|
+
x: -1.704794877102097,
|
|
1483
|
+
y: -1.9722372952861567,
|
|
1484
|
+
z: -0.4852079204210754
|
|
1485
|
+
},
|
|
1486
|
+
coordinate_system: "",
|
|
1487
|
+
tcp: "Flange"
|
|
1488
|
+
},
|
|
1489
|
+
velocity: {
|
|
1490
|
+
linear: {
|
|
1491
|
+
x: 0,
|
|
1492
|
+
y: 0,
|
|
1493
|
+
z: 0
|
|
1494
|
+
},
|
|
1495
|
+
angular: {
|
|
1496
|
+
x: -0,
|
|
1497
|
+
y: 0,
|
|
1498
|
+
z: 0
|
|
1499
|
+
},
|
|
1500
|
+
coordinate_system: ""
|
|
1501
|
+
},
|
|
1502
|
+
force: {
|
|
1503
|
+
force: {
|
|
1504
|
+
x: 0,
|
|
1505
|
+
y: 0,
|
|
1506
|
+
z: 0
|
|
1507
|
+
},
|
|
1508
|
+
moment: {
|
|
1509
|
+
x: 0,
|
|
1510
|
+
y: 0,
|
|
1511
|
+
z: 0
|
|
1512
|
+
},
|
|
1513
|
+
coordinate_system: ""
|
|
1514
|
+
},
|
|
1515
|
+
joint_limit_reached: {
|
|
1516
|
+
limit_reached: [
|
|
1517
|
+
false,
|
|
1518
|
+
false,
|
|
1519
|
+
false,
|
|
1520
|
+
false,
|
|
1521
|
+
false,
|
|
1522
|
+
false
|
|
1523
|
+
]
|
|
1524
|
+
},
|
|
1525
|
+
joint_current: {
|
|
1526
|
+
joints: [0, 0, 0, 0, 0, 0]
|
|
1527
|
+
},
|
|
1528
|
+
sequence_number: "627897"
|
|
1529
|
+
}
|
|
1530
|
+
],
|
|
1531
|
+
sequence_number: "627897"
|
|
1532
|
+
},
|
|
1533
|
+
movement_state: "MOVEMENT_STATE_MOVING"
|
|
1534
|
+
}
|
|
1535
|
+
})
|
|
1536
|
+
})
|
|
1537
|
+
);
|
|
1538
|
+
}
|
|
1539
|
+
}, 10);
|
|
1540
|
+
}
|
|
1541
|
+
handleWebsocketMessage(socket, message) {
|
|
1542
|
+
console.log(`Received message on ${socket.url}`, message);
|
|
1543
|
+
}
|
|
1544
|
+
};
|
|
1545
|
+
var defaultMotionState = {
|
|
1546
|
+
result: {
|
|
1547
|
+
motion_group: "0@universalrobots-ur5e",
|
|
1548
|
+
controller: "universalrobots-ur5e",
|
|
1549
|
+
joint_position: {
|
|
1550
|
+
joints: [
|
|
1551
|
+
1.1699999570846558,
|
|
1552
|
+
-1.5700000524520874,
|
|
1553
|
+
1.3600000143051147,
|
|
1554
|
+
1.0299999713897705,
|
|
1555
|
+
1.2899999618530273,
|
|
1556
|
+
1.2799999713897705
|
|
1557
|
+
]
|
|
1558
|
+
},
|
|
1559
|
+
joint_velocity: {
|
|
1560
|
+
joints: [0, 0, 0, 0, 0, 0]
|
|
1561
|
+
},
|
|
1562
|
+
flange_pose: {
|
|
1563
|
+
position: [1.3300010259703043, -409.2680714682808, 531.0203477065281],
|
|
1564
|
+
orientation: [
|
|
1565
|
+
1.7564919306270736,
|
|
1566
|
+
-1.7542521568325058,
|
|
1567
|
+
0.7326972590614671
|
|
1568
|
+
],
|
|
1569
|
+
coordinate_system: ""
|
|
1570
|
+
},
|
|
1571
|
+
tcp_pose: {
|
|
1572
|
+
position: [1.3300010259703043, -409.2680714682808, 531.0203477065281],
|
|
1573
|
+
orientation: [
|
|
1574
|
+
1.7564919306270736,
|
|
1575
|
+
-1.7542521568325058,
|
|
1576
|
+
0.7326972590614671
|
|
1577
|
+
],
|
|
1578
|
+
coordinate_system: "",
|
|
1579
|
+
tcp: "Flange"
|
|
1580
|
+
},
|
|
1581
|
+
velocity: {
|
|
1582
|
+
linear: [0, 0, 0],
|
|
1583
|
+
angular: [0, 0, 0],
|
|
1584
|
+
coordinate_system: ""
|
|
1585
|
+
},
|
|
1586
|
+
force: {
|
|
1587
|
+
force: [0, 0, 0],
|
|
1588
|
+
moment: [0, 0, 0],
|
|
1589
|
+
coordinate_system: ""
|
|
1590
|
+
},
|
|
1591
|
+
joint_limit_reached: {
|
|
1592
|
+
limit_reached: [false, false, false, false, false, false]
|
|
1593
|
+
},
|
|
1594
|
+
joint_current: {
|
|
1595
|
+
joints: [0, 0, 0, 0, 0, 0]
|
|
1596
|
+
}
|
|
1597
|
+
}
|
|
1598
|
+
};
|
|
1599
|
+
|
|
1600
|
+
// src/lib/v2/NovaClient.ts
|
|
1601
|
+
var NovaClient = class {
|
|
1602
|
+
constructor(config) {
|
|
1603
|
+
this.authPromise = null;
|
|
1604
|
+
this.accessToken = null;
|
|
1605
|
+
var _a;
|
|
1606
|
+
console.warn("Using experimental NOVA v2 client");
|
|
1607
|
+
const cellId = (_a = config.cellId) != null ? _a : "cell";
|
|
1608
|
+
this.config = __spreadValues({
|
|
1609
|
+
cellId
|
|
1610
|
+
}, config);
|
|
1611
|
+
this.accessToken = config.accessToken || availableStorage.getString("wbjs.access_token") || null;
|
|
1612
|
+
if (this.config.instanceUrl === "https://mock.example.com") {
|
|
1613
|
+
this.mock = new MockNovaInstance();
|
|
1614
|
+
}
|
|
1615
|
+
const axiosInstance = axios2.create({
|
|
1616
|
+
baseURL: urlJoin(this.config.instanceUrl, "/api/v2")
|
|
1617
|
+
});
|
|
1618
|
+
axiosInstance.interceptors.request.use((request) => __async(this, null, function* () {
|
|
1619
|
+
if (!request.headers.Authorization) {
|
|
1620
|
+
if (this.accessToken) {
|
|
1621
|
+
request.headers.Authorization = `Bearer ${this.accessToken}`;
|
|
1622
|
+
} else if (this.config.username && this.config.password) {
|
|
1623
|
+
request.headers.Authorization = `Basic ${btoa(config.username + ":" + config.password)}`;
|
|
1624
|
+
}
|
|
1625
|
+
}
|
|
1626
|
+
return request;
|
|
1627
|
+
}));
|
|
1628
|
+
if (typeof window !== "undefined") {
|
|
1629
|
+
axiosInstance.interceptors.response.use(
|
|
1630
|
+
(r) => r,
|
|
1631
|
+
(error) => __async(this, null, function* () {
|
|
1632
|
+
var _a2, _b;
|
|
1633
|
+
if (isAxiosError(error)) {
|
|
1634
|
+
if (((_a2 = error.response) == null ? void 0 : _a2.status) === 401) {
|
|
1635
|
+
try {
|
|
1636
|
+
yield this.renewAuthentication();
|
|
1637
|
+
if (error.config) {
|
|
1638
|
+
if (this.accessToken) {
|
|
1639
|
+
error.config.headers.Authorization = `Bearer ${this.accessToken}`;
|
|
1640
|
+
} else {
|
|
1641
|
+
delete error.config.headers.Authorization;
|
|
1642
|
+
}
|
|
1643
|
+
return axiosInstance.request(error.config);
|
|
1644
|
+
}
|
|
1645
|
+
} catch (err) {
|
|
1646
|
+
return Promise.reject(err);
|
|
1647
|
+
}
|
|
1648
|
+
} else if (((_b = error.response) == null ? void 0 : _b.status) === 503) {
|
|
1649
|
+
const res = yield fetch(window.location.href);
|
|
1650
|
+
if (res.status === 503) {
|
|
1651
|
+
window.location.reload();
|
|
1652
|
+
}
|
|
1653
|
+
}
|
|
1654
|
+
}
|
|
1655
|
+
return Promise.reject(error);
|
|
1656
|
+
})
|
|
1657
|
+
);
|
|
1658
|
+
}
|
|
1659
|
+
this.api = new NovaCellAPIClient(cellId, __spreadProps(__spreadValues({}, config), {
|
|
1660
|
+
basePath: urlJoin(this.config.instanceUrl, "/api/v1"),
|
|
1661
|
+
isJsonMime: (mime) => {
|
|
1662
|
+
return mime === "application/json";
|
|
1663
|
+
},
|
|
1664
|
+
baseOptions: __spreadValues(__spreadValues({}, this.mock ? {
|
|
1665
|
+
adapter: (config2) => {
|
|
1666
|
+
return this.mock.handleAPIRequest(config2);
|
|
1667
|
+
}
|
|
1668
|
+
} : {}), config.baseOptions),
|
|
1669
|
+
axiosInstance
|
|
1670
|
+
}));
|
|
1671
|
+
}
|
|
1672
|
+
renewAuthentication() {
|
|
1673
|
+
return __async(this, null, function* () {
|
|
1674
|
+
if (this.authPromise) {
|
|
1675
|
+
return;
|
|
1676
|
+
}
|
|
1677
|
+
this.authPromise = loginWithAuth0(this.config.instanceUrl);
|
|
1678
|
+
try {
|
|
1679
|
+
this.accessToken = yield this.authPromise;
|
|
1680
|
+
if (this.accessToken) {
|
|
1681
|
+
availableStorage.setString("wbjs.access_token", this.accessToken);
|
|
1682
|
+
} else {
|
|
1683
|
+
availableStorage.delete("wbjs.access_token");
|
|
1684
|
+
}
|
|
1685
|
+
} finally {
|
|
1686
|
+
this.authPromise = null;
|
|
1687
|
+
}
|
|
1688
|
+
});
|
|
1689
|
+
}
|
|
1690
|
+
makeWebsocketURL(path) {
|
|
1691
|
+
const url = new URL(
|
|
1692
|
+
urlJoin(
|
|
1693
|
+
this.config.instanceUrl,
|
|
1694
|
+
`/api/v1/cells/${this.config.cellId}`,
|
|
1695
|
+
path
|
|
1696
|
+
)
|
|
1697
|
+
);
|
|
1698
|
+
url.protocol = url.protocol.replace("http", "ws");
|
|
1699
|
+
url.protocol = url.protocol.replace("https", "wss");
|
|
1700
|
+
if (this.accessToken) {
|
|
1701
|
+
url.searchParams.append("token", this.accessToken);
|
|
1702
|
+
} else if (this.config.username && this.config.password) {
|
|
1703
|
+
url.username = this.config.username;
|
|
1704
|
+
url.password = this.config.password;
|
|
1705
|
+
}
|
|
1706
|
+
return url.toString();
|
|
1707
|
+
}
|
|
1708
|
+
/**
|
|
1709
|
+
* Retrieve an AutoReconnectingWebsocket to the given path on the Nova instance.
|
|
1710
|
+
* If you explicitly want to reconnect an existing websocket, call `reconnect`
|
|
1711
|
+
* on the returned object.
|
|
1712
|
+
*/
|
|
1713
|
+
openReconnectingWebsocket(path) {
|
|
1714
|
+
return new AutoReconnectingWebsocket(this.makeWebsocketURL(path), {
|
|
1715
|
+
mock: this.mock
|
|
1716
|
+
});
|
|
1717
|
+
}
|
|
1718
|
+
/**
|
|
1719
|
+
* Connect to the motion state websocket(s) for a given motion group
|
|
1720
|
+
*/
|
|
1721
|
+
connectMotionStream(motionGroupId) {
|
|
1722
|
+
return __async(this, null, function* () {
|
|
1723
|
+
return yield MotionStreamConnection.open(this, motionGroupId);
|
|
1724
|
+
});
|
|
1725
|
+
}
|
|
1726
|
+
connectMotionGroups(motionGroupIds) {
|
|
1727
|
+
return __async(this, null, function* () {
|
|
1728
|
+
const { controllers } = yield this.api.controller.listControllers();
|
|
1729
|
+
return Promise.all(
|
|
1730
|
+
motionGroupIds.map(
|
|
1731
|
+
(motionGroupId) => ConnectedMotionGroup.connect(this, motionGroupId, controllers)
|
|
1732
|
+
)
|
|
1733
|
+
);
|
|
1734
|
+
});
|
|
1735
|
+
}
|
|
1736
|
+
connectMotionGroup(motionGroupId) {
|
|
1737
|
+
return __async(this, null, function* () {
|
|
1738
|
+
const motionGroups = yield this.connectMotionGroups([motionGroupId]);
|
|
1739
|
+
return motionGroups[0];
|
|
1740
|
+
});
|
|
1741
|
+
}
|
|
1742
|
+
};
|
|
1743
|
+
|
|
1744
|
+
// src/lib/v2/ProgramStateConnection.ts
|
|
1745
|
+
import { AxiosError as AxiosError3 } from "axios";
|
|
1746
|
+
import { makeAutoObservable as makeAutoObservable3, runInAction as runInAction3 } from "mobx";
|
|
1747
|
+
var ProgramState = /* @__PURE__ */ ((ProgramState2) => {
|
|
1748
|
+
ProgramState2["NotStarted"] = "not started";
|
|
1749
|
+
ProgramState2["Running"] = "running";
|
|
1750
|
+
ProgramState2["Stopped"] = "stopped";
|
|
1751
|
+
ProgramState2["Failed"] = "failed";
|
|
1752
|
+
ProgramState2["Completed"] = "completed";
|
|
1753
|
+
return ProgramState2;
|
|
1754
|
+
})(ProgramState || {});
|
|
1755
|
+
var ProgramStateConnection = class {
|
|
1756
|
+
constructor(nova) {
|
|
1757
|
+
this.nova = nova;
|
|
1758
|
+
this.currentProgram = {};
|
|
1759
|
+
this.logs = [];
|
|
1760
|
+
this.executionState = "idle";
|
|
1761
|
+
this.currentlyExecutingProgramRunnerId = null;
|
|
1762
|
+
makeAutoObservable3(this, {}, { autoBind: true });
|
|
1763
|
+
this.programStateSocket = nova.openReconnectingWebsocket(`/programs/state`);
|
|
1764
|
+
this.programStateSocket.addEventListener("message", (ev) => {
|
|
1765
|
+
const msg = tryParseJson(ev.data);
|
|
1766
|
+
if (!msg) {
|
|
1767
|
+
console.error("Failed to parse program state message", ev.data);
|
|
1768
|
+
return;
|
|
1769
|
+
}
|
|
1770
|
+
if (msg.type === "update") {
|
|
1771
|
+
this.handleProgramStateMessage(msg);
|
|
1772
|
+
}
|
|
1773
|
+
});
|
|
1774
|
+
}
|
|
1775
|
+
/** Handle a program state update from the backend */
|
|
1776
|
+
handleProgramStateMessage(msg) {
|
|
1777
|
+
return __async(this, null, function* () {
|
|
1778
|
+
var _a;
|
|
1779
|
+
const { runner } = msg;
|
|
1780
|
+
if (runner.id !== this.currentlyExecutingProgramRunnerId) return;
|
|
1781
|
+
if (runner.state === "failed" /* Failed */) {
|
|
1782
|
+
try {
|
|
1783
|
+
const runnerState = yield this.nova.api.program.getProgramRunner(
|
|
1784
|
+
runner.id
|
|
1785
|
+
);
|
|
1786
|
+
const stdout = runnerState.stdout;
|
|
1787
|
+
if (stdout) {
|
|
1788
|
+
this.log(stdout);
|
|
1789
|
+
}
|
|
1790
|
+
this.logError(
|
|
1791
|
+
`Program runner ${runner.id} failed with error: ${runnerState.error}
|
|
1792
|
+
${runnerState.traceback}`
|
|
1793
|
+
);
|
|
1794
|
+
} catch (err) {
|
|
1795
|
+
this.logError(
|
|
1796
|
+
`Failed to retrieve results for program ${runner.id}: ${err}`
|
|
1797
|
+
);
|
|
1798
|
+
}
|
|
1799
|
+
this.currentProgram.state = "failed" /* Failed */;
|
|
1800
|
+
this.gotoIdleState();
|
|
1801
|
+
} else if (runner.state === "stopped" /* Stopped */) {
|
|
1802
|
+
try {
|
|
1803
|
+
const runnerState = yield this.nova.api.program.getProgramRunner(
|
|
1804
|
+
runner.id
|
|
1805
|
+
);
|
|
1806
|
+
const stdout = runnerState.stdout;
|
|
1807
|
+
if (stdout) {
|
|
1808
|
+
this.log(stdout);
|
|
1809
|
+
}
|
|
1810
|
+
this.currentProgram.state = "stopped" /* Stopped */;
|
|
1811
|
+
this.log(`Program runner ${runner.id} stopped`);
|
|
1812
|
+
} catch (err) {
|
|
1813
|
+
this.logError(
|
|
1814
|
+
`Failed to retrieve results for program ${runner.id}: ${err}`
|
|
1815
|
+
);
|
|
1816
|
+
}
|
|
1817
|
+
this.gotoIdleState();
|
|
1818
|
+
} else if (runner.state === "completed" /* Completed */) {
|
|
1819
|
+
try {
|
|
1820
|
+
const runnerState = yield this.nova.api.program.getProgramRunner(
|
|
1821
|
+
runner.id
|
|
1822
|
+
);
|
|
1823
|
+
const stdout = runnerState.stdout;
|
|
1824
|
+
if (stdout) {
|
|
1825
|
+
this.log(stdout);
|
|
1826
|
+
}
|
|
1827
|
+
this.log(
|
|
1828
|
+
`Program runner ${runner.id} finished successfully in ${(_a = runner.execution_time) == null ? void 0 : _a.toFixed(2)} seconds`
|
|
1829
|
+
);
|
|
1830
|
+
this.currentProgram.state = "completed" /* Completed */;
|
|
1831
|
+
} catch (err) {
|
|
1832
|
+
this.logError(
|
|
1833
|
+
`Failed to retrieve results for program ${runner.id}: ${err}`
|
|
1834
|
+
);
|
|
1835
|
+
}
|
|
1836
|
+
this.gotoIdleState();
|
|
1837
|
+
} else if (runner.state === "running" /* Running */) {
|
|
1838
|
+
this.currentProgram.state = "running" /* Running */;
|
|
1839
|
+
this.log(`Program runner ${runner.id} now running`);
|
|
1840
|
+
} else if (runner.state !== "not started" /* NotStarted */) {
|
|
1841
|
+
console.error(runner);
|
|
1842
|
+
this.logError(
|
|
1843
|
+
`Program runner ${runner.id} entered unexpected state: ${runner.state}`
|
|
1844
|
+
);
|
|
1845
|
+
this.currentProgram.state = "not started" /* NotStarted */;
|
|
1846
|
+
this.gotoIdleState();
|
|
1847
|
+
}
|
|
1848
|
+
});
|
|
1849
|
+
}
|
|
1850
|
+
/** Call when a program is no longer executing */
|
|
1851
|
+
gotoIdleState() {
|
|
1852
|
+
runInAction3(() => {
|
|
1853
|
+
this.executionState = "idle";
|
|
1854
|
+
});
|
|
1855
|
+
this.currentlyExecutingProgramRunnerId = null;
|
|
1856
|
+
}
|
|
1857
|
+
executeProgram(wandelscript, initial_state, activeRobot) {
|
|
1858
|
+
return __async(this, null, function* () {
|
|
1859
|
+
this.currentProgram = {
|
|
1860
|
+
wandelscript,
|
|
1861
|
+
state: "not started" /* NotStarted */
|
|
1862
|
+
};
|
|
1863
|
+
const { currentProgram: openProgram } = this;
|
|
1864
|
+
if (!openProgram) return;
|
|
1865
|
+
runInAction3(() => {
|
|
1866
|
+
this.executionState = "starting";
|
|
1867
|
+
});
|
|
1868
|
+
const trimmedCode = openProgram.wandelscript.replaceAll(/^\s*$/gm, "");
|
|
1869
|
+
try {
|
|
1870
|
+
const programRunnerRef = yield this.nova.api.program.createProgramRunner(
|
|
1871
|
+
{
|
|
1872
|
+
code: trimmedCode,
|
|
1873
|
+
initial_state,
|
|
1874
|
+
default_robot: activeRobot == null ? void 0 : activeRobot.wandelscriptIdentifier
|
|
1875
|
+
},
|
|
1876
|
+
{
|
|
1877
|
+
headers: {
|
|
1878
|
+
"Content-Type": "application/json"
|
|
1879
|
+
}
|
|
1880
|
+
}
|
|
1881
|
+
);
|
|
1882
|
+
this.log(`Created program runner ${programRunnerRef.id}"`);
|
|
1883
|
+
runInAction3(() => {
|
|
1884
|
+
this.executionState = "executing";
|
|
1885
|
+
});
|
|
1886
|
+
this.currentlyExecutingProgramRunnerId = programRunnerRef.id;
|
|
1887
|
+
} catch (error) {
|
|
1888
|
+
if (error instanceof AxiosError3 && error.response && error.request) {
|
|
1889
|
+
this.logError(
|
|
1890
|
+
`${error.response.status} ${error.response.statusText} from ${error.response.config.url} ${JSON.stringify(error.response.data)}`
|
|
1891
|
+
);
|
|
1892
|
+
} else {
|
|
1893
|
+
this.logError(JSON.stringify(error));
|
|
1894
|
+
}
|
|
1895
|
+
runInAction3(() => {
|
|
1896
|
+
this.executionState = "idle";
|
|
1897
|
+
});
|
|
1898
|
+
}
|
|
1899
|
+
});
|
|
1900
|
+
}
|
|
1901
|
+
stopProgram() {
|
|
1902
|
+
return __async(this, null, function* () {
|
|
1903
|
+
if (!this.currentlyExecutingProgramRunnerId) return;
|
|
1904
|
+
runInAction3(() => {
|
|
1905
|
+
this.executionState = "stopping";
|
|
1906
|
+
});
|
|
1907
|
+
try {
|
|
1908
|
+
yield this.nova.api.program.stopProgramRunner(
|
|
1909
|
+
this.currentlyExecutingProgramRunnerId
|
|
1910
|
+
);
|
|
1911
|
+
} catch (err) {
|
|
1912
|
+
runInAction3(() => {
|
|
1913
|
+
this.executionState = "executing";
|
|
1914
|
+
});
|
|
1915
|
+
throw err;
|
|
1916
|
+
}
|
|
1917
|
+
});
|
|
1918
|
+
}
|
|
1919
|
+
reset() {
|
|
1920
|
+
this.currentProgram = {};
|
|
1921
|
+
}
|
|
1922
|
+
log(message) {
|
|
1923
|
+
console.log(message);
|
|
1924
|
+
this.logs.push({
|
|
1925
|
+
timestamp: Date.now(),
|
|
1926
|
+
message
|
|
1927
|
+
});
|
|
1928
|
+
}
|
|
1929
|
+
logError(message) {
|
|
1930
|
+
console.log(message);
|
|
1931
|
+
this.logs.push({
|
|
1932
|
+
timestamp: Date.now(),
|
|
1933
|
+
message,
|
|
1934
|
+
level: "error"
|
|
1935
|
+
});
|
|
1936
|
+
}
|
|
1937
|
+
};
|
|
1938
|
+
export {
|
|
1939
|
+
ConnectedMotionGroup,
|
|
1940
|
+
JoggerConnection,
|
|
1941
|
+
MotionStreamConnection,
|
|
1942
|
+
NovaCellAPIClient,
|
|
1943
|
+
NovaClient,
|
|
1944
|
+
ProgramState,
|
|
1945
|
+
ProgramStateConnection
|
|
1946
|
+
};
|
|
1947
|
+
//# sourceMappingURL=index.js.map
|