-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutil.tsx
More file actions
391 lines (334 loc) · 8.8 KB
/
Copy pathutil.tsx
File metadata and controls
391 lines (334 loc) · 8.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
import ROSLIB, { Message } from "roslib";
import { cmd } from "./commands";
export type ValidJoints =
| "head_tilt_joint"
| "head_pan_joint"
| "stretch_gripper_joint"
| "arm_joint"
| "wrist_extension"
| "lift_joint"
| "wrist_roll_joint"
| "wrist_pitch_joint"
| "wrist_yaw_joint"
| "translate_mobile_base"
| "rotate_mobile_base"
| "gripper_aperture"
| "arm_l0_joint"
| "arm_l1_joint"
| "arm_l2_joint"
| "arm_l3_joint"
| "arm_l4_joint";
export type RemoteStream = {
stream: MediaStream;
track: MediaStreamTrack;
};
export type ValidJointStateDict = { [key in ValidJoints]?: [boolean, boolean] };
export interface ROSJointState extends Message {
name: [ValidJoints?];
position: [number];
effort: [number];
velocity: [number];
}
export interface DiagnosticArray extends Message {
status: DiagnosticStatus[];
}
export interface DiagnosticStatus extends Message {
name: string;
level: number;
message: string;
hardware_id: string;
values: KeyValue[];
}
export interface KeyValue {
key: string;
value: string;
}
export enum StretchTool {
DW4 = "eoa_wrist_dw4_tool_sg4",
TABLET = "eoa_wrist_dw3_tool_tablet",
UNKNOWN = "unknown",
}
export function getStretchTool(stretchTool: string) {
if (stretchTool === "eoa_wrist_dw3_tool_tablet") {
return StretchTool.TABLET;
} else if (stretchTool === "eoa_wrist_dw4_tool_sg4") {
return StretchTool.DW4;
} else {
return StretchTool.UNKNOWN;
}
}
export interface ROSBatteryState extends Message {
voltage: number;
}
export interface ROSCompressedImage extends Message {
header: string;
format: "jpeg" | "png";
data: string;
}
export interface CameraInfo {
[key: string]: string;
}
export interface SignallingMessage {
candidate?: RTCIceCandidate;
sessionDescription?: RTCSessionDescription;
cameraInfo?: CameraInfo;
}
export interface Transform {
transform: ROSLIB.Transform;
}
export type WebRTCMessage =
| ValidJointStateMessage
| OccupancyGridMessage
| MapPoseMessage
| StopTrajectoryMessage
| StopMoveBaseMessage
| BatteryVoltageMessage
| ModeMessage
| IsHomedMessage
| IsRunStoppedMessage
| StretchToolMessage
| ActionStateMessage
| cmd;
interface StopTrajectoryMessage {
type: "stopTrajectory";
}
interface StopMoveBaseMessage {
type: "stopMoveBase";
}
export type RobotPose = { [key in ValidJoints]?: number };
export interface ValidJointStateMessage {
type: "validJointState";
robotPose: RobotPose;
jointsInLimits: { [key in ValidJoints]?: [boolean, boolean] };
jointsInCollision: { [key in ValidJoints]?: [boolean, boolean] };
}
export interface ModeMessage {
type: "mode";
value: string;
}
export interface IsHomedMessage {
type: "isHomed";
value: boolean;
}
export interface IsRunStoppedMessage {
type: "isRunStopped";
enabled: boolean;
}
export interface StretchToolMessage {
type: "stretchTool";
value: string;
}
export interface ActionState {
state: string;
alert_type: string;
}
export interface ActionStateMessage {
type: string;
message: ActionState;
}
export interface ActionStatusList {
status_list: { status: number }[];
}
export interface OccupancyGridMessage {
type: "occupancyGrid";
message: ROSOccupancyGrid;
}
export interface MapPoseMessage {
type: "amclPose";
message: ROSLIB.Transform;
}
export interface BatteryVoltageMessage {
type: "batteryVoltage";
message: number;
}
export interface ROSPoint extends Message {
x: number;
y: number;
z: number;
}
export interface ROSQuaternion extends Message {
x: number;
y: number;
z: number;
w: number;
}
export interface ROSPose extends Message {
position: ROSPoint;
orientation: ROSQuaternion;
}
export interface ROSMapMetaData extends Message {
map_load_time: number;
resolution: number;
width: number;
height: number;
origin: ROSPose;
}
export interface ROSOccupancyGrid {
header: string;
info: ROSMapMetaData;
data: number[];
}
export const JOINT_LIMITS: { [key in ValidJoints]?: [number, number] } = {
arm_joint: [0.001, 0.518],
wrist_roll_joint: [-2.95, 2.94],
wrist_pitch_joint: [-1.57, 0.57],
wrist_yaw_joint: [-1.37, 4.41],
lift_joint: [0.001, 1.1],
translate_mobile_base: [-30.0, 30.0],
rotate_mobile_base: [-3.14, 3.14],
stretch_gripper_joint: [-0.37, 0.17],
head_tilt_joint: [-1.6, 0.3],
head_pan_joint: [-3.95, 1.7],
};
export const JOINT_VELOCITIES: { [key in ValidJoints]?: number } = {
head_tilt_joint: 0.3,
head_pan_joint: 0.3,
arm_joint: 0.04,
lift_joint: 0.04,
wrist_roll_joint: 0.1,
wrist_pitch_joint: 0.1,
wrist_yaw_joint: 0.4,
translate_mobile_base: 0.2,
rotate_mobile_base: 0.3,
};
export const JOINT_INCREMENTS: { [key in ValidJoints]?: number } = {
head_tilt_joint: 0.1,
head_pan_joint: 0.1,
stretch_gripper_joint: 0.1,
arm_joint: 0.1,
lift_joint: 0.1,
wrist_roll_joint: 0.1,
wrist_pitch_joint: 0.1,
wrist_yaw_joint: 0.1,
translate_mobile_base: 0.2,
rotate_mobile_base: 0.5,
};
export const navigationProps = {
width: 768, // 800,
height: 768, // 1280,
scale: 1,
fps: 6.0,
streamName: "navigation",
};
export const gripperProps = {
width: 768, // 1024
height: 768,
scale: 1,
fps: 6.0,
streamName: "gripper",
};
// audioProps are empty for now, but are included in case we want to customize
// the audio stream in the future.
export const audioProps = {};
export interface VideoProps {
topicName: string;
callback: (message: ROSCompressedImage) => void;
}
export function rosJointStatetoRobotPose(jointState: ROSJointState): RobotPose {
let robotPose: RobotPose = {};
const names = jointState.name;
const positions = jointState.position;
names.map((name, index) => {
if (name) {
robotPose[name] = positions[index];
}
});
return robotPose;
}
////////////////////////////////////////////////////////////
// safelyParseJSON code copied from
// https://stackoverflow.com/questions/29797946/handling-bad-json-parse-in-node-safely
// on August 18, 2017
export function safelyParseJSON<T = any>(json: string): T {
// This function cannot be optimized, it's best to
// keep it small!
let parsed;
try {
parsed = JSON.parse(json);
} catch (e) {
console.warn(e);
}
return parsed; // Could be undefined!
}
export type uuid = string;
// From: https://stackoverflow.com/a/2117523/6454085
export function generateUUID(): uuid {
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(
/[xy]/g,
function (c) {
var r = (Math.random() * 16) | 0,
v = c == "x" ? r : (r & 0x3) | 0x8;
return v.toString(16);
}
);
}
export async function waitUntil(
condition,
timeout = 5000,
checkInterval = 100
) {
let interval;
let waitPromise = new Promise((resolve) => {
interval = setInterval(() => {
if (!condition()) {
return;
}
clearInterval(interval);
resolve(true);
}, checkInterval);
});
let timeoutPromise = new Promise((resolve) =>
setTimeout(() => {
clearInterval(interval);
resolve(false);
}, timeout)
);
return await Promise.any([waitPromise, timeoutPromise]);
}
export async function waitUntilAsync(
condition,
timeout = 5000,
checkInterval = 100
) {
let interval;
let waitPromise = new Promise((resolve) => {
interval = setInterval(async () => {
let value = await condition();
if (!value) {
return;
}
clearInterval(interval);
resolve(true);
}, checkInterval);
});
let timeoutPromise = new Promise((resolve) =>
setTimeout(() => {
clearInterval(interval);
resolve(false);
}, timeout)
);
return await Promise.any([waitPromise, timeoutPromise]);
}
export const delay = (ms: number) => new Promise((res) => setTimeout(res, ms));
/**
* Creates a class name string based on a base class name and additional flags
* to include.
*
* @param baseName base name of the class
* @param flags additional flags to append to the class name
* @returns returns a string for the class name
*
* @example ```js
* className("foreground-button", {"active": false, "customizing": true})
* // returns "foreground-button customizing"
* ```
*/
export function className(baseName: string, flags: {}): string {
let className = baseName;
for (const [k, b] of Object.entries(flags)) {
if (b) {
className += " " + k;
}
}
return className;
}