@wandelbots/wandelbots-js-react-components 6.3.0 → 6.4.0-pr.chore-playground-tool-steps.664.4537d63

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 (191) hide show
  1. package/README.md +323 -120
  2. package/dist/3d.cjs +1 -1
  3. package/dist/3d.d.ts +5 -3
  4. package/dist/3d.js +24 -23
  5. package/dist/CurrentPoseBar/index.cjs +1 -0
  6. package/dist/CurrentPoseBar/index.d.ts +2 -0
  7. package/dist/CurrentPoseBar/index.js +5 -0
  8. package/dist/JoggingButtons/index.cjs +1 -0
  9. package/dist/JoggingButtons/index.d.ts +3 -0
  10. package/dist/JoggingButtons/index.js +5 -0
  11. package/dist/JoggingGizmo/index.cjs +1 -0
  12. package/dist/JoggingGizmo/index.d.ts +4 -0
  13. package/dist/JoggingGizmo/index.js +7 -0
  14. package/dist/JoggingJointSlider/index.cjs +1 -0
  15. package/dist/JoggingJointSlider/index.d.ts +2 -0
  16. package/dist/JoggingJointSlider/index.js +5 -0
  17. package/dist/RobotControlPanel/index.cjs +1 -0
  18. package/dist/RobotControlPanel/index.d.ts +2 -0
  19. package/dist/RobotControlPanel/index.js +5 -0
  20. package/dist/RobotHeader/index.cjs +1 -0
  21. package/dist/RobotHeader/index.d.ts +4 -0
  22. package/dist/RobotHeader/index.js +5 -0
  23. package/dist/SafetyBar/index.cjs +1 -1
  24. package/dist/SafetyBar/index.js +1 -1
  25. package/dist/chunks/CurrentPoseBar-CyHUWmjM.cjs +1 -0
  26. package/dist/chunks/CurrentPoseBar-zTZi68tY.js +505 -0
  27. package/dist/chunks/JoggingButtons-CXaozFVz.js +108 -0
  28. package/dist/chunks/JoggingButtons-CbL-5LMK.cjs +1 -0
  29. package/dist/chunks/JoggingGizmo-DGbFLWgT.cjs +1 -0
  30. package/dist/chunks/JoggingGizmo-SuS9MmL7.js +810 -0
  31. package/dist/chunks/JoggingGizmoOrientation-dzned4f4.cjs +1 -0
  32. package/dist/chunks/JoggingGizmoOrientation-x_crT_64.js +14 -0
  33. package/dist/chunks/JoggingJointSlider-CZ-k6XCa.js +406 -0
  34. package/dist/chunks/JoggingJointSlider-R3_A9Ppj.cjs +1 -0
  35. package/dist/chunks/Robot-D0ZqUCn3.cjs +1 -0
  36. package/dist/chunks/Robot-UoykZeYH.js +1272 -0
  37. package/dist/chunks/RobotControlPanel-BnMfmO41.js +822 -0
  38. package/dist/chunks/RobotControlPanel-BuDGcxPR.cjs +1 -0
  39. package/dist/chunks/RobotHeader-BZci9ahT.js +244 -0
  40. package/dist/chunks/RobotHeader-CqK0700U.cjs +1 -0
  41. package/dist/chunks/SafetyBar-Bbg-o8h9.cjs +1 -0
  42. package/dist/chunks/{SafetyBar-Cy9DiXp9.js → SafetyBar-Cuak4ffd.js} +11 -10
  43. package/dist/chunks/SmallSelect-BdD9uLKK.js +52 -0
  44. package/dist/chunks/SmallSelect-Dcsd7_6_.cjs +1 -0
  45. package/dist/chunks/TrajectoryExecutionStore-DPqfDcfn.js +3398 -0
  46. package/dist/chunks/TrajectoryExecutionStore-DV6mLEx9.cjs +3 -0
  47. package/dist/chunks/converters-C8I_A_tA.cjs +1 -0
  48. package/dist/chunks/converters-DpNB_WNQ.js +39 -0
  49. package/dist/chunks/externalizeComponent-BdxGBLIv.cjs +2 -0
  50. package/dist/chunks/externalizeComponent-_w2d1_pz.js +283 -0
  51. package/dist/chunks/holdSafety-BtoZ5We3.cjs +1 -0
  52. package/dist/chunks/holdSafety-Di1GZAWg.js +37 -0
  53. package/dist/chunks/joggingColors-CuT5u0H8.js +135 -0
  54. package/dist/chunks/joggingColors-ZDc_2UCp.cjs +1 -0
  55. package/dist/chunks/useEveryFrame-G_-ma1nC.js +142 -0
  56. package/dist/chunks/useEveryFrame-dmPPTKtT.cjs +1 -0
  57. package/dist/chunks/useSmoothedMotionState-COMJRcOt.js +214 -0
  58. package/dist/chunks/useSmoothedMotionState-Con0E5Bx.cjs +1 -0
  59. package/dist/components/AppHeader.d.ts +1 -1
  60. package/dist/components/currentPoseBar/CurrentPoseBar.d.ts +48 -0
  61. package/dist/components/currentPoseBar/OrientationFormatPopover.d.ts +19 -0
  62. package/dist/components/currentPoseBar/StreamStatus.d.ts +10 -0
  63. package/dist/components/currentPoseBar/orientation.d.ts +34 -0
  64. package/dist/components/currentPoseBar/poseValues.d.ts +15 -0
  65. package/dist/components/jogging/JoggingButtons.d.ts +16 -0
  66. package/dist/components/jogging/JoggingCartesianAxisControl.d.ts +1 -1
  67. package/dist/components/jogging/JoggingJointTab.d.ts +1 -1
  68. package/dist/components/jogging/JoggingPanel.d.ts +6 -3
  69. package/dist/components/jogging/JoggingStore.d.ts +96 -19
  70. package/dist/components/jogging/gizmo/JoggingGizmo.d.ts +43 -0
  71. package/dist/components/jogging/gizmo/JoggingGizmoOrientation.d.ts +26 -0
  72. package/dist/components/jogging/gizmo/RotationHandles.d.ts +7 -0
  73. package/dist/components/jogging/gizmo/RotationScene.d.ts +6 -0
  74. package/dist/components/jogging/gizmo/TranslationHandles.d.ts +6 -0
  75. package/dist/components/jogging/gizmo/TranslationScene.d.ts +6 -0
  76. package/dist/components/jogging/gizmo/arcGrabAreas.d.ts +58 -0
  77. package/dist/components/jogging/gizmo/arcs.d.ts +54 -0
  78. package/dist/components/jogging/gizmo/arrows.d.ts +63 -0
  79. package/dist/components/jogging/gizmo/gizmoShared.d.ts +125 -0
  80. package/dist/components/jogging/gizmo/gizmoView.d.ts +42 -0
  81. package/dist/components/jogging/gizmo/useGizmoTurn.d.ts +11 -0
  82. package/dist/components/jogging/holdSafety.d.ts +44 -0
  83. package/dist/components/jogging/jogError.d.ts +9 -0
  84. package/dist/components/jogging/jogHandle.d.ts +23 -0
  85. package/dist/components/jogging/joggingColors.d.ts +24 -0
  86. package/dist/components/jogging/joggingVelocity.d.ts +21 -0
  87. package/dist/components/jogging/joint/JoggingJointSlider.d.ts +52 -0
  88. package/dist/components/jogging/joint/JointSliderTrack.d.ts +27 -0
  89. package/dist/components/jogging/joint/jointJog.d.ts +55 -0
  90. package/dist/components/jogging/joint/useJointJogHold.d.ts +48 -0
  91. package/dist/components/jogging/useHold.d.ts +38 -0
  92. package/dist/components/jogging/useJogControls.d.ts +45 -0
  93. package/dist/components/robotControl/CartesianJogTab.d.ts +21 -0
  94. package/dist/components/robotControl/HoldToMoveButton.d.ts +25 -0
  95. package/dist/components/robotControl/JogArea.d.ts +22 -0
  96. package/dist/components/robotControl/JogModeToggle.d.ts +8 -0
  97. package/dist/components/robotControl/JointJogTab.d.ts +11 -0
  98. package/dist/components/robotControl/MoveToTab.d.ts +18 -0
  99. package/dist/components/robotControl/PanelSelect.d.ts +13 -0
  100. package/dist/components/robotControl/PoseField.d.ts +21 -0
  101. package/dist/components/robotControl/RobotControlPanel.d.ts +212 -0
  102. package/dist/components/robotControl/Section.d.ts +5 -0
  103. package/dist/components/robotControl/SmallSelect.d.ts +15 -0
  104. package/dist/components/robotControl/VelocityRow.d.ts +14 -0
  105. package/dist/components/robotControl/atPose.d.ts +8 -0
  106. package/dist/components/robotControl/poseText.d.ts +15 -0
  107. package/dist/components/robotControl/units.d.ts +16 -0
  108. package/dist/components/robotControl/useCopyText.d.ts +12 -0
  109. package/dist/components/robotControl/useEveryFrame.d.ts +6 -0
  110. package/dist/components/robotHeader/ActivationSwitch.d.ts +7 -0
  111. package/dist/components/robotHeader/AppNavigation.d.ts +15 -0
  112. package/dist/components/robotHeader/RobotHeader.d.ts +42 -0
  113. package/dist/components/robots/GenericRobot.d.ts +2 -1
  114. package/dist/components/robots/LinearAxis.d.ts +1 -1
  115. package/dist/components/robots/LinearAxisAnimator.d.ts +11 -2
  116. package/dist/components/robots/Robot.d.ts +1 -1
  117. package/dist/components/robots/robotModelLogic.d.ts +11 -9
  118. package/dist/components/utils/hooks.d.ts +1 -6
  119. package/dist/core.cjs +1 -1
  120. package/dist/core.d.ts +13 -18
  121. package/dist/core.js +37 -51
  122. package/dist/index.cjs +1 -1
  123. package/dist/index.js +58 -71
  124. package/dist/lib/ConnectedMotionGroup.d.ts +5 -7
  125. package/dist/lib/JoggerConnection.d.ts +137 -27
  126. package/dist/lib/MotionStreamConnection.d.ts +15 -6
  127. package/dist/lib/Pose3.d.ts +22 -0
  128. package/dist/lib/PoseTransformer.d.ts +25 -0
  129. package/dist/lib/TrajectoryExecutionStore.d.ts +129 -0
  130. package/dist/lib/connectionLogger.d.ts +9 -0
  131. package/dist/lib/incrementalCartesianMotion.d.ts +40 -0
  132. package/dist/lib/motionStateUpdate.d.ts +27 -0
  133. package/dist/lib/novaConnection.d.ts +23 -0
  134. package/dist/lib/planErrorTranslation.d.ts +8 -0
  135. package/dist/lib/rotation.d.ts +12 -0
  136. package/package.json +31 -66
  137. package/dist/Setup.d.ts +0 -11
  138. package/dist/chunks/MotionGroupVisualizer-DshWR1wY.js +0 -1653
  139. package/dist/chunks/MotionGroupVisualizer-eD7yFEcF.cjs +0 -1
  140. package/dist/chunks/SafetyBar-DPrv_OQA.cjs +0 -1
  141. package/dist/chunks/externalizeComponent-EDymnaGR.js +0 -268
  142. package/dist/chunks/externalizeComponent-OO4jcrz5.cjs +0 -2
  143. package/dist/chunks/theming-DfSy4-Ic.cjs +0 -4
  144. package/dist/chunks/theming-mF9Rt8SS.js +0 -5542
  145. package/dist/chunks/useSmoothedMotionState-DyDgSVYX.js +0 -478
  146. package/dist/chunks/useSmoothedMotionState-VYxEIyfr.cjs +0 -1
  147. package/dist/components/3d-viewport/CoordinateSystemTransform.d.ts +0 -11
  148. package/dist/components/AdornedTextField.d.ts +0 -7
  149. package/dist/components/CopyableText.d.ts +0 -6
  150. package/dist/components/CycleTimer/CycleTimer.d.ts +0 -3
  151. package/dist/components/CycleTimer/DefaultVariant.d.ts +0 -9
  152. package/dist/components/CycleTimer/SmallVariant.d.ts +0 -10
  153. package/dist/components/CycleTimer/index.d.ts +0 -27
  154. package/dist/components/CycleTimer/types.d.ts +0 -49
  155. package/dist/components/CycleTimer/useAnimations.d.ts +0 -14
  156. package/dist/components/CycleTimer/useTimerLogic.d.ts +0 -24
  157. package/dist/components/CycleTimer/utils.d.ts +0 -21
  158. package/dist/components/CycleTimer.d.ts +0 -3
  159. package/dist/components/DataGrid.d.ts +0 -66
  160. package/dist/components/LogPanel.d.ts +0 -38
  161. package/dist/components/LogStore.d.ts +0 -12
  162. package/dist/components/LogViewer.d.ts +0 -46
  163. package/dist/components/ProgramControl.d.ts +0 -55
  164. package/dist/components/ProgramStateIndicator.d.ts +0 -26
  165. package/dist/components/RobotCard.d.ts +0 -98
  166. package/dist/components/RobotListItem.d.ts +0 -34
  167. package/dist/components/RobotSetupReadinessIndicator.d.ts +0 -37
  168. package/dist/components/SelectableFab.d.ts +0 -7
  169. package/dist/components/TabBar.d.ts +0 -45
  170. package/dist/components/ThemeSelect.d.ts +0 -6
  171. package/dist/components/Timer/Timer.d.ts +0 -3
  172. package/dist/components/Timer/TimerDefaultVariant.d.ts +0 -9
  173. package/dist/components/Timer/TimerSmallVariant.d.ts +0 -10
  174. package/dist/components/Timer/index.d.ts +0 -19
  175. package/dist/components/Timer/types.d.ts +0 -35
  176. package/dist/components/Timer/useTimerAnimations.d.ts +0 -10
  177. package/dist/components/Timer/useTimerLogic.d.ts +0 -19
  178. package/dist/components/Timer/utils.d.ts +0 -17
  179. package/dist/components/Timer.d.ts +0 -3
  180. package/dist/components/TransparentOverlay.d.ts +0 -4
  181. package/dist/components/jogging/JoggingFreedriveTab.d.ts +0 -1
  182. package/dist/components/jogging/PoseCartesianValues.d.ts +0 -9
  183. package/dist/components/jogging/PoseJointValues.d.ts +0 -8
  184. package/dist/components/robots/AxisConfig.d.ts +0 -2
  185. package/dist/components/robots/manufacturerHomePositions.d.ts +0 -20
  186. package/dist/icons/DropdownArrowIcon.d.ts +0 -2
  187. package/dist/icons/index.d.ts +0 -12
  188. package/dist/lib/novaCompat.d.ts +0 -16
  189. package/dist/themes/createDarkTheme.d.ts +0 -7
  190. package/dist/themes/themeTypes.d.ts +0 -40
  191. package/dist/themes/theming.d.ts +0 -24
@@ -0,0 +1,3398 @@
1
+ import { jsxs as y, Fragment as et, jsx as c } from "react/jsx-runtime";
2
+ import Wt from "@mui/material/AppBar";
3
+ import Tt from "@mui/material/Backdrop";
4
+ import F from "@mui/material/Box";
5
+ import qt from "@mui/material/Menu";
6
+ import $ from "@mui/material/MenuItem";
7
+ import Ht from "@mui/material/Toolbar";
8
+ import _ from "@mui/material/Typography";
9
+ import { ZeroGravityComponentsBackdropFill as Kt } from "@wandelbots/design-tokens";
10
+ import { ExpandMoreFilled as Yt } from "@wandelbots/icons/ExpandMoreFilled";
11
+ import { RoundedIconButton as Qt } from "@wandelbots/mui";
12
+ import { observer as M, useLocalObservable as kt } from "mobx-react-lite";
13
+ import * as v from "react";
14
+ import { useState as Z, forwardRef as z, useEffect as ot, useRef as at, useId as Zt } from "react";
15
+ import { e as X } from "./externalizeComponent-_w2d1_pz.js";
16
+ import Xt from "@mui/icons-material/OpenWith";
17
+ import te from "@mui/icons-material/Share";
18
+ import x from "@mui/material/Stack";
19
+ import ee from "@mui/material/Tab";
20
+ import oe from "@mui/material/Tabs";
21
+ import { runInAction as S, makeAutoObservable as st, computed as ie, when as it, autorun as bt, reaction as ne } from "mobx";
22
+ import { useTranslation as V } from "react-i18next";
23
+ import { radiansToDegrees as Ot, tryParseJson as J, XYZ_TO_VECTOR as Ct, degreesToRadians as re } from "@wandelbots/nova-js";
24
+ import { JointTypeEnum as N } from "@wandelbots/nova-js/v2";
25
+ import * as vt from "three";
26
+ import { Quaternion as L, Vector3 as P } from "three";
27
+ import { d as pt, c as Y, e as ct } from "./useSmoothedMotionState-COMJRcOt.js";
28
+ import Rt from "@mui/material/CircularProgress";
29
+ import { capitalize as ae } from "@mui/material/utils";
30
+ import { lowerFirst as se, countBy as le } from "lodash-es";
31
+ import { m as ce } from "./SafetyBar-Cuak4ffd.js";
32
+ import de from "@mui/material/Alert";
33
+ import ge from "@mui/material/AlertTitle";
34
+ import dt from "@mui/material/Button";
35
+ import { useTheme as U, styled as Jt } from "@mui/material/styles";
36
+ import B from "@mui/material/Divider";
37
+ import xt from "@mui/material/ToggleButton";
38
+ import nt from "@mui/material/IconButton";
39
+ import { e as It, v as he, c as lt } from "./joggingColors-CuT5u0H8.js";
40
+ import me from "lodash-es/isEqual.js";
41
+ import ue from "@mui/material/InputAdornment";
42
+ import pe from "@mui/material/FormControl";
43
+ import fe from "@mui/material/InputLabel";
44
+ import ye from "@mui/material/Select";
45
+ import K from "lodash-es/keyBy.js";
46
+ import Se from "lodash-es/uniqueId.js";
47
+ import be from "@mui/material/ToggleButtonGroup";
48
+ import At from "@mui/material/Slider";
49
+ import Ce from "lodash-es/isNumber.js";
50
+ import ve from "@mui/icons-material/ChevronLeft";
51
+ import xe from "@mui/icons-material/ChevronRight";
52
+ import Ie from "lodash-es/throttle.js";
53
+ import _e from "@mui/material/Dialog";
54
+ import we from "@mui/material/DialogActions";
55
+ import je from "@mui/material/DialogContent";
56
+ import Ee from "@mui/material/DialogTitle";
57
+ const vi = X(
58
+ M((e) => {
59
+ const {
60
+ appIcon: t,
61
+ appName: o,
62
+ apps: i = [],
63
+ onAppSelect: n,
64
+ disabled: r = !1,
65
+ sx: a
66
+ } = e, [s, h] = Z(null), m = !!s, g = (l) => {
67
+ h(l.currentTarget);
68
+ }, u = () => {
69
+ h(null);
70
+ }, d = (l) => {
71
+ u(), l.onClick ? l.onClick() : l.href && (window.location.href = l.href), n == null || n(l);
72
+ };
73
+ return /* @__PURE__ */ y(et, { children: [
74
+ /* @__PURE__ */ c(
75
+ Wt,
76
+ {
77
+ position: "static",
78
+ sx: {
79
+ boxShadow: "none",
80
+ backgroundImage: "none",
81
+ "& .MuiAppBar-root": {
82
+ backgroundImage: "none",
83
+ backgroundColor: "transparent"
84
+ },
85
+ ...a
86
+ },
87
+ children: /* @__PURE__ */ y(Ht, { sx: { minHeight: "62px !important" }, children: [
88
+ /* @__PURE__ */ c(F, { sx: { mr: 1, display: "flex", alignItems: "center" }, children: t }),
89
+ /* @__PURE__ */ y(F, { sx: { display: "flex", alignItems: "center", flexGrow: 1 }, children: [
90
+ /* @__PURE__ */ c(_, { component: "h1", variant: "subtitle1", children: o }),
91
+ i.length > 0 && /* @__PURE__ */ c(
92
+ Qt,
93
+ {
94
+ icon: /* @__PURE__ */ c(Yt, { size: 20 }),
95
+ ariaLabel: "switch app",
96
+ "aria-controls": "app-menu",
97
+ "aria-haspopup": "true",
98
+ onClick: g,
99
+ disabled: r,
100
+ sx: { ml: 1 }
101
+ }
102
+ )
103
+ ] })
104
+ ] })
105
+ }
106
+ ),
107
+ /* @__PURE__ */ c(
108
+ Tt,
109
+ {
110
+ open: m,
111
+ onClick: u,
112
+ sx: {
113
+ backdropFilter: "blur(4px)",
114
+ backgroundColor: Kt,
115
+ zIndex: (l) => l.zIndex.modal - 1
116
+ }
117
+ }
118
+ ),
119
+ /* @__PURE__ */ c(
120
+ qt,
121
+ {
122
+ id: "app-menu",
123
+ anchorEl: s,
124
+ open: m,
125
+ onClose: u,
126
+ anchorOrigin: {
127
+ vertical: "bottom",
128
+ horizontal: "left"
129
+ },
130
+ transformOrigin: {
131
+ vertical: "top",
132
+ horizontal: "left"
133
+ },
134
+ sx: {
135
+ zIndex: (l) => l.zIndex.modal,
136
+ "& .MuiPaper-root": {
137
+ minWidth: 200,
138
+ mt: 1
139
+ }
140
+ },
141
+ children: i.map((l) => /* @__PURE__ */ y($, { onClick: () => d(l), children: [
142
+ /* @__PURE__ */ c(F, { sx: { display: "flex", alignItems: "center" }, children: l.icon }),
143
+ /* @__PURE__ */ c(_, { variant: "body1", sx: { ml: 2 }, children: l.name })
144
+ ] }, l.id))
145
+ }
146
+ )
147
+ ] });
148
+ })
149
+ ), Me = ({
150
+ title: e,
151
+ titleId: t,
152
+ ...o
153
+ }, i) => /* @__PURE__ */ v.createElement("svg", { width: 21, height: 21, viewBox: "0 0 21 21", fill: "none", xmlns: "http://www.w3.org/2000/svg", ref: i, "aria-labelledby": t, ...o }, e ? /* @__PURE__ */ v.createElement("title", { id: t }, e) : null, /* @__PURE__ */ v.createElement("g", { id: "JogMinus" }, /* @__PURE__ */ v.createElement("path", { id: "Minus", d: "M0 13V8H21V13H0Z", fill: "white" }))), Te = z(Me), ke = ({
154
+ title: e,
155
+ titleId: t,
156
+ ...o
157
+ }, i) => /* @__PURE__ */ v.createElement("svg", { width: 21, height: 21, viewBox: "0 0 21 21", fill: "none", xmlns: "http://www.w3.org/2000/svg", ref: i, "aria-labelledby": t, ...o }, e ? /* @__PURE__ */ v.createElement("title", { id: t }, e) : null, /* @__PURE__ */ v.createElement("g", { id: "JogPlus" }, /* @__PURE__ */ v.createElement("g", { id: "Plus" }, /* @__PURE__ */ v.createElement("path", { d: "M0 13V8H8V13H0Z", fill: "white" }), /* @__PURE__ */ v.createElement("path", { d: "M8 0L13 2.18557e-07L13 21H8L8 0Z", fill: "white" }), /* @__PURE__ */ v.createElement("path", { d: "M13 13V8H21V13H13Z", fill: "white" })))), Oe = z(ke), _t = X(
158
+ M(
159
+ ({
160
+ colors: e,
161
+ label: t,
162
+ getDisplayedValue: o,
163
+ startJogging: i,
164
+ stopJogging: n,
165
+ disabled: r,
166
+ activeJoggingDirection: a,
167
+ ...s
168
+ }) => {
169
+ var T, k, O, I, R, G, W;
170
+ pt(() => {
171
+ const A = o(), D = d.current;
172
+ D && (D.textContent = A);
173
+ });
174
+ const h = U(), [m, g] = Z(null);
175
+ ot(() => {
176
+ r && j();
177
+ }, [r]);
178
+ const u = a || m, d = at(null);
179
+ e || (e = {
180
+ color: "#fff",
181
+ backgroundColor: "#000",
182
+ borderColor: "#000",
183
+ buttonBackgroundColor: {
184
+ disabled: "#000",
185
+ default: "#000",
186
+ hovered: "#000",
187
+ pressed: "#000"
188
+ },
189
+ labelColor: "#000"
190
+ });
191
+ const l = u ? (T = e.buttonBackgroundColor) == null ? void 0 : T.pressed : e.borderColor, f = {
192
+ width: "55px",
193
+ color: e.color,
194
+ path: { fill: e.color },
195
+ alignContent: "center",
196
+ fontSize: "37px",
197
+ svg: {
198
+ pointerEvents: "none"
199
+ }
200
+ }, p = {
201
+ ...f,
202
+ backgroundColor: (k = e.buttonBackgroundColor) == null ? void 0 : k.default,
203
+ ":hover": {
204
+ backgroundColor: (O = e.buttonBackgroundColor) == null ? void 0 : O.hovered
205
+ },
206
+ ":active": {
207
+ backgroundColor: (I = e.buttonBackgroundColor) == null ? void 0 : I.pressed,
208
+ color: e.backgroundColor,
209
+ path: { fill: e.backgroundColor }
210
+ },
211
+ ":disabled": {
212
+ backgroundColor: (R = e.buttonBackgroundColor) == null ? void 0 : R.disabled,
213
+ "svg path": { fill: h.palette.action.disabled }
214
+ }
215
+ }, C = {
216
+ ...f,
217
+ backgroundColor: (G = e.buttonBackgroundColor) == null ? void 0 : G.pressed,
218
+ color: e.backgroundColor,
219
+ path: { fill: e.backgroundColor },
220
+ ":disabled": {
221
+ backgroundColor: (W = e.buttonBackgroundColor) == null ? void 0 : W.pressed,
222
+ "svg path": { fill: h.palette.action.disabled }
223
+ }
224
+ };
225
+ function E(A, D) {
226
+ r || A.button === 0 && (g(D), i(D));
227
+ }
228
+ function j() {
229
+ g(null), n();
230
+ }
231
+ return /* @__PURE__ */ y(x, { height: "64px", direction: "row", justifyContent: "center", ...s, children: [
232
+ /* @__PURE__ */ c(
233
+ nt,
234
+ {
235
+ disabled: r,
236
+ disableRipple: !0,
237
+ onPointerDown: (A) => E(A, "-"),
238
+ onPointerUp: j,
239
+ onPointerOut: j,
240
+ size: "large",
241
+ sx: {
242
+ ...u === "-" ? C : p,
243
+ borderRadius: "16px 0px 0px 16px",
244
+ borderLeft: `2px solid ${l ?? "#fff"}`,
245
+ borderBottom: `2px solid ${l ?? "#fff"}`,
246
+ borderTop: `2px solid ${l ?? "#fff"}`
247
+ },
248
+ children: /* @__PURE__ */ c(Te, {})
249
+ }
250
+ ),
251
+ /* @__PURE__ */ y(
252
+ x,
253
+ {
254
+ spacing: "6px",
255
+ sx: {
256
+ width: "150px",
257
+ backgroundColor: e.backgroundColor,
258
+ alignItems: "center",
259
+ justifyContent: "center",
260
+ opacity: "0.9",
261
+ borderBottom: `2px solid ${l ?? "#fff"}`,
262
+ borderTop: `2px solid ${l ?? "#fff"}`
263
+ },
264
+ children: [
265
+ /* @__PURE__ */ c(
266
+ x,
267
+ {
268
+ height: "22px",
269
+ direction: "row",
270
+ alignItems: "center",
271
+ justifyItems: "center",
272
+ spacing: 1,
273
+ sx: {
274
+ userSelect: "none",
275
+ color: e.color,
276
+ ".MuiTypography-root": {
277
+ fontWeight: 700,
278
+ ...r ? { color: h.palette.action.disabled } : {}
279
+ },
280
+ ...r ? { "svg path": { fill: h.palette.action.disabled } } : {}
281
+ },
282
+ children: t
283
+ }
284
+ ),
285
+ /* @__PURE__ */ c(
286
+ _,
287
+ {
288
+ height: "22px",
289
+ sx: {
290
+ fontSize: "15px",
291
+ color: r ? h.palette.action.disabled : e.color,
292
+ fontWeight: 700,
293
+ fontVariantNumeric: "tabular-nums",
294
+ minWidth: "80px",
295
+ textAlign: "center"
296
+ },
297
+ ref: d,
298
+ children: o()
299
+ }
300
+ )
301
+ ]
302
+ }
303
+ ),
304
+ /* @__PURE__ */ c(
305
+ nt,
306
+ {
307
+ disableRipple: !0,
308
+ disabled: r,
309
+ onPointerDown: (A) => E(A, "+"),
310
+ onPointerUp: j,
311
+ onPointerOut: j,
312
+ size: "large",
313
+ sx: {
314
+ ...u === "+" ? C : p,
315
+ borderRadius: "0px 16px 16px 0px",
316
+ borderRight: `2px solid ${l ?? "#fff"}`,
317
+ borderBottom: `2px solid ${l ?? "#fff"}`,
318
+ borderTop: `2px solid ${l ?? "#fff"}`
319
+ },
320
+ children: /* @__PURE__ */ c(Oe, {})
321
+ }
322
+ )
323
+ ] });
324
+ }
325
+ )
326
+ ), Re = X(
327
+ M(
328
+ ({
329
+ startJogging: e,
330
+ stopJogging: t,
331
+ lowerLimit: o,
332
+ upperLimit: i,
333
+ useDegree: n,
334
+ getValue: r,
335
+ disabled: a,
336
+ ...s
337
+ }) => {
338
+ var I, R, G, W, A, D, St;
339
+ const { t: h } = V(), [m, g] = Z(), u = U(), d = {
340
+ background: (I = u.palette.backgroundPaperElevation) == null ? void 0 : I[4],
341
+ color: (R = u.palette.backgroundPaperElevation) == null ? void 0 : R[11]
342
+ }, l = kt(() => ({
343
+ activeJoggingDir: null,
344
+ startJogging(b) {
345
+ this.activeJoggingDir = b, e(b);
346
+ },
347
+ stopJogging() {
348
+ this.activeJoggingDir = null, t();
349
+ }
350
+ })), f = Ie(() => {
351
+ const b = n ? p(r()) : r();
352
+ (b === void 0 || m === void 0 || Math.abs(m - b) > 1e-9) && g(b);
353
+ }, 50);
354
+ pt(f);
355
+ function p(b) {
356
+ if (b !== void 0)
357
+ return Ot(b);
358
+ }
359
+ function C(b) {
360
+ b.button === 0 && l.startJogging("-");
361
+ }
362
+ function E(b) {
363
+ b.button === 0 && l.startJogging("+");
364
+ }
365
+ function j(b) {
366
+ l.stopJogging();
367
+ }
368
+ function T(b) {
369
+ l.stopJogging();
370
+ }
371
+ function k(b, q = 1) {
372
+ if (b === void 0 || Number.isNaN(b)) return "";
373
+ const H = h("General.degree.variable", {
374
+ amount: b.toFixed(q)
375
+ });
376
+ return b > 0 && q === 0 ? `+${H}` : H;
377
+ }
378
+ function O(b, q = 1) {
379
+ if (b === void 0 || Number.isNaN(b)) return "";
380
+ const H = h("General.mm.variable", {
381
+ amount: b.toFixed(q)
382
+ });
383
+ return b > 0 && q === 0 ? `+${H}` : H;
384
+ }
385
+ return /* @__PURE__ */ y(
386
+ x,
387
+ {
388
+ height: "64px",
389
+ width: "100%",
390
+ maxWidth: "260px",
391
+ direction: "row",
392
+ ...s,
393
+ sx: {
394
+ "& .MuiIconButton-root": {
395
+ width: "52px",
396
+ color: u.palette.text.primary,
397
+ alignContent: "center",
398
+ backgroundColor: (G = u.palette.backgroundPaperElevation) == null ? void 0 : G[11],
399
+ "& svg": {
400
+ width: "42px",
401
+ height: "42px"
402
+ },
403
+ "&.Mui-disabled": {
404
+ backgroundColor: (W = u.palette.backgroundPaperElevation) == null ? void 0 : W[11],
405
+ color: u.palette.action.disabled,
406
+ opacity: 1
407
+ },
408
+ "&:hover": {
409
+ backgroundColor: (A = u.palette.backgroundPaperElevation) == null ? void 0 : A[9]
410
+ },
411
+ "&:active": {
412
+ ...d
413
+ }
414
+ }
415
+ },
416
+ children: [
417
+ /* @__PURE__ */ c(
418
+ nt,
419
+ {
420
+ onPointerDown: C,
421
+ onPointerUp: j,
422
+ onPointerOut: T,
423
+ disabled: a,
424
+ disableRipple: !0,
425
+ sx: {
426
+ borderRadius: "16px 0px 0px 16px",
427
+ ...l.activeJoggingDir === "-" ? d : {}
428
+ },
429
+ children: /* @__PURE__ */ c(
430
+ ve,
431
+ {
432
+ sx: {
433
+ pointerEvents: "none",
434
+ color: It
435
+ }
436
+ }
437
+ )
438
+ }
439
+ ),
440
+ /* @__PURE__ */ y(
441
+ x,
442
+ {
443
+ flexGrow: 1,
444
+ alignItems: "center",
445
+ justifyContent: "center",
446
+ sx: {
447
+ borderStyle: "solid",
448
+ borderLeftWidth: 0,
449
+ borderRightWidth: 0,
450
+ border: "none",
451
+ backgroundColor: (D = u.palette.backgroundPaperElevation) == null ? void 0 : D[11],
452
+ paddingLeft: "20px",
453
+ paddingRight: "20px",
454
+ zIndex: 1
455
+ },
456
+ children: [
457
+ /* @__PURE__ */ c(
458
+ _,
459
+ {
460
+ sx: {
461
+ fontSize: "15px",
462
+ fontWeight: 700,
463
+ position: "relative",
464
+ top: "5px",
465
+ fontVariantNumeric: "tabular-nums",
466
+ minWidth: "80px",
467
+ textAlign: "center",
468
+ color: a ? u.palette.action.disabled : u.palette.text.primary
469
+ },
470
+ children: n ? k(m) : O(m)
471
+ }
472
+ ),
473
+ /* @__PURE__ */ c(
474
+ At,
475
+ {
476
+ disabled: !0,
477
+ "aria-label": "Joint position",
478
+ min: n ? p(o) : o,
479
+ max: n ? p(i) : i,
480
+ value: m || 0,
481
+ track: !1,
482
+ sx: {
483
+ "& .MuiSlider-mark": {
484
+ display: "none"
485
+ },
486
+ "& .MuiSlider-thumb": {
487
+ width: "5px",
488
+ height: "12px",
489
+ borderRadius: "2px",
490
+ color: a ? u.palette.action.disabled : u.palette.text.primary
491
+ },
492
+ "& .MuiSlider-markLabel": {
493
+ top: "20px",
494
+ fontSize: "12px",
495
+ color: a ? u.palette.action.disabled : u.palette.text.secondary
496
+ },
497
+ "& .MuiSlider-rail": {
498
+ backgroundColor: (St = u.palette.backgroundPaperElevation) == null ? void 0 : St[5],
499
+ opacity: 1
500
+ }
501
+ },
502
+ marks: o !== void 0 && i !== void 0 && [
503
+ {
504
+ value: n ? p(o) : o,
505
+ label: n ? k(p(o), 0) : O(o)
506
+ },
507
+ {
508
+ value: n ? p(i) : i,
509
+ label: n ? k(p(i), 0) : O(i)
510
+ }
511
+ ]
512
+ }
513
+ )
514
+ ]
515
+ }
516
+ ),
517
+ /* @__PURE__ */ c(
518
+ nt,
519
+ {
520
+ onPointerDown: E,
521
+ onPointerUp: j,
522
+ onPointerOut: T,
523
+ disabled: a,
524
+ disableRipple: !0,
525
+ sx: {
526
+ borderRadius: "0px 16px 16px 0px",
527
+ ...l.activeJoggingDir === "+" ? d : {}
528
+ },
529
+ children: /* @__PURE__ */ c(
530
+ xe,
531
+ {
532
+ sx: {
533
+ pointerEvents: "none",
534
+ color: It
535
+ }
536
+ }
537
+ )
538
+ }
539
+ )
540
+ ]
541
+ }
542
+ );
543
+ }
544
+ )
545
+ );
546
+ function Q(e, t) {
547
+ if (t === "QUATERNION" && e)
548
+ return new L(...e);
549
+ if (t === "ROTATION_VECTOR" && e) {
550
+ if (e && e.length < 3)
551
+ throw new Error(
552
+ `Invalid rotation vector length: ${e.length}. Expected at least 3 values.`
553
+ );
554
+ const o = new P(
555
+ e[0],
556
+ e[1],
557
+ e[2]
558
+ ), i = o.length(), n = o.normalize();
559
+ return new L().setFromAxisAngle(n, i);
560
+ } else
561
+ return console.warn(
562
+ `Unsupported rotation type '${t}'. Only QUATERNION and ROTATION_VECTOR are supported for now.`
563
+ ), new L();
564
+ }
565
+ function Pt(e) {
566
+ const t = new P(e.x, e.y, e.z), o = 2 * Math.atan2(t.length(), Math.abs(e.w));
567
+ t.normalize();
568
+ const i = (e.w >= 0 ? 1 : 0) - (e.w < 0 ? 1 : 0);
569
+ return t.multiplyScalar(i).multiplyScalar(o);
570
+ }
571
+ function Je({
572
+ currentTcpPose: e,
573
+ axis: t,
574
+ direction: o,
575
+ motion: i,
576
+ useToolCoordinateSystem: n,
577
+ coordinateSystemRotation: r
578
+ }) {
579
+ const a = o === "-" ? -1 : 1;
580
+ if (i.type === "translate") {
581
+ if (!e.position)
582
+ throw new Error(
583
+ "Current pose has no position, cannot perform translation"
584
+ );
585
+ const u = i.distanceMm * a, d = new P();
586
+ if (d[t] = u, n) {
587
+ if (!e.orientation)
588
+ throw new Error(
589
+ "Current pose has no orientation, cannot translate relative to tool"
590
+ );
591
+ d.applyQuaternion(
592
+ Q(
593
+ e.orientation,
594
+ "ROTATION_VECTOR"
595
+ )
596
+ );
597
+ } else r && d.applyQuaternion(r);
598
+ const l = [...e.position];
599
+ return l[0] = (l[0] ?? 0) + d.x, l[1] = (l[1] ?? 0) + d.y, l[2] = (l[2] ?? 0) + d.z, {
600
+ position: l,
601
+ orientation: e.orientation
602
+ };
603
+ }
604
+ if (!e.orientation)
605
+ throw new Error("Current pose has no orientation, cannot perform rotation");
606
+ const s = Q(
607
+ e.orientation,
608
+ "ROTATION_VECTOR"
609
+ ), h = new P();
610
+ h[t] = 1, !n && r && h.applyQuaternion(r);
611
+ const m = new L().setFromAxisAngle(
612
+ h,
613
+ i.distanceRads * a
614
+ ), g = n ? s.multiply(m) : m.multiply(s);
615
+ return {
616
+ position: e.position,
617
+ orientation: [...Pt(g)]
618
+ };
619
+ }
620
+ function Ae(e, t, o) {
621
+ return t.length !== e.length ? !1 : Dt(e, t, o);
622
+ }
623
+ function Vt(e, t, o) {
624
+ return t.length !== e.length ? !0 : Dt(e, t, o);
625
+ }
626
+ function Dt(e, t, o) {
627
+ for (let i = 0; i < t.length; i++)
628
+ if (Math.abs(
629
+ (t[i] ?? 0) - (e[i] ?? 0)
630
+ ) > o)
631
+ return !1;
632
+ return !0;
633
+ }
634
+ function Pe(e, t, o) {
635
+ if (e === void 0 && t || e && t === void 0 || (e == null ? void 0 : e.orientation) === void 0 || (t == null ? void 0 : t.orientation) === void 0 || (e == null ? void 0 : e.position) === void 0 || (t == null ? void 0 : t.position) === void 0)
636
+ return !1;
637
+ if (e === void 0 || t === void 0)
638
+ return !0;
639
+ let i = 0;
640
+ return i += Math.abs(e.orientation[0] - t.orientation[0]), i += Math.abs(e.orientation[1] - t.orientation[1]), i += Math.abs(e.orientation[2] - t.orientation[2]), i += Math.abs(e.position[0] - t.position[0]), i += Math.abs(e.position[1] - t.position[1]), i += Math.abs(e.position[2] - t.position[2]), i <= o;
641
+ }
642
+ function Nt(e, t, o) {
643
+ return e.coordinate_system === t.coordinate_system && e.tcp === t.tcp && Pe(
644
+ e.tcp_pose,
645
+ t.tcp_pose,
646
+ o
647
+ );
648
+ }
649
+ function Ve(e, t) {
650
+ const o = new P(
651
+ t[0],
652
+ t[1],
653
+ t[2]
654
+ ), i = new P(
655
+ e[0],
656
+ e[1],
657
+ e[2]
658
+ ), n = o.length(), r = o.normalize();
659
+ let a = i.length(), s = i.normalize();
660
+ s.dot(r) < 0 && (a = -a, s = s.multiplyScalar(-1));
661
+ let h = a - n;
662
+ return h -= 2 * Math.PI * Math.floor((h + Math.PI) / (2 * Math.PI)), a = n + h, [...s.multiplyScalar(a)];
663
+ }
664
+ const De = 2e-4;
665
+ function Ne(e) {
666
+ const { joint_position: t, tcp_pose: o, tcp: i, coordinate_system: n } = e;
667
+ return { joint_position: t, tcp_pose: o, tcp: i, coordinate_system: n };
668
+ }
669
+ function Fe(e, t) {
670
+ return e.tcp === t.tcp && e.coordinate_system === t.coordinate_system && e.tcp_pose === void 0 == (t.tcp_pose === void 0) && Ae(
671
+ e.joint_position,
672
+ t.joint_position,
673
+ De
674
+ );
675
+ }
676
+ const wt = 1e-4;
677
+ class ft {
678
+ constructor(t, o, i, n, r, a, s = "cell", h = {}) {
679
+ this.controller = o, this.motionGroup = i, this.description = n, this.initialMotionState = r, this.motionStateSocket = a, this.cellId = s, this.nova = Y(t), this.logger = h.logger ?? console, this.rapidlyChangingMotionState = r, a.addEventListener("message", (m) => {
680
+ var l;
681
+ const g = (l = J(m.data)) == null ? void 0 : l.result;
682
+ if (!g)
683
+ throw new Error(
684
+ `Failed to get motion state for ${this.motionGroupId}: ${m.data}`
685
+ );
686
+ Nt(
687
+ this.rapidlyChangingMotionState,
688
+ g,
689
+ wt
690
+ ) || S(() => {
691
+ var f, p, C;
692
+ this.rapidlyChangingMotionState.tcp_pose == null ? this.rapidlyChangingMotionState.tcp_pose = g.tcp_pose : (f = g.tcp_pose) != null && f.orientation && ((p = g.tcp_pose) != null && p.position) && ((C = this.rapidlyChangingMotionState.tcp_pose) != null && C.orientation) ? this.rapidlyChangingMotionState.tcp_pose = {
693
+ position: g.tcp_pose.position,
694
+ orientation: Ve(
695
+ g.tcp_pose.orientation,
696
+ this.rapidlyChangingMotionState.tcp_pose.orientation
697
+ )
698
+ } : this.logger.debug("Received incomplete tcp_pose, ignoring", {
699
+ tcpPose: g.tcp_pose
700
+ });
701
+ }), Vt(
702
+ this.rapidlyChangingMotionState.joint_position,
703
+ g.joint_position,
704
+ wt
705
+ ) || S(() => {
706
+ this.rapidlyChangingMotionState.joint_position = g.joint_position;
707
+ }), g.tcp !== void 0 && this.rapidlyChangingMotionState.tcp !== g.tcp && S(() => {
708
+ this.rapidlyChangingMotionState.tcp = g.tcp;
709
+ }), this.rapidlyChangingMotionState.standstill !== g.standstill && S(() => {
710
+ this.rapidlyChangingMotionState.standstill = g.standstill;
711
+ });
712
+ const u = this.rapidlyChangingMotionState.joint_limit_reached.limit_reached, d = g.joint_limit_reached.limit_reached;
713
+ u.some((f, p) => f !== d[p]) && S(() => {
714
+ this.rapidlyChangingMotionState.joint_limit_reached = g.joint_limit_reached;
715
+ }), this.rapidlyChangingMotionState.execute !== g.execute && S(() => {
716
+ this.rapidlyChangingMotionState.execute = g.execute;
717
+ });
718
+ }), st(this, {
719
+ logger: !1,
720
+ // keepAlive: pose readouts poll it from requestAnimationFrame, which
721
+ // MobX does not track, and a computed nobody observes is recomputed on
722
+ // every read without consulting `equals`
723
+ readoutState: ie({ equals: Fe, keepAlive: !0 })
724
+ });
725
+ }
726
+ static async open(t, o, i = {}) {
727
+ var p;
728
+ const n = Y(t), r = i.cellId ?? ct(t) ?? "cell", [a, s] = o.split("@"), h = await n.api.controller.getCurrentRobotControllerState(
729
+ r,
730
+ s
731
+ ), m = h == null ? void 0 : h.motion_groups.find(
732
+ (C) => C.motion_group === o
733
+ );
734
+ if (!h || !m)
735
+ throw new Error(
736
+ `Controller ${s} or motion group ${o} not found`
737
+ );
738
+ const g = n.openReconnectingWebsocket(
739
+ `/cells/${r}/controllers/${s}/motion-groups/${o}/state-stream`
740
+ ), u = await g.firstMessage(), d = (p = J(u.data)) == null ? void 0 : p.result;
741
+ if (!d)
742
+ throw new Error(
743
+ `Unable to parse initial motion state message ${u.data}`
744
+ );
745
+ const l = i.logger ?? console;
746
+ l.info("Connected motion state websocket to motion group", {
747
+ motionGroup: m.motion_group,
748
+ initialMotionState: d
749
+ });
750
+ const f = await n.api.motionGroup.getMotionGroupDescription(
751
+ r,
752
+ s,
753
+ m.motion_group
754
+ );
755
+ return new ft(
756
+ n,
757
+ h,
758
+ m,
759
+ f,
760
+ d,
761
+ g,
762
+ r,
763
+ { logger: l }
764
+ );
765
+ }
766
+ /**
767
+ * What pose readouts show (joints, TCP pose): it holds the previous reading
768
+ * while the joints only jitter, see {@link readoutsEqual}. Kept alive, so it
769
+ * also holds for untracked reads, e.g. from requestAnimationFrame.
770
+ */
771
+ get readoutState() {
772
+ return Ne(this.rapidlyChangingMotionState);
773
+ }
774
+ get motionGroupId() {
775
+ return this.motionGroup.motion_group;
776
+ }
777
+ get controllerId() {
778
+ return this.controller.controller;
779
+ }
780
+ get joints() {
781
+ return this.initialMotionState.joint_position.map((t, o) => ({
782
+ index: o
783
+ }));
784
+ }
785
+ dispose() {
786
+ this.motionStateSocket.close();
787
+ }
788
+ }
789
+ class w {
790
+ constructor(t, o) {
791
+ this.position = t, this.quaternion = o;
792
+ }
793
+ static fromPose(t) {
794
+ const o = t.orientation ? Q(t.orientation, "ROTATION_VECTOR") : new L(), i = t.position ?? [0, 0, 0];
795
+ return new w(
796
+ new P(i[0] ?? 0, i[1] ?? 0, i[2] ?? 0),
797
+ o
798
+ );
799
+ }
800
+ /** A TCP's offset from the flange */
801
+ static fromRobotTcp(t) {
802
+ const o = t.orientation ? Q(
803
+ t.orientation,
804
+ t.orientation_type ?? "ROTATION_VECTOR"
805
+ ) : new L(), i = t.position ?? [0, 0, 0];
806
+ return new w(
807
+ new P(i[0] ?? 0, i[1] ?? 0, i[2] ?? 0),
808
+ o
809
+ );
810
+ }
811
+ static fromCoordinateSystem(t) {
812
+ const o = t.orientation ? Q(
813
+ t.orientation,
814
+ t.orientation_type ?? "ROTATION_VECTOR"
815
+ ) : new L(), i = t.position ?? [0, 0, 0];
816
+ return new w(
817
+ new P(i[0] ?? 0, i[1] ?? 0, i[2] ?? 0),
818
+ o
819
+ );
820
+ }
821
+ inverse() {
822
+ const t = this.quaternion.clone().invert();
823
+ return new w(
824
+ this.position.clone().applyQuaternion(t).multiplyScalar(-1),
825
+ t
826
+ );
827
+ }
828
+ multiply(t) {
829
+ return new w(
830
+ this.position.clone().add(t.position.clone().applyQuaternion(this.quaternion)),
831
+ this.quaternion.clone().multiply(t.quaternion).normalize()
832
+ );
833
+ }
834
+ get orientation() {
835
+ return Pt(this.quaternion);
836
+ }
837
+ }
838
+ const jt = "Movement request rejected. Another client is currently executing a 'Jogging' motion!", Le = 500, $e = 5e3;
839
+ function Be(e) {
840
+ var o;
841
+ return (((o = e.times) == null ? void 0 : o[e.times.length - 1]) ?? 0) * 2e3 + $e;
842
+ }
843
+ class yt {
844
+ constructor(t, o = {}) {
845
+ this.motionStream = t, this.options = o, this.DEFAULT_MODE = "off", this.DEFAULT_TCP = "Flange", this.NO_TCP = void 0, this.DEFAULT_INIT_TIMEOUT = 5e3, this.DEFAULT_ORIENTATION = "coordsys", this.mode = "off", this.joggingSocket = null, this.trajectorySocket = null, this.timeout = this.DEFAULT_INIT_TIMEOUT, this.incrementalMotionInFlight = !1, this.ownsMotionStream = !1, this.tcp = (o == null ? void 0 : o.tcp) || t.motionGroup.tcp || this.getDefaultTcp(t), this.coordinateSystem = o == null ? void 0 : o.coordinateSystem, this.orientation = (o == null ? void 0 : o.orientation) || this.DEFAULT_ORIENTATION, this.timeout = (o == null ? void 0 : o.timeout) || this.DEFAULT_INIT_TIMEOUT, this.mode = (o == null ? void 0 : o.mode) || this.DEFAULT_MODE, this.onError = o == null ? void 0 : o.onError, this.logger = (o == null ? void 0 : o.logger) ?? console;
846
+ }
847
+ /**
848
+ * Initialize the jogging connection using jogging endpoint or trajectory endpoint depending on the selected mode.
849
+ *
850
+ * @param connection - The base URL of a NOVA instance, or a NOVA client of the app (see `NovaConnection`)
851
+ * @param motionGroupId - The ID of the motion group to connect to
852
+ * @param options - Configuration options for the jogger connection
853
+ * @param options.mode - The jogging mode to initialize:
854
+ * - "jogging": Continuous jogging mode with persistent websocket for real-time velocity commands
855
+ * - "trajectory": Incremental jogging mode for fixed-distance motions via trajectory planning
856
+ * - "off": No jogging enabled, all websockets closed (default)
857
+ * @param options.timeout - Timeout in milliseconds for websocket initialization (default: 5000ms)
858
+ * @param options.tcp - TCP frame to use for motions (default: from motion group)
859
+ * @param options.coordinateSystem - Coordinate system whose axes cartesian jogging moves along, relative to world (default: world)
860
+ * @param options.orientation - If set to "tool", jogging TcpVelocityRequest will use `use_tool_coordinate_system` option (default: "coordsys")
861
+ * @param options.onError - Error handler for websocket errors and step jogs
862
+ * @param options.motionGroupModel - Model name for planning step jogs (default: from the motion group description)
863
+ * @param options.logger - Where the jogger and its motion stream log (default: the console)
864
+ * @returns Promise resolving to initialized JoggerConnection instance. Its
865
+ * `dispose()` also closes the motion stream that this function opens.
866
+ */
867
+ static async open(t, o, i = {}) {
868
+ const n = await ft.open(
869
+ t,
870
+ o,
871
+ {
872
+ cellId: i.cellId,
873
+ logger: i.logger
874
+ }
875
+ ), r = new yt(n, i);
876
+ r.ownsMotionStream = !0;
877
+ try {
878
+ await r.setJoggingMode(r.mode);
879
+ } catch (a) {
880
+ throw r.dispose(), a;
881
+ }
882
+ return r;
883
+ }
884
+ getDefaultTcp(t) {
885
+ var i, n;
886
+ const o = (n = (i = t.description.dh_parameters) == null ? void 0 : i[0]) == null ? void 0 : n.type;
887
+ return t.joints.length < 6 && (o === N.RevoluteJoint || o === N.PrismaticJoint) ? this.NO_TCP : this.DEFAULT_TCP;
888
+ }
889
+ // Set a new tcp or other options. If current mode is jogging, will reinitialize the jogging websocket
890
+ async setOptions(t) {
891
+ return t.tcp && (this.tcp = t.tcp), t.orientation && (this.orientation = t.orientation), "coordinateSystem" in t && (this.coordinateSystem = t.coordinateSystem), t.timeout && (this.timeout = t.timeout), t.mode && (this.mode = t.mode), t.onError && (this.onError = t.onError), this.setJoggingMode(this.mode, !1);
892
+ }
893
+ get motionGroupId() {
894
+ return this.motionStream.motionGroupId;
895
+ }
896
+ /**
897
+ * The library's own NOVA client of the motion stream
898
+ * @internal
899
+ */
900
+ get nova() {
901
+ return this.motionStream.nova;
902
+ }
903
+ get cellId() {
904
+ return this.motionStream.cellId;
905
+ }
906
+ get numJoints() {
907
+ return this.motionStream.joints.length;
908
+ }
909
+ // get activeJoggingMode() {
910
+ // return this.mode
911
+ // }
912
+ // get activeWebsocket() {
913
+ // return this.mode === "jogging" ? this.joggingSocket : this.trajectorySocket;
914
+ // }
915
+ // Sends stop movement command to robot
916
+ async stop() {
917
+ if (this.joggingSocket) {
918
+ const t = new Array(this.numJoints).fill(0);
919
+ this.joggingSocket.sendJson({
920
+ message_type: "JointVelocityRequest",
921
+ velocity: t
922
+ });
923
+ }
924
+ this.trajectorySocket && this.trajectorySocket.sendJson({
925
+ message_type: "PauseMovementRequest"
926
+ });
927
+ }
928
+ /**
929
+ * Dispose the jogger, closing all open websockets: the jogging websockets,
930
+ * and the motion stream if the jogger opened it (in `open()`). A motion
931
+ * stream given to the constructor stays open: its caller closes it.
932
+ */
933
+ async dispose() {
934
+ const t = this.closeJoggingSockets();
935
+ return this.ownsMotionStream && this.motionStream.dispose(), t;
936
+ }
937
+ /** Closes the jogging and trajectory websockets */
938
+ closeJoggingSockets() {
939
+ var o, i;
940
+ (o = this.endJoggingInit) == null || o.call(this), (i = this.endIncrementalMotion) == null || i.call(this);
941
+ const t = [this.joggingSocket, this.trajectorySocket].filter(
942
+ (n) => n !== null
943
+ );
944
+ return t.forEach((n) => {
945
+ n.dispose();
946
+ }), this.joggingSocket = null, this.trajectorySocket = null, Promise.all(t.map((n) => n.closed()));
947
+ }
948
+ // Activate jogger in one of the supported modes
949
+ // Will iniitialize or close websockets as necessary
950
+ // If mode is unchanged, does nothing (unless skipReinitializeIfSameMode is false)
951
+ async setJoggingMode(t, o = !0) {
952
+ if (!(this.mode === t && o) && (this.closeJoggingSockets(), this.mode = t, this.mode === "jogging"))
953
+ return this.initializeJoggingWebsocket();
954
+ }
955
+ /**
956
+ * Opens the continuous jogging websocket and initializes it; called by
957
+ * `setJoggingMode("jogging")`. The promise settles once:
958
+ * - it resolves when NOVA confirms the initialization (INITIALIZE_RECEIVED),
959
+ * when the jogger closes the websocket before that (`setJoggingMode`,
960
+ * `dispose`), or when an error message goes to `onBlocked` or `onError`;
961
+ * - it rejects on an error message without such a handler, and when NOVA
962
+ * does not confirm the initialization within `timeout` milliseconds.
963
+ */
964
+ async initializeJoggingWebsocket() {
965
+ return new Promise((t, o) => {
966
+ const i = this.nova.openReconnectingWebsocket(
967
+ `/cells/${this.cellId}/controllers/${this.motionStream.controllerId}/execution/jogging`
968
+ );
969
+ this.joggingSocket = i;
970
+ let n = !1;
971
+ const r = setTimeout(() => {
972
+ a(
973
+ new Error(`Jogging initialization timeout after ${this.timeout} ms`)
974
+ );
975
+ }, this.timeout), a = (m) => {
976
+ n || (n = !0, clearTimeout(r), i.removeEventListener("close", h), this.endJoggingInit === s && (this.endJoggingInit = void 0), m ? o(m) : t());
977
+ }, s = () => a(), h = () => {
978
+ i.disposed && a();
979
+ };
980
+ this.endJoggingInit = s, i.addEventListener("close", h), i.addEventListener("message", (m) => {
981
+ var u, d, l;
982
+ const g = J(m.data);
983
+ if (((u = g == null ? void 0 : g.result) == null ? void 0 : u.kind) === "INITIALIZE_RECEIVED") {
984
+ a();
985
+ return;
986
+ }
987
+ if (((d = g == null ? void 0 : g.result) == null ? void 0 : d.kind) === "MOTION_ERROR")
988
+ if (this.onBlocked && ((l = g == null ? void 0 : g.result) != null && l.message.includes(jt))) {
989
+ a(), i.dispose(), this.onBlocked();
990
+ return;
991
+ } else this.onError ? (a(), this.onError(m.data)) : a(new Error(m.data));
992
+ }), i.sendJson({
993
+ message_type: "InitializeJoggingRequest",
994
+ motion_group: this.motionGroupId,
995
+ ...this.tcp ? { tcp: this.tcp } : {}
996
+ });
997
+ });
998
+ }
999
+ /**
1000
+ * Jogging: Start rotation of a single robot joint at the specified velocity
1001
+ */
1002
+ async rotateJoints({
1003
+ joint: t,
1004
+ direction: o,
1005
+ velocityValue: i,
1006
+ velocityUnit: n
1007
+ }) {
1008
+ if (!this.joggingSocket || this.mode !== "jogging")
1009
+ throw new Error(
1010
+ "Joint jogging websocket not connected; create one by setting jogging mode to 'jogging'"
1011
+ );
1012
+ const r = new Array(this.numJoints).fill(0);
1013
+ r[t] = o === "-" ? -i : i, this.joggingSocket.sendJson({
1014
+ message_type: "JointVelocityRequest",
1015
+ velocity: r
1016
+ });
1017
+ }
1018
+ /**
1019
+ * Jogging: Start the TCP moving along a specified axis at a given velocity
1020
+ */
1021
+ async translateTCP({
1022
+ axis: t,
1023
+ direction: o,
1024
+ velocityMmPerSec: i
1025
+ }) {
1026
+ if (!this.joggingSocket || this.mode !== "jogging")
1027
+ throw new Error(
1028
+ "Continuous jogging websocket not connected; create one by setting jogging mode to 'jogging'"
1029
+ );
1030
+ this.joggingSocket.sendJson({
1031
+ message_type: "TcpVelocityRequest",
1032
+ translation: this.velocityAlongAxis(
1033
+ t,
1034
+ o === "-" ? -i : i
1035
+ ),
1036
+ rotation: [0, 0, 0],
1037
+ use_tool_coordinate_system: this.orientation === "tool"
1038
+ });
1039
+ }
1040
+ /**
1041
+ * Jogging: Start the TCP rotating around a specified axis at a given velocity
1042
+ */
1043
+ async rotateTCP({
1044
+ axis: t,
1045
+ direction: o,
1046
+ velocityRadsPerSec: i
1047
+ }) {
1048
+ if (!this.joggingSocket || this.mode !== "jogging")
1049
+ throw new Error(
1050
+ "Continuous jogging websocket not connected; create one by setting jogging mode to 'jogging'"
1051
+ );
1052
+ this.joggingSocket.sendJson({
1053
+ message_type: "TcpVelocityRequest",
1054
+ translation: [0, 0, 0],
1055
+ rotation: this.velocityAlongAxis(
1056
+ t,
1057
+ o === "-" ? -i : i
1058
+ ),
1059
+ use_tool_coordinate_system: this.orientation === "tool"
1060
+ });
1061
+ }
1062
+ /**
1063
+ * Rotation from {@link JoggerConnection.coordinateSystem} into world,
1064
+ * while jogging along its axes. Undefined when jogging along world or tool
1065
+ * axes.
1066
+ */
1067
+ get coordinateSystemRotation() {
1068
+ if (!(this.orientation === "tool" || !this.coordinateSystem))
1069
+ return w.fromCoordinateSystem(this.coordinateSystem).quaternion;
1070
+ }
1071
+ /**
1072
+ * Velocity vector along one axis of the jogging frame. The API takes TCP
1073
+ * velocities in either the tool frame or world, so an axis of
1074
+ * {@link JoggerConnection.coordinateSystem} is rotated into world here.
1075
+ */
1076
+ velocityAlongAxis(t, o) {
1077
+ const i = new P();
1078
+ i[t] = o;
1079
+ const n = this.coordinateSystemRotation;
1080
+ return n && i.applyQuaternion(n), [i.x, i.y, i.z];
1081
+ }
1082
+ /**
1083
+ * Trajectory jogging:
1084
+ *
1085
+ * Move the robot by a fixed distance in a single cartesian
1086
+ * axis, either rotating or translating relative to the TCP.
1087
+ * The axis is one of the tool in tool orientation, else one of
1088
+ * {@link JoggerConnection.coordinateSystem} (default: world).
1089
+ *
1090
+ * Promise resolves only after the motion has completed: once the robot
1091
+ * stands still again, or after a watchdog of twice the planned duration
1092
+ * plus 5 s. A step requested while another one runs is dropped (resolves
1093
+ * at once). Every error (a refused or failed plan, a refused trajectory, an
1094
+ * error of the controller, the watchdog) goes to `onError`, or without it
1095
+ * rejects the promise.
1096
+ */
1097
+ async runIncrementalCartesianMotion(t) {
1098
+ if (this.mode !== "trajectory")
1099
+ throw new Error(
1100
+ "Set jogging mode to 'trajectory' to run incremental cartesian motions"
1101
+ );
1102
+ if (!this.incrementalMotionInFlight) {
1103
+ this.incrementalMotionInFlight = !0;
1104
+ try {
1105
+ const o = await this.planIncrementalCartesianMotion(t);
1106
+ o && await this.executeTrajectory(o);
1107
+ } finally {
1108
+ this.incrementalMotionInFlight = !1;
1109
+ }
1110
+ }
1111
+ }
1112
+ /**
1113
+ * Plan the trajectory for a single incremental jog. Returns undefined when
1114
+ * no trajectory could be produced; the reason (a planner rejection such as a
1115
+ * singularity, or a motion group without a cycle time) is reported through
1116
+ * {@link JoggerConnection.onError} or logged.
1117
+ */
1118
+ async planIncrementalCartesianMotion({
1119
+ currentTcpPose: t,
1120
+ currentJoints: o,
1121
+ velocityInRelevantUnits: i,
1122
+ axis: n,
1123
+ direction: r,
1124
+ motion: a
1125
+ }) {
1126
+ var p, C, E;
1127
+ const s = [], h = Je({
1128
+ currentTcpPose: t,
1129
+ axis: n,
1130
+ direction: r,
1131
+ motion: a,
1132
+ useToolCoordinateSystem: this.orientation === "tool",
1133
+ coordinateSystemRotation: this.coordinateSystemRotation
1134
+ });
1135
+ s.push({
1136
+ limits_override: a.type === "translate" ? { tcp_velocity_limit: i } : { tcp_orientation_velocity_limit: i },
1137
+ path: {
1138
+ path_definition_name: "PathLine",
1139
+ target_pose: {
1140
+ position: h.position,
1141
+ orientation: h.orientation
1142
+ }
1143
+ }
1144
+ });
1145
+ const m = this.motionStream.description;
1146
+ if (m.cycle_time === void 0) {
1147
+ this.logger.warn(
1148
+ "Current motion group has no cycle time, cannot plan jogging motion"
1149
+ );
1150
+ return;
1151
+ }
1152
+ const g = this.motionStream.rapidlyChangingMotionState.tcp, u = g ? (C = (p = m.tcps) == null ? void 0 : p[g]) == null ? void 0 : C.pose : void 0, d = {
1153
+ motion_group_model: ((E = this.options) == null ? void 0 : E.motionGroupModel) ?? m.motion_group_model,
1154
+ cycle_time: m.cycle_time,
1155
+ mounting: m.mounting,
1156
+ tcp_offset: u,
1157
+ // FIXME use proper mode's limits if set
1158
+ global: m.operation_limits.auto_limits
1159
+ }, l = await this.nova.api.trajectoryPlanning.planTrajectory(
1160
+ this.cellId,
1161
+ {
1162
+ motion_group_setup: d,
1163
+ start_joint_position: o,
1164
+ motion_commands: s
1165
+ }
1166
+ ), f = l.response;
1167
+ if (!f)
1168
+ throw new Error(
1169
+ `Failed to plan jogging increment motion ${JSON.stringify(l)}`
1170
+ );
1171
+ if ("error_feedback" in f) {
1172
+ if (this.onError) {
1173
+ this.onError(f);
1174
+ return;
1175
+ }
1176
+ throw new Error(
1177
+ `Failed to plan jogging increment motion: ${JSON.stringify(f.error_feedback)}`
1178
+ );
1179
+ }
1180
+ return f;
1181
+ }
1182
+ /**
1183
+ * Execute a planned trajectory https://portal.wandelbots.io/docs/api/v2/ui/#/operations/executeTrajectory
1184
+ * and resolve once the robot has come to a standstill again, so that the
1185
+ * caller -- and with it the jogging UI's motion lock -- stays blocked for the
1186
+ * whole motion. It also resolves when the jogger closes the websocket
1187
+ * (`setJoggingMode`, `dispose`).
1188
+ *
1189
+ * Each call owns its own websocket. Sharing
1190
+ * {@link JoggerConnection.trajectorySocket} across motions meant a finishing
1191
+ * motion closed the socket of a later one.
1192
+ */
1193
+ async executeTrajectory(t) {
1194
+ const o = this.nova.openReconnectingWebsocket(
1195
+ `/cells/${this.cellId}/controllers/${this.motionStream.controllerId}/execution/trajectory`
1196
+ );
1197
+ this.trajectorySocket = o;
1198
+ const i = new AbortController();
1199
+ let n, r;
1200
+ try {
1201
+ await new Promise((a, s) => {
1202
+ let h = !1;
1203
+ const m = () => {
1204
+ h || (h = !0, a());
1205
+ }, g = (d) => {
1206
+ if (!h) {
1207
+ if (h = !0, this.onError) {
1208
+ this.onError(d), a();
1209
+ return;
1210
+ }
1211
+ s(
1212
+ d instanceof Error ? d : new Error(
1213
+ `Failed to execute trajectory: ${JSON.stringify(d)}`
1214
+ )
1215
+ );
1216
+ }
1217
+ };
1218
+ r = m, this.endIncrementalMotion = m;
1219
+ const u = Be(t);
1220
+ n = setTimeout(() => {
1221
+ g(
1222
+ new Error(`Jogging motion did not complete within ${u}ms`)
1223
+ );
1224
+ }, u), o.addEventListener("message", (d) => {
1225
+ var f, p;
1226
+ const l = (f = J(d.data)) == null ? void 0 : f.result;
1227
+ if (!(l != null && l.kind)) {
1228
+ g(
1229
+ new Error(
1230
+ `Failed to execute trajectory: Received invalid message ${d.data}`
1231
+ )
1232
+ );
1233
+ return;
1234
+ }
1235
+ if (this.onBlocked && ((p = l.message) != null && p.includes(jt))) {
1236
+ this.onBlocked(), m();
1237
+ return;
1238
+ }
1239
+ if (l.kind === "INITIALIZE_RECEIVED") {
1240
+ if (l.add_trajectory_error || l.message) {
1241
+ g(l);
1242
+ return;
1243
+ }
1244
+ o.sendJson({
1245
+ message_type: "StartMovementRequest",
1246
+ direction: "DIRECTION_FORWARD"
1247
+ });
1248
+ } else if (l.kind === "START_RECEIVED") {
1249
+ if (l.message) {
1250
+ g(l);
1251
+ return;
1252
+ }
1253
+ this.waitForMotionToFinish(i.signal).then(m, g);
1254
+ } else l.kind === "PAUSE_RECEIVED" || (l.kind === "MOTION_ERROR" && l.message ? g(l) : g(
1255
+ new Error(
1256
+ `Failed to execute trajectory, cannot handle message type "${l.kind}"`
1257
+ )
1258
+ ));
1259
+ }), o.sendJson({
1260
+ message_type: "InitializeMovementRequest",
1261
+ trajectory: {
1262
+ message_type: "TrajectoryData",
1263
+ motion_group: this.motionGroupId,
1264
+ data: t,
1265
+ tcp: this.tcp
1266
+ }
1267
+ });
1268
+ });
1269
+ } finally {
1270
+ clearTimeout(n), i.abort(), this.endIncrementalMotion === r && (this.endIncrementalMotion = void 0), o.dispose(), this.trajectorySocket === o && (this.trajectorySocket = null);
1271
+ }
1272
+ }
1273
+ /**
1274
+ * Resolve once the robot has finished executing a trajectory.
1275
+ *
1276
+ * `standstill` from the motion stream is the only completion signal we get.
1277
+ * The robot is still at standstill for a moment after the controller
1278
+ * acknowledges the start, and a short increment can be over before the stream
1279
+ * reports any movement at all -- so movement is waited for as a grace period,
1280
+ * never required.
1281
+ */
1282
+ async waitForMotionToFinish(t) {
1283
+ const o = () => this.motionStream.rapidlyChangingMotionState.standstill;
1284
+ await it(() => !o(), {
1285
+ timeout: Le,
1286
+ signal: t
1287
+ }).catch(() => {
1288
+ }), await it(o, { signal: t });
1289
+ }
1290
+ }
1291
+ const ze = (e) => {
1292
+ const t = e.softTimeout || 3e3, [o, i] = Z(!1);
1293
+ return ot(() => {
1294
+ const n = setTimeout(() => {
1295
+ i(!0);
1296
+ }, t);
1297
+ return () => clearTimeout(n);
1298
+ }), /* @__PURE__ */ c(
1299
+ x,
1300
+ {
1301
+ width: "100%",
1302
+ height: "100%",
1303
+ alignItems: "center",
1304
+ justifyContent: "center",
1305
+ sx: { color: "text.primary" },
1306
+ children: e.error ? /* @__PURE__ */ c(
1307
+ Ue,
1308
+ {
1309
+ loadingMessage: e.message,
1310
+ error: e.error
1311
+ }
1312
+ ) : /* @__PURE__ */ y(et, { children: [
1313
+ /* @__PURE__ */ c(Rt, { sx: { mb: 3 } }),
1314
+ !!e.message && /* @__PURE__ */ c(_, { variant: "body1", children: e.message }),
1315
+ /* @__PURE__ */ c(
1316
+ _,
1317
+ {
1318
+ variant: "body2",
1319
+ sx: {
1320
+ visibility: o ? "visible" : "hidden",
1321
+ mt: 2,
1322
+ color: "text.secondary"
1323
+ },
1324
+ children: "This is taking longer than expected..."
1325
+ }
1326
+ )
1327
+ ] })
1328
+ }
1329
+ );
1330
+ }, Ue = (e) => {
1331
+ const t = ce(e.error), o = e.error instanceof Error ? e.error.stack : null;
1332
+ return /* @__PURE__ */ y(
1333
+ x,
1334
+ {
1335
+ sx: {
1336
+ maxHeight: "100%",
1337
+ maxWidth: "min(100%, 800px)",
1338
+ p: 2,
1339
+ overflow: "auto",
1340
+ color: "error.main"
1341
+ },
1342
+ children: [
1343
+ /* @__PURE__ */ c(_, { variant: "body1", children: (e.loadingMessage ? `Error while ${se(ae(e.loadingMessage))} - ` : "") + t }),
1344
+ o && /* @__PURE__ */ c(
1345
+ F,
1346
+ {
1347
+ component: "pre",
1348
+ sx: {
1349
+ typography: "body2",
1350
+ fontFamily: "monospace",
1351
+ whiteSpace: "pre-wrap",
1352
+ wordBreak: "break-word",
1353
+ mt: 2,
1354
+ pb: 6
1355
+ },
1356
+ children: o
1357
+ }
1358
+ )
1359
+ ]
1360
+ }
1361
+ );
1362
+ }, Ge = M(({ store: e }) => {
1363
+ const { t } = V();
1364
+ return /* @__PURE__ */ c(
1365
+ Tt,
1366
+ {
1367
+ "data-testid": "jogging-blocked",
1368
+ "aria-label": "jogging-blocked",
1369
+ open: !0,
1370
+ sx: {
1371
+ position: "absolute",
1372
+ zIndex: (o) => o.zIndex.drawer + 1,
1373
+ color: "#fff",
1374
+ background: "rgba(15, 15, 15, 0.88)",
1375
+ justifyContent: "flex-start",
1376
+ alignItems: "flex-start"
1377
+ },
1378
+ children: /* @__PURE__ */ y(x, { sx: { m: 2, width: "100%" }, children: [
1379
+ /* @__PURE__ */ y(de, { severity: "error", sx: { mb: 2 }, children: [
1380
+ /* @__PURE__ */ c(ge, { children: t("Jogging.Blocked.ti") }),
1381
+ t("Jogging.Blocked.lb")
1382
+ ] }),
1383
+ /* @__PURE__ */ c(
1384
+ dt,
1385
+ {
1386
+ variant: "contained",
1387
+ color: "secondary",
1388
+ onClick: () => e.unblock(),
1389
+ children: t("Jogging.Blocked.Reenable.bt")
1390
+ }
1391
+ )
1392
+ ] })
1393
+ }
1394
+ );
1395
+ }), We = ({
1396
+ title: e,
1397
+ titleId: t,
1398
+ ...o
1399
+ }, i) => /* @__PURE__ */ v.createElement("svg", { xmlns: "http://www.w3.org/2000/svg", width: 19, height: 10, fill: "none", ref: i, "aria-labelledby": t, ...o }, e ? /* @__PURE__ */ v.createElement("title", { id: t }, e) : null, /* @__PURE__ */ v.createElement("path", { fill: "#fff", fillRule: "evenodd", d: "M5.131.312a.9.9 0 0 1 0 1.272L3.07 3.645h12.44l-2.06-2.061A.9.9 0 0 1 14.72.313l3.596 3.596a.9.9 0 0 1 0 1.271l-3.596 3.597a.9.9 0 0 1-1.271-1.272l2.061-2.062H3.07L5.13 7.505A.9.9 0 0 1 3.86 8.777L.263 5.18a.9.9 0 0 1 0-1.271L3.86.312a.9.9 0 0 1 1.271 0", clipRule: "evenodd" })), qe = z(We), He = ({
1400
+ title: e,
1401
+ titleId: t,
1402
+ ...o
1403
+ }, i) => /* @__PURE__ */ v.createElement("svg", { xmlns: "http://www.w3.org/2000/svg", width: 19, height: 10, fill: "none", ref: i, "aria-labelledby": t, ...o }, e ? /* @__PURE__ */ v.createElement("title", { id: t }, e) : null, /* @__PURE__ */ v.createElement("path", { fill: "#fff", fillRule: "evenodd", d: "M5.131.312a.9.9 0 0 1 0 1.272L3.07 3.645h12.44l-2.06-2.061A.9.9 0 0 1 14.72.313l3.596 3.596a.9.9 0 0 1 0 1.271l-3.596 3.597a.9.9 0 0 1-1.271-1.272l2.061-2.062H3.07L5.13 7.505A.9.9 0 0 1 3.86 8.777L.263 5.18a.9.9 0 0 1 0-1.271L3.86.312a.9.9 0 0 1 1.271 0", clipRule: "evenodd" })), Ke = z(He), Ye = ({
1404
+ title: e,
1405
+ titleId: t,
1406
+ ...o
1407
+ }, i) => /* @__PURE__ */ v.createElement("svg", { xmlns: "http://www.w3.org/2000/svg", width: 10, height: 19, fill: "none", ref: i, "aria-labelledby": t, ...o }, e ? /* @__PURE__ */ v.createElement("title", { id: t }, e) : null, /* @__PURE__ */ v.createElement("path", { fill: "#fff", fillRule: "evenodd", d: "M9.522 14.811A.899.899 0 1 0 8.25 13.54L6.19 15.601V3.16L8.25 5.221A.9.9 0 0 0 9.522 3.95L5.926.354a.9.9 0 0 0-1.272 0L1.058 3.95a.9.9 0 1 0 1.271 1.271L4.391 3.16v12.442L2.329 13.54a.899.899 0 1 0-1.271 1.271l3.596 3.597a.9.9 0 0 0 1.272 0z", clipRule: "evenodd" })), Qe = z(Ye), Ze = ({
1408
+ title: e,
1409
+ titleId: t,
1410
+ ...o
1411
+ }, i) => /* @__PURE__ */ v.createElement("svg", { width: 16, height: 16, viewBox: "0 0 16 16", fill: "none", xmlns: "http://www.w3.org/2000/svg", ref: i, "aria-labelledby": t, ...o }, e ? /* @__PURE__ */ v.createElement("title", { id: t }, e) : null, /* @__PURE__ */ v.createElement("path", { d: "M8 16C5.76667 16 3.875 15.225 2.325 13.675C0.775 12.125 0 10.2333 0 8C0 5.76667 0.775 3.875 2.325 2.325C3.875 0.775 5.76667 0 8 0C9.15 0 10.25 0.2375 11.3 0.7125C12.35 1.1875 13.25 1.86667 14 2.75V0H16V7H9V5H13.2C12.6667 4.06667 11.9375 3.33333 11.0125 2.8C10.0875 2.26667 9.08333 2 8 2C6.33333 2 4.91667 2.58333 3.75 3.75C2.58333 4.91667 2 6.33333 2 8C2 9.66667 2.58333 11.0833 3.75 12.25C4.91667 13.4167 6.33333 14 8 14C9.28333 14 10.4417 13.6333 11.475 12.9C11.0583 14.1 12.5083 12.1667 11.475 12.9L12.9 14.325C11.4667 15.4417 9.83333 16 8 16Z", fill: "white" })), Xe = z(Ze), Ft = M(
1412
+ ({ store: e }) => {
1413
+ const { t } = V(), [o, i] = Z(
1414
+ e.jogger.motionStream.rapidlyChangingMotionState.joint_limit_reached.limit_reached
1415
+ ), n = at(o);
1416
+ pt(() => {
1417
+ const a = e.jogger.motionStream.rapidlyChangingMotionState.joint_limit_reached.limit_reached;
1418
+ me(n.current, a) || (n.current = a, i(a));
1419
+ });
1420
+ const r = [];
1421
+ for (const [a, s] of o.entries())
1422
+ s && r.push(a);
1423
+ return /* @__PURE__ */ c(
1424
+ F,
1425
+ {
1426
+ sx: {
1427
+ display: "flex",
1428
+ flexDirection: "row",
1429
+ justifyContent: "center"
1430
+ },
1431
+ children: /* @__PURE__ */ c(
1432
+ _,
1433
+ {
1434
+ "data-testid": "jogging-joint-limit-detector",
1435
+ "aria-label": "jogging-joint-limit-detector",
1436
+ color: "error",
1437
+ variant: "body2",
1438
+ sx: {
1439
+ fontSize: "0.75rem",
1440
+ lineHeight: 1.2,
1441
+ visibility: r.length ? "visible" : "hidden"
1442
+ },
1443
+ children: t("Jogging.JointLimitsReached.lb", {
1444
+ jointNumbers: r.map((a) => a + 1).join(", ")
1445
+ })
1446
+ }
1447
+ )
1448
+ }
1449
+ );
1450
+ }
1451
+ ), to = Jt(pe)(({ theme: e }) => ({
1452
+ "&.MuiFormControl-root": {
1453
+ ".MuiSelect-select": {
1454
+ paddingTop: "20px",
1455
+ paddingLeft: "12px"
1456
+ },
1457
+ label: {
1458
+ pointerEvents: "none",
1459
+ fontSize: "16px"
1460
+ },
1461
+ ".MuiInputLabel-root": {
1462
+ "&.Mui-focused": {
1463
+ color: e.palette.text.primary
1464
+ }
1465
+ }
1466
+ }
1467
+ }));
1468
+ function tt({
1469
+ labelValue: e,
1470
+ ...t
1471
+ }) {
1472
+ return /* @__PURE__ */ y(to, { fullWidth: !0, variant: "filled", children: [
1473
+ /* @__PURE__ */ c(fe, { id: t.labelId, children: e }),
1474
+ /* @__PURE__ */ c(ye, { ...t })
1475
+ ] });
1476
+ }
1477
+ function Et(e) {
1478
+ const t = e.lastIndexOf("On");
1479
+ return t > 0 ? e.slice(0, t) : e;
1480
+ }
1481
+ function Lt(e, t) {
1482
+ const o = e[t];
1483
+ if (o)
1484
+ return o;
1485
+ const i = Et(t), n = e[i];
1486
+ if (n)
1487
+ return n;
1488
+ const r = Object.keys(e).filter(
1489
+ (s) => Et(s) === i
1490
+ );
1491
+ if (r.length !== 1)
1492
+ return;
1493
+ const a = r[0];
1494
+ return a ? e[a] : void 0;
1495
+ }
1496
+ const eo = {
1497
+ coordinate_system: "world",
1498
+ name: "world",
1499
+ reference_coordinate_system: "",
1500
+ position: [0, 0, 0],
1501
+ orientation: [0, 0, 0],
1502
+ orientation_type: "ROTATION_VECTOR"
1503
+ };
1504
+ function $t(e) {
1505
+ const t = K(
1506
+ e.map((n) => ({
1507
+ ...n,
1508
+ coordinate_system: n.coordinate_system || "world"
1509
+ })),
1510
+ "coordinate_system"
1511
+ );
1512
+ t.world ?? (t.world = eo);
1513
+ const o = {}, i = (n) => {
1514
+ const r = o[n];
1515
+ if (r)
1516
+ return r;
1517
+ const a = Lt(t, n);
1518
+ if (!a)
1519
+ throw new Error(
1520
+ `Unknown coordinate system ${n}. Known coordinate systems are: ${Object.keys(t).join(", ")}`
1521
+ );
1522
+ const s = a.reference_coordinate_system || "world";
1523
+ let h;
1524
+ if (s === "world")
1525
+ h = a;
1526
+ else {
1527
+ const m = i(s), g = w.fromCoordinateSystem(m).multiply(
1528
+ w.fromCoordinateSystem(a)
1529
+ );
1530
+ h = {
1531
+ ...a,
1532
+ position: [
1533
+ g.position.x,
1534
+ g.position.y,
1535
+ g.position.z
1536
+ ],
1537
+ orientation: [
1538
+ g.orientation.x,
1539
+ g.orientation.y,
1540
+ g.orientation.z
1541
+ ],
1542
+ orientation_type: "ROTATION_VECTOR",
1543
+ reference_coordinate_system: m.reference_coordinate_system
1544
+ };
1545
+ }
1546
+ return o[n] = h, h;
1547
+ };
1548
+ return Object.fromEntries(
1549
+ Object.keys(t).map((n) => [
1550
+ n,
1551
+ i(n)
1552
+ ])
1553
+ );
1554
+ }
1555
+ function gt(e, t) {
1556
+ const o = Lt(
1557
+ e,
1558
+ t || "world"
1559
+ );
1560
+ if (!o)
1561
+ throw new Error(
1562
+ `Unknown coordinate system ${t}. Known coordinate systems are: ${Object.keys(e).join(", ")}`
1563
+ );
1564
+ return o;
1565
+ }
1566
+ function oo(e, t) {
1567
+ return gt(
1568
+ $t(t),
1569
+ e
1570
+ );
1571
+ }
1572
+ function ht(e, t, o) {
1573
+ if (e.coordinateSystemId === t)
1574
+ return e;
1575
+ const i = $t(o), n = gt(
1576
+ i,
1577
+ e.coordinateSystemId || "world"
1578
+ ), r = gt(
1579
+ i,
1580
+ t
1581
+ );
1582
+ if (n.coordinate_system === r.coordinate_system)
1583
+ return {
1584
+ ...e,
1585
+ coordinateSystemId: r.coordinate_system
1586
+ };
1587
+ const a = w.fromCoordinateSystem(r).inverse().multiply(
1588
+ w.fromCoordinateSystem(n).multiply(
1589
+ w.fromPose(e.pose)
1590
+ )
1591
+ );
1592
+ return {
1593
+ pose: {
1594
+ position: [
1595
+ a.position.x,
1596
+ a.position.y,
1597
+ a.position.z
1598
+ ],
1599
+ orientation: [
1600
+ a.orientation.x,
1601
+ a.orientation.y,
1602
+ a.orientation.z
1603
+ ]
1604
+ },
1605
+ coordinateSystemId: r.coordinate_system
1606
+ };
1607
+ }
1608
+ function io(e, t, o) {
1609
+ const i = w.fromPose(e).multiply(w.fromRobotTcp(t).inverse()).multiply(w.fromRobotTcp(o)), { position: n, orientation: r } = i;
1610
+ return {
1611
+ position: [n.x, n.y, n.z],
1612
+ orientation: [r.x, r.y, r.z]
1613
+ };
1614
+ }
1615
+ function Bt(e) {
1616
+ var t, o, i, n, r;
1617
+ if (typeof e == "string") {
1618
+ const a = J(e);
1619
+ return a ? Bt(a) : e;
1620
+ }
1621
+ if (e && typeof e == "object") {
1622
+ const a = e;
1623
+ return (
1624
+ // PlanTrajectoryFailedResponse: the feedback name identifies the
1625
+ // failure cause (e.g. "FeedbackSingularity") and is translated to a
1626
+ // friendly message by getJogErrorTranslationKey
1627
+ ((t = a.error_feedback) == null ? void 0 : t.error_feedback_name) || ((o = a.add_trajectory_error) == null ? void 0 : o.message) || a.message || ((n = (i = a.result) == null ? void 0 : i.add_trajectory_error) == null ? void 0 : n.message) || ((r = a.result) == null ? void 0 : r.message) || "Jogging motion failed"
1628
+ );
1629
+ }
1630
+ return "Jogging motion failed";
1631
+ }
1632
+ const no = [
1633
+ // Trajectory-planning failure causes, identified by the error_feedback_name
1634
+ // of a PlanTrajectoryFailedResponse (see extractJogErrorMessage)
1635
+ {
1636
+ pattern: /^FeedbackSingularity$/,
1637
+ translationKey: "Jogging.StreamStateSection.Error.Singularity.lb"
1638
+ },
1639
+ {
1640
+ pattern: /^FeedbackJointLimitExceeded$/,
1641
+ translationKey: "Jogging.StreamStateSection.Error.JointLimit.lb"
1642
+ },
1643
+ {
1644
+ pattern: /^FeedbackOutOfWorkspace$/,
1645
+ translationKey: "Jogging.StreamStateSection.Error.OutOfWorkspace.lb"
1646
+ },
1647
+ {
1648
+ pattern: /^FeedbackCollision$/,
1649
+ translationKey: "Jogging.StreamStateSection.Error.Collision.lb"
1650
+ },
1651
+ {
1652
+ pattern: /^FeedbackNoSolutionInCurrentConfiguration$/,
1653
+ translationKey: "Jogging.StreamStateSection.Error.NoSolutionInConfiguration.lb"
1654
+ },
1655
+ {
1656
+ // Catch-all for the remaining Feedback* causes we have no specific
1657
+ // message for -- must stay after the specific patterns above
1658
+ pattern: /^Feedback\w+$/,
1659
+ translationKey: "Jogging.StreamStateSection.Error.PlanningFailed.lb"
1660
+ }
1661
+ ];
1662
+ function ro(e) {
1663
+ var t;
1664
+ return ((t = no.find(({ pattern: o }) => o.test(e))) == null ? void 0 : t.translationKey) ?? null;
1665
+ }
1666
+ const ao = 5, so = 250;
1667
+ function lo(e) {
1668
+ var i, n, r, a;
1669
+ const t = [
1670
+ (n = (i = e == null ? void 0 : e.manual_t1_limits) == null ? void 0 : i.tcp) == null ? void 0 : n.velocity,
1671
+ (a = (r = e == null ? void 0 : e.manual_limits) == null ? void 0 : r.tcp) == null ? void 0 : a.velocity
1672
+ ].filter(
1673
+ (s) => typeof s == "number" && Number.isFinite(s) && s > 0
1674
+ );
1675
+ return Math.min(so, ...t) / 10;
1676
+ }
1677
+ const mt = [
1678
+ { id: "0.1", mm: 0.1, degrees: 0.05 },
1679
+ { id: "1", mm: 1, degrees: 0.5 },
1680
+ { id: "5", mm: 5, degrees: 2.5 },
1681
+ { id: "10", mm: 10, degrees: 5 }
1682
+ ], co = [
1683
+ { id: "continuous" },
1684
+ ...mt
1685
+ ], go = ["coordsys", "tool"];
1686
+ class rt {
1687
+ constructor(t, o, i, n, r) {
1688
+ var s, h, m;
1689
+ this.jogger = t, this.coordSystems = o, this.motionGroupDescription = i, this.tcps = n, this.inverseSolverValue = r, this.selectedTabId = "cartesian", this.locks = /* @__PURE__ */ new Set(), this.blocked = !1, this.selectedCoordSystemId = "world", this.jogCoordSystemId = "world", this.selectedTcpId = "", this.tcpChangeInProgress = !1, this.selectedOrientation = "coordsys", this.selectedIncrementId = "continuous", this.selectedCartesianMotionType = "translate", this.incrementJogInProgress = null, this.lastJogError = null, this.onBeforeActivate = null, this.rotationVelocityDegPerSec = ao, this.minTranslationVelocityMmPerSec = 1, this.maxTranslationVelocityMmPerSec = 250, this.minRotationVelocityDegPerSec = 1, this.maxRotationVelocityDegPerSec = 60, this.showCoordSystemSelect = !1, this.showTcpSelect = !0, this.showOrientationSelect = !0, this.showIncrementSelect = !0, this.showTabIcons = !1, this.showVelocitySliderLabel = !0, this.showVelocityLegend = !1, this.showJointsLegend = !1, this.disposers = [], this.inverseSolver = void 0, this.jointType = N.RevoluteJoint;
1690
+ for (const g of o)
1691
+ if (g.coordinate_system === "") {
1692
+ g.coordinate_system = "world";
1693
+ break;
1694
+ }
1695
+ this.selectedCoordSystemId = ((s = o[0]) == null ? void 0 : s.coordinate_system) || "world", this.jogCoordSystemId = this.selectedCoordSystemId, this.selectedTcpId = t.motionStream.rapidlyChangingMotionState.tcp ?? "", this.tcpChangeInProgress = this.tcps.length > 0 && !this.selectedTcpId, this.inverseSolver = r, this.translationVelocityMmPerSec = lo(
1696
+ i == null ? void 0 : i.operation_limits
1697
+ ), this.jointType = ((m = (h = i == null ? void 0 : i.dh_parameters) == null ? void 0 : h[0]) == null ? void 0 : m.type) ?? N.RevoluteJoint, st(this, {}, { autoBind: !0 }), this.jogger.onBlocked = () => {
1698
+ this.block();
1699
+ };
1700
+ const a = this.jogger.onError;
1701
+ this.jogger.onError = (g) => {
1702
+ this.setLastJogError(Bt(g)), a == null || a(g);
1703
+ }, this.loadFromLocalStorage(), this.disposers.push(bt(() => this.saveToLocalStorage())), this.disposers.push(
1704
+ bt(() => {
1705
+ const g = this.jogger.motionStream.rapidlyChangingMotionState.tcp;
1706
+ g && g !== this.selectedTcpId && S(() => {
1707
+ this.selectedTcpId = g, this.tcpChangeInProgress = !1;
1708
+ });
1709
+ })
1710
+ ), window.joggingStore = this;
1711
+ }
1712
+ /**
1713
+ * Load a jogging store with the relevant data it needs
1714
+ * from the backend
1715
+ */
1716
+ static async loadFor(t) {
1717
+ const { nova: o, cellId: i } = t, [n, r] = await Promise.all([
1718
+ // Fetch coord systems so user can select between them
1719
+ o.api.controller.listCoordinateSystems(
1720
+ i,
1721
+ t.motionStream.controllerId,
1722
+ "ROTATION_VECTOR"
1723
+ ),
1724
+ // Same for TCPs and other info from description
1725
+ o.api.motionGroup.getMotionGroupDescription(
1726
+ i,
1727
+ t.motionStream.controllerId,
1728
+ t.motionGroupId
1729
+ )
1730
+ ]), a = await o.api.motionGroupModels.getMotionGroupKinematicModel(
1731
+ r.motion_group_model
1732
+ );
1733
+ return rt.create(t, {
1734
+ coordinateSystems: n || [],
1735
+ description: r,
1736
+ kinematicModel: a
1737
+ });
1738
+ }
1739
+ /**
1740
+ * Make a jogging store from data that was loaded before: the coordinate
1741
+ * systems of the controller, the description and the kinematic model of the
1742
+ * motion group. An app that loads them once for several stores uses this
1743
+ * instead of {@link JoggingStore.loadFor}.
1744
+ */
1745
+ static create(t, o) {
1746
+ const { coordinateSystems: i, description: n, kinematicModel: r } = o, a = Object.entries(n.tcps || {}).map(([s, h]) => ({
1747
+ id: s,
1748
+ readable_name: h.name,
1749
+ position: h.pose.position,
1750
+ orientation: h.pose.orientation
1751
+ }));
1752
+ return new rt(
1753
+ t,
1754
+ i,
1755
+ n,
1756
+ a,
1757
+ r.inverse_solver
1758
+ );
1759
+ }
1760
+ dispose() {
1761
+ for (const t of this.disposers)
1762
+ t();
1763
+ this.jogger.dispose();
1764
+ }
1765
+ get coordSystemCountByName() {
1766
+ return le(this.coordSystems, (t) => t.name);
1767
+ }
1768
+ async deactivate() {
1769
+ this.jogger.mode === "jogging" && await this.jogger.setJoggingMode("off");
1770
+ }
1771
+ /**
1772
+ * Activate the jogger with current settings. Resolves when the jogging
1773
+ * websocket is initialized, or when the jogging was stopped before that
1774
+ * (`deactivate`).
1775
+ */
1776
+ async activate() {
1777
+ var t;
1778
+ return this.lastJogError = null, await ((t = this.onBeforeActivate) == null ? void 0 : t.call(this)), this.currentTab.id === "cartesian" ? ((this.jogger.tcp !== this.selectedTcpId || this.jogger.orientation !== this.selectedOrientation) && await this.jogger.setOptions({
1779
+ tcp: this.selectedTcpId || void 0,
1780
+ orientation: this.selectedOrientation
1781
+ }), this.jogger.coordinateSystem = this.jogCoordSystem, this.activeDiscreteIncrement ? await this.jogger.setJoggingMode("trajectory") : await this.jogger.setJoggingMode("jogging")) : await this.jogger.setJoggingMode("jogging"), this.jogger;
1782
+ }
1783
+ loadFromLocalStorage() {
1784
+ const t = J(localStorage.getItem("joggingToolStore"));
1785
+ t && (this.tabsById[t.selectedTabId] && (this.selectedTabId = t.selectedTabId), this.coordSystemsById[t.selectedCoordSystemId] && (this.selectedCoordSystemId = t.selectedCoordSystemId), this.coordSystemsById[t.jogCoordSystemId] && (this.jogCoordSystemId = t.jogCoordSystemId), this.incrementOptionsById[t.selectedIncrementId] && (this.selectedIncrementId = t.selectedIncrementId), ["translate", "rotate"].includes(t.selectedCartesianMotionType) && (this.selectedCartesianMotionType = t.selectedCartesianMotionType), ["coordsys", "tool"].includes(t.selectedOrientation) && (this.selectedOrientation = t.selectedOrientation));
1786
+ }
1787
+ saveToLocalStorage() {
1788
+ localStorage.setItem(
1789
+ "joggingToolStore",
1790
+ JSON.stringify(this.localStorageSave)
1791
+ );
1792
+ }
1793
+ get isLocked() {
1794
+ return this.locks.size > 0;
1795
+ }
1796
+ /**
1797
+ * Translation key for a friendlier version of
1798
+ * {@link JoggingStore.lastJogError}, if the raw backend message is
1799
+ * recognized. `null` when there's no latched error or the message isn't one
1800
+ * we have a friendlier version for (in which case the raw message should be
1801
+ * shown as-is).
1802
+ */
1803
+ get lastJogErrorTranslationKey() {
1804
+ return this.lastJogError ? ro(this.lastJogError) : null;
1805
+ }
1806
+ get localStorageSave() {
1807
+ return {
1808
+ selectedTabId: this.selectedTabId,
1809
+ selectedCoordSystemId: this.selectedCoordSystemId,
1810
+ jogCoordSystemId: this.jogCoordSystemId,
1811
+ selectedOrientation: this.selectedOrientation,
1812
+ selectedIncrementId: this.selectedIncrementId,
1813
+ selectedCartesianMotionType: this.selectedCartesianMotionType
1814
+ };
1815
+ }
1816
+ get tabs() {
1817
+ const t = [
1818
+ {
1819
+ id: "joint",
1820
+ label: "Joints"
1821
+ }
1822
+ ];
1823
+ return this.inverseSolver !== null && t.unshift({
1824
+ id: "cartesian",
1825
+ label: "Cartesian"
1826
+ }), t;
1827
+ }
1828
+ get incrementOptions() {
1829
+ return co;
1830
+ }
1831
+ get discreteIncrementOptions() {
1832
+ return mt;
1833
+ }
1834
+ get incrementOptionsById() {
1835
+ return K(this.incrementOptions, (t) => t.id);
1836
+ }
1837
+ get tabsById() {
1838
+ return K(this.tabs, (t) => t.id);
1839
+ }
1840
+ get currentTab() {
1841
+ return this.tabsById[this.selectedTabId] || this.tabs[0];
1842
+ }
1843
+ get tabIndex() {
1844
+ return this.tabs.indexOf(this.currentTab);
1845
+ }
1846
+ get coordSystemsById() {
1847
+ return K(this.coordSystems, (t) => t.coordinate_system);
1848
+ }
1849
+ /**
1850
+ * The id of the coordinate system to use for jogging.
1851
+ * If in tool orientation, this is set to "tool", not the
1852
+ * selected coordinate system.
1853
+ */
1854
+ get activeCoordSystemId() {
1855
+ return this.selectedOrientation === "tool" ? "tool" : this.selectedCoordSystemId;
1856
+ }
1857
+ /** The coordinate system to jog along, resolved relative to world */
1858
+ get jogCoordSystem() {
1859
+ return oo(
1860
+ this.jogCoordSystemId,
1861
+ this.coordSystems
1862
+ );
1863
+ }
1864
+ /**
1865
+ * The streamed TCP pose (its readout, see
1866
+ * {@link MotionStreamConnection.readoutState}) expressed in the selected
1867
+ * coordinate system, for values that show what a pose field in that
1868
+ * coordinate system shows.
1869
+ */
1870
+ get tcpPoseInSelectedCoordSystem() {
1871
+ const { tcp_pose: t, coordinate_system: o } = this.jogger.motionStream.readoutState;
1872
+ return !(t != null && t.position) || !t.orientation ? t : ht(
1873
+ {
1874
+ pose: {
1875
+ position: t.position,
1876
+ orientation: t.orientation
1877
+ },
1878
+ coordinateSystemId: o || "world"
1879
+ },
1880
+ this.selectedCoordSystemId,
1881
+ this.coordSystems
1882
+ ).pose;
1883
+ }
1884
+ get tcpsById() {
1885
+ return K(this.tcps, (t) => t.id);
1886
+ }
1887
+ /**
1888
+ * The streamed TCP pose (its readout) as the pose of a TCP, relative to a
1889
+ * coordinate system: for a pose display with a TCP and frame of its own,
1890
+ * like CurrentPoseBar. Undefined without a pose, or for an unknown TCP or
1891
+ * coordinate system.
1892
+ */
1893
+ tcpPoseIn(t, o) {
1894
+ const { tcp_pose: i, tcp: n, coordinate_system: r } = this.jogger.motionStream.readoutState, a = this.tcpsById[n || this.selectedTcpId], s = this.tcpsById[t];
1895
+ if (!(!(i != null && i.position) || !i.orientation) && !(!a || !s))
1896
+ try {
1897
+ return ht(
1898
+ {
1899
+ pose: io(i, a, s),
1900
+ coordinateSystemId: r || "world"
1901
+ },
1902
+ o,
1903
+ this.coordSystems
1904
+ ).pose;
1905
+ } catch {
1906
+ return;
1907
+ }
1908
+ }
1909
+ /**
1910
+ * The step of the selected increment, or undefined for continuous jogging.
1911
+ * In tool orientation, a step moves along the tool's axes.
1912
+ */
1913
+ get activeDiscreteIncrement() {
1914
+ return mt.find(
1915
+ (t) => t.id === this.selectedIncrementId
1916
+ );
1917
+ }
1918
+ /** The selected rotation velocity converted to radians per second */
1919
+ get rotationVelocityRadsPerSec() {
1920
+ return this.rotationVelocityDegPerSec * Math.PI / 180;
1921
+ }
1922
+ /** Selected velocity in mm/sec or deg/sec */
1923
+ velocityInDisplayUnits(t) {
1924
+ return t ? this.rotationVelocityDegPerSec : this.translationVelocityMmPerSec;
1925
+ }
1926
+ /** Minimum selectable velocity in mm/sec or deg/sec */
1927
+ minVelocityInDisplayUnits(t) {
1928
+ return t ? this.minRotationVelocityDegPerSec : this.minTranslationVelocityMmPerSec;
1929
+ }
1930
+ /** Maximum selectable velocity in mm/sec or deg/sec */
1931
+ maxVelocityInDisplayUnits(t) {
1932
+ return t ? this.maxRotationVelocityDegPerSec : this.maxTranslationVelocityMmPerSec;
1933
+ }
1934
+ onTabChange(t, o) {
1935
+ const i = this.tabs[o] || this.tabs[0];
1936
+ this.selectedTabId = i.id;
1937
+ }
1938
+ setSelectedCoordSystemId(t) {
1939
+ this.selectedCoordSystemId = t;
1940
+ }
1941
+ /**
1942
+ * @deprecated Use {@link JoggingStore.requestTcpChange} instead. This method now delegates
1943
+ * to `requestTcpChange` which properly communicates the TCP change to the server.
1944
+ */
1945
+ setSelectedTcpId(t) {
1946
+ this.requestTcpChange(t).catch((o) => {
1947
+ console.error("Failed to change TCP:", o);
1948
+ });
1949
+ }
1950
+ /**
1951
+ * Request a TCP change on the server. Sends an InitializeJoggingRequest
1952
+ * with the new TCP to the backend via the jogging websocket.
1953
+ *
1954
+ * If the jogger is actively jogging, the websocket is reinitialised with the new TCP.
1955
+ * If the jogger is idle, a jogging websocket is briefly opened to communicate the
1956
+ * TCP change. The websocket is kept open until the state-stream confirms the
1957
+ * change (or a 1s timeout), to ensure the backend has time to process it.
1958
+ */
1959
+ async requestTcpChange(t) {
1960
+ if (t === this.selectedTcpId) return;
1961
+ this.tcpChangeInProgress = !0;
1962
+ const o = this.jogger.tcp, i = this.jogger.mode !== "jogging";
1963
+ try {
1964
+ this.jogger.tcp = t, i ? await this.jogger.setJoggingMode("jogging") : await this.jogger.setJoggingMode("jogging", !1);
1965
+ let n = await this.waitForTcpConfirmation(t, 1e3);
1966
+ i && await this.jogger.setJoggingMode("off"), n || (n = await this.waitForTcpConfirmation(t, 2e3)), S(() => {
1967
+ n ? this.selectedTcpId = t : (this.jogger.tcp = o, this.selectedTcpId = this.jogger.motionStream.rapidlyChangingMotionState.tcp ?? "");
1968
+ });
1969
+ } catch (n) {
1970
+ throw i && await this.jogger.setJoggingMode("off").catch(() => {
1971
+ }), S(() => {
1972
+ this.jogger.tcp = o, this.selectedTcpId = this.jogger.motionStream.rapidlyChangingMotionState.tcp ?? "";
1973
+ }), n;
1974
+ } finally {
1975
+ S(() => {
1976
+ this.tcpChangeInProgress = !1;
1977
+ });
1978
+ }
1979
+ }
1980
+ waitForTcpConfirmation(t, o) {
1981
+ return new Promise((i) => {
1982
+ const n = setTimeout(() => {
1983
+ r(), i(!1);
1984
+ }, o), r = it(
1985
+ () => this.jogger.motionStream.rapidlyChangingMotionState.tcp === t,
1986
+ () => {
1987
+ clearTimeout(n), i(!0);
1988
+ }
1989
+ );
1990
+ });
1991
+ }
1992
+ setSelectedOrientation(t) {
1993
+ this.selectedOrientation = t;
1994
+ }
1995
+ /** "Move relative to" the selected TCP: jog along its own axes */
1996
+ setMoveRelativeToSelectedTcp() {
1997
+ this.selectedOrientation = "tool";
1998
+ }
1999
+ /** "Move relative to" a coordinate system: jog along its axes */
2000
+ setMoveRelativeToCoordSystem(t) {
2001
+ this.selectedOrientation = "coordsys", this.jogCoordSystemId = t;
2002
+ }
2003
+ setSelectedIncrementId(t) {
2004
+ this.selectedIncrementId = t;
2005
+ }
2006
+ setCurrentIncrementJog(t) {
2007
+ this.incrementJogInProgress = t;
2008
+ }
2009
+ setLastJogError(t) {
2010
+ this.lastJogError = t;
2011
+ }
2012
+ /**
2013
+ * Set the selected velocity in mm/s or °/s, from the slider or a velocity
2014
+ * text field. Values outside the slider range (and values that are not a
2015
+ * finite number) are ignored; a text field reports them to the user
2016
+ * instead of applying them.
2017
+ */
2018
+ setVelocityFromSlider(t, o) {
2019
+ !Number.isFinite(t) || t < this.minVelocityInDisplayUnits(o) || t > this.maxVelocityInDisplayUnits(o) || (o ? this.rotationVelocityDegPerSec = t : this.translationVelocityMmPerSec = t);
2020
+ }
2021
+ setSelectedCartesianMotionType(t) {
2022
+ this.selectedCartesianMotionType = t;
2023
+ }
2024
+ lock(t) {
2025
+ this.locks.add(t);
2026
+ }
2027
+ unlock(t) {
2028
+ this.locks.delete(t);
2029
+ }
2030
+ block() {
2031
+ this.blocked = !0;
2032
+ }
2033
+ unblock() {
2034
+ this.blocked = !1, this.jogger.mode === "jogging" && this.jogger.initializeJoggingWebsocket().catch((t) => {
2035
+ console.error("Failed to initialize jogging:", t);
2036
+ });
2037
+ }
2038
+ /** Lock the UI until the given async callback resolves */
2039
+ async withMotionLock(t) {
2040
+ const o = Se();
2041
+ this.lock(o);
2042
+ try {
2043
+ return await t();
2044
+ } finally {
2045
+ this.unlock(o);
2046
+ }
2047
+ }
2048
+ }
2049
+ const ho = M(
2050
+ ({ store: e, useDegree: t }) => {
2051
+ var a;
2052
+ const { t: o } = V(), i = Zt(), n = [];
2053
+ function r(s) {
2054
+ switch (s) {
2055
+ case "coordsys":
2056
+ return o("Jogging.Orientation.coordsys");
2057
+ case "tool":
2058
+ return o("Jogging.Orientation.tool");
2059
+ default:
2060
+ return s;
2061
+ }
2062
+ }
2063
+ return e.showCoordSystemSelect && n.push(
2064
+ /* @__PURE__ */ c(
2065
+ tt,
2066
+ {
2067
+ labelId: `jogging-coord-select-${i}`,
2068
+ labelValue: o("Jogging.CoordinateSystem.hlb"),
2069
+ value: e.selectedCoordSystemId,
2070
+ size: "small",
2071
+ variant: "filled",
2072
+ displayEmpty: !0,
2073
+ onChange: (s) => e.setSelectedCoordSystemId(s.target.value),
2074
+ children: e.coordSystems.map((s) => /* @__PURE__ */ c($, { value: s.coordinate_system, children: s.name && e.coordSystemCountByName[s.name] > 1 ? `${s.name} / ${s.coordinate_system}` : s.name || s.coordinate_system }, s.coordinate_system))
2075
+ },
2076
+ "coord"
2077
+ )
2078
+ ), e.showTcpSelect && n.push(
2079
+ /* @__PURE__ */ c(
2080
+ tt,
2081
+ {
2082
+ labelId: `jogging-tcp-select-${i}`,
2083
+ labelValue: "TCP",
2084
+ value: e.selectedTcpId,
2085
+ size: "small",
2086
+ variant: "filled",
2087
+ displayEmpty: e.tcpChangeInProgress,
2088
+ onChange: (s) => {
2089
+ e.requestTcpChange(s.target.value).catch((h) => {
2090
+ console.error("Failed to change TCP:", h);
2091
+ });
2092
+ },
2093
+ disabled: e.tcpChangeInProgress,
2094
+ endAdornment: e.tcpChangeInProgress ? /* @__PURE__ */ c(ue, { position: "end", children: /* @__PURE__ */ c(Rt, { size: 16 }) }) : void 0,
2095
+ children: e.tcps.map((s) => /* @__PURE__ */ c($, { value: s.id, children: s.id }, s.id))
2096
+ },
2097
+ "tcp"
2098
+ )
2099
+ ), e.showOrientationSelect && n.push(
2100
+ /* @__PURE__ */ c(
2101
+ tt,
2102
+ {
2103
+ labelValue: o("Jogging.Cartesian.Orientation.lb"),
2104
+ labelId: `orientation-select-${i}`,
2105
+ value: e.selectedOrientation,
2106
+ onChange: (s) => e.setSelectedOrientation(s.target.value),
2107
+ children: go.map((s) => /* @__PURE__ */ c($, { value: s, children: r(s) }, s))
2108
+ },
2109
+ "orientation"
2110
+ )
2111
+ ), e.showIncrementSelect && n.push(
2112
+ /* @__PURE__ */ y(
2113
+ tt,
2114
+ {
2115
+ labelValue: o("Jogging.Increment.hlb"),
2116
+ labelId: `jogging-increment-select-${i}`,
2117
+ size: "small",
2118
+ variant: "filled",
2119
+ value: ((a = e.activeDiscreteIncrement) == null ? void 0 : a.id) || "continuous",
2120
+ onChange: (s) => e.setSelectedIncrementId(
2121
+ s.target.value
2122
+ ),
2123
+ children: [
2124
+ /* @__PURE__ */ c($, { value: "continuous", children: o("Jogging.Increment.Continuous.dd") }, "continuous"),
2125
+ e.discreteIncrementOptions.map((s) => /* @__PURE__ */ c($, { value: s.id, children: t ? `${s.degrees}°` : `${s.mm}mm` }, s.id))
2126
+ ]
2127
+ },
2128
+ "increment"
2129
+ )
2130
+ ), /* @__PURE__ */ c(
2131
+ F,
2132
+ {
2133
+ component: "div",
2134
+ "data-testid": "jogging-options",
2135
+ "aria-label": "jogging-options",
2136
+ sx: {
2137
+ display: "grid",
2138
+ gap: "16px",
2139
+ gridTemplateColumns: "1fr 1fr",
2140
+ gridAutoRows: "min-content",
2141
+ "& label": { opacity: 0.7, fontSize: "12px", marginBottom: "4px" }
2142
+ },
2143
+ children: n.map((s, h) => /* @__PURE__ */ c(
2144
+ F,
2145
+ {
2146
+ sx: {
2147
+ gridColumn: n.length % 2 === 1 && h === n.length - 1 ? "span 2" : "auto"
2148
+ },
2149
+ children: s
2150
+ },
2151
+ h
2152
+ ))
2153
+ }
2154
+ );
2155
+ }
2156
+ ), mo = Jt(be)(({ theme: e }) => {
2157
+ var t;
2158
+ return {
2159
+ "&.MuiToggleButtonGroup-root": {
2160
+ background: (t = e.palette.backgroundPaperElevation) == null ? void 0 : t[8],
2161
+ borderRadius: "8px",
2162
+ padding: "4px",
2163
+ gap: "4px",
2164
+ button: {
2165
+ border: "none",
2166
+ borderRadius: "4px",
2167
+ flex: "1 1 0px",
2168
+ minWidth: 0,
2169
+ "&.MuiToggleButtonGroup-firstButton": {
2170
+ borderRadius: "8px 4px 4px 8px"
2171
+ },
2172
+ "&.MuiToggleButtonGroup-lastButton": {
2173
+ borderRadius: "4px 8px 8px 4px"
2174
+ }
2175
+ }
2176
+ }
2177
+ };
2178
+ }), uo = X(
2179
+ M((e) => {
2180
+ const { store: t } = e, { t: o } = V();
2181
+ function i(n, r) {
2182
+ r === e.velocity || !Ce(r) || e.onVelocityChange(r, e.useDegree);
2183
+ }
2184
+ return /* @__PURE__ */ y(
2185
+ x,
2186
+ {
2187
+ direction: "row",
2188
+ gap: 2,
2189
+ alignItems: "center",
2190
+ "data-testid": "velocity-slider",
2191
+ "aria-label": "velocity-slider",
2192
+ children: [
2193
+ t.showVelocityLegend && /* @__PURE__ */ c(
2194
+ _,
2195
+ {
2196
+ sx: {
2197
+ color: he,
2198
+ fontSize: "14px"
2199
+ },
2200
+ children: o("Jogging.Velocity.bt")
2201
+ }
2202
+ ),
2203
+ /* @__PURE__ */ c(
2204
+ At,
2205
+ {
2206
+ value: e.velocity,
2207
+ color: "secondary",
2208
+ onChange: i,
2209
+ min: e.min,
2210
+ max: e.max,
2211
+ "aria-labelledby": "input-slider",
2212
+ disabled: e.disabled,
2213
+ sx: {
2214
+ "& .MuiSlider-valueLabelOpen": {
2215
+ zIndex: 100,
2216
+ backgroundColor: "transparent",
2217
+ top: "0px"
2218
+ }
2219
+ }
2220
+ }
2221
+ ),
2222
+ t.showVelocitySliderLabel && (e.renderValue ? e.renderValue(e.velocity) : /* @__PURE__ */ c(zt, { value: e.velocity.toString() }))
2223
+ ]
2224
+ }
2225
+ );
2226
+ })
2227
+ );
2228
+ function zt({ value: e, sx: t }) {
2229
+ var i;
2230
+ const o = U();
2231
+ return /* @__PURE__ */ c(
2232
+ x,
2233
+ {
2234
+ direction: "row",
2235
+ justifyContent: "center",
2236
+ alignItems: "center",
2237
+ gap: "5px",
2238
+ sx: {
2239
+ padding: "6px 12px",
2240
+ background: (i = o.palette.backgroundPaperElevation) == null ? void 0 : i[8],
2241
+ borderRadius: "10px",
2242
+ minWidth: "111px",
2243
+ ...t
2244
+ },
2245
+ children: /* @__PURE__ */ c(
2246
+ _,
2247
+ {
2248
+ component: "span",
2249
+ sx: {
2250
+ textAlign: "right",
2251
+ fontSize: "14px",
2252
+ opacity: 0.8,
2253
+ color: o.palette.text.primary,
2254
+ whiteSpace: "nowrap"
2255
+ },
2256
+ children: e
2257
+ }
2258
+ )
2259
+ }
2260
+ );
2261
+ }
2262
+ const Ut = M(
2263
+ ({ store: e, useDegree: t }) => {
2264
+ const { t: o } = V();
2265
+ function i(n, r) {
2266
+ return r ? `ω = ${o("Jogging.Cartesian.Rotation.velocityDegPerSec.lb", { amount: n })}` : `v = ${o("Jogging.Cartesian.Translation.velocityMmPerSec.lb", { amount: n })}`;
2267
+ }
2268
+ return /* @__PURE__ */ c(
2269
+ uo,
2270
+ {
2271
+ store: e,
2272
+ velocity: e.velocityInDisplayUnits(t),
2273
+ min: e.minVelocityInDisplayUnits(t),
2274
+ max: e.maxVelocityInDisplayUnits(t),
2275
+ onVelocityChange: e.setVelocityFromSlider,
2276
+ useDegree: t,
2277
+ disabled: e.isLocked,
2278
+ renderValue: (n) => /* @__PURE__ */ c(
2279
+ zt,
2280
+ {
2281
+ value: i(n, t),
2282
+ sx: {
2283
+ minWidth: "111px",
2284
+ span: {
2285
+ transform: "translateY(-1.5px)"
2286
+ }
2287
+ }
2288
+ }
2289
+ )
2290
+ }
2291
+ );
2292
+ }
2293
+ ), Gt = M(({ store: e }) => {
2294
+ var a, s, h;
2295
+ const { t } = V(), o = U(), i = ((h = (s = (a = e.jogger.motionStream.rapidlyChangingMotionState.execute) == null ? void 0 : a.details) == null ? void 0 : s.state) == null ? void 0 : h.kind) ?? "KIND_UNKNOWN", n = e.lastJogError, r = e.lastJogErrorTranslationKey;
2296
+ return /* @__PURE__ */ y(
2297
+ F,
2298
+ {
2299
+ sx: {
2300
+ display: "flex",
2301
+ flexDirection: "row",
2302
+ justifyContent: "space-between",
2303
+ color: o.palette.text.primary
2304
+ },
2305
+ children: [
2306
+ /* @__PURE__ */ c(
2307
+ _,
2308
+ {
2309
+ variant: "body2",
2310
+ sx: {
2311
+ fontSize: "0.75rem",
2312
+ // Smaller than body2
2313
+ lineHeight: 1.2
2314
+ },
2315
+ children: t("Jogging.StreamStateSection.lb")
2316
+ }
2317
+ ),
2318
+ /* @__PURE__ */ c(
2319
+ _,
2320
+ {
2321
+ variant: "body2",
2322
+ color: n ? "error" : void 0,
2323
+ sx: {
2324
+ fontSize: "0.75rem",
2325
+ // Smaller than body2
2326
+ lineHeight: 1.2,
2327
+ textAlign: "right"
2328
+ },
2329
+ "data-testid": n ? "JOG_ERROR" : i,
2330
+ children: n ? r ? t(r) : n : t(`Jogging.StreamStateSection.${i}.lb`)
2331
+ }
2332
+ )
2333
+ ]
2334
+ }
2335
+ );
2336
+ }), po = M(
2337
+ ({
2338
+ store: e,
2339
+ children: t
2340
+ }) => {
2341
+ const { t: o } = V(), i = U(), n = at(0);
2342
+ function r(d, l) {
2343
+ (l === "translate" || l === "rotate") && e.setSelectedCartesianMotionType(l);
2344
+ }
2345
+ async function a(d, l) {
2346
+ const f = await e.activate(), p = f.motionStream.rapidlyChangingMotionState.tcp_pose, C = f.motionStream.rapidlyChangingMotionState.joint_position;
2347
+ p && await e.withMotionLock(async () => {
2348
+ try {
2349
+ e.setCurrentIncrementJog({
2350
+ axis: d.axis,
2351
+ direction: d.direction
2352
+ }), await e.jogger.runIncrementalCartesianMotion({
2353
+ currentTcpPose: p,
2354
+ currentJoints: C,
2355
+ coordSystemId: e.activeCoordSystemId,
2356
+ velocityInRelevantUnits: e.selectedCartesianMotionType === "translate" ? e.translationVelocityMmPerSec : e.rotationVelocityRadsPerSec,
2357
+ axis: d.axis,
2358
+ direction: d.direction,
2359
+ motion: e.selectedCartesianMotionType === "translate" ? {
2360
+ type: "translate",
2361
+ distanceMm: l.mm
2362
+ } : {
2363
+ type: "rotate",
2364
+ distanceRads: re(l.degrees)
2365
+ }
2366
+ });
2367
+ } finally {
2368
+ e.setCurrentIncrementJog(null), await e.deactivate();
2369
+ }
2370
+ });
2371
+ }
2372
+ async function s(d) {
2373
+ if (e.isLocked) return;
2374
+ const l = ++n.current;
2375
+ try {
2376
+ if (await e.activate(), l !== n.current) return;
2377
+ if (e.activeDiscreteIncrement)
2378
+ return await a(
2379
+ d,
2380
+ e.activeDiscreteIncrement
2381
+ );
2382
+ d.motionType === "translate" ? await e.jogger.translateTCP({
2383
+ axis: d.axis,
2384
+ direction: d.direction,
2385
+ velocityMmPerSec: e.translationVelocityMmPerSec
2386
+ }) : await e.jogger.rotateTCP({
2387
+ axis: d.axis,
2388
+ direction: d.direction,
2389
+ velocityRadsPerSec: e.rotationVelocityRadsPerSec
2390
+ });
2391
+ } catch (f) {
2392
+ console.error("Jogging failed:", f);
2393
+ }
2394
+ }
2395
+ async function h() {
2396
+ e.isLocked || e.activeDiscreteIncrement || (n.current++, await e.deactivate());
2397
+ }
2398
+ const m = [
2399
+ {
2400
+ id: "x",
2401
+ icon: /* @__PURE__ */ c(qe, {}),
2402
+ colors: lt.X
2403
+ },
2404
+ {
2405
+ id: "y",
2406
+ icon: /* @__PURE__ */ c(Ke, {}),
2407
+ colors: lt.Y
2408
+ },
2409
+ {
2410
+ id: "z",
2411
+ icon: /* @__PURE__ */ c(Qe, {}),
2412
+ colors: lt.Z
2413
+ }
2414
+ ];
2415
+ function g(d) {
2416
+ return o("General.mm.variable", { amount: d.toFixed(1) });
2417
+ }
2418
+ function u(d) {
2419
+ return o("General.degree.variable", {
2420
+ amount: Ot(d).toFixed(1)
2421
+ });
2422
+ }
2423
+ return /* @__PURE__ */ y(
2424
+ x,
2425
+ {
2426
+ "data-testid": "jogging-cartesian-tab",
2427
+ "aria-label": "jogging-cartesian-tab",
2428
+ flexGrow: 1,
2429
+ gap: 2,
2430
+ sx: { padding: "18px 24px" },
2431
+ children: [
2432
+ /* @__PURE__ */ y(x, { gap: 2, children: [
2433
+ /* @__PURE__ */ c(
2434
+ ho,
2435
+ {
2436
+ store: e,
2437
+ useDegree: e.selectedCartesianMotionType === "rotate"
2438
+ }
2439
+ ),
2440
+ /* @__PURE__ */ c(
2441
+ Ut,
2442
+ {
2443
+ store: e,
2444
+ useDegree: e.selectedCartesianMotionType === "rotate"
2445
+ }
2446
+ ),
2447
+ /* @__PURE__ */ c(B, {})
2448
+ ] }),
2449
+ /* @__PURE__ */ c(
2450
+ x,
2451
+ {
2452
+ marginLeft: "auto",
2453
+ marginRight: "auto",
2454
+ gap: "24px",
2455
+ justifyContent: "center",
2456
+ sx: { flexGrow: "1" },
2457
+ children: /* @__PURE__ */ y(
2458
+ x,
2459
+ {
2460
+ alignItems: "center",
2461
+ justifyContent: "center",
2462
+ gap: "24px",
2463
+ sx: { flexGrow: 1 },
2464
+ children: [
2465
+ /* @__PURE__ */ y(
2466
+ mo,
2467
+ {
2468
+ value: e.selectedCartesianMotionType,
2469
+ onChange: r,
2470
+ exclusive: !0,
2471
+ "aria-label": o("Jogging.Cartesian.MotionType.lb"),
2472
+ sx: { justifyContent: "center" },
2473
+ children: [
2474
+ /* @__PURE__ */ c(xt, { value: "translate", children: o("Jogging.Cartesian.Translation.bt") }),
2475
+ /* @__PURE__ */ c(xt, { value: "rotate", children: o("Jogging.Cartesian.Rotation.bt") })
2476
+ ]
2477
+ }
2478
+ ),
2479
+ e.selectedCartesianMotionType === "translate" && m.map((d) => {
2480
+ var l, f;
2481
+ return /* @__PURE__ */ c(
2482
+ _t,
2483
+ {
2484
+ "data-testid": `jogging-cartesian-axis-control-${d.id}`,
2485
+ "aria-label": `jogging-cartesian-axis-control-${d.id}`,
2486
+ colors: d.colors,
2487
+ disabled: e.isLocked,
2488
+ activeJoggingDirection: ((l = e.incrementJogInProgress) == null ? void 0 : l.axis) === d.id ? e.incrementJogInProgress.direction : void 0,
2489
+ label: /* @__PURE__ */ y(et, { children: [
2490
+ d.icon,
2491
+ /* @__PURE__ */ c(
2492
+ _,
2493
+ {
2494
+ sx: {
2495
+ fontSize: "24px",
2496
+ color: ((f = d.colors) == null ? void 0 : f.labelColor) ?? i.palette.text.primary
2497
+ },
2498
+ children: d.id.toUpperCase()
2499
+ }
2500
+ )
2501
+ ] }),
2502
+ getDisplayedValue: () => {
2503
+ var p, C;
2504
+ return g(
2505
+ ((C = (p = e.jogger.motionStream.rapidlyChangingMotionState.tcp_pose) == null ? void 0 : p.position) == null ? void 0 : C[Ct[d.id]]) || 0
2506
+ );
2507
+ },
2508
+ startJogging: (p) => s({
2509
+ axis: d.id,
2510
+ motionType: "translate",
2511
+ direction: p
2512
+ }),
2513
+ stopJogging: h
2514
+ },
2515
+ d.id
2516
+ );
2517
+ }),
2518
+ e.selectedCartesianMotionType === "rotate" && m.map((d) => {
2519
+ var l, f;
2520
+ return /* @__PURE__ */ c(
2521
+ _t,
2522
+ {
2523
+ "data-testid": `jogging-cartesian-axis-control-${d.id}`,
2524
+ "aria-label": `jogging-cartesian-axis-control-${d.id}`,
2525
+ colors: d.colors,
2526
+ disabled: e.isLocked,
2527
+ activeJoggingDirection: ((l = e.incrementJogInProgress) == null ? void 0 : l.axis) === d.id ? e.incrementJogInProgress.direction : void 0,
2528
+ label: /* @__PURE__ */ y(et, { children: [
2529
+ /* @__PURE__ */ c(Xe, {}),
2530
+ /* @__PURE__ */ c(
2531
+ _,
2532
+ {
2533
+ sx: {
2534
+ fontSize: "24px",
2535
+ color: ((f = d.colors) == null ? void 0 : f.labelColor) ?? i.palette.text.primary
2536
+ },
2537
+ children: d.id.toUpperCase()
2538
+ }
2539
+ )
2540
+ ] }),
2541
+ getDisplayedValue: () => {
2542
+ var p, C;
2543
+ return u(
2544
+ ((C = (p = e.jogger.motionStream.rapidlyChangingMotionState.tcp_pose) == null ? void 0 : p.orientation) == null ? void 0 : C[Ct[d.id]]) || 0
2545
+ );
2546
+ },
2547
+ startJogging: (p) => s({
2548
+ axis: d.id,
2549
+ motionType: "rotate",
2550
+ direction: p
2551
+ }),
2552
+ stopJogging: h
2553
+ },
2554
+ d.id
2555
+ );
2556
+ })
2557
+ ]
2558
+ }
2559
+ )
2560
+ }
2561
+ ),
2562
+ /* @__PURE__ */ c(Ft, { store: e }),
2563
+ /* @__PURE__ */ c(B, {}),
2564
+ /* @__PURE__ */ c(Gt, { store: e }),
2565
+ t && /* @__PURE__ */ c(B, {}),
2566
+ t
2567
+ ]
2568
+ }
2569
+ );
2570
+ }
2571
+ ), fo = M(
2572
+ ({ store: e, children: t }) => {
2573
+ const o = U(), i = at(0);
2574
+ async function n(a) {
2575
+ const s = ++i.current;
2576
+ try {
2577
+ if (await e.activate(), s !== i.current) return;
2578
+ await e.jogger.rotateJoints({
2579
+ joint: a.joint,
2580
+ direction: a.direction,
2581
+ velocityUnit: e.jointType === N.PrismaticJoint ? "mm/s" : "rad/s",
2582
+ velocityValue: e.jointType === N.PrismaticJoint ? e.translationVelocityMmPerSec : e.rotationVelocityRadsPerSec
2583
+ });
2584
+ } catch (h) {
2585
+ console.error("Jogging failed:", h);
2586
+ }
2587
+ }
2588
+ async function r() {
2589
+ i.current++, await e.jogger.stop(), await e.deactivate();
2590
+ }
2591
+ return /* @__PURE__ */ y(
2592
+ x,
2593
+ {
2594
+ "data-testid": "jogging-joint-tab",
2595
+ "aria-label": "jogging-joint-tab",
2596
+ flexGrow: 1,
2597
+ gap: 2,
2598
+ sx: { padding: "18px 24px" },
2599
+ children: [
2600
+ /* @__PURE__ */ c(
2601
+ Ut,
2602
+ {
2603
+ store: e,
2604
+ useDegree: e.jointType === N.RevoluteJoint
2605
+ }
2606
+ ),
2607
+ /* @__PURE__ */ c(B, {}),
2608
+ /* @__PURE__ */ c(
2609
+ x,
2610
+ {
2611
+ justifyContent: "center",
2612
+ alignItems: "stretch",
2613
+ sx: { flexGrow: "1" },
2614
+ children: /* @__PURE__ */ c(
2615
+ x,
2616
+ {
2617
+ "data-testid": "jogging-joint-value-controls-wrapper",
2618
+ "aria-label": "jogging-joint-value-controls-wrapper",
2619
+ alignItems: "center",
2620
+ gap: "24px",
2621
+ children: e.jogger.motionStream.joints.map((a) => {
2622
+ var h, m, g;
2623
+ const s = (g = (m = (h = e.motionGroupDescription.operation_limits.auto_limits) == null ? void 0 : h.joints) == null ? void 0 : m[a.index]) == null ? void 0 : g.position;
2624
+ return /* @__PURE__ */ y(
2625
+ x,
2626
+ {
2627
+ "data-testid": `jogging-joint-value-control-${a.index}`,
2628
+ "aria-label": `jogging-joint-value-control-${a.index}`,
2629
+ direction: "row",
2630
+ alignItems: "center",
2631
+ justifyContent: "center",
2632
+ spacing: 1.5,
2633
+ width: "100%",
2634
+ children: [
2635
+ e.showJointsLegend && /* @__PURE__ */ c(
2636
+ _,
2637
+ {
2638
+ color: e.isLocked ? o.palette.text.disabled : o.palette.text.secondary,
2639
+ children: `G${a.index + 1}`
2640
+ }
2641
+ ),
2642
+ /* @__PURE__ */ c(
2643
+ Re,
2644
+ {
2645
+ disabled: e.isLocked,
2646
+ lowerLimit: s == null ? void 0 : s.lower_limit,
2647
+ upperLimit: s == null ? void 0 : s.upper_limit,
2648
+ useDegree: e.jointType === N.RevoluteJoint,
2649
+ getValue: () => {
2650
+ const u = e.jogger.motionStream.rapidlyChangingMotionState.joint_position[a.index];
2651
+ return u !== void 0 ? u : void 0;
2652
+ },
2653
+ startJogging: (u) => n({
2654
+ joint: a.index,
2655
+ direction: u
2656
+ }),
2657
+ stopJogging: r
2658
+ }
2659
+ )
2660
+ ]
2661
+ },
2662
+ `joint-${a.index}`
2663
+ );
2664
+ })
2665
+ }
2666
+ )
2667
+ }
2668
+ ),
2669
+ /* @__PURE__ */ c(Ft, { store: e }),
2670
+ /* @__PURE__ */ c(B, {}),
2671
+ /* @__PURE__ */ c(Gt, { store: e }),
2672
+ t && /* @__PURE__ */ c(B, {}),
2673
+ t
2674
+ ]
2675
+ }
2676
+ );
2677
+ }
2678
+ ), xi = X(
2679
+ M((e) => {
2680
+ const t = kt(() => ({
2681
+ joggingStore: null,
2682
+ loadingError: null
2683
+ }));
2684
+ return ot(() => {
2685
+ let o = !1, i;
2686
+ async function n() {
2687
+ S(() => {
2688
+ t.loadingError = null, t.joggingStore = null;
2689
+ });
2690
+ try {
2691
+ let r = e.store;
2692
+ if (!r) {
2693
+ const a = await yt.open(
2694
+ e.nova,
2695
+ e.motionGroupId,
2696
+ {
2697
+ cellId: e.cellId
2698
+ }
2699
+ );
2700
+ if (o) {
2701
+ a.dispose();
2702
+ return;
2703
+ }
2704
+ try {
2705
+ r = await rt.loadFor(a);
2706
+ } catch (s) {
2707
+ throw a.dispose(), s;
2708
+ }
2709
+ if (i = r, o) {
2710
+ r.dispose();
2711
+ return;
2712
+ }
2713
+ }
2714
+ S(() => {
2715
+ t.joggingStore = r;
2716
+ }), e.onSetup && e.onSetup(r);
2717
+ } catch (r) {
2718
+ if (o) return;
2719
+ S(() => {
2720
+ t.loadingError = r;
2721
+ });
2722
+ }
2723
+ }
2724
+ return n(), () => {
2725
+ o = !0, i == null || i.dispose();
2726
+ };
2727
+ }, [e.store, e.nova, e.motionGroupId, e.cellId]), ot(() => {
2728
+ const o = t.joggingStore;
2729
+ o && (e.locked ? o.lock("external") : o.unlock("external"));
2730
+ }, [t.joggingStore, e.locked]), /* @__PURE__ */ c(
2731
+ x,
2732
+ {
2733
+ "data-testid": "jogging-panel",
2734
+ "aria-label": "jogging-panel",
2735
+ sx: {
2736
+ maxWidth: "460px",
2737
+ minWidth: "320px",
2738
+ position: "relative",
2739
+ ...e.sx
2740
+ },
2741
+ children: t.joggingStore ? /* @__PURE__ */ c(yo, { store: t.joggingStore, children: e.children }) : /* @__PURE__ */ c(ze, { message: "Loading jogging", error: t.loadingError })
2742
+ }
2743
+ );
2744
+ })
2745
+ ), yo = M(
2746
+ ({
2747
+ store: e,
2748
+ children: t
2749
+ }) => {
2750
+ const { t: o } = V();
2751
+ function i() {
2752
+ if (e.currentTab.id === "cartesian")
2753
+ return /* @__PURE__ */ c(po, { store: e, children: t });
2754
+ if (e.currentTab.id === "joint")
2755
+ return /* @__PURE__ */ c(fo, { store: e, children: t });
2756
+ }
2757
+ return /* @__PURE__ */ y(x, { flexGrow: 1, sx: { overflow: "hidden" }, children: [
2758
+ /* @__PURE__ */ c(
2759
+ oe,
2760
+ {
2761
+ "data-testid": "jogging-tabs",
2762
+ "aria-label": "jogging-tabs",
2763
+ value: e.tabIndex,
2764
+ onChange: e.onTabChange,
2765
+ variant: "fullWidth",
2766
+ children: e.tabs.map((n) => {
2767
+ const r = n.label === "Cartesian" ? o("Jogging.Cartesian.bt") : o("Jogging.Joints.bt"), a = n.label === "cartesian" ? /* @__PURE__ */ c(Xt, { fontSize: "small", sx: { mr: 1 } }) : /* @__PURE__ */ c(te, { fontSize: "small", sx: { mr: 1 } });
2768
+ return /* @__PURE__ */ c(
2769
+ ee,
2770
+ {
2771
+ "data-testid": `jogging-tab-${n.id}`,
2772
+ "aria-label": `jogging-tab-${n.id}`,
2773
+ label: e.showTabIcons ? /* @__PURE__ */ y(x, { direction: "row", alignItems: "center", children: [
2774
+ a,
2775
+ r
2776
+ ] }) : r,
2777
+ id: `jogging-tab-${n.id}`,
2778
+ "aria-controls": `jogging-tab-${n.id}`
2779
+ },
2780
+ n.id
2781
+ );
2782
+ })
2783
+ }
2784
+ ),
2785
+ /* @__PURE__ */ c(
2786
+ x,
2787
+ {
2788
+ flexGrow: 1,
2789
+ position: "relative",
2790
+ sx: { overflowY: "auto", overflowX: "hidden" },
2791
+ children: i()
2792
+ }
2793
+ ),
2794
+ e.blocked && /* @__PURE__ */ c(Ge, { store: e })
2795
+ ] });
2796
+ }
2797
+ );
2798
+ function So() {
2799
+ const e = window.location.href;
2800
+ return e.substring(
2801
+ 0,
2802
+ e.indexOf("/", e.indexOf("//") + 2)
2803
+ );
2804
+ }
2805
+ function Ii({
2806
+ baseUrl: e = So(),
2807
+ ...t
2808
+ }) {
2809
+ return /* @__PURE__ */ y(
2810
+ _e,
2811
+ {
2812
+ "aria-labelledby": "no-motion-group-modal-title",
2813
+ open: !0,
2814
+ fullWidth: !0,
2815
+ sx: {
2816
+ "& .MuiModal-backdrop": {
2817
+ backdropFilter: "blur(10px)"
2818
+ },
2819
+ "& .MuiDialog-paper": {
2820
+ "::before": {
2821
+ content: '""',
2822
+ height: "8px",
2823
+ width: "100%",
2824
+ background: "linear-gradient(90deg, #FF0E65 0%, #47D3FF 100%)"
2825
+ },
2826
+ background: "#101629"
2827
+ }
2828
+ },
2829
+ children: [
2830
+ /* @__PURE__ */ c(Ee, { id: "no-motion-group-modal-title", children: "No motion group found" }),
2831
+ /* @__PURE__ */ y(
2832
+ je,
2833
+ {
2834
+ sx: {
2835
+ marginTop: "3rem",
2836
+ marginBottom: "1.5rem",
2837
+ textAlign: "center"
2838
+ },
2839
+ children: [
2840
+ /* @__PURE__ */ c(_, { color: "#fff", children: "Found no devices to connect to." }),
2841
+ /* @__PURE__ */ c(_, { color: "#fff", children: "Please ensure a motion group has been created." })
2842
+ ]
2843
+ }
2844
+ ),
2845
+ /* @__PURE__ */ c(we, { children: /* @__PURE__ */ y(x, { width: "100%", maxWidth: "300px", margin: "auto", marginBottom: "2rem", children: [
2846
+ /* @__PURE__ */ c(
2847
+ dt,
2848
+ {
2849
+ href: `${e}/settings`,
2850
+ variant: "contained",
2851
+ sx: {
2852
+ borderRadius: "8px",
2853
+ width: "100%"
2854
+ },
2855
+ children: "Go to settings app"
2856
+ }
2857
+ ),
2858
+ /* @__PURE__ */ c(
2859
+ dt,
2860
+ {
2861
+ href: `${e}`,
2862
+ variant: "text",
2863
+ sx: {
2864
+ marginTop: "1rem",
2865
+ color: "#fff",
2866
+ textDecoration: "underline",
2867
+ fontSize: "0.75rem"
2868
+ },
2869
+ children: "Back to Homescreen"
2870
+ }
2871
+ )
2872
+ ] }) })
2873
+ ]
2874
+ }
2875
+ );
2876
+ }
2877
+ const Mt = 1e-4, bo = {
2878
+ a: 0,
2879
+ d: 0,
2880
+ alpha: 0,
2881
+ theta: 0,
2882
+ reverse_rotation_direction: !1
2883
+ };
2884
+ class ut {
2885
+ constructor(t, o, i, n, r, a, s, h, m, g, u = "cell") {
2886
+ this.controller = o, this.motionGroup = i, this.initialMotionState = n, this.motionStateSocket = r, this.isVirtual = a, this.tcps = s, this.description = h, this.initialControllerState = m, this.controllerStateSocket = g, this.cellId = u, this.connectedJoggingSocket = null, this.joggingVelocity = 10, this.activationState = "inactive", this.nova = Y(t), this.rapidlyChangingMotionState = n, this.controllerState = m, g.addEventListener("message", (d) => {
2887
+ var f;
2888
+ const l = (f = J(d.data)) == null ? void 0 : f.result;
2889
+ l && S(() => {
2890
+ this.controllerState = l;
2891
+ });
2892
+ }), r.addEventListener("message", (d) => {
2893
+ var f;
2894
+ const l = (f = J(d.data)) == null ? void 0 : f.result;
2895
+ if (!l)
2896
+ throw new Error(
2897
+ `Failed to get motion state for ${this.motionGroupId}: ${d.data}`
2898
+ );
2899
+ Vt(
2900
+ this.rapidlyChangingMotionState.joint_position,
2901
+ l.joint_position,
2902
+ Mt
2903
+ ) || S(() => {
2904
+ this.rapidlyChangingMotionState.joint_position = l.joint_position;
2905
+ }), Nt(
2906
+ this.rapidlyChangingMotionState,
2907
+ l,
2908
+ Mt
2909
+ ) || S(() => {
2910
+ this.rapidlyChangingMotionState.tcp_pose = l.tcp_pose;
2911
+ }), l.tcp !== void 0 && this.rapidlyChangingMotionState.tcp !== l.tcp && S(() => {
2912
+ this.rapidlyChangingMotionState.tcp = l.tcp;
2913
+ }), this.rapidlyChangingMotionState.standstill !== l.standstill && S(() => {
2914
+ this.rapidlyChangingMotionState.standstill = l.standstill;
2915
+ });
2916
+ }), st(this);
2917
+ }
2918
+ static async connectMultiple(t, o, i = {}) {
2919
+ const n = Y(t), r = i.cellId ?? ct(t);
2920
+ return Promise.all(
2921
+ o.map(
2922
+ (a) => ut.connect(n, a, {
2923
+ ...i,
2924
+ cellId: r
2925
+ })
2926
+ )
2927
+ );
2928
+ }
2929
+ static async connect(t, o, i = {}) {
2930
+ var k, O;
2931
+ const n = Y(t), r = i.cellId ?? ct(t) ?? "cell", [a, s] = o.split("@"), h = await n.api.controller.getCurrentRobotControllerState(
2932
+ r,
2933
+ s
2934
+ ), m = h == null ? void 0 : h.motion_groups.find(
2935
+ (I) => I.motion_group === o
2936
+ );
2937
+ if (!h || !m)
2938
+ throw new Error(
2939
+ `Controller ${s} or motion group ${o} not found`
2940
+ );
2941
+ const g = n.openReconnectingWebsocket(
2942
+ `/cells/${r}/controllers/${s}/motion-groups/${o}/state-stream`
2943
+ ), u = await g.firstMessage(), d = (k = J(u.data)) == null ? void 0 : k.result;
2944
+ if (!d)
2945
+ throw new Error(
2946
+ `Unable to parse initial motion state message ${u.data}`
2947
+ );
2948
+ console.log(
2949
+ `Connected motion state websocket to motion group ${m.motion_group}. Initial state:
2950
+ `,
2951
+ d
2952
+ );
2953
+ const f = (await n.api.controller.getRobotController(
2954
+ r,
2955
+ h.controller
2956
+ )).configuration.kind === "VirtualController", p = await n.api.motionGroup.getMotionGroupDescription(
2957
+ r,
2958
+ s,
2959
+ m.motion_group
2960
+ ), C = Object.entries(p.tcps || {}).map(
2961
+ ([I, R]) => ({
2962
+ id: I,
2963
+ readable_name: R.name,
2964
+ position: R.pose.position,
2965
+ orientation: R.pose.orientation
2966
+ })
2967
+ ), E = n.openReconnectingWebsocket(
2968
+ `/cells/${r}/controllers/${h.controller}/state-stream?response_rate=1000`
2969
+ ), j = await E.firstMessage(), T = (O = J(j.data)) == null ? void 0 : O.result;
2970
+ if (!T)
2971
+ throw new Error(
2972
+ `Unable to parse initial controller state message ${j.data}`
2973
+ );
2974
+ return console.log(
2975
+ `Connected controller state websocket to controller ${h.controller}. Initial state:
2976
+ `,
2977
+ T
2978
+ ), new ut(
2979
+ n,
2980
+ h,
2981
+ m,
2982
+ d,
2983
+ g,
2984
+ f,
2985
+ C,
2986
+ p,
2987
+ T,
2988
+ E,
2989
+ r
2990
+ );
2991
+ }
2992
+ get motionGroupId() {
2993
+ return this.motionGroup.motion_group;
2994
+ }
2995
+ get controllerId() {
2996
+ return this.controller.controller;
2997
+ }
2998
+ get modelFromController() {
2999
+ return this.description.motion_group_model;
3000
+ }
3001
+ /** Jogging velocity in radians for rotation and joint movement */
3002
+ get joggingVelocityRads() {
3003
+ return this.joggingVelocity * Math.PI / 180;
3004
+ }
3005
+ get joints() {
3006
+ return this.initialMotionState.joint_position.map((t, o) => ({
3007
+ index: o
3008
+ }));
3009
+ }
3010
+ // Please note that API v2 omits 0 values
3011
+ get dhParameters() {
3012
+ if (this.description.dh_parameters !== void 0)
3013
+ return this.description.dh_parameters.map((t) => ({
3014
+ ...bo,
3015
+ ...t
3016
+ }));
3017
+ }
3018
+ get safetyZones() {
3019
+ return this.description.safety_zones;
3020
+ }
3021
+ /** Gets the robot mounting position offset in 3D viz coordinates */
3022
+ get mountingPosition() {
3023
+ var t, o, i;
3024
+ return this.description.mounting ? [
3025
+ (((t = this.description.mounting.position) == null ? void 0 : t[0]) || 0) / 1e3,
3026
+ (((o = this.description.mounting.position) == null ? void 0 : o[1]) || 0) / 1e3,
3027
+ (((i = this.description.mounting.position) == null ? void 0 : i[2]) || 0) / 1e3
3028
+ ] : [0, 0, 0];
3029
+ }
3030
+ /** Gets the robot mounting position rotation in 3D viz coordinates */
3031
+ get mountingQuaternion() {
3032
+ var n, r, a, s, h, m;
3033
+ const t = new vt.Vector3(
3034
+ ((r = (n = this.description.mounting) == null ? void 0 : n.orientation) == null ? void 0 : r[0]) || 0,
3035
+ ((s = (a = this.description.mounting) == null ? void 0 : a.orientation) == null ? void 0 : s[1]) || 0,
3036
+ ((m = (h = this.description.mounting) == null ? void 0 : h.orientation) == null ? void 0 : m[2]) || 0
3037
+ ), o = t.length(), i = t.normalize();
3038
+ return new vt.Quaternion().setFromAxisAngle(i, o);
3039
+ }
3040
+ /**
3041
+ * Whether the controller is currently in a safety state
3042
+ * corresponding to an emergency stop
3043
+ */
3044
+ get isEstopActive() {
3045
+ return [
3046
+ "SAFETY_STATE_ROBOT_EMERGENCY_STOP",
3047
+ "SAFETY_STATE_DEVICE_EMERGENCY_STOP"
3048
+ ].includes(this.controllerState.safety_state);
3049
+ }
3050
+ /**
3051
+ * Whether the controller is in a safety state
3052
+ * that may be non-functional for robot pad purposes
3053
+ */
3054
+ get isMoveableSafetyState() {
3055
+ return [
3056
+ "SAFETY_STATE_NORMAL",
3057
+ "SAFETY_STATE_REDUCED"
3058
+ ].includes(this.controllerState.safety_state);
3059
+ }
3060
+ /**
3061
+ * Whether the controller is in an operation mode that allows movement
3062
+ */
3063
+ get isMoveableOperationMode() {
3064
+ return [
3065
+ "OPERATION_MODE_AUTO",
3066
+ "OPERATION_MODE_MANUAL",
3067
+ "OPERATION_MODE_MANUAL_T1",
3068
+ "OPERATION_MODE_MANUAL_T2"
3069
+ ].includes(this.controllerState.operation_mode);
3070
+ }
3071
+ /**
3072
+ * Whether the robot is currently active and can be moved, based on the
3073
+ * safety state, operation mode and servo toggle activation state.
3074
+ */
3075
+ get canBeMoved() {
3076
+ return this.isMoveableSafetyState && this.isMoveableOperationMode && this.activationState === "active";
3077
+ }
3078
+ async deactivate() {
3079
+ if (this.activationState !== "active") {
3080
+ console.error("Tried to deactivate while already deactivating");
3081
+ return;
3082
+ }
3083
+ S(() => {
3084
+ this.activationState = "deactivating";
3085
+ });
3086
+ try {
3087
+ await this.nova.api.controller.setDefaultMode(
3088
+ this.cellId,
3089
+ this.controllerId,
3090
+ "ROBOT_SYSTEM_MODE_MONITOR"
3091
+ ), S(() => {
3092
+ this.activationState = "inactive";
3093
+ });
3094
+ } catch (t) {
3095
+ throw S(() => {
3096
+ this.activationState = "active";
3097
+ }), t;
3098
+ }
3099
+ }
3100
+ async activate() {
3101
+ if (this.activationState !== "inactive") {
3102
+ console.error("Tried to activate while already activating");
3103
+ return;
3104
+ }
3105
+ S(() => {
3106
+ this.activationState = "activating";
3107
+ });
3108
+ try {
3109
+ await this.nova.api.controller.setDefaultMode(
3110
+ this.cellId,
3111
+ this.controllerId,
3112
+ "ROBOT_SYSTEM_MODE_CONTROL"
3113
+ ), S(() => {
3114
+ this.activationState = "active";
3115
+ });
3116
+ } catch (t) {
3117
+ throw S(() => {
3118
+ this.activationState = "inactive";
3119
+ }), t;
3120
+ }
3121
+ }
3122
+ toggleActivation() {
3123
+ this.activationState === "inactive" ? this.activate() : this.activationState === "active" && this.deactivate();
3124
+ }
3125
+ dispose() {
3126
+ this.motionStateSocket.close(), this.controllerStateSocket.close(), this.connectedJoggingSocket && this.connectedJoggingSocket.close();
3127
+ }
3128
+ setJoggingVelocity(t) {
3129
+ this.joggingVelocity = t;
3130
+ }
3131
+ }
3132
+ const Co = [
3133
+ "FeedbackOutOfWorkspace",
3134
+ "FeedbackJointLimitExceeded",
3135
+ "FeedbackAxisRangeExceeded",
3136
+ "FeedbackNoSolutionInCurrentConfiguration"
3137
+ ];
3138
+ function _i(e) {
3139
+ return e === "FeedbackSingularity" ? "Jogging.TargetPose.Error.Singularity.lb" : e === "FeedbackCollision" ? "Jogging.TargetPose.Error.Collision.lb" : Co.includes(e) ? "Jogging.TargetPose.Error.NotReachable.lb" : "Jogging.TargetPose.Error.PlanningFailed.lb";
3140
+ }
3141
+ class wi {
3142
+ constructor(t) {
3143
+ this.options = t, this.plannedTrajectory = null, this.trajectoryState = "idle", this.lastError = null, this.disposers = [], this.logger = t.logger ?? console, st(
3144
+ this,
3145
+ { socket: !1, disposers: !1, logger: !1, options: !1 },
3146
+ { autoBind: !0 }
3147
+ ), this.socket = this.openSocket(), this.disposers.push(
3148
+ ne(
3149
+ () => this.executionState,
3150
+ (o) => {
3151
+ o === "END_OF_TRAJECTORY" && this.reset();
3152
+ }
3153
+ )
3154
+ );
3155
+ }
3156
+ get joggingStore() {
3157
+ return this.options.joggingStore;
3158
+ }
3159
+ get jogger() {
3160
+ return this.options.joggingStore.jogger;
3161
+ }
3162
+ get motionStream() {
3163
+ return this.options.joggingStore.jogger.motionStream;
3164
+ }
3165
+ /** The execution state that the motion stream reports, e.g. "RUNNING" */
3166
+ get executionState() {
3167
+ var t, o;
3168
+ return (o = (t = this.motionStream.rapidlyChangingMotionState.execute) == null ? void 0 : t.details) == null ? void 0 : o.state.kind;
3169
+ }
3170
+ /**
3171
+ * Plans a trajectory from the current joints to the target and initializes
3172
+ * it on the execution websocket. The store is "planned" once NOVA accepted
3173
+ * it. Returns a planner rejection as a value; throws while the app locks
3174
+ * the robot and when the planner cannot be reached.
3175
+ */
3176
+ async planTrajectory(t) {
3177
+ var E, j, T, k, O;
3178
+ if ((j = (E = this.options).isLocked) != null && j.call(E))
3179
+ throw this.reset(), new Error("Cannot plan trajectory: the robot is locked");
3180
+ await this.ensureMovementOwnership();
3181
+ const o = this.motionStream.rapidlyChangingMotionState.joint_position ?? [], { cycle_time: i, mounting: n, motion_group_model: r, tcps: a } = this.motionStream.description, s = this.joggingStore.selectedTcpId, h = s ? (T = a == null ? void 0 : a[s]) == null ? void 0 : T.pose : void 0, m = {
3182
+ // The model the jogger plans step jogs with: the custom copy that holds
3183
+ // this robot's data, if the app gave one
3184
+ motion_group_model: ((k = this.jogger.options) == null ? void 0 : k.motionGroupModel) ?? r,
3185
+ cycle_time: i ?? 0,
3186
+ mounting: n,
3187
+ ...h && { tcp_offset: h }
3188
+ };
3189
+ let g;
3190
+ if (t.type === "cartesian") {
3191
+ let I = t.pose;
3192
+ const R = t.coordinateSystemId || "world";
3193
+ if (R !== "world")
3194
+ try {
3195
+ I = ht(
3196
+ {
3197
+ pose: {
3198
+ position: I.position ?? [0, 0, 0],
3199
+ orientation: I.orientation ?? [0, 0, 0]
3200
+ },
3201
+ coordinateSystemId: R
3202
+ },
3203
+ "world",
3204
+ this.joggingStore.coordSystems
3205
+ ).pose;
3206
+ } catch {
3207
+ return this.reset(), { ok: !1, errorFeedbackName: "FeedbackUnknown" };
3208
+ }
3209
+ g = {
3210
+ limits_override: {
3211
+ tcp_velocity_limit: this.joggingStore.translationVelocityMmPerSec
3212
+ },
3213
+ path: {
3214
+ target_pose: I,
3215
+ path_definition_name: "PathCartesianPTP"
3216
+ }
3217
+ };
3218
+ } else
3219
+ g = {
3220
+ limits_override: {
3221
+ joint_velocity_limits: Array(o.length).fill(
3222
+ this.joggingStore.rotationVelocityRadsPerSec
3223
+ )
3224
+ },
3225
+ path: {
3226
+ target_joint_position: t.joints,
3227
+ path_definition_name: "PathJointPTP"
3228
+ }
3229
+ };
3230
+ S(() => {
3231
+ this.lastError = null, this.trajectoryState = "planning";
3232
+ });
3233
+ let u;
3234
+ try {
3235
+ u = await this.jogger.nova.api.trajectoryPlanning.planTrajectory(
3236
+ this.jogger.cellId,
3237
+ {
3238
+ motion_group_setup: m,
3239
+ start_joint_position: o,
3240
+ motion_commands: [g]
3241
+ }
3242
+ );
3243
+ } catch (I) {
3244
+ throw this.reset(), I;
3245
+ }
3246
+ const d = u.response;
3247
+ if ("error_feedback" in d) {
3248
+ const I = ((O = d.error_feedback) == null ? void 0 : O.error_feedback_name) ?? "FeedbackUnknown";
3249
+ return this.reset(), { ok: !1, errorFeedbackName: I };
3250
+ }
3251
+ const l = d.joint_positions, f = l[0], p = l[l.length - 1];
3252
+ if (!f || !p)
3253
+ throw this.reset(), new Error("Trajectory returned invalid joint positions");
3254
+ const C = {
3255
+ message_type: "InitializeMovementRequest",
3256
+ trajectory: {
3257
+ message_type: "TrajectoryData",
3258
+ motion_group: this.jogger.motionGroupId,
3259
+ tcp: s || void 0,
3260
+ data: d
3261
+ }
3262
+ };
3263
+ return this.socket.sendJson(C), S(() => {
3264
+ this.plannedTrajectory = { startJoints: f, endJoints: p };
3265
+ }), { ok: !0 };
3266
+ }
3267
+ /** Starts the motion along the planned trajectory */
3268
+ start() {
3269
+ if (!this.plannedTrajectory)
3270
+ throw new Error("Cannot start trajectory: no planned trajectory exists");
3271
+ if (this.trajectoryState !== "planned")
3272
+ throw new Error(
3273
+ `Cannot start trajectory: expected state "planned", got "${this.trajectoryState}"`
3274
+ );
3275
+ if (this.executionState === "RUNNING")
3276
+ throw new Error("Cannot start trajectory: robot is already running");
3277
+ const t = {
3278
+ message_type: "StartMovementRequest",
3279
+ direction: "DIRECTION_FORWARD"
3280
+ };
3281
+ this.socket.sendJson(t);
3282
+ }
3283
+ /**
3284
+ * Pauses the motion. Resolves once the robot stands still; the trajectory
3285
+ * stays planned, so `start` goes on from there.
3286
+ */
3287
+ async pause() {
3288
+ if (this.trajectoryState !== "moving")
3289
+ throw new Error(
3290
+ `Cannot pause trajectory: expected state "moving", got "${this.trajectoryState}"`
3291
+ );
3292
+ if (this.executionState === "PAUSED_BY_USER")
3293
+ throw new Error("Cannot pause trajectory: robot is already paused");
3294
+ const t = {
3295
+ message_type: "PauseMovementRequest"
3296
+ };
3297
+ this.socket.sendJson(t), await this.waitUntilStopped(), S(() => {
3298
+ this.trajectoryState = this.plannedTrajectory ? "planned" : "idle";
3299
+ });
3300
+ }
3301
+ /**
3302
+ * Stops a moving robot, drops the trajectory and hands the controller's
3303
+ * execution session back: closes the execution websocket and opens a new
3304
+ * one for the next plan
3305
+ */
3306
+ async stopAndReset() {
3307
+ try {
3308
+ if (this.executionState === "RUNNING" || this.trajectoryState === "moving") {
3309
+ const t = {
3310
+ message_type: "PauseMovementRequest"
3311
+ };
3312
+ this.socket.sendJson(t), await this.waitUntilStopped();
3313
+ }
3314
+ } catch (t) {
3315
+ this.logger.warn("Failed to stop trajectory execution cleanly", t);
3316
+ } finally {
3317
+ this.reset(), this.closeSocket(), this.socket = this.openSocket();
3318
+ }
3319
+ }
3320
+ /** Drops the planned trajectory, without telling NOVA */
3321
+ reset() {
3322
+ this.plannedTrajectory = null, this.trajectoryState = "idle";
3323
+ }
3324
+ /** Removes {@link TrajectoryExecutionStore.lastError} */
3325
+ clearError() {
3326
+ this.lastError = null;
3327
+ }
3328
+ /** Closes the execution websocket and stops following the motion stream */
3329
+ dispose() {
3330
+ for (const t of this.disposers)
3331
+ t();
3332
+ this.closeSocket();
3333
+ }
3334
+ /** Ends continuous jogging, unless the app has its own way */
3335
+ async ensureMovementOwnership() {
3336
+ if (this.options.ensureMovementOwnership) {
3337
+ await this.options.ensureMovementOwnership();
3338
+ return;
3339
+ }
3340
+ this.jogger.mode !== "trajectory" && (await this.joggingStore.deactivate(), await this.jogger.setJoggingMode("trajectory"));
3341
+ }
3342
+ /** Resolves once the motion stream reports that the robot stands still */
3343
+ async waitUntilStopped() {
3344
+ await it(() => this.motionStream.rapidlyChangingMotionState.standstill);
3345
+ }
3346
+ handleMessage(t) {
3347
+ var i, n;
3348
+ const o = (i = J(t.data)) == null ? void 0 : i.result;
3349
+ if (o)
3350
+ switch (o.kind) {
3351
+ case "INITIALIZE_RECEIVED":
3352
+ o.add_trajectory_error || o.message ? (this.lastError = ((n = o.add_trajectory_error) == null ? void 0 : n.message) ?? o.message ?? "NOVA refused the trajectory", this.reset()) : this.trajectoryState = "planned";
3353
+ break;
3354
+ case "START_RECEIVED":
3355
+ this.trajectoryState = "moving";
3356
+ break;
3357
+ case "PAUSE_RECEIVED":
3358
+ this.trajectoryState === "moving" && (this.trajectoryState = "stopping");
3359
+ break;
3360
+ case "MOTION_ERROR":
3361
+ this.lastError = o.message, this.reset();
3362
+ break;
3363
+ }
3364
+ }
3365
+ openSocket() {
3366
+ const t = this.jogger.nova.openReconnectingWebsocket(
3367
+ `/cells/${this.jogger.cellId}/controllers/${this.motionStream.controllerId}/execution/trajectory`
3368
+ );
3369
+ return t.addEventListener("message", this.handleMessage), t;
3370
+ }
3371
+ closeSocket() {
3372
+ this.socket.removeEventListener("message", this.handleMessage), this.socket.dispose();
3373
+ }
3374
+ }
3375
+ export {
3376
+ vi as A,
3377
+ ut as C,
3378
+ yt as J,
3379
+ ze as L,
3380
+ ft as M,
3381
+ Ii as N,
3382
+ wi as T,
3383
+ uo as V,
3384
+ _t as a,
3385
+ Re as b,
3386
+ xi as c,
3387
+ rt as d,
3388
+ Ue as e,
3389
+ zt as f,
3390
+ Vt as g,
3391
+ Pe as h,
3392
+ Fe as i,
3393
+ Ae as j,
3394
+ _i as p,
3395
+ Ne as r,
3396
+ Nt as t,
3397
+ Ve as u
3398
+ };