@wandelbots/wandelbots-js-react-components 6.4.0-pr.fix-hold-macos.651.fc760c0 → 6.4.0-pr.refactor-shared-hold-safety.654.1d3d9d8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +49 -0
- package/dist/3d.cjs +1 -1
- package/dist/3d.d.ts +1 -0
- package/dist/3d.js +2 -2
- package/dist/chunks/ConnectedMotionGroup-BAlTfBxM.cjs +4 -0
- package/dist/chunks/{ConnectedMotionGroup-neDeA3uW.js → ConnectedMotionGroup-DezR_n_l.js} +1152 -662
- package/dist/chunks/Robot-BLqRmhXn.js +2081 -0
- package/dist/chunks/Robot-BqLfTxOF.cjs +1 -0
- package/dist/chunks/useSmoothedMotionState-DaudLphD.cjs +1 -0
- package/dist/chunks/useSmoothedMotionState-FMSF0dtk.js +378 -0
- package/dist/components/jogging/JoggingButtons.d.ts +16 -0
- package/dist/components/jogging/gizmo/JoggingGizmo.d.ts +4 -20
- package/dist/components/jogging/gizmo/gizmoShared.d.ts +7 -6
- package/dist/components/jogging/holdSafety.d.ts +44 -0
- package/dist/components/jogging/joggingColors.d.ts +6 -0
- package/dist/components/jogging/joint/JoggingJointSlider.d.ts +52 -0
- package/dist/components/jogging/joint/JointSliderTrack.d.ts +27 -0
- package/dist/components/jogging/joint/jointJog.d.ts +55 -0
- package/dist/components/jogging/joint/useJointJogHold.d.ts +48 -0
- package/dist/components/jogging/useHold.d.ts +10 -11
- package/dist/components/jogging/useJogControls.d.ts +45 -0
- package/dist/core.cjs +1 -1
- package/dist/core.d.ts +4 -0
- package/dist/core.js +24 -22
- package/dist/index.cjs +1 -1
- package/dist/index.js +32 -30
- package/package.json +1 -1
- package/dist/chunks/ConnectedMotionGroup-_YUOhOLL.cjs +0 -4
- package/dist/chunks/Robot-BLB4PI8_.js +0 -2159
- package/dist/chunks/Robot-CyO0YcOs.cjs +0 -1
- package/dist/chunks/useSmoothedMotionState-BidFV3kQ.js +0 -255
- package/dist/chunks/useSmoothedMotionState-CdhkBCqt.cjs +0 -1
- package/dist/components/jogging/useHoldToJog.d.ts +0 -24
package/README.md
CHANGED
|
@@ -196,6 +196,55 @@ const orientation = useRef<Quaternion | null>(null)
|
|
|
196
196
|
/>
|
|
197
197
|
```
|
|
198
198
|
|
|
199
|
+
**JoggingButtons** - Jogging by buttons: a row per axis with a minus and a plus button, held to jog (X-, X+; or Rx-, Rx+ when `motion` is `"rotate"`). It takes the same props as `JoggingGizmo` (`JogControlsProps`: `motion`, `onJogStart`, `onJogStop`, `activeHandle`, `disabled`), so an app wires both the same way and can offer both. Unlike the gizmo, the buttons do not turn with the 3D view: X+ is X+ of the jog frame, wherever the camera looks from. They draw nothing in 3D, so they need no `<Canvas>` and no `JoggingGizmoOrientation`.
|
|
200
|
+
|
|
201
|
+
```tsx
|
|
202
|
+
<JoggingButtons
|
|
203
|
+
motion={motion} // "translate" or "rotate"
|
|
204
|
+
onJogStart={(axis, direction) =>
|
|
205
|
+
motion === "rotate"
|
|
206
|
+
? startRotating(axis, direction)
|
|
207
|
+
: startJogging(axis, direction)
|
|
208
|
+
}
|
|
209
|
+
onJogStop={() => stopJogging()}
|
|
210
|
+
/>
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
**JoggingJointSlider** - One joint as a slider across its limits, with the thumb at the joint's value and the limits below; an app shows one per joint. Hover the track to see the goal under the pointer, and press there to jog the joint toward it: it stops when it gets there or when the slider is let go. While held, the goal follows the pointer, and the joint turns around when the goal passes it. An arrow key held on the focused slider jogs toward that limit.
|
|
214
|
+
|
|
215
|
+
- `value`, `min` and `max` are in NOVA's units: radians, or mm with `linear`. A revolute joint with one limit spans one turn from it, and without limits the turn it stands in. A linear axis needs both limits to be jogged with the slider; without them it only shows its value. `angleUnit` shows degrees (default) or radians.
|
|
216
|
+
- `onJogStart(direction)` and `onJogStop` leave the jogging to the app, as for `JoggingGizmo` and `JoggingButtons`. One press can bring several starts and stops, always in turn: the joint stops at the goal, and starts again when the goal moves on. When the goal passes the joint, `onJogStop` and the `onJogStart` of the other way come in the same event: an app with asynchronous jog commands must apply them in that order, and must not tear down its jogging connection on that stop.
|
|
217
|
+
- One joint at a time is up to the app. Keep the jogging joint in a ref, which changes at once, and ignore the others' calls: `disabled` alone changes only with the next render, too late for two fingers that move in the same frame.
|
|
218
|
+
|
|
219
|
+
```tsx
|
|
220
|
+
const jogging = useRef<number | null>(null)
|
|
221
|
+
const [active, setActive] = useState<number | null>(null)
|
|
222
|
+
|
|
223
|
+
{jointValues.map((value, index) => (
|
|
224
|
+
<JoggingJointSlider
|
|
225
|
+
key={index}
|
|
226
|
+
label={`J${index + 1}`}
|
|
227
|
+
value={value}
|
|
228
|
+
min={limits[index].lower_limit}
|
|
229
|
+
max={limits[index].upper_limit}
|
|
230
|
+
onJogStart={(direction) => {
|
|
231
|
+
if (jogging.current !== null && jogging.current !== index) return
|
|
232
|
+
jogging.current = index
|
|
233
|
+
setActive(index)
|
|
234
|
+
startJointJogging(index, direction)
|
|
235
|
+
}}
|
|
236
|
+
onJogStop={() => {
|
|
237
|
+
if (jogging.current !== index) return
|
|
238
|
+
jogging.current = null
|
|
239
|
+
setActive(null)
|
|
240
|
+
stopJogging()
|
|
241
|
+
}}
|
|
242
|
+
// Shows the others as unavailable; the ref does the excluding
|
|
243
|
+
disabled={active !== null && active !== index}
|
|
244
|
+
/>
|
|
245
|
+
))}
|
|
246
|
+
```
|
|
247
|
+
|
|
199
248
|
### 3D Visualization & Robotics
|
|
200
249
|
|
|
201
250
|
3D components for robot visualization. They render inside the `<Canvas>` of React Three Fiber.
|
package/dist/3d.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./chunks/Robot-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./chunks/Robot-BqLfTxOF.cjs"),o=require("./chunks/useSmoothedMotionState-DaudLphD.cjs");exports.CollisionSceneRenderer=e.CollisionSceneRenderer;exports.JoggingGizmo=e.JoggingGizmo;exports.JoggingGizmoOrientation=e.JoggingGizmoOrientation;exports.JointLimitGizmo=e.JointLimitGizmo;exports.LinearAxis=e.LinearAxis;exports.MotionGroupVisualizer=e.MotionGroupVisualizer;exports.MotionGroupVisualizerExact=e.MotionGroupVisualizerExact;exports.PresetEnvironment=e.PresetEnvironment;exports.Robot=e.Robot;exports.SafetyZonesRenderer=e.SafetyZonesRenderer;exports.SupportedLinearAxis=e.SupportedLinearAxis;exports.SupportedLinearAxisExact=e.SupportedLinearAxisExact;exports.SupportedRobot=e.SupportedRobot;exports.SupportedRobotExact=e.SupportedRobotExact;exports.TrajectoryRenderer=e.TrajectoryRenderer;exports.defaultGetModel=e.defaultGetModel;exports.ValueInterpolator=o.ValueInterpolator;exports.useSmoothedMotionState=o.useSmoothedMotionState;
|
package/dist/3d.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ export * from "./components/3d-viewport/TrajectoryRenderer";
|
|
|
6
6
|
export { JoggingGizmo, type JoggingGizmoProps, } from "./components/jogging/gizmo/JoggingGizmo";
|
|
7
7
|
export { JoggingGizmoOrientation, type JoggingGizmoOrientationProps, } from "./components/jogging/gizmo/JoggingGizmoOrientation";
|
|
8
8
|
export type { JogAxis, JogDirection, JogHandle, } from "./components/jogging/jogHandle";
|
|
9
|
+
export type { JogControlsProps } from "./components/jogging/useJogControls";
|
|
9
10
|
export * from "./components/robots/LinearAxis";
|
|
10
11
|
export * from "./components/robots/MotionGroupVisualizer";
|
|
11
12
|
export * from "./components/robots/Robot";
|
package/dist/3d.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { C as a, J as t, a as r, b as s, L as i, M as n, c as p, P as d, R as u, S, d as l, e as m, f as x, g, T as R, h as c } from "./chunks/Robot-
|
|
2
|
-
import { V as f, a as z } from "./chunks/useSmoothedMotionState-
|
|
1
|
+
import { C as a, J as t, a as r, b as s, L as i, M as n, c as p, P as d, R as u, S, d as l, e as m, f as x, g, T as R, h as c } from "./chunks/Robot-BLqRmhXn.js";
|
|
2
|
+
import { V as f, a as z } from "./chunks/useSmoothedMotionState-FMSF0dtk.js";
|
|
3
3
|
export {
|
|
4
4
|
a as CollisionSceneRenderer,
|
|
5
5
|
t as JoggingGizmo,
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
"use strict";const i=require("react/jsx-runtime"),zt=require("@mui/material/AppBar"),_t=require("@mui/material/Backdrop"),O=require("@mui/material/Box"),Gt=require("@mui/material/Menu"),Y=require("@mui/material/MenuItem"),Ut=require("@mui/material/Toolbar"),k=require("@mui/material/Typography"),Ht=require("@wandelbots/design-tokens"),Wt=require("@wandelbots/icons/ExpandMoreFilled"),Tt=require("@wandelbots/mui"),L=require("mobx-react-lite"),b=require("react"),H=require("./externalizeComponent-CdX5L_lW.cjs"),Z=require("@mui/material/Button"),I=require("@mui/material/Stack"),A=require("@mui/material/styles"),Yt=require("@wandelbots/icons/Rotation"),w=require("./useSmoothedMotionState-DaudLphD.cjs"),Zt=require("@mui/icons-material/OpenWith"),Xt=require("@mui/icons-material/Share"),Kt=require("@mui/material/Tab"),Qt=require("@mui/material/Tabs"),j=require("mobx"),z=require("react-i18next"),P=require("@wandelbots/nova-js"),G=require("@wandelbots/nova-js/v2"),at=require("three/src/math/Vector3.js"),Et=require("@mui/material/CircularProgress"),te=require("@mui/material/utils"),kt=require("lodash-es"),ee=require("./SafetyBar-D7QT6J0m.cjs"),oe=require("@mui/material/Alert"),ne=require("@mui/material/AlertTitle"),X=require("@mui/material/Divider"),bt=require("@mui/material/ToggleButton"),ot=require("@mui/material/IconButton"),ie=require("lodash-es/isEqual.js"),re=require("@mui/material/InputAdornment"),se=require("@mui/material/FormControl"),ae=require("@mui/material/InputLabel"),le=require("@mui/material/Select"),Q=require("lodash-es/keyBy.js"),ce=require("lodash-es/uniqueId.js"),de=require("@mui/material/ToggleButtonGroup"),Jt=require("@mui/material/Slider"),ge=require("lodash-es/isNumber.js"),ue=require("@mui/icons-material/ChevronLeft"),he=require("@mui/icons-material/ChevronRight"),me=require("lodash-es/throttle.js"),pe=require("@mui/material/Dialog"),fe=require("@mui/material/DialogActions"),xe=require("@mui/material/DialogContent"),ye=require("@mui/material/DialogTitle"),dt=require("three");function Rt(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const o in e)if(o!=="default"){const n=Object.getOwnPropertyDescriptor(e,o);Object.defineProperty(t,o,n.get?n:{enumerable:!0,get:()=>e[o]})}}return t.default=e,Object.freeze(t)}const E=Rt(b),jt=Rt(dt),be=H.externalizeComponent(L.observer(e=>{const{appIcon:t,appName:o,apps:n=[],onAppSelect:r,disabled:s=!1,sx:l}=e,[a,d]=b.useState(null),c=!!a,f=g=>{d(g.currentTarget)},m=()=>{d(null)},h=g=>{m(),g.onClick?g.onClick():g.href&&(window.location.href=g.href),r==null||r(g)};return i.jsxs(i.Fragment,{children:[i.jsx(zt,{position:"static",sx:{boxShadow:"none",backgroundImage:"none","& .MuiAppBar-root":{backgroundImage:"none",backgroundColor:"transparent"},...l},children:i.jsxs(Ut,{sx:{minHeight:"62px !important"},children:[i.jsx(O,{sx:{mr:1,display:"flex",alignItems:"center"},children:t}),i.jsxs(O,{sx:{display:"flex",alignItems:"center",flexGrow:1},children:[i.jsx(k,{component:"h1",variant:"subtitle1",children:o}),n.length>0&&i.jsx(Tt.RoundedIconButton,{icon:i.jsx(Wt.ExpandMoreFilled,{size:20}),ariaLabel:"switch app","aria-controls":"app-menu","aria-haspopup":"true",onClick:f,disabled:s,sx:{ml:1}})]})]})}),i.jsx(_t,{open:c,onClick:m,sx:{backdropFilter:"blur(4px)",backgroundColor:Ht.ZeroGravityComponentsBackdropFill,zIndex:g=>g.zIndex.modal-1}}),i.jsx(Gt,{id:"app-menu",anchorEl:a,open:c,onClose:m,anchorOrigin:{vertical:"bottom",horizontal:"left"},transformOrigin:{vertical:"top",horizontal:"left"},sx:{zIndex:g=>g.zIndex.modal,"& .MuiPaper-root":{minWidth:200,mt:1}},children:n.map(g=>i.jsxs(Y,{onClick:()=>h(g),children:[i.jsx(O,{sx:{display:"flex",alignItems:"center"},children:g.icon}),i.jsx(k,{variant:"body1",sx:{ml:2},children:g.name})]},g.id))})]})}));function je({axis:e,motion:t,disabled:o}){const n=w.jogAxisColors[e];return i.jsx(O,{"aria-hidden":!0,sx:{opacity:o?.4:1,width:30,height:30,flexShrink:0,display:"flex",alignItems:"center",justifyContent:"center",borderRadius:1,backgroundColor:A.alpha(n,.15),border:`1px solid ${A.alpha(n,.4)}`},children:i.jsx(k,{variant:"caption",sx:{color:n},children:t==="rotate"?`R${e}`:e.toUpperCase()})})}function Se(e){return i.jsx(Yt.Rotation,{style:e.direction==="-"?{transform:"scaleX(-1)"}:void 0})}const ve=H.externalizeComponent(e=>{const{motion:t="translate",disabled:o=!1}=e,{handlersFor:n,label:r,isPressed:s}=w.useJogControls(e);return i.jsx(I,{"data-testid":"jogging-buttons",sx:{gap:"16px",width:280,maxWidth:"100%"},children:w.JOG_AXES.map(l=>i.jsxs(I,{direction:"row",sx:{alignItems:"center",gap:"16px"},children:[i.jsx(je,{axis:l,motion:t,disabled:o}),w.JOG_DIRECTIONS.map(a=>{const d={axis:l,direction:a},c=s(d),f=t==="rotate"?Se(d):void 0,m=w.jogAxisColors[l],h={backgroundColor:A.alpha(m,.25),borderColor:A.alpha(m,.4)};return i.jsx(Tt.SecondaryButton,{size:"large",disabled:o,"aria-label":r(d),"aria-pressed":c,startIcon:a==="-"?f:void 0,endIcon:a==="+"?f:void 0,...n(d),sx:{flex:1,touchAction:"none",userSelect:"none","& svg":{width:24,height:24},[`& .${Z.buttonClasses.startIcon}`]:{marginLeft:"-6px"},[`& .${Z.buttonClasses.endIcon}`]:{marginRight:"-6px"},...c&&{...h,[`&.${Z.buttonClasses.disabled}`]:h}},children:w.jogHandleName(d,t)},a)})]},l))})}),Ce=({title:e,titleId:t,...o},n)=>E.createElement("svg",{width:21,height:21,viewBox:"0 0 21 21",fill:"none",xmlns:"http://www.w3.org/2000/svg",ref:n,"aria-labelledby":t,...o},e?E.createElement("title",{id:t},e):null,E.createElement("g",{id:"JogMinus"},E.createElement("path",{id:"Minus",d:"M0 13V8H21V13H0Z",fill:"white"}))),we=b.forwardRef(Ce),Ie=({title:e,titleId:t,...o},n)=>E.createElement("svg",{width:21,height:21,viewBox:"0 0 21 21",fill:"none",xmlns:"http://www.w3.org/2000/svg",ref:n,"aria-labelledby":t,...o},e?E.createElement("title",{id:t},e):null,E.createElement("g",{id:"JogPlus"},E.createElement("g",{id:"Plus"},E.createElement("path",{d:"M0 13V8H8V13H0Z",fill:"white"}),E.createElement("path",{d:"M8 0L13 2.18557e-07L13 21H8L8 0Z",fill:"white"}),E.createElement("path",{d:"M13 13V8H21V13H13Z",fill:"white"})))),Me=b.forwardRef(Ie),gt=H.externalizeComponent(L.observer(({colors:e,label:t,getDisplayedValue:o,startJogging:n,stopJogging:r,disabled:s,activeJoggingDirection:l,...a})=>{var M,R,v,J,D,B,q;w.useAnimationFrame(()=>{const $=o(),V=h.current;V&&(V.textContent=$)});const d=A.useTheme(),[c,f]=b.useState(null);b.useEffect(()=>{s&&S()},[s]);const m=l||c,h=b.useRef(null);e||(e={color:"#fff",backgroundColor:"#000",borderColor:"#000",buttonBackgroundColor:{disabled:"#000",default:"#000",hovered:"#000",pressed:"#000"},labelColor:"#000"});const g=m?(M=e.buttonBackgroundColor)==null?void 0:M.pressed:e.borderColor,y={width:"55px",color:e.color,path:{fill:e.color},alignContent:"center",fontSize:"37px",svg:{pointerEvents:"none"}},x={...y,backgroundColor:(R=e.buttonBackgroundColor)==null?void 0:R.default,":hover":{backgroundColor:(v=e.buttonBackgroundColor)==null?void 0:v.hovered},":active":{backgroundColor:(J=e.buttonBackgroundColor)==null?void 0:J.pressed,color:e.backgroundColor,path:{fill:e.backgroundColor}},":disabled":{backgroundColor:(D=e.buttonBackgroundColor)==null?void 0:D.disabled,"svg path":{fill:d.palette.action.disabled}}},u={...y,backgroundColor:(B=e.buttonBackgroundColor)==null?void 0:B.pressed,color:e.backgroundColor,path:{fill:e.backgroundColor},":disabled":{backgroundColor:(q=e.buttonBackgroundColor)==null?void 0:q.pressed,"svg path":{fill:d.palette.action.disabled}}};function p($,V){s||$.button===0&&(f(V),n(V))}function S(){f(null),r()}return i.jsxs(I,{height:"64px",direction:"row",justifyContent:"center",...a,children:[i.jsx(ot,{disabled:s,disableRipple:!0,onPointerDown:$=>p($,"-"),onPointerUp:S,onPointerOut:S,size:"large",sx:{...m==="-"?u:x,borderRadius:"16px 0px 0px 16px",borderLeft:`2px solid ${g??"#fff"}`,borderBottom:`2px solid ${g??"#fff"}`,borderTop:`2px solid ${g??"#fff"}`},children:i.jsx(we,{})}),i.jsxs(I,{spacing:"6px",sx:{width:"150px",backgroundColor:e.backgroundColor,alignItems:"center",justifyContent:"center",opacity:"0.9",borderBottom:`2px solid ${g??"#fff"}`,borderTop:`2px solid ${g??"#fff"}`},children:[i.jsx(I,{height:"22px",direction:"row",alignItems:"center",justifyItems:"center",spacing:1,sx:{userSelect:"none",color:e.color,".MuiTypography-root":{fontWeight:700,...s?{color:d.palette.action.disabled}:{}},...s?{"svg path":{fill:d.palette.action.disabled}}:{}},children:t}),i.jsx(k,{height:"22px",sx:{fontSize:"15px",color:s?d.palette.action.disabled:e.color,fontWeight:700,fontVariantNumeric:"tabular-nums",minWidth:"80px",textAlign:"center"},ref:h,children:o()})]}),i.jsx(ot,{disableRipple:!0,disabled:s,onPointerDown:$=>p($,"+"),onPointerUp:S,onPointerOut:S,size:"large",sx:{...m==="+"?u:x,borderRadius:"0px 16px 16px 0px",borderRight:`2px solid ${g??"#fff"}`,borderBottom:`2px solid ${g??"#fff"}`,borderTop:`2px solid ${g??"#fff"}`},children:i.jsx(Me,{})})]})})),Ot=H.externalizeComponent(L.observer(({startJogging:e,stopJogging:t,lowerLimit:o,upperLimit:n,useDegree:r,getValue:s,disabled:l,...a})=>{var J,D,B,q,$,V,W;const{t:d}=z.useTranslation(),[c,f]=b.useState(),m=A.useTheme(),h={background:(J=m.palette.backgroundPaperElevation)==null?void 0:J[4],color:(D=m.palette.backgroundPaperElevation)==null?void 0:D[11]},g=L.useLocalObservable(()=>({activeJoggingDir:null,startJogging(C){this.activeJoggingDir=C,e(C)},stopJogging(){this.activeJoggingDir=null,t()}})),y=me(()=>{const C=r?x(s()):s();(C===void 0||c===void 0||Math.abs(c-C)>1e-9)&&f(C)},50);w.useAnimationFrame(y);function x(C){if(C!==void 0)return P.radiansToDegrees(C)}function u(C){C.button===0&&g.startJogging("-")}function p(C){C.button===0&&g.startJogging("+")}function S(C){g.stopJogging()}function M(C){g.stopJogging()}function R(C,F=1){if(C===void 0||Number.isNaN(C))return"";const U=d("General.degree.variable",{amount:C.toFixed(F)});return C>0&&F===0?`+${U}`:U}function v(C,F=1){if(C===void 0||Number.isNaN(C))return"";const U=d("General.mm.variable",{amount:C.toFixed(F)});return C>0&&F===0?`+${U}`:U}return i.jsxs(I,{height:"64px",width:"100%",maxWidth:"260px",direction:"row",...a,sx:{"& .MuiIconButton-root":{width:"52px",color:m.palette.text.primary,alignContent:"center",backgroundColor:(B=m.palette.backgroundPaperElevation)==null?void 0:B[11],"& svg":{width:"42px",height:"42px"},"&.Mui-disabled":{backgroundColor:(q=m.palette.backgroundPaperElevation)==null?void 0:q[11],color:m.palette.action.disabled,opacity:1},"&:hover":{backgroundColor:($=m.palette.backgroundPaperElevation)==null?void 0:$[9]},"&:active":{...h}}},children:[i.jsx(ot,{onPointerDown:u,onPointerUp:S,onPointerOut:M,disabled:l,disableRipple:!0,sx:{borderRadius:"16px 0px 0px 16px",...g.activeJoggingDir==="-"?h:{}},children:i.jsx(ue,{sx:{pointerEvents:"none",color:w.jointArrowColor}})}),i.jsxs(I,{flexGrow:1,alignItems:"center",justifyContent:"center",sx:{borderStyle:"solid",borderLeftWidth:0,borderRightWidth:0,border:"none",backgroundColor:(V=m.palette.backgroundPaperElevation)==null?void 0:V[11],paddingLeft:"20px",paddingRight:"20px",zIndex:1},children:[i.jsx(k,{sx:{fontSize:"15px",fontWeight:700,position:"relative",top:"5px",fontVariantNumeric:"tabular-nums",minWidth:"80px",textAlign:"center",color:l?m.palette.action.disabled:m.palette.text.primary},children:r?R(c):v(c)}),i.jsx(Jt,{disabled:!0,"aria-label":"Joint position",min:r?x(o):o,max:r?x(n):n,value:c||0,track:!1,sx:{"& .MuiSlider-mark":{display:"none"},"& .MuiSlider-thumb":{width:"5px",height:"12px",borderRadius:"2px",color:l?m.palette.action.disabled:m.palette.text.primary},"& .MuiSlider-markLabel":{top:"20px",fontSize:"12px",color:l?m.palette.action.disabled:m.palette.text.secondary},"& .MuiSlider-rail":{backgroundColor:(W=m.palette.backgroundPaperElevation)==null?void 0:W[5],opacity:1}},marks:o!==void 0&&n!==void 0&&[{value:r?x(o):o,label:r?R(x(o),0):v(o)},{value:r?x(n):n,label:r?R(x(n),0):v(n)}]})]}),i.jsx(ot,{onPointerDown:p,onPointerUp:S,onPointerOut:M,disabled:l,disableRipple:!0,sx:{borderRadius:"0px 16px 16px 0px",...g.activeJoggingDir==="+"?h:{}},children:i.jsx(he,{sx:{pointerEvents:"none",color:w.jointArrowColor}})})]})})),tt=2*Math.PI;function _e({min:e,max:t,linear:o},n){const r=e!==void 0,s=t!==void 0;if(r&&s&&t>e)return{min:e,max:t};if(o)return null;if(r&&!s)return{min:e,max:e+tt};if(s&&!r)return{min:t-tt,max:t};const l=Math.round(n/tt)*tt;return{min:l-Math.PI,max:l+Math.PI}}function ut(e,t){return Math.min(1,Math.max(0,(e-t.min)/(t.max-t.min)))}function Te(e,t){const o=Math.min(1,Math.max(0,e));return t.min+o*(t.max-t.min)}function Ee(e){return e.min>0||e.max<0?null:ut(0,e)}function Pt(e,t,o){return Math.abs(t-e)<=o?null:t>e?"+":"-"}function ke(e,t,o){return o==="+"?e>=t:e<=t}function Je(e,t){return e?"mm":t}const mt={deg:{shown:e=>e*180/Math.PI,decimals:1,limitDecimals:0,suffix:"°"},rad:{shown:e=>e,decimals:3,limitDecimals:2,suffix:" rad"},mm:{shown:e=>e,decimals:1,limitDecimals:0,suffix:" mm"}};function At(e,t){const o=e.toFixed(t);return Number(o)===0?0 .toFixed(t):o}function lt(e,t){return mt[t].shown(e)}function Re(e,t){const{shown:o,decimals:n,suffix:r}=mt[t];return`${At(o(e),n)}${r}`}function St(e,t){const{shown:o,limitDecimals:n,suffix:r}=mt[t],s=10**n,l=o(e),a=Math.sign(l)*Math.round(Math.abs(l)*s)/s;return`${a>0?"+":""}${At(a,n)}${r}`}const vt=16,ct=4;function Ct({railRef:e,at:t,goalAt:o,held:n,zeroAt:r,limits:s,disabled:l}){const a=A.useTheme(),d=a.palette.primary.main,c=`0 0 0 8px ${A.alpha(d,.16)}`;return i.jsxs(i.Fragment,{children:[i.jsxs(O,{ref:e,sx:{position:"absolute",left:0,right:0,top:"50%",height:ct,transform:"translateY(-50%)"},children:[i.jsx(O,{sx:{position:"absolute",inset:0,borderRadius:ct/2,backgroundColor:A.alpha(d,.38)}}),t!==null&&o!==null&&i.jsx(O,{sx:{position:"absolute",top:0,bottom:0,borderRadius:ct/2,backgroundColor:d},style:{left:`${Math.min(t,o)*100}%`,width:`${Math.abs(o-t)*100}%`,opacity:n?1:.5}}),r!==null&&i.jsx(O,{"aria-hidden":!0,sx:{position:"absolute",top:"50%",width:2,height:12,transform:"translate(-50%, -50%)",borderRadius:1,backgroundColor:"text.secondary"},style:{left:`${r*100}%`}}),t!==null&&i.jsx(O,{sx:{position:"absolute",top:"50%",boxSizing:"border-box",width:vt,height:vt,transform:"translate(-50%, -50%)",borderRadius:"50%",border:`3px solid ${d}`,backgroundColor:"background.paper",boxShadow:n?c:a.shadows[2],transition:"box-shadow 150ms","&:hover":l?{}:{boxShadow:c}},style:{left:`${t*100}%`}})]}),s&&i.jsx(I,{direction:"row",sx:{position:"absolute",left:0,right:0,top:30,justifyContent:"space-between"},children:[s.min,s.max].map((f,m)=>i.jsx(k,{variant:"caption",color:"text.secondary",sx:{fontSize:10,lineHeight:"14px"},children:f},m))})]})}function Oe({value:e,onJogStart:t,onJogStop:o,disabled:n}){const r=b.useRef(null),[s,l]=b.useState(null),a=b.useCallback(u=>{r.current=u,l(u)},[]),d=b.useRef({value:e,onJogStart:t,onJogStop:o});d.current={value:e,onJogStart:t,onJogStop:o};const c=b.useCallback((u,p,S)=>{const M=Pt(d.current.value,p,S);a({...u,goal:p,direction:M,settledAt:M?null:u.settledAt}),u.direction&&u.direction!==M&&d.current.onJogStop(),M&&M!==u.direction&&d.current.onJogStart(M)},[a]),f=b.useCallback(()=>r.current!==null,[]),m=b.useCallback((u,p,S)=>n||r.current?!1:(c({goal:u,direction:null,settledAt:null,by:S},u,p),!0),[n,c]),h=b.useCallback((u,p)=>{const S=r.current;if(S){if(S.direction===null&&S.settledAt!==null&&Math.abs(u-S.settledAt)<=p){a({...S,goal:u});return}c(S,u,p)}},[c,a]),g=b.useCallback(()=>{const u=r.current;u&&(a(null),u.direction&&d.current.onJogStop())},[a]),y=b.useCallback(()=>{var u;return((u=r.current)==null?void 0:u.by)??null},[]),x=b.useCallback(u=>{const p=r.current;p&&u(p.by)&&g()},[g]);return b.useEffect(()=>{const u=r.current;u!=null&&u.direction&&ke(e,u.goal,u.direction)&&(a({...u,direction:null,settledAt:u.goal}),d.current.onJogStop())},[e,a]),w.useEndHoldWhenUnattended(s!==null,n,g),{hold:s,isHolding:f,heldBy:y,begin:m,moveGoal:h,end:g,endIfHeldBy:x}}const Pe=4;function Ae(e){return e==="ArrowRight"||e==="ArrowUp"?"+":e==="ArrowLeft"||e==="ArrowDown"?"-":null}const De=H.externalizeComponent(({label:e,name:t,value:o,min:n,max:r,linear:s=!1,angleUnit:l="deg",onJogStart:a,onJogStop:d,disabled:c=!1})=>{const f=A.useTheme(),m=b.useRef(null),{hold:h,isHolding:g,heldBy:y,begin:x,moveGoal:u,end:p,endIfHeldBy:S}=Oe({value:o,onJogStart:a,onJogStop:d,disabled:c}),[M,R]=b.useState(null);b.useEffect(()=>{c&&R(null)},[c]);const v=_e({min:n,max:r,linear:s},o),J=Je(s,l),D=T=>Re(T,J);function B(T){if(!v||!m.current)return null;const _=m.current.getBoundingClientRect();return _.width<=0?null:{goal:Te((T-_.left)/_.width,v),deadband:Pe/_.width*(v.max-v.min)}}function q(T){var N,K;if(!w.startsPointerHold(T)||c||g())return;const _=B(T.clientX);if(_){try{(K=(N=T.currentTarget).setPointerCapture)==null||K.call(N,T.pointerId)}catch{}x(_.goal,_.deadband,{pointer:T.pointerId})}}function $(T){const _=B(T.clientX);R(c?null:(_==null?void 0:_.goal)??null);const N=y();if(!(!N||!("pointer"in N)||N.pointer!==T.pointerId)){if(w.primaryReleased(T)){p();return}_&&u(_.goal,_.deadband)}}function V(T){S(_=>"pointer"in _&&_.pointer===T.pointerId)}function W(T){const _=Ae(T.key);if(_&&T.preventDefault(),g()){w.endsHold(T)&&p();return}if(!_||!w.startsKeyHold(T)||c||!v)return;const N=_==="+"?v.max:v.min,K=(v.max-v.min)*1e-4;Pt(o,N,K)===_&&x(N,K,{key:T.key})}function C(T){S(_=>"key"in _&&_.key===T.key)}const F=(h==null?void 0:h.goal)??M,U=v&&{min:St(v.min,J),max:St(v.max,J)},yt=i.jsxs(I,{direction:"row",sx:{justifyContent:"space-between",gap:1,mb:"-4px"},children:[i.jsxs(k,{variant:"body2",noWrap:!0,children:[e,t&&i.jsx(O,{component:"span",sx:{color:"text.secondary"},children:` - ${t}`})]}),i.jsxs(k,{variant:"body2",sx:{fontVariantNumeric:"tabular-nums",whiteSpace:"nowrap"},children:[D(o),v&&F!==null&&i.jsx(O,{component:"span",sx:{color:"text.secondary"},children:` / ${D(F)}`})]})]});return v?i.jsxs(I,{"data-testid":"jogging-joint-slider",children:[yt,i.jsx(O,{role:"slider",tabIndex:c?-1:0,"aria-label":t?`${e} ${t}`:e,"aria-valuemin":lt(v.min,J),"aria-valuemax":lt(v.max,J),"aria-valuenow":lt(o,J),"aria-valuetext":D(o),"aria-disabled":c||void 0,onPointerDown:q,onPointerMove:$,onPointerLeave:()=>R(null),onPointerUp:V,onPointerCancel:V,onLostPointerCapture:V,onKeyDown:W,onKeyUp:C,onBlur:p,onContextMenu:w.preventContextMenu,sx:{position:"relative",height:44,borderRadius:1,opacity:c?.5:1,cursor:c?"default":"pointer",touchAction:"none",userSelect:"none",outline:"none","&:focus-visible":{outline:`2px solid ${f.palette.primary.main}`,outlineOffset:"2px"}},children:i.jsx(Ct,{railRef:m,at:ut(o,v),goalAt:F===null?null:ut(F,v),held:h!==null,zeroAt:Ee(v),limits:U??void 0,disabled:c})})]}):i.jsxs(I,{"data-testid":"jogging-joint-slider",children:[yt,i.jsx(O,{"aria-hidden":!0,sx:{position:"relative",height:44},children:i.jsx(Ct,{at:null,goalAt:null,held:!1,zeroAt:null,disabled:!0})})]})});function pt(e,t,o){if(t.length!==e.length)return!0;for(let n=0;n<t.length;n++)if(Math.abs(t[n]-e[n])>o)return!1;return!0}function Dt(e,t,o){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)return!1;if(e===void 0||t===void 0)return!0;let n=0;return n+=Math.abs(e.orientation[0]-t.orientation[0]),n+=Math.abs(e.orientation[1]-t.orientation[1]),n+=Math.abs(e.orientation[2]-t.orientation[2]),n+=Math.abs(e.position[0]-t.position[0]),n+=Math.abs(e.position[1]-t.position[1]),n+=Math.abs(e.position[2]-t.position[2]),n<=o}function ft(e,t,o){return e.coordinate_system===t.coordinate_system&&e.tcp===t.tcp&&Dt(e.tcp_pose,t.tcp_pose,o)}function Vt(e,t){const o=new dt.Vector3(t[0],t[1],t[2]),n=new dt.Vector3(e[0],e[1],e[2]),r=o.length(),s=o.normalize();let l=n.length(),a=n.normalize();a.dot(s)<0&&(l=-l,a=a.multiplyScalar(-1));let d=l-r;return d-=2*Math.PI*Math.floor((d+Math.PI)/(2*Math.PI)),l=r+d,[...a.multiplyScalar(l)]}const wt=1e-4;class it{constructor(t,o,n,r,s,l,a="cell"){this.controller=o,this.motionGroup=n,this.description=r,this.initialMotionState=s,this.motionStateSocket=l,this.cellId=a,this.nova=w.createNovaClient(t),this.rapidlyChangingMotionState=s,l.addEventListener("message",d=>{var h;const c=(h=P.tryParseJson(d.data))==null?void 0:h.result;if(!c)throw new Error(`Failed to get motion state for ${this.motionGroupId}: ${d.data}`);pt(this.rapidlyChangingMotionState.joint_position,c.joint_position,wt)||j.runInAction(()=>{this.rapidlyChangingMotionState.joint_position=c.joint_position}),ft(this.rapidlyChangingMotionState,c,wt)||j.runInAction(()=>{var g,y,x;this.rapidlyChangingMotionState.tcp_pose==null?this.rapidlyChangingMotionState.tcp_pose=c.tcp_pose:(g=c.tcp_pose)!=null&&g.orientation&&((y=c.tcp_pose)!=null&&y.position)&&((x=this.rapidlyChangingMotionState.tcp_pose)!=null&&x.orientation)?this.rapidlyChangingMotionState.tcp_pose={position:c.tcp_pose.position,orientation:Vt(c.tcp_pose.orientation,this.rapidlyChangingMotionState.tcp_pose.orientation)}:console.warn("Received incomplete tcp_pose, ignoring",c.tcp_pose)}),c.tcp!==void 0&&this.rapidlyChangingMotionState.tcp!==c.tcp&&j.runInAction(()=>{this.rapidlyChangingMotionState.tcp=c.tcp}),this.rapidlyChangingMotionState.standstill!==c.standstill&&j.runInAction(()=>{this.rapidlyChangingMotionState.standstill=c.standstill});const f=this.rapidlyChangingMotionState.joint_limit_reached.limit_reached,m=c.joint_limit_reached.limit_reached;f.some((g,y)=>g!==m[y])&&j.runInAction(()=>{this.rapidlyChangingMotionState.joint_limit_reached=c.joint_limit_reached}),this.rapidlyChangingMotionState.execute!==c.execute&&j.runInAction(()=>{this.rapidlyChangingMotionState.execute=c.execute})}),j.makeAutoObservable(this)}static async open(t,o,n={}){var y;const r=w.createNovaClient(t),s=n.cellId??w.cellIdOf(t)??"cell",[l,a]=o.split("@"),d=await r.api.controller.getCurrentRobotControllerState(s,a),c=d==null?void 0:d.motion_groups.find(x=>x.motion_group===o);if(!d||!c)throw new Error(`Controller ${a} or motion group ${o} not found`);const f=r.openReconnectingWebsocket(`/cells/${s}/controllers/${a}/motion-groups/${o}/state-stream`),m=await f.firstMessage(),h=(y=P.tryParseJson(m.data))==null?void 0:y.result;if(!h)throw new Error(`Unable to parse initial motion state message ${m.data}`);console.log(`Connected motion state websocket to motion group ${c.motion_group}. Initial state:
|
|
2
|
+
`,h);const g=await r.api.motionGroup.getMotionGroupDescription(s,a,c.motion_group);return new it(r,d,c,g,h,f,s)}get motionGroupId(){return this.motionGroup.motion_group}get controllerId(){return this.controller.controller}get joints(){return this.initialMotionState.joint_position.map((t,o)=>({index:o}))}dispose(){this.motionStateSocket.close()}}const It="Movement request rejected. Another client is currently executing a 'Jogging' motion!";class rt{constructor(t,o={}){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.ownsMotionStream=!1,this.tcp=(o==null?void 0:o.tcp)||t.motionGroup.tcp||this.getDefaultTcp(t),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}static async open(t,o,n={}){const r=await it.open(t,o,{cellId:n.cellId}),s=new rt(r,n);s.ownsMotionStream=!0;try{await s.setJoggingMode(s.mode)}catch(l){throw s.dispose(),l}return s}getDefaultTcp(t){var n,r;const o=(r=(n=t.description.dh_parameters)==null?void 0:n[0])==null?void 0:r.type;return t.joints.length<6&&(o===G.JointTypeEnum.RevoluteJoint||o===G.JointTypeEnum.PrismaticJoint)?this.NO_TCP:this.DEFAULT_TCP}async setOptions(t){return t.tcp&&(this.tcp=t.tcp),t.orientation&&(this.orientation=t.orientation),t.timeout&&(this.timeout=t.timeout),t.mode&&(this.mode=t.mode),t.onError&&(this.onError=t.onError),this.setJoggingMode(this.mode,!1)}get motionGroupId(){return this.motionStream.motionGroupId}get nova(){return this.motionStream.nova}get cellId(){return this.motionStream.cellId}get numJoints(){return this.motionStream.joints.length}async stop(){if(this.joggingSocket){const t=new Array(this.numJoints).fill(0);this.joggingSocket.sendJson({message_type:"JointVelocityRequest",velocity:t})}this.trajectorySocket&&this.trajectorySocket.sendJson({message_type:"PauseMovementRequest"})}async dispose(){const t=this.closeJoggingSockets();return this.ownsMotionStream&&this.motionStream.dispose(),t}closeJoggingSockets(){var o;(o=this.endJoggingInit)==null||o.call(this);const t=[this.joggingSocket,this.trajectorySocket].filter(n=>n!==null);return t.forEach(n=>{n.dispose()}),this.joggingSocket=null,this.trajectorySocket=null,Promise.all(t.map(n=>n.closed()))}async setJoggingMode(t,o=!0){if(!(this.mode===t&&o)&&(this.closeJoggingSockets(),this.mode=t,this.mode==="jogging"))return this.initializeJoggingWebsocket()}async initializeJoggingWebsocket(){return new Promise((t,o)=>{const n=this.nova.openReconnectingWebsocket(`/cells/${this.cellId}/controllers/${this.motionStream.controllerId}/execution/jogging`);this.joggingSocket=n;let r=!1;const s=setTimeout(()=>{l(new Error(`Jogging initialization timeout after ${this.timeout} ms`))},this.timeout),l=c=>{r||(r=!0,clearTimeout(s),n.removeEventListener("close",d),this.endJoggingInit===a&&(this.endJoggingInit=void 0),c?o(c):t())},a=()=>l(),d=()=>{n.disposed&&l()};this.endJoggingInit=a,n.addEventListener("close",d),n.addEventListener("message",c=>{var m,h,g;const f=P.tryParseJson(c.data);if(((m=f==null?void 0:f.result)==null?void 0:m.kind)==="INITIALIZE_RECEIVED"){l();return}if(((h=f==null?void 0:f.result)==null?void 0:h.kind)==="MOTION_ERROR")if(this.onBlocked&&((g=f==null?void 0:f.result)!=null&&g.message.includes(It))){l(),n.dispose(),this.onBlocked();return}else this.onError?(l(),this.onError(c.data)):l(new Error(c.data))}),n.sendJson({message_type:"InitializeJoggingRequest",motion_group:this.motionGroupId,...this.tcp?{tcp:this.tcp}:{}})})}async rotateJoints({joint:t,direction:o,velocityValue:n,velocityUnit:r}){if(!this.joggingSocket||this.mode!=="jogging")throw new Error("Joint jogging websocket not connected; create one by setting jogging mode to 'jogging'");const s=new Array(this.numJoints).fill(0);s[t]=o==="-"?-n:n,this.joggingSocket.sendJson({message_type:"JointVelocityRequest",velocity:s})}async translateTCP({axis:t,direction:o,velocityMmPerSec:n}){if(!this.joggingSocket||this.mode!=="jogging")throw new Error("Continuous jogging websocket not connected; create one by setting jogging mode to 'jogging'");const r=[0,0,0],s=[0,0,0];s[P.XYZ_TO_VECTOR[t]]=o==="-"?-n:n,this.joggingSocket.sendJson({message_type:"TcpVelocityRequest",translation:s,rotation:r,use_tool_coordinate_system:this.orientation==="tool"})}async rotateTCP({axis:t,direction:o,velocityRadsPerSec:n}){if(!this.joggingSocket||this.mode!=="jogging")throw new Error("Continuous jogging websocket not connected; create one by setting jogging mode to 'jogging'");const r=[0,0,0],s=[0,0,0];r[P.XYZ_TO_VECTOR[t]]=o==="-"?-n:n,this.joggingSocket.sendJson({message_type:"TcpVelocityRequest",translation:s,rotation:r,use_tool_coordinate_system:this.orientation==="tool"})}async runIncrementalCartesianMotion({currentTcpPose:t,currentJoints:o,velocityInRelevantUnits:n,axis:r,direction:s,motion:l}){const a=[];if(this.mode!=="trajectory")throw new Error("Set jogging mode to 'trajectory' to run incremental cartesian motions");if(l.type==="translate"){if(!t.position)throw new Error("Current pose has no position, cannot perform translation");const u=[...t.position];u[P.XYZ_TO_VECTOR[r]]+=l.distanceMm*(s==="-"?-1:1),a.push({limits_override:{tcp_velocity_limit:n},path:{path_definition_name:"PathLine",target_pose:{position:u,orientation:t.orientation}}})}else if(l.type==="rotate"){if(!t.orientation)throw new Error("Current pose has no orientation, cannot perform rotation");const u=new at.Vector3(t.orientation[0],t.orientation[1],t.orientation[2]),p=u.length(),S=u.clone().normalize(),M=l.distanceRads*(s==="-"?-1:1),R=new at.Vector3(0,0,0);R[r]=1;const v=Math.cos(.5*M)*Math.cos(.5*p),J=Math.sin(.5*M)*Math.sin(.5*p),D=Math.sin(.5*M)*Math.cos(.5*p),B=Math.cos(.5*M)*Math.sin(.5*p),q=R.dot(S),$=R.clone().cross(S),V=2*Math.acos(v-J*q),W=V/Math.sin(.5*V),C=new at.Vector3().addScaledVector($,J).addScaledVector(R,D).addScaledVector(S,B).multiplyScalar(W);a.push({limits_override:{tcp_orientation_velocity_limit:n},path:{path_definition_name:"PathLine",target_pose:{position:t.position,orientation:[...C]}}})}const d=this.motionStream.description;if(d.cycle_time===void 0){console.warn("Current motion group has no cycle time, cannot plan jogging motion");return}const c={motion_group_model:d.motion_group_model,cycle_time:d.cycle_time,mounting:d.mounting,global:d.operation_limits.auto_limits},f=await this.nova.api.trajectoryPlanning.planTrajectory(this.cellId,{motion_group_setup:c,start_joint_position:o,motion_commands:a}),m=f.response;if(!m)throw new Error(`Failed to plan jogging increment motion ${JSON.stringify(f)}`);this.trajectorySocket&&(console.warn("Trajectory jogging websocket already open; will close"),this.trajectorySocket.dispose()),this.trajectorySocket=this.nova.openReconnectingWebsocket(`/cells/${this.cellId}/controllers/${this.motionStream.controllerId}/execution/trajectory`);const h=u=>{var p;if(!u||u.add_trajectory_error||u.message)if(this.onError)this.onError(u);else throw new Error(((p=u==null?void 0:u.add_trajectory_error)==null?void 0:p.message)||(u==null?void 0:u.message)||"Failed to execute trajectory, unknown error");if(!this.trajectorySocket)throw new Error("Failed to execute trajectory, websocket not available anymore");this.trajectorySocket.sendJson({message_type:"StartMovementRequest",direction:"DIRECTION_FORWARD"})},g=async()=>{var u;await j.when(()=>!this.motionStream.rapidlyChangingMotionState.standstill),await j.when(()=>this.motionStream.rapidlyChangingMotionState.standstill),(u=this.trajectorySocket)==null||u.dispose(),this.trajectorySocket=null},y=async()=>{var u;await j.when(()=>this.motionStream.rapidlyChangingMotionState.standstill),(u=this.trajectorySocket)==null||u.dispose(),this.trajectorySocket=null},x=async u=>{if(u!=null&&u.message)if(this.onError){this.onError(u);return}else throw new Error(u.message||"Failed to execute trajectory, unknown error");this.motionStream.rapidlyChangingMotionState.standstill?await g():await y()};this.trajectorySocket.addEventListener("message",u=>{var S,M;const p=P.tryParseJson(u.data);if(!((S=p==null?void 0:p.result)!=null&&S.kind))throw new Error(`Failed to execute trajectory: Received invalid message ${u.data}`);if(this.onBlocked&&((M=p.result.message)!=null&&M.includes(It))){this.onBlocked();return}if(p.result.kind==="INITIALIZE_RECEIVED")h(p.result);else if(p.result.kind==="START_RECEIVED")x(p);else if(p.result.kind!=="PAUSE_RECEIVED")if(p.result.kind==="MOTION_ERROR"&&p.result.message)if(this.onError){this.onError(p);return}else throw new Error(p.result.message);else throw new Error(`Failed to execute trajectory, cannot handle message type "${p.result.kind}"`)}),this.trajectorySocket.sendJson({message_type:"InitializeMovementRequest",trajectory:{message_type:"TrajectoryData",motion_group:this.motionGroupId,data:m,tcp:this.tcp}})}}const Lt=e=>{const t=e.softTimeout||3e3,[o,n]=b.useState(!1);return b.useEffect(()=>{const r=setTimeout(()=>{n(!0)},t);return()=>clearTimeout(r)}),i.jsx(I,{width:"100%",height:"100%",alignItems:"center",justifyContent:"center",sx:{color:"text.primary"},children:e.error?i.jsx($t,{loadingMessage:e.message,error:e.error}):i.jsxs(i.Fragment,{children:[i.jsx(Et,{sx:{mb:3}}),!!e.message&&i.jsx(k,{variant:"body1",children:e.message}),i.jsx(k,{variant:"body2",sx:{visibility:o?"visible":"hidden",mt:2,color:"text.secondary"},children:"This is taking longer than expected..."})]})})},$t=e=>{const t=ee.makeErrorMessage(e.error),o=e.error instanceof Error?e.error.stack:null;return i.jsxs(I,{sx:{maxHeight:"100%",maxWidth:"min(100%, 800px)",p:2,overflow:"auto",color:"error.main"},children:[i.jsx(k,{variant:"body1",children:(e.loadingMessage?`Error while ${kt.lowerFirst(te.capitalize(e.loadingMessage))} - `:"")+t}),o&&i.jsx(O,{component:"pre",sx:{typography:"body2",fontFamily:"monospace",whiteSpace:"pre-wrap",wordBreak:"break-word",mt:2,pb:6},children:o})]})},Ve=L.observer(({store:e})=>{const{t}=z.useTranslation();return i.jsx(_t,{"data-testid":"jogging-blocked","aria-label":"jogging-blocked",open:!0,sx:{position:"absolute",zIndex:o=>o.zIndex.drawer+1,color:"#fff",background:"rgba(15, 15, 15, 0.88)",justifyContent:"flex-start",alignItems:"flex-start"},children:i.jsxs(I,{sx:{m:2,width:"100%"},children:[i.jsxs(oe,{severity:"error",sx:{mb:2},children:[i.jsx(ne,{children:t("Jogging.Blocked.ti")}),t("Jogging.Blocked.lb")]}),i.jsx(Z,{variant:"contained",color:"secondary",onClick:()=>e.unblock(),children:t("Jogging.Blocked.Reenable.bt")})]})})}),Le=({title:e,titleId:t,...o},n)=>E.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",width:19,height:10,fill:"none",ref:n,"aria-labelledby":t,...o},e?E.createElement("title",{id:t},e):null,E.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"})),$e=b.forwardRef(Le),Be=({title:e,titleId:t,...o},n)=>E.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",width:19,height:10,fill:"none",ref:n,"aria-labelledby":t,...o},e?E.createElement("title",{id:t},e):null,E.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"})),Fe=b.forwardRef(Be),qe=({title:e,titleId:t,...o},n)=>E.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",width:10,height:19,fill:"none",ref:n,"aria-labelledby":t,...o},e?E.createElement("title",{id:t},e):null,E.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"})),Ne=b.forwardRef(qe),ze=({title:e,titleId:t,...o},n)=>E.createElement("svg",{width:16,height:16,viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",ref:n,"aria-labelledby":t,...o},e?E.createElement("title",{id:t},e):null,E.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"})),Ge=b.forwardRef(ze),Bt=L.observer(({store:e})=>{const{t}=z.useTranslation(),[o,n]=b.useState(e.jogger.motionStream.rapidlyChangingMotionState.joint_limit_reached.limit_reached),r=b.useRef(o);w.useAnimationFrame(()=>{const l=e.jogger.motionStream.rapidlyChangingMotionState.joint_limit_reached.limit_reached;ie(r.current,l)||(r.current=l,n(l))});const s=[];for(const[l,a]of o.entries())a&&s.push(l);return i.jsx(O,{sx:{display:"flex",flexDirection:"row",justifyContent:"center"},children:i.jsx(k,{"data-testid":"jogging-joint-limit-detector","aria-label":"jogging-joint-limit-detector",color:"error",variant:"body2",sx:{fontSize:"0.75rem",lineHeight:1.2,visibility:s.length?"visible":"hidden"},children:t("Jogging.JointLimitsReached.lb",{jointNumbers:s.map(l=>l+1).join(", ")})})})}),Ue=A.styled(se)(({theme:e})=>({"&.MuiFormControl-root":{".MuiSelect-select":{paddingTop:"20px",paddingLeft:"12px"},label:{pointerEvents:"none",fontSize:"16px"},".MuiInputLabel-root":{"&.Mui-focused":{color:e.palette.text.primary}}}}));function et({labelValue:e,...t}){return i.jsxs(Ue,{fullWidth:!0,variant:"filled",children:[i.jsx(ae,{id:t.labelId,children:e}),i.jsx(le,{...t})]})}const ht=[{id:"0.1",mm:.1,degrees:.05},{id:"1",mm:1,degrees:.5},{id:"5",mm:5,degrees:2.5},{id:"10",mm:10,degrees:5}],He=[{id:"continuous"},...ht],We=["coordsys","tool"];class st{constructor(t,o,n,r,s){var l,a,d;this.jogger=t,this.coordSystems=o,this.motionGroupDescription=n,this.tcps=r,this.inverseSolverValue=s,this.selectedTabId="cartesian",this.locks=new Set,this.blocked=!1,this.selectedCoordSystemId="world",this.selectedTcpId="",this.tcpChangeInProgress=!1,this.selectedOrientation="coordsys",this.selectedIncrementId="continuous",this.selectedCartesianMotionType="translate",this.incrementJogInProgress=null,this.translationVelocityMmPerSec=10,this.rotationVelocityDegPerSec=1,this.minTranslationVelocityMmPerSec=5,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=G.JointTypeEnum.RevoluteJoint;for(const c of o)if(c.coordinate_system===""){c.coordinate_system="world";break}this.selectedCoordSystemId=((l=o[0])==null?void 0:l.coordinate_system)||"world",this.selectedTcpId=t.motionStream.rapidlyChangingMotionState.tcp??"",this.tcpChangeInProgress=this.tcps.length>0&&!this.selectedTcpId,this.inverseSolver=s,this.jointType=((d=(a=n==null?void 0:n.dh_parameters)==null?void 0:a[0])==null?void 0:d.type)??G.JointTypeEnum.RevoluteJoint,j.makeAutoObservable(this,{},{autoBind:!0}),this.jogger.onBlocked=()=>{this.block()},this.loadFromLocalStorage(),this.disposers.push(j.autorun(()=>this.saveToLocalStorage())),this.disposers.push(j.autorun(()=>{const c=this.jogger.motionStream.rapidlyChangingMotionState.tcp;c&&c!==this.selectedTcpId&&j.runInAction(()=>{this.selectedTcpId=c,this.tcpChangeInProgress=!1})})),window.joggingStore=this}static async loadFor(t){const{nova:o,cellId:n}=t,[r,s]=await Promise.all([o.api.controller.listCoordinateSystems(n,t.motionStream.controllerId,"ROTATION_VECTOR"),o.api.motionGroup.getMotionGroupDescription(n,t.motionStream.controllerId,t.motionGroupId)]),l=await o.api.motionGroupModels.getMotionGroupKinematicModel(s.motion_group_model),a=Object.entries(s.tcps||{}).map(([d,c])=>({id:d,readable_name:c.name,position:c.pose.position,orientation:c.pose.orientation}));return new st(t,r||[],s,a,l.inverse_solver)}dispose(){for(const t of this.disposers)t();this.jogger.dispose()}get coordSystemCountByName(){return kt.countBy(this.coordSystems,t=>t.name)}async deactivate(){this.jogger.mode==="jogging"&&await this.jogger.setJoggingMode("off")}async activate(){return this.currentTab.id==="cartesian"?((this.jogger.tcp!==this.selectedTcpId||this.jogger.orientation!==this.selectedOrientation)&&await this.jogger.setOptions({tcp:this.selectedTcpId||void 0,orientation:this.selectedOrientation}),this.activeDiscreteIncrement?await this.jogger.setJoggingMode("trajectory"):await this.jogger.setJoggingMode("jogging")):await this.jogger.setJoggingMode("jogging"),this.jogger}loadFromLocalStorage(){const t=P.tryParseJson(localStorage.getItem("joggingToolStore"));t&&(this.tabsById[t.selectedTabId]&&(this.selectedTabId=t.selectedTabId),this.coordSystemsById[t.selectedCoordSystemId]&&(this.selectedCoordSystemId=t.selectedCoordSystemId),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))}saveToLocalStorage(){localStorage.setItem("joggingToolStore",JSON.stringify(this.localStorageSave))}get isLocked(){return this.locks.size>0}get localStorageSave(){return{selectedTabId:this.selectedTabId,selectedCoordSystemId:this.selectedCoordSystemId,selectedOrientation:this.selectedOrientation,selectedIncrementId:this.selectedIncrementId,selectedCartesianMotionType:this.selectedCartesianMotionType}}get tabs(){const t=[{id:"joint",label:"Joints"}];return this.inverseSolver!==null&&t.unshift({id:"cartesian",label:"Cartesian"}),t}get incrementOptions(){return He}get discreteIncrementOptions(){return ht}get incrementOptionsById(){return Q(this.incrementOptions,t=>t.id)}get tabsById(){return Q(this.tabs,t=>t.id)}get currentTab(){return this.tabsById[this.selectedTabId]||this.tabs[0]}get tabIndex(){return this.tabs.indexOf(this.currentTab)}get coordSystemsById(){return Q(this.coordSystems,t=>t.coordinate_system)}get activeCoordSystemId(){return this.selectedOrientation==="tool"?"tool":this.selectedCoordSystemId}get tcpsById(){return Q(this.tcps,t=>t.id)}get activeDiscreteIncrement(){return this.selectedOrientation==="tool"?void 0:ht.find(t=>t.id===this.selectedIncrementId)}get rotationVelocityRadsPerSec(){return this.rotationVelocityDegPerSec*Math.PI/180}velocityInDisplayUnits(t){return t?this.rotationVelocityDegPerSec:this.translationVelocityMmPerSec}minVelocityInDisplayUnits(t){return t?this.minRotationVelocityDegPerSec:this.minTranslationVelocityMmPerSec}maxVelocityInDisplayUnits(t){return t?this.maxRotationVelocityDegPerSec:this.maxTranslationVelocityMmPerSec}onTabChange(t,o){const n=this.tabs[o]||this.tabs[0];this.selectedTabId=n.id}setSelectedCoordSystemId(t){this.selectedCoordSystemId=t}setSelectedTcpId(t){this.requestTcpChange(t).catch(o=>{console.error("Failed to change TCP:",o)})}async requestTcpChange(t){if(t===this.selectedTcpId)return;this.tcpChangeInProgress=!0;const o=this.jogger.tcp,n=this.jogger.mode!=="jogging";try{this.jogger.tcp=t,n?await this.jogger.setJoggingMode("jogging"):await this.jogger.setJoggingMode("jogging",!1);let r=await this.waitForTcpConfirmation(t,1e3);n&&await this.jogger.setJoggingMode("off"),r||(r=await this.waitForTcpConfirmation(t,2e3)),j.runInAction(()=>{r?this.selectedTcpId=t:(this.jogger.tcp=o,this.selectedTcpId=this.jogger.motionStream.rapidlyChangingMotionState.tcp??"")})}catch(r){throw n&&await this.jogger.setJoggingMode("off").catch(()=>{}),j.runInAction(()=>{this.jogger.tcp=o,this.selectedTcpId=this.jogger.motionStream.rapidlyChangingMotionState.tcp??""}),r}finally{j.runInAction(()=>{this.tcpChangeInProgress=!1})}}waitForTcpConfirmation(t,o){return new Promise(n=>{const r=setTimeout(()=>{s(),n(!1)},o),s=j.when(()=>this.jogger.motionStream.rapidlyChangingMotionState.tcp===t,()=>{clearTimeout(r),n(!0)})})}setSelectedOrientation(t){this.selectedOrientation=t}setSelectedIncrementId(t){this.selectedIncrementId=t}setCurrentIncrementJog(t){this.incrementJogInProgress=t}setVelocityFromSlider(t,o){o?this.rotationVelocityDegPerSec=t:this.translationVelocityMmPerSec=t}setSelectedCartesianMotionType(t){this.selectedCartesianMotionType=t}lock(t){this.locks.add(t)}unlock(t){this.locks.delete(t)}block(){this.blocked=!0}unblock(){this.blocked=!1,this.jogger.mode==="jogging"&&this.jogger.initializeJoggingWebsocket().catch(t=>{console.error("Failed to initialize jogging:",t)})}async withMotionLock(t){const o=ce();this.lock(o);try{return await t()}finally{this.unlock(o)}}}const Ye=L.observer(({store:e,useDegree:t})=>{var l;const{t:o}=z.useTranslation(),n=b.useId(),r=[];function s(a){switch(a){case"coordsys":return o("Jogging.Orientation.coordsys");case"tool":return o("Jogging.Orientation.tool");default:return a}}return e.showCoordSystemSelect&&r.push(i.jsx(et,{labelId:`jogging-coord-select-${n}`,labelValue:o("Jogging.CoordinateSystem.hlb"),value:e.selectedCoordSystemId,size:"small",variant:"filled",displayEmpty:!0,onChange:a=>e.setSelectedCoordSystemId(a.target.value),children:e.coordSystems.map(a=>i.jsx(Y,{value:a.coordinate_system,children:a.name&&e.coordSystemCountByName[a.name]>1?`${a.name} / ${a.coordinate_system}`:a.name||a.coordinate_system},a.coordinate_system))},"coord")),e.showTcpSelect&&r.push(i.jsx(et,{labelId:`jogging-tcp-select-${n}`,labelValue:"TCP",value:e.selectedTcpId,size:"small",variant:"filled",displayEmpty:e.tcpChangeInProgress,onChange:a=>{e.requestTcpChange(a.target.value).catch(d=>{console.error("Failed to change TCP:",d)})},disabled:e.tcpChangeInProgress,endAdornment:e.tcpChangeInProgress?i.jsx(re,{position:"end",children:i.jsx(Et,{size:16})}):void 0,children:e.tcps.map(a=>i.jsx(Y,{value:a.id,children:a.id},a.id))},"tcp")),e.showOrientationSelect&&r.push(i.jsx(et,{labelValue:o("Jogging.Cartesian.Orientation.lb"),labelId:`orientation-select-${n}`,value:e.selectedOrientation,onChange:a=>e.setSelectedOrientation(a.target.value),children:We.map(a=>i.jsx(Y,{value:a,children:s(a)},a))},"orientation")),e.showIncrementSelect&&r.push(i.jsxs(et,{labelValue:o("Jogging.Increment.hlb"),labelId:`jogging-increment-select-${n}`,size:"small",variant:"filled",value:((l=e.activeDiscreteIncrement)==null?void 0:l.id)||"continuous",onChange:a=>e.setSelectedIncrementId(a.target.value),children:[i.jsx(Y,{value:"continuous",children:o("Jogging.Increment.Continuous.dd")},"continuous"),e.selectedOrientation==="tool"?null:e.discreteIncrementOptions.map(a=>i.jsx(Y,{value:a.id,children:t?`${a.degrees}°`:`${a.mm}mm`},a.id))]},"increment")),i.jsx(O,{component:"div","data-testid":"jogging-options","aria-label":"jogging-options",sx:{display:"grid",gap:"16px",gridTemplateColumns:"1fr 1fr",gridAutoRows:"min-content","& label":{opacity:.7,fontSize:"12px",marginBottom:"4px"}},children:r.map((a,d)=>i.jsx(O,{sx:{gridColumn:r.length%2===1&&d===r.length-1?"span 2":"auto"},children:a},d))})}),Ze=A.styled(de)(({theme:e})=>{var t;return{"&.MuiToggleButtonGroup-root":{background:(t=e.palette.backgroundPaperElevation)==null?void 0:t[8],borderRadius:"8px",padding:"4px",gap:"4px",button:{border:"none",borderRadius:"4px",flex:"1 1 0px",minWidth:0,"&.MuiToggleButtonGroup-firstButton":{borderRadius:"8px 4px 4px 8px"},"&.MuiToggleButtonGroup-lastButton":{borderRadius:"4px 8px 8px 4px"}}}}}),Ft=H.externalizeComponent(L.observer(e=>{const{store:t}=e,{t:o}=z.useTranslation();function n(r,s){s===e.velocity||!ge(s)||e.onVelocityChange(s,e.useDegree)}return i.jsxs(I,{direction:"row",gap:2,alignItems:"center","data-testid":"velocity-slider","aria-label":"velocity-slider",children:[t.showVelocityLegend&&i.jsx(k,{sx:{color:w.velocitySliderLegendColor,fontSize:"14px"},children:o("Jogging.Velocity.bt")}),i.jsx(Jt,{value:e.velocity,color:"secondary",onChange:n,min:e.min,max:e.max,"aria-labelledby":"input-slider",disabled:e.disabled,sx:{"& .MuiSlider-valueLabelOpen":{zIndex:100,backgroundColor:"transparent",top:"0px"}}}),t.showVelocitySliderLabel&&(e.renderValue?e.renderValue(e.velocity):i.jsx(xt,{value:e.velocity.toString()}))]})}));function xt({value:e,sx:t}){var n;const o=A.useTheme();return i.jsx(I,{direction:"row",justifyContent:"center",alignItems:"center",gap:"5px",sx:{padding:"6px 12px",background:(n=o.palette.backgroundPaperElevation)==null?void 0:n[8],borderRadius:"10px",minWidth:"111px",...t},children:i.jsx(k,{component:"span",sx:{textAlign:"right",fontSize:"14px",opacity:.8,color:o.palette.text.primary,whiteSpace:"nowrap"},children:e})})}const qt=L.observer(({store:e,useDegree:t})=>{const{t:o}=z.useTranslation();function n(r,s){return s?`ω = ${o("Jogging.Cartesian.Rotation.velocityDegPerSec.lb",{amount:r})}`:`v = ${o("Jogging.Cartesian.Translation.velocityMmPerSec.lb",{amount:r})}`}return i.jsx(Ft,{store:e,velocity:e.velocityInDisplayUnits(t),min:e.minVelocityInDisplayUnits(t),max:e.maxVelocityInDisplayUnits(t),onVelocityChange:e.setVelocityFromSlider,useDegree:t,disabled:e.isLocked,renderValue:r=>i.jsx(xt,{value:n(r,t),sx:{minWidth:"111px",span:{transform:"translateY(-1.5px)"}}})})}),Nt=L.observer(({store:e})=>{var r,s,l;const{t}=z.useTranslation(),o=A.useTheme(),n=((l=(s=(r=e.jogger.motionStream.rapidlyChangingMotionState.execute)==null?void 0:r.details)==null?void 0:s.state)==null?void 0:l.kind)??"KIND_UNKNOWN";return i.jsxs(O,{sx:{display:"flex",flexDirection:"row",justifyContent:"space-between",color:o.palette.text.primary},children:[i.jsx(k,{variant:"body2",sx:{fontSize:"0.75rem",lineHeight:1.2},children:t("Jogging.StreamStateSection.lb")}),i.jsx(k,{variant:"body2",sx:{fontSize:"0.75rem",lineHeight:1.2},"data-testid":n,children:t(`Jogging.StreamStateSection.${n}.lb`)})]})}),Xe=L.observer(({store:e,children:t})=>{const{t:o}=z.useTranslation(),n=A.useTheme(),r=b.useRef(0);function s(h,g){(g==="translate"||g==="rotate")&&e.setSelectedCartesianMotionType(g)}async function l(h,g){const y=await e.activate(),x=y.motionStream.rapidlyChangingMotionState.tcp_pose,u=y.motionStream.rapidlyChangingMotionState.joint_position;x&&await e.withMotionLock(async()=>{try{e.setCurrentIncrementJog({axis:h.axis,direction:h.direction}),await e.jogger.runIncrementalCartesianMotion({currentTcpPose:x,currentJoints:u,coordSystemId:e.activeCoordSystemId,velocityInRelevantUnits:e.selectedCartesianMotionType==="translate"?e.translationVelocityMmPerSec:e.rotationVelocityRadsPerSec,axis:h.axis,direction:h.direction,motion:e.selectedCartesianMotionType==="translate"?{type:"translate",distanceMm:g.mm}:{type:"rotate",distanceRads:P.degreesToRadians(g.degrees)}})}finally{e.setCurrentIncrementJog(null),await e.deactivate()}})}async function a(h){if(e.isLocked)return;const g=++r.current;try{if(await e.activate(),g!==r.current)return;if(e.activeDiscreteIncrement)return await l(h,e.activeDiscreteIncrement);h.motionType==="translate"?await e.jogger.translateTCP({axis:h.axis,direction:h.direction,velocityMmPerSec:e.translationVelocityMmPerSec}):await e.jogger.rotateTCP({axis:h.axis,direction:h.direction,velocityRadsPerSec:e.rotationVelocityRadsPerSec})}catch(y){console.error("Jogging failed:",y)}}async function d(){e.isLocked||e.activeDiscreteIncrement||(r.current++,await e.deactivate())}const c=[{id:"x",icon:i.jsx($e,{}),colors:w.cartesianAxisColors.X},{id:"y",icon:i.jsx(Fe,{}),colors:w.cartesianAxisColors.Y},{id:"z",icon:i.jsx(Ne,{}),colors:w.cartesianAxisColors.Z}];function f(h){return o("General.mm.variable",{amount:h.toFixed(1)})}function m(h){return o("General.degree.variable",{amount:P.radiansToDegrees(h).toFixed(1)})}return i.jsxs(I,{"data-testid":"jogging-cartesian-tab","aria-label":"jogging-cartesian-tab",flexGrow:1,gap:2,sx:{padding:"18px 24px"},children:[i.jsxs(I,{gap:2,children:[i.jsx(Ye,{store:e,useDegree:e.selectedCartesianMotionType==="rotate"}),i.jsx(qt,{store:e,useDegree:e.selectedCartesianMotionType==="rotate"}),i.jsx(X,{})]}),i.jsx(I,{marginLeft:"auto",marginRight:"auto",gap:"24px",justifyContent:"center",sx:{flexGrow:"1"},children:i.jsxs(I,{alignItems:"center",justifyContent:"center",gap:"24px",sx:{flexGrow:1},children:[i.jsxs(Ze,{value:e.selectedCartesianMotionType,onChange:s,exclusive:!0,"aria-label":o("Jogging.Cartesian.MotionType.lb"),sx:{justifyContent:"center"},children:[i.jsx(bt,{value:"translate",children:o("Jogging.Cartesian.Translation.bt")}),i.jsx(bt,{value:"rotate",children:o("Jogging.Cartesian.Rotation.bt")})]}),e.selectedCartesianMotionType==="translate"&&c.map(h=>{var g,y;return i.jsx(gt,{"data-testid":`jogging-cartesian-axis-control-${h.id}`,"aria-label":`jogging-cartesian-axis-control-${h.id}`,colors:h.colors,disabled:e.isLocked,activeJoggingDirection:((g=e.incrementJogInProgress)==null?void 0:g.axis)===h.id?e.incrementJogInProgress.direction:void 0,label:i.jsxs(i.Fragment,{children:[h.icon,i.jsx(k,{sx:{fontSize:"24px",color:((y=h.colors)==null?void 0:y.labelColor)??n.palette.text.primary},children:h.id.toUpperCase()})]}),getDisplayedValue:()=>{var x,u;return f(((u=(x=e.jogger.motionStream.rapidlyChangingMotionState.tcp_pose)==null?void 0:x.position)==null?void 0:u[P.XYZ_TO_VECTOR[h.id]])||0)},startJogging:x=>a({axis:h.id,motionType:"translate",direction:x}),stopJogging:d},h.id)}),e.selectedCartesianMotionType==="rotate"&&c.map(h=>{var g,y;return i.jsx(gt,{"data-testid":`jogging-cartesian-axis-control-${h.id}`,"aria-label":`jogging-cartesian-axis-control-${h.id}`,colors:h.colors,disabled:e.isLocked,activeJoggingDirection:((g=e.incrementJogInProgress)==null?void 0:g.axis)===h.id?e.incrementJogInProgress.direction:void 0,label:i.jsxs(i.Fragment,{children:[i.jsx(Ge,{}),i.jsx(k,{sx:{fontSize:"24px",color:((y=h.colors)==null?void 0:y.labelColor)??n.palette.text.primary},children:h.id.toUpperCase()})]}),getDisplayedValue:()=>{var x,u;return m(((u=(x=e.jogger.motionStream.rapidlyChangingMotionState.tcp_pose)==null?void 0:x.orientation)==null?void 0:u[P.XYZ_TO_VECTOR[h.id]])||0)},startJogging:x=>a({axis:h.id,motionType:"rotate",direction:x}),stopJogging:d},h.id)})]})}),i.jsx(Bt,{store:e}),i.jsx(X,{}),i.jsx(Nt,{store:e}),t&&i.jsx(X,{}),t]})}),Ke=L.observer(({store:e,children:t})=>{const o=A.useTheme(),n=b.useRef(0);async function r(l){const a=++n.current;try{if(await e.activate(),a!==n.current)return;await e.jogger.rotateJoints({joint:l.joint,direction:l.direction,velocityUnit:e.jointType===G.JointTypeEnum.PrismaticJoint?"mm/s":"rad/s",velocityValue:e.jointType===G.JointTypeEnum.PrismaticJoint?e.translationVelocityMmPerSec:e.rotationVelocityRadsPerSec})}catch(d){console.error("Jogging failed:",d)}}async function s(){n.current++,await e.jogger.stop(),await e.deactivate()}return i.jsxs(I,{"data-testid":"jogging-joint-tab","aria-label":"jogging-joint-tab",flexGrow:1,gap:2,sx:{padding:"18px 24px"},children:[i.jsx(qt,{store:e,useDegree:e.jointType===G.JointTypeEnum.RevoluteJoint}),i.jsx(X,{}),i.jsx(I,{justifyContent:"center",alignItems:"stretch",sx:{flexGrow:"1"},children:i.jsx(I,{"data-testid":"jogging-joint-value-controls-wrapper","aria-label":"jogging-joint-value-controls-wrapper",alignItems:"center",gap:"24px",children:e.jogger.motionStream.joints.map(l=>{var d,c,f;const a=(f=(c=(d=e.motionGroupDescription.operation_limits.auto_limits)==null?void 0:d.joints)==null?void 0:c[l.index])==null?void 0:f.position;return i.jsxs(I,{"data-testid":`jogging-joint-value-control-${l.index}`,"aria-label":`jogging-joint-value-control-${l.index}`,direction:"row",alignItems:"center",justifyContent:"center",spacing:1.5,width:"100%",children:[e.showJointsLegend&&i.jsx(k,{color:e.isLocked?o.palette.text.disabled:o.palette.text.secondary,children:`G${l.index+1}`}),i.jsx(Ot,{disabled:e.isLocked,lowerLimit:a==null?void 0:a.lower_limit,upperLimit:a==null?void 0:a.upper_limit,useDegree:e.jointType===G.JointTypeEnum.RevoluteJoint,getValue:()=>{const m=e.jogger.motionStream.rapidlyChangingMotionState.joint_position[l.index];return m!==void 0?m:void 0},startJogging:m=>r({joint:l.index,direction:m}),stopJogging:s})]},`joint-${l.index}`)})})}),i.jsx(Bt,{store:e}),i.jsx(X,{}),i.jsx(Nt,{store:e}),t&&i.jsx(X,{}),t]})}),Qe=H.externalizeComponent(L.observer(e=>{const t=L.useLocalObservable(()=>({joggingStore:null,loadingError:null}));return b.useEffect(()=>{let o=!1,n;async function r(){j.runInAction(()=>{t.loadingError=null,t.joggingStore=null});try{let s=e.store;if(!s){const l=await rt.open(e.nova,e.motionGroupId,{cellId:e.cellId});if(o){l.dispose();return}try{s=await st.loadFor(l)}catch(a){throw l.dispose(),a}if(n=s,o){s.dispose();return}}j.runInAction(()=>{t.joggingStore=s}),e.onSetup&&e.onSetup(s)}catch(s){if(o)return;j.runInAction(()=>{t.loadingError=s})}}return r(),()=>{o=!0,n==null||n.dispose()}},[e.store,e.nova,e.motionGroupId,e.cellId]),b.useEffect(()=>{const o=t.joggingStore;o&&(e.locked?o.lock("external"):o.unlock("external"))},[t.joggingStore,e.locked]),i.jsx(I,{"data-testid":"jogging-panel","aria-label":"jogging-panel",sx:{maxWidth:"460px",minWidth:"320px",position:"relative",...e.sx},children:t.joggingStore?i.jsx(to,{store:t.joggingStore,children:e.children}):i.jsx(Lt,{message:"Loading jogging",error:t.loadingError})})})),to=L.observer(({store:e,children:t})=>{const{t:o}=z.useTranslation();function n(){if(e.currentTab.id==="cartesian")return i.jsx(Xe,{store:e,children:t});if(e.currentTab.id==="joint")return i.jsx(Ke,{store:e,children:t})}return i.jsxs(I,{flexGrow:1,sx:{overflow:"hidden"},children:[i.jsx(Qt,{"data-testid":"jogging-tabs","aria-label":"jogging-tabs",value:e.tabIndex,onChange:e.onTabChange,variant:"fullWidth",children:e.tabs.map(r=>{const s=r.label==="Cartesian"?o("Jogging.Cartesian.bt"):o("Jogging.Joints.bt"),l=r.label==="cartesian"?i.jsx(Zt,{fontSize:"small",sx:{mr:1}}):i.jsx(Xt,{fontSize:"small",sx:{mr:1}});return i.jsx(Kt,{"data-testid":`jogging-tab-${r.id}`,"aria-label":`jogging-tab-${r.id}`,label:e.showTabIcons?i.jsxs(I,{direction:"row",alignItems:"center",children:[l,s]}):s,id:`jogging-tab-${r.id}`,"aria-controls":`jogging-tab-${r.id}`},r.id)})}),i.jsx(I,{flexGrow:1,position:"relative",sx:{overflowY:"auto",overflowX:"hidden"},children:n()}),e.blocked&&i.jsx(Ve,{store:e})]})});function eo(){const e=window.location.href;return e.substring(0,e.indexOf("/",e.indexOf("//")+2))}function oo({baseUrl:e=eo(),...t}){return i.jsxs(pe,{"aria-labelledby":"no-motion-group-modal-title",open:!0,fullWidth:!0,sx:{"& .MuiModal-backdrop":{backdropFilter:"blur(10px)"},"& .MuiDialog-paper":{"::before":{content:'""',height:"8px",width:"100%",background:"linear-gradient(90deg, #FF0E65 0%, #47D3FF 100%)"},background:"#101629"}},children:[i.jsx(ye,{id:"no-motion-group-modal-title",children:"No motion group found"}),i.jsxs(xe,{sx:{marginTop:"3rem",marginBottom:"1.5rem",textAlign:"center"},children:[i.jsx(k,{color:"#fff",children:"Found no devices to connect to."}),i.jsx(k,{color:"#fff",children:"Please ensure a motion group has been created."})]}),i.jsx(fe,{children:i.jsxs(I,{width:"100%",maxWidth:"300px",margin:"auto",marginBottom:"2rem",children:[i.jsx(Z,{href:`${e}/settings`,variant:"contained",sx:{borderRadius:"8px",width:"100%"},children:"Go to settings app"}),i.jsx(Z,{href:`${e}`,variant:"text",sx:{marginTop:"1rem",color:"#fff",textDecoration:"underline",fontSize:"0.75rem"},children:"Back to Homescreen"})]})})]})}const Mt=1e-4,no={a:0,d:0,alpha:0,theta:0,reverse_rotation_direction:!1};class nt{constructor(t,o,n,r,s,l,a,d,c,f,m="cell"){this.controller=o,this.motionGroup=n,this.initialMotionState=r,this.motionStateSocket=s,this.isVirtual=l,this.tcps=a,this.description=d,this.initialControllerState=c,this.controllerStateSocket=f,this.cellId=m,this.connectedJoggingSocket=null,this.joggingVelocity=10,this.activationState="inactive",this.nova=w.createNovaClient(t),this.rapidlyChangingMotionState=r,this.controllerState=c,f.addEventListener("message",h=>{var y;const g=(y=P.tryParseJson(h.data))==null?void 0:y.result;g&&j.runInAction(()=>{this.controllerState=g})}),s.addEventListener("message",h=>{var y;const g=(y=P.tryParseJson(h.data))==null?void 0:y.result;if(!g)throw new Error(`Failed to get motion state for ${this.motionGroupId}: ${h.data}`);pt(this.rapidlyChangingMotionState.joint_position,g.joint_position,Mt)||j.runInAction(()=>{this.rapidlyChangingMotionState.joint_position=g.joint_position}),ft(this.rapidlyChangingMotionState,g,Mt)||j.runInAction(()=>{this.rapidlyChangingMotionState.tcp_pose=g.tcp_pose}),g.tcp!==void 0&&this.rapidlyChangingMotionState.tcp!==g.tcp&&j.runInAction(()=>{this.rapidlyChangingMotionState.tcp=g.tcp}),this.rapidlyChangingMotionState.standstill!==g.standstill&&j.runInAction(()=>{this.rapidlyChangingMotionState.standstill=g.standstill})}),j.makeAutoObservable(this)}static async connectMultiple(t,o,n={}){const r=w.createNovaClient(t),s=n.cellId??w.cellIdOf(t);return Promise.all(o.map(l=>nt.connect(r,l,{...n,cellId:s})))}static async connect(t,o,n={}){var R,v;const r=w.createNovaClient(t),s=n.cellId??w.cellIdOf(t)??"cell",[l,a]=o.split("@"),d=await r.api.controller.getCurrentRobotControllerState(s,a),c=d==null?void 0:d.motion_groups.find(J=>J.motion_group===o);if(!d||!c)throw new Error(`Controller ${a} or motion group ${o} not found`);const f=r.openReconnectingWebsocket(`/cells/${s}/controllers/${a}/motion-groups/${o}/state-stream`),m=await f.firstMessage(),h=(R=P.tryParseJson(m.data))==null?void 0:R.result;if(!h)throw new Error(`Unable to parse initial motion state message ${m.data}`);console.log(`Connected motion state websocket to motion group ${c.motion_group}. Initial state:
|
|
3
|
+
`,h);const y=(await r.api.controller.getRobotController(s,d.controller)).configuration.kind==="VirtualController",x=await r.api.motionGroup.getMotionGroupDescription(s,a,c.motion_group),u=Object.entries(x.tcps||{}).map(([J,D])=>({id:J,readable_name:D.name,position:D.pose.position,orientation:D.pose.orientation})),p=r.openReconnectingWebsocket(`/cells/${s}/controllers/${d.controller}/state-stream?response_rate=1000`),S=await p.firstMessage(),M=(v=P.tryParseJson(S.data))==null?void 0:v.result;if(!M)throw new Error(`Unable to parse initial controller state message ${S.data}`);return console.log(`Connected controller state websocket to controller ${d.controller}. Initial state:
|
|
4
|
+
`,M),new nt(r,d,c,h,f,y,u,x,M,p,s)}get motionGroupId(){return this.motionGroup.motion_group}get controllerId(){return this.controller.controller}get modelFromController(){return this.description.motion_group_model}get joggingVelocityRads(){return this.joggingVelocity*Math.PI/180}get joints(){return this.initialMotionState.joint_position.map((t,o)=>({index:o}))}get dhParameters(){if(this.description.dh_parameters!==void 0)return this.description.dh_parameters.map(t=>({...no,...t}))}get safetyZones(){return this.description.safety_zones}get mountingPosition(){var t,o,n;return this.description.mounting?[(((t=this.description.mounting.position)==null?void 0:t[0])||0)/1e3,(((o=this.description.mounting.position)==null?void 0:o[1])||0)/1e3,(((n=this.description.mounting.position)==null?void 0:n[2])||0)/1e3]:[0,0,0]}get mountingQuaternion(){var r,s,l,a,d,c;const t=new jt.Vector3(((s=(r=this.description.mounting)==null?void 0:r.orientation)==null?void 0:s[0])||0,((a=(l=this.description.mounting)==null?void 0:l.orientation)==null?void 0:a[1])||0,((c=(d=this.description.mounting)==null?void 0:d.orientation)==null?void 0:c[2])||0),o=t.length(),n=t.normalize();return new jt.Quaternion().setFromAxisAngle(n,o)}get isEstopActive(){return["SAFETY_STATE_ROBOT_EMERGENCY_STOP","SAFETY_STATE_DEVICE_EMERGENCY_STOP"].includes(this.controllerState.safety_state)}get isMoveableSafetyState(){return["SAFETY_STATE_NORMAL","SAFETY_STATE_REDUCED"].includes(this.controllerState.safety_state)}get isMoveableOperationMode(){return["OPERATION_MODE_AUTO","OPERATION_MODE_MANUAL","OPERATION_MODE_MANUAL_T1","OPERATION_MODE_MANUAL_T2"].includes(this.controllerState.operation_mode)}get canBeMoved(){return this.isMoveableSafetyState&&this.isMoveableOperationMode&&this.activationState==="active"}async deactivate(){if(this.activationState!=="active"){console.error("Tried to deactivate while already deactivating");return}j.runInAction(()=>{this.activationState="deactivating"});try{await this.nova.api.controller.setDefaultMode(this.cellId,this.controllerId,"ROBOT_SYSTEM_MODE_MONITOR"),j.runInAction(()=>{this.activationState="inactive"})}catch(t){throw j.runInAction(()=>{this.activationState="active"}),t}}async activate(){if(this.activationState!=="inactive"){console.error("Tried to activate while already activating");return}j.runInAction(()=>{this.activationState="activating"});try{await this.nova.api.controller.setDefaultMode(this.cellId,this.controllerId,"ROBOT_SYSTEM_MODE_CONTROL"),j.runInAction(()=>{this.activationState="active"})}catch(t){throw j.runInAction(()=>{this.activationState="inactive"}),t}}toggleActivation(){this.activationState==="inactive"?this.activate():this.activationState==="active"&&this.deactivate()}dispose(){this.motionStateSocket.close(),this.controllerStateSocket.close(),this.connectedJoggingSocket&&this.connectedJoggingSocket.close()}setJoggingVelocity(t){this.joggingVelocity=t}}exports.AppHeader=be;exports.ConnectedMotionGroup=nt;exports.JoggerConnection=rt;exports.JoggingButtons=ve;exports.JoggingCartesianAxisControl=gt;exports.JoggingJointSlider=De;exports.JoggingJointValueControl=Ot;exports.JoggingPanel=Qe;exports.JoggingStore=st;exports.LoadingCover=Lt;exports.LoadingErrorMessage=$t;exports.MotionStreamConnection=it;exports.NoMotionGroupModal=oo;exports.VelocitySlider=Ft;exports.VelocitySliderLabel=xt;exports.jointValuesEqual=pt;exports.poseEqual=Dt;exports.tcpMotionEqual=ft;exports.unwrapRotationVector=Vt;
|