@wandelbots/wandelbots-js-react-components 6.4.0-pr.revamp.667.5d2eede → 6.4.0-pr.revamp.667.e1da7d4
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/dist/3d.cjs +1 -1
- package/dist/3d.js +1 -1
- package/dist/RobotHeader/index.cjs +1 -1
- package/dist/RobotHeader/index.js +1 -1
- package/dist/SafetyBar/index.cjs +1 -1
- package/dist/SafetyBar/index.js +1 -1
- package/dist/chunks/{Robot-B3vKEVXP.cjs → Robot-BeTWgowU.cjs} +1 -1
- package/dist/chunks/{Robot-DXhaz1tq.js → Robot-D4XbngYI.js} +1 -1
- package/dist/chunks/{RobotHeader-DDmDkUoV.js → RobotHeader-BZci9ahT.js} +1 -1
- package/dist/chunks/{RobotHeader-Daft80jq.cjs → RobotHeader-CqK0700U.cjs} +1 -1
- package/dist/chunks/{SafetyBar-BVk-SH_0.cjs → SafetyBar-Bbg-o8h9.cjs} +1 -1
- package/dist/chunks/{SafetyBar-RkN0I1Cb.js → SafetyBar-Cuak4ffd.js} +1 -1
- package/dist/chunks/{TrajectoryExecutionStore-DYVukgCz.js → TrajectoryExecutionStore-BNZzZ1Gx.js} +671 -897
- package/dist/chunks/TrajectoryExecutionStore-CYrVePlx.cjs +3 -0
- package/dist/chunks/converters-C8I_A_tA.cjs +1 -0
- package/dist/chunks/{converters-DAr6IQbG.js → converters-DpNB_WNQ.js} +7 -15
- package/dist/core.cjs +1 -1
- package/dist/core.d.ts +0 -2
- package/dist/core.js +38 -41
- package/dist/index.cjs +1 -1
- package/dist/index.js +46 -49
- package/package.json +1 -1
- package/dist/chunks/TrajectoryExecutionStore-CKfEoKo8.cjs +0 -3
- package/dist/chunks/converters-BsXgcxCW.cjs +0 -1
- package/dist/lib/ControllerStateStream.d.ts +0 -125
- package/dist/lib/controllerStateSource.d.ts +0 -35
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
"use strict";const s=require("react/jsx-runtime"),Ut=require("@mui/material/AppBar"),It=require("@mui/material/Backdrop"),D=require("@mui/material/Box"),Gt=require("@mui/material/Menu"),F=require("@mui/material/MenuItem"),Wt=require("@mui/material/Toolbar"),w=require("@mui/material/Typography"),Ht=require("@wandelbots/design-tokens"),Kt=require("@wandelbots/icons/ExpandMoreFilled"),Yt=require("@wandelbots/mui"),E=require("mobx-react-lite"),C=require("react"),Q=require("./externalizeComponent-BdxGBLIv.cjs"),Qt=require("@mui/icons-material/OpenWith"),Zt=require("@mui/icons-material/Share"),v=require("@mui/material/Stack"),Xt=require("@mui/material/Tab"),te=require("@mui/material/Tabs"),y=require("mobx"),P=require("react-i18next"),_=require("@wandelbots/nova-js"),V=require("@wandelbots/nova-js/v2"),$=require("three"),x=require("./Pose3-DIyg-aZA.cjs"),_t=require("@mui/material/CircularProgress"),ee=require("@mui/material/utils"),wt=require("lodash-es"),oe=require("./SafetyBar-BVk-SH_0.cjs"),ne=require("@mui/material/Alert"),ie=require("@mui/material/AlertTitle"),nt=require("@mui/material/Button"),N=require("@mui/material/styles"),q=require("@mui/material/Divider"),pt=require("@mui/material/ToggleButton"),X=require("@mui/material/IconButton"),B=require("./joggingColors-ZDc_2UCp.cjs"),Et=require("lodash-es/isEqual.js"),re=require("@mui/material/InputAdornment"),se=require("@mui/material/FormControl"),ae=require("@mui/material/InputLabel"),ce=require("@mui/material/Select"),H=require("lodash-es/keyBy.js"),le=require("lodash-es/uniqueId.js"),de=require("@mui/material/ToggleButtonGroup"),Mt=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"),ye=require("@mui/material/DialogContent"),Se=require("@mui/material/DialogTitle"),xe=require("./converters-BsXgcxCW.cjs");function Tt(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 b=Tt(C),ft=Tt($),je=Q.externalizeComponent(E.observer(e=>{const{appIcon:t,appName:o,apps:n=[],onAppSelect:i,disabled:r=!1,sx:a}=e,[c,d]=C.useState(null),h=!!c,u=l=>{d(l.currentTarget)},m=()=>{d(null)},g=l=>{m(),l.onClick?l.onClick():l.href&&(window.location.href=l.href),i==null||i(l)};return s.jsxs(s.Fragment,{children:[s.jsx(Ut,{position:"static",sx:{boxShadow:"none",backgroundImage:"none","& .MuiAppBar-root":{backgroundImage:"none",backgroundColor:"transparent"},...a},children:s.jsxs(Wt,{sx:{minHeight:"62px !important"},children:[s.jsx(D,{sx:{mr:1,display:"flex",alignItems:"center"},children:t}),s.jsxs(D,{sx:{display:"flex",alignItems:"center",flexGrow:1},children:[s.jsx(w,{component:"h1",variant:"subtitle1",children:o}),n.length>0&&s.jsx(Yt.RoundedIconButton,{icon:s.jsx(Kt.ExpandMoreFilled,{size:20}),ariaLabel:"switch app","aria-controls":"app-menu","aria-haspopup":"true",onClick:u,disabled:r,sx:{ml:1}})]})]})}),s.jsx(It,{open:h,onClick:m,sx:{backdropFilter:"blur(4px)",backgroundColor:Ht.ZeroGravityComponentsBackdropFill,zIndex:l=>l.zIndex.modal-1}}),s.jsx(Gt,{id:"app-menu",anchorEl:c,open:h,onClose:m,anchorOrigin:{vertical:"bottom",horizontal:"left"},transformOrigin:{vertical:"top",horizontal:"left"},sx:{zIndex:l=>l.zIndex.modal,"& .MuiPaper-root":{minWidth:200,mt:1}},children:n.map(l=>s.jsxs(F,{onClick:()=>g(l),children:[s.jsx(D,{sx:{display:"flex",alignItems:"center"},children:l.icon}),s.jsx(w,{variant:"body1",sx:{ml:2},children:l.name})]},l.id))})]})})),be=({title:e,titleId:t,...o},n)=>b.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?b.createElement("title",{id:t},e):null,b.createElement("g",{id:"JogMinus"},b.createElement("path",{id:"Minus",d:"M0 13V8H21V13H0Z",fill:"white"}))),ve=C.forwardRef(be),Ce=({title:e,titleId:t,...o},n)=>b.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?b.createElement("title",{id:t},e):null,b.createElement("g",{id:"JogPlus"},b.createElement("g",{id:"Plus"},b.createElement("path",{d:"M0 13V8H8V13H0Z",fill:"white"}),b.createElement("path",{d:"M8 0L13 2.18557e-07L13 21H8L8 0Z",fill:"white"}),b.createElement("path",{d:"M13 13V8H21V13H13Z",fill:"white"})))),Ie=C.forwardRef(Ce),it=Q.externalizeComponent(E.observer(({colors:e,label:t,getDisplayedValue:o,startJogging:n,stopJogging:i,disabled:r,activeJoggingDirection:a,...c})=>{var k,O,J,I,R,z,U;x.useAnimationFrame(()=>{const A=o(),L=g.current;L&&(L.textContent=A)});const d=N.useTheme(),[h,u]=C.useState(null);C.useEffect(()=>{r&&M()},[r]);const m=a||h,g=C.useRef(null);e||(e={color:"#fff",backgroundColor:"#000",borderColor:"#000",buttonBackgroundColor:{disabled:"#000",default:"#000",hovered:"#000",pressed:"#000"},labelColor:"#000"});const l=m?(k=e.buttonBackgroundColor)==null?void 0:k.pressed:e.borderColor,f={width:"55px",color:e.color,path:{fill:e.color},alignContent:"center",fontSize:"37px",svg:{pointerEvents:"none"}},p={...f,backgroundColor:(O=e.buttonBackgroundColor)==null?void 0:O.default,":hover":{backgroundColor:(J=e.buttonBackgroundColor)==null?void 0:J.hovered},":active":{backgroundColor:(I=e.buttonBackgroundColor)==null?void 0:I.pressed,color:e.backgroundColor,path:{fill:e.backgroundColor}},":disabled":{backgroundColor:(R=e.buttonBackgroundColor)==null?void 0:R.disabled,"svg path":{fill:d.palette.action.disabled}}},j={...f,backgroundColor:(z=e.buttonBackgroundColor)==null?void 0:z.pressed,color:e.backgroundColor,path:{fill:e.backgroundColor},":disabled":{backgroundColor:(U=e.buttonBackgroundColor)==null?void 0:U.pressed,"svg path":{fill:d.palette.action.disabled}}};function T(A,L){r||A.button===0&&(u(L),n(L))}function M(){u(null),i()}return s.jsxs(v,{height:"64px",direction:"row",justifyContent:"center",...c,children:[s.jsx(X,{disabled:r,disableRipple:!0,onPointerDown:A=>T(A,"-"),onPointerUp:M,onPointerOut:M,size:"large",sx:{...m==="-"?j:p,borderRadius:"16px 0px 0px 16px",borderLeft:`2px solid ${l??"#fff"}`,borderBottom:`2px solid ${l??"#fff"}`,borderTop:`2px solid ${l??"#fff"}`},children:s.jsx(ve,{})}),s.jsxs(v,{spacing:"6px",sx:{width:"150px",backgroundColor:e.backgroundColor,alignItems:"center",justifyContent:"center",opacity:"0.9",borderBottom:`2px solid ${l??"#fff"}`,borderTop:`2px solid ${l??"#fff"}`},children:[s.jsx(v,{height:"22px",direction:"row",alignItems:"center",justifyItems:"center",spacing:1,sx:{userSelect:"none",color:e.color,".MuiTypography-root":{fontWeight:700,...r?{color:d.palette.action.disabled}:{}},...r?{"svg path":{fill:d.palette.action.disabled}}:{}},children:t}),s.jsx(w,{height:"22px",sx:{fontSize:"15px",color:r?d.palette.action.disabled:e.color,fontWeight:700,fontVariantNumeric:"tabular-nums",minWidth:"80px",textAlign:"center"},ref:g,children:o()})]}),s.jsx(X,{disableRipple:!0,disabled:r,onPointerDown:A=>T(A,"+"),onPointerUp:M,onPointerOut:M,size:"large",sx:{...m==="+"?j:p,borderRadius:"0px 16px 16px 0px",borderRight:`2px solid ${l??"#fff"}`,borderBottom:`2px solid ${l??"#fff"}`,borderTop:`2px solid ${l??"#fff"}`},children:s.jsx(Ie,{})})]})})),kt=Q.externalizeComponent(E.observer(({startJogging:e,stopJogging:t,lowerLimit:o,upperLimit:n,useDegree:i,getValue:r,disabled:a,...c})=>{var I,R,z,U,A,L,mt;const{t:d}=P.useTranslation(),[h,u]=C.useState(),m=N.useTheme(),g={background:(I=m.palette.backgroundPaperElevation)==null?void 0:I[4],color:(R=m.palette.backgroundPaperElevation)==null?void 0:R[11]},l=E.useLocalObservable(()=>({activeJoggingDir:null,startJogging(S){this.activeJoggingDir=S,e(S)},stopJogging(){this.activeJoggingDir=null,t()}})),f=me(()=>{const S=i?p(r()):r();(S===void 0||h===void 0||Math.abs(h-S)>1e-9)&&u(S)},50);x.useAnimationFrame(f);function p(S){if(S!==void 0)return _.radiansToDegrees(S)}function j(S){S.button===0&&l.startJogging("-")}function T(S){S.button===0&&l.startJogging("+")}function M(S){l.stopJogging()}function k(S){l.stopJogging()}function O(S,G=1){if(S===void 0||Number.isNaN(S))return"";const W=d("General.degree.variable",{amount:S.toFixed(G)});return S>0&&G===0?`+${W}`:W}function J(S,G=1){if(S===void 0||Number.isNaN(S))return"";const W=d("General.mm.variable",{amount:S.toFixed(G)});return S>0&&G===0?`+${W}`:W}return s.jsxs(v,{height:"64px",width:"100%",maxWidth:"260px",direction:"row",...c,sx:{"& .MuiIconButton-root":{width:"52px",color:m.palette.text.primary,alignContent:"center",backgroundColor:(z=m.palette.backgroundPaperElevation)==null?void 0:z[11],"& svg":{width:"42px",height:"42px"},"&.Mui-disabled":{backgroundColor:(U=m.palette.backgroundPaperElevation)==null?void 0:U[11],color:m.palette.action.disabled,opacity:1},"&:hover":{backgroundColor:(A=m.palette.backgroundPaperElevation)==null?void 0:A[9]},"&:active":{...g}}},children:[s.jsx(X,{onPointerDown:j,onPointerUp:M,onPointerOut:k,disabled:a,disableRipple:!0,sx:{borderRadius:"16px 0px 0px 16px",...l.activeJoggingDir==="-"?g:{}},children:s.jsx(ue,{sx:{pointerEvents:"none",color:B.jointArrowColor}})}),s.jsxs(v,{flexGrow:1,alignItems:"center",justifyContent:"center",sx:{borderStyle:"solid",borderLeftWidth:0,borderRightWidth:0,border:"none",backgroundColor:(L=m.palette.backgroundPaperElevation)==null?void 0:L[11],paddingLeft:"20px",paddingRight:"20px",zIndex:1},children:[s.jsx(w,{sx:{fontSize:"15px",fontWeight:700,position:"relative",top:"5px",fontVariantNumeric:"tabular-nums",minWidth:"80px",textAlign:"center",color:a?m.palette.action.disabled:m.palette.text.primary},children:i?O(h):J(h)}),s.jsx(Mt,{disabled:!0,"aria-label":"Joint position",min:i?p(o):o,max:i?p(n):n,value:h||0,track:!1,sx:{"& .MuiSlider-mark":{display:"none"},"& .MuiSlider-thumb":{width:"5px",height:"12px",borderRadius:"2px",color:a?m.palette.action.disabled:m.palette.text.primary},"& .MuiSlider-markLabel":{top:"20px",fontSize:"12px",color:a?m.palette.action.disabled:m.palette.text.secondary},"& .MuiSlider-rail":{backgroundColor:(mt=m.palette.backgroundPaperElevation)==null?void 0:mt[5],opacity:1}},marks:o!==void 0&&n!==void 0&&[{value:i?p(o):o,label:i?O(p(o),0):J(o)},{value:i?p(n):n,label:i?O(p(n),0):J(n)}]})]}),s.jsx(X,{onPointerDown:T,onPointerUp:M,onPointerOut:k,disabled:a,disableRipple:!0,sx:{borderRadius:"0px 16px 16px 0px",...l.activeJoggingDir==="+"?g:{}},children:s.jsx(he,{sx:{pointerEvents:"none",color:B.jointArrowColor}})})]})}));function _e({currentTcpPose:e,axis:t,direction:o,motion:n,useToolCoordinateSystem:i,coordinateSystemRotation:r}){const a=o==="-"?-1:1;if(n.type==="translate"){if(!e.position)throw new Error("Current pose has no position, cannot perform translation");const m=n.distanceMm*a,g=new $.Vector3;if(g[t]=m,i){if(!e.orientation)throw new Error("Current pose has no orientation, cannot translate relative to tool");g.applyQuaternion(x.parseRotationToQuaternion(e.orientation,"ROTATION_VECTOR"))}else r&&g.applyQuaternion(r);const l=[...e.position];return l[0]=(l[0]??0)+g.x,l[1]=(l[1]??0)+g.y,l[2]=(l[2]??0)+g.z,{position:l,orientation:e.orientation}}if(!e.orientation)throw new Error("Current pose has no orientation, cannot perform rotation");const c=x.parseRotationToQuaternion(e.orientation,"ROTATION_VECTOR"),d=new $.Vector3;d[t]=1,!i&&r&&d.applyQuaternion(r);const h=new $.Quaternion().setFromAxisAngle(d,n.distanceRads*a),u=i?c.multiply(h):h.multiply(c);return{position:e.position,orientation:[...x.quaternionToRotationVector(u)]}}function at(e,t,o){return t.length!==e.length?!1:Ot(e,t,o)}function ct(e,t,o){return t.length!==e.length?!0:Ot(e,t,o)}function Ot(e,t,o){for(let n=0;n<t.length;n++)if(Math.abs((t[n]??0)-(e[n]??0))>o)return!1;return!0}function Jt(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 lt(e,t,o){return e.coordinate_system===t.coordinate_system&&e.tcp===t.tcp&&Jt(e.tcp_pose,t.tcp_pose,o)}function dt(e,t){const o=new $.Vector3(t[0],t[1],t[2]),n=new $.Vector3(e[0],e[1],e[2]),i=o.length(),r=o.normalize();let a=n.length(),c=n.normalize();c.dot(r)<0&&(a=-a,c=c.multiplyScalar(-1));let d=a-i;return d-=2*Math.PI*Math.floor((d+Math.PI)/(2*Math.PI)),a=i+d,[...c.multiplyScalar(a)]}const we=2e-4;function gt(e){const{joint_position:t,tcp_pose:o,tcp:n,coordinate_system:i}=e;return{joint_position:t,tcp_pose:o,tcp:n,coordinate_system:i}}function ut(e,t){return e.tcp===t.tcp&&e.coordinate_system===t.coordinate_system&&e.tcp_pose===void 0==(t.tcp_pose===void 0)&&at(e.joint_position,t.joint_position,we)}const yt=1e-4;class et{constructor(t,o,n,i,r,a,c="cell",d={}){this.controller=o,this.motionGroup=n,this.description=i,this.initialMotionState=r,this.motionStateSocket=a,this.cellId=c,this.nova=x.createNovaClient(t),this.logger=d.logger??console,this.rapidlyChangingMotionState=r,a.addEventListener("message",h=>{var l;const u=(l=_.tryParseJson(h.data))==null?void 0:l.result;if(!u)throw new Error(`Failed to get motion state for ${this.motionGroupId}: ${h.data}`);lt(this.rapidlyChangingMotionState,u,yt)||y.runInAction(()=>{var f,p,j;this.rapidlyChangingMotionState.tcp_pose==null?this.rapidlyChangingMotionState.tcp_pose=u.tcp_pose:(f=u.tcp_pose)!=null&&f.orientation&&((p=u.tcp_pose)!=null&&p.position)&&((j=this.rapidlyChangingMotionState.tcp_pose)!=null&&j.orientation)?this.rapidlyChangingMotionState.tcp_pose={position:u.tcp_pose.position,orientation:dt(u.tcp_pose.orientation,this.rapidlyChangingMotionState.tcp_pose.orientation)}:this.logger.debug("Received incomplete tcp_pose, ignoring",{tcpPose:u.tcp_pose})}),ct(this.rapidlyChangingMotionState.joint_position,u.joint_position,yt)||y.runInAction(()=>{this.rapidlyChangingMotionState.joint_position=u.joint_position}),u.tcp!==void 0&&this.rapidlyChangingMotionState.tcp!==u.tcp&&y.runInAction(()=>{this.rapidlyChangingMotionState.tcp=u.tcp}),this.rapidlyChangingMotionState.standstill!==u.standstill&&y.runInAction(()=>{this.rapidlyChangingMotionState.standstill=u.standstill});const m=this.rapidlyChangingMotionState.joint_limit_reached.limit_reached,g=u.joint_limit_reached.limit_reached;m.some((f,p)=>f!==g[p])&&y.runInAction(()=>{this.rapidlyChangingMotionState.joint_limit_reached=u.joint_limit_reached}),this.rapidlyChangingMotionState.execute!==u.execute&&y.runInAction(()=>{this.rapidlyChangingMotionState.execute=u.execute})}),y.makeAutoObservable(this,{logger:!1,readoutState:y.computed({equals:ut,keepAlive:!0})})}static async open(t,o,n={}){var p;const i=x.createNovaClient(t),r=n.cellId??x.cellIdOf(t)??"cell",[a,c]=o.split("@"),d=await i.api.controller.getCurrentRobotControllerState(r,c),h=d==null?void 0:d.motion_groups.find(j=>j.motion_group===o);if(!d||!h)throw new Error(`Controller ${c} or motion group ${o} not found`);const u=i.openReconnectingWebsocket(`/cells/${r}/controllers/${c}/motion-groups/${o}/state-stream`),m=await u.firstMessage(),g=(p=_.tryParseJson(m.data))==null?void 0:p.result;if(!g)throw new Error(`Unable to parse initial motion state message ${m.data}`);const l=n.logger??console;l.info("Connected motion state websocket to motion group",{motionGroup:h.motion_group,initialMotionState:g});const f=await i.api.motionGroup.getMotionGroupDescription(r,c,h.motion_group);return new et(i,d,h,f,g,u,r,{logger:l})}get readoutState(){return gt(this.rapidlyChangingMotionState)}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 St="Movement request rejected. Another client is currently executing a 'Jogging' motion!",Ee=500,Me=5e3;function Te(e){var o;return(((o=e.times)==null?void 0:o[e.times.length-1])??0)*2e3+Me}class ot{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.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}static async open(t,o,n={}){const i=await et.open(t,o,{cellId:n.cellId,logger:n.logger}),r=new ot(i,n);r.ownsMotionStream=!0;try{await r.setJoggingMode(r.mode)}catch(a){throw r.dispose(),a}return r}getDefaultTcp(t){var n,i;const o=(i=(n=t.description.dh_parameters)==null?void 0:n[0])==null?void 0:i.type;return t.joints.length<6&&(o===V.JointTypeEnum.RevoluteJoint||o===V.JointTypeEnum.PrismaticJoint)?this.NO_TCP:this.DEFAULT_TCP}async setOptions(t){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)}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,n;(o=this.endJoggingInit)==null||o.call(this),(n=this.endIncrementalMotion)==null||n.call(this);const t=[this.joggingSocket,this.trajectorySocket].filter(i=>i!==null);return t.forEach(i=>{i.dispose()}),this.joggingSocket=null,this.trajectorySocket=null,Promise.all(t.map(i=>i.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 i=!1;const r=setTimeout(()=>{a(new Error(`Jogging initialization timeout after ${this.timeout} ms`))},this.timeout),a=h=>{i||(i=!0,clearTimeout(r),n.removeEventListener("close",d),this.endJoggingInit===c&&(this.endJoggingInit=void 0),h?o(h):t())},c=()=>a(),d=()=>{n.disposed&&a()};this.endJoggingInit=c,n.addEventListener("close",d),n.addEventListener("message",h=>{var m,g,l;const u=_.tryParseJson(h.data);if(((m=u==null?void 0:u.result)==null?void 0:m.kind)==="INITIALIZE_RECEIVED"){a();return}if(((g=u==null?void 0:u.result)==null?void 0:g.kind)==="MOTION_ERROR")if(this.onBlocked&&((l=u==null?void 0:u.result)!=null&&l.message.includes(St))){a(),n.dispose(),this.onBlocked();return}else this.onError?(a(),this.onError(h.data)):a(new Error(h.data))}),n.sendJson({message_type:"InitializeJoggingRequest",motion_group:this.motionGroupId,...this.tcp?{tcp:this.tcp}:{}})})}async rotateJoints({joint:t,direction:o,velocityValue:n,velocityUnit:i}){if(!this.joggingSocket||this.mode!=="jogging")throw new Error("Joint jogging websocket not connected; create one by setting jogging mode to 'jogging'");const r=new Array(this.numJoints).fill(0);r[t]=o==="-"?-n:n,this.joggingSocket.sendJson({message_type:"JointVelocityRequest",velocity:r})}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'");this.joggingSocket.sendJson({message_type:"TcpVelocityRequest",translation:this.velocityAlongAxis(t,o==="-"?-n:n),rotation:[0,0,0],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'");this.joggingSocket.sendJson({message_type:"TcpVelocityRequest",translation:[0,0,0],rotation:this.velocityAlongAxis(t,o==="-"?-n:n),use_tool_coordinate_system:this.orientation==="tool"})}get coordinateSystemRotation(){if(!(this.orientation==="tool"||!this.coordinateSystem))return x.Pose3.fromCoordinateSystem(this.coordinateSystem).quaternion}velocityAlongAxis(t,o){const n=new $.Vector3;n[t]=o;const i=this.coordinateSystemRotation;return i&&n.applyQuaternion(i),[n.x,n.y,n.z]}async runIncrementalCartesianMotion(t){if(this.mode!=="trajectory")throw new Error("Set jogging mode to 'trajectory' to run incremental cartesian motions");if(!this.incrementalMotionInFlight){this.incrementalMotionInFlight=!0;try{const o=await this.planIncrementalCartesianMotion(t);o&&await this.executeTrajectory(o)}finally{this.incrementalMotionInFlight=!1}}}async planIncrementalCartesianMotion({currentTcpPose:t,currentJoints:o,velocityInRelevantUnits:n,axis:i,direction:r,motion:a}){var p,j,T;const c=[],d=_e({currentTcpPose:t,axis:i,direction:r,motion:a,useToolCoordinateSystem:this.orientation==="tool",coordinateSystemRotation:this.coordinateSystemRotation});c.push({limits_override:a.type==="translate"?{tcp_velocity_limit:n}:{tcp_orientation_velocity_limit:n},path:{path_definition_name:"PathLine",target_pose:{position:d.position,orientation:d.orientation}}});const h=this.motionStream.description;if(h.cycle_time===void 0){this.logger.warn("Current motion group has no cycle time, cannot plan jogging motion");return}const u=this.motionStream.rapidlyChangingMotionState.tcp,m=u?(j=(p=h.tcps)==null?void 0:p[u])==null?void 0:j.pose:void 0,g={motion_group_model:((T=this.options)==null?void 0:T.motionGroupModel)??h.motion_group_model,cycle_time:h.cycle_time,mounting:h.mounting,tcp_offset:m,global:h.operation_limits.auto_limits},l=await this.nova.api.trajectoryPlanning.planTrajectory(this.cellId,{motion_group_setup:g,start_joint_position:o,motion_commands:c}),f=l.response;if(!f)throw new Error(`Failed to plan jogging increment motion ${JSON.stringify(l)}`);if("error_feedback"in f){if(this.onError){this.onError(f);return}throw new Error(`Failed to plan jogging increment motion: ${JSON.stringify(f.error_feedback)}`)}return f}async executeTrajectory(t){const o=this.nova.openReconnectingWebsocket(`/cells/${this.cellId}/controllers/${this.motionStream.controllerId}/execution/trajectory`);this.trajectorySocket=o;const n=new AbortController;let i,r;try{await new Promise((a,c)=>{let d=!1;const h=()=>{d||(d=!0,a())},u=g=>{if(!d){if(d=!0,this.onError){this.onError(g),a();return}c(g instanceof Error?g:new Error(`Failed to execute trajectory: ${JSON.stringify(g)}`))}};r=h,this.endIncrementalMotion=h;const m=Te(t);i=setTimeout(()=>{u(new Error(`Jogging motion did not complete within ${m}ms`))},m),o.addEventListener("message",g=>{var f,p;const l=(f=_.tryParseJson(g.data))==null?void 0:f.result;if(!(l!=null&&l.kind)){u(new Error(`Failed to execute trajectory: Received invalid message ${g.data}`));return}if(this.onBlocked&&((p=l.message)!=null&&p.includes(St))){this.onBlocked(),h();return}if(l.kind==="INITIALIZE_RECEIVED"){if(l.add_trajectory_error||l.message){u(l);return}o.sendJson({message_type:"StartMovementRequest",direction:"DIRECTION_FORWARD"})}else if(l.kind==="START_RECEIVED"){if(l.message){u(l);return}this.waitForMotionToFinish(n.signal).then(h,u)}else l.kind==="PAUSE_RECEIVED"||(l.kind==="MOTION_ERROR"&&l.message?u(l):u(new Error(`Failed to execute trajectory, cannot handle message type "${l.kind}"`)))}),o.sendJson({message_type:"InitializeMovementRequest",trajectory:{message_type:"TrajectoryData",motion_group:this.motionGroupId,data:t,tcp:this.tcp}})})}finally{clearTimeout(i),n.abort(),this.endIncrementalMotion===r&&(this.endIncrementalMotion=void 0),o.dispose(),this.trajectorySocket===o&&(this.trajectorySocket=null)}}async waitForMotionToFinish(t){const o=()=>this.motionStream.rapidlyChangingMotionState.standstill;await y.when(()=>!o(),{timeout:Ee,signal:t}).catch(()=>{}),await y.when(o,{signal:t})}}const Rt=e=>{const t=e.softTimeout||3e3,[o,n]=C.useState(!1);return C.useEffect(()=>{const i=setTimeout(()=>{n(!0)},t);return()=>clearTimeout(i)}),s.jsx(v,{width:"100%",height:"100%",alignItems:"center",justifyContent:"center",sx:{color:"text.primary"},children:e.error?s.jsx(At,{loadingMessage:e.message,error:e.error}):s.jsxs(s.Fragment,{children:[s.jsx(_t,{sx:{mb:3}}),!!e.message&&s.jsx(w,{variant:"body1",children:e.message}),s.jsx(w,{variant:"body2",sx:{visibility:o?"visible":"hidden",mt:2,color:"text.secondary"},children:"This is taking longer than expected..."})]})})},At=e=>{const t=oe.makeErrorMessage(e.error),o=e.error instanceof Error?e.error.stack:null;return s.jsxs(v,{sx:{maxHeight:"100%",maxWidth:"min(100%, 800px)",p:2,overflow:"auto",color:"error.main"},children:[s.jsx(w,{variant:"body1",children:(e.loadingMessage?`Error while ${wt.lowerFirst(ee.capitalize(e.loadingMessage))} - `:"")+t}),o&&s.jsx(D,{component:"pre",sx:{typography:"body2",fontFamily:"monospace",whiteSpace:"pre-wrap",wordBreak:"break-word",mt:2,pb:6},children:o})]})},ke=E.observer(({store:e})=>{const{t}=P.useTranslation();return s.jsx(It,{"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:s.jsxs(v,{sx:{m:2,width:"100%"},children:[s.jsxs(ne,{severity:"error",sx:{mb:2},children:[s.jsx(ie,{children:t("Jogging.Blocked.ti")}),t("Jogging.Blocked.lb")]}),s.jsx(nt,{variant:"contained",color:"secondary",onClick:()=>e.unblock(),children:t("Jogging.Blocked.Reenable.bt")})]})})}),Oe=({title:e,titleId:t,...o},n)=>b.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",width:19,height:10,fill:"none",ref:n,"aria-labelledby":t,...o},e?b.createElement("title",{id:t},e):null,b.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"})),Je=C.forwardRef(Oe),Re=({title:e,titleId:t,...o},n)=>b.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",width:19,height:10,fill:"none",ref:n,"aria-labelledby":t,...o},e?b.createElement("title",{id:t},e):null,b.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"})),Ae=C.forwardRef(Re),Pe=({title:e,titleId:t,...o},n)=>b.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",width:10,height:19,fill:"none",ref:n,"aria-labelledby":t,...o},e?b.createElement("title",{id:t},e):null,b.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"})),Le=C.forwardRef(Pe),Ve=({title:e,titleId:t,...o},n)=>b.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?b.createElement("title",{id:t},e):null,b.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"})),De=C.forwardRef(Ve),Pt=E.observer(({store:e})=>{const{t}=P.useTranslation(),[o,n]=C.useState(e.jogger.motionStream.rapidlyChangingMotionState.joint_limit_reached.limit_reached),i=C.useRef(o);x.useAnimationFrame(()=>{const a=e.jogger.motionStream.rapidlyChangingMotionState.joint_limit_reached.limit_reached;Et(i.current,a)||(i.current=a,n(a))});const r=[];for(const[a,c]of o.entries())c&&r.push(a);return s.jsx(D,{sx:{display:"flex",flexDirection:"row",justifyContent:"center"},children:s.jsx(w,{"data-testid":"jogging-joint-limit-detector","aria-label":"jogging-joint-limit-detector",color:"error",variant:"body2",sx:{fontSize:"0.75rem",lineHeight:1.2,visibility:r.length?"visible":"hidden"},children:t("Jogging.JointLimitsReached.lb",{jointNumbers:r.map(a=>a+1).join(", ")})})})}),Ne=N.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 Z({labelValue:e,...t}){return s.jsxs(Ne,{fullWidth:!0,variant:"filled",children:[s.jsx(ae,{id:t.labelId,children:e}),s.jsx(ce,{...t})]})}function xt(e){const t=e.lastIndexOf("On");return t>0?e.slice(0,t):e}function Lt(e,t){const o=e[t];if(o)return o;const n=xt(t),i=e[n];if(i)return i;const r=Object.keys(e).filter(c=>xt(c)===n);if(r.length!==1)return;const a=r[0];return a?e[a]:void 0}const $e={coordinate_system:"world",name:"world",reference_coordinate_system:"",position:[0,0,0],orientation:[0,0,0],orientation_type:"ROTATION_VECTOR"};function Vt(e){const t=H(e.map(i=>({...i,coordinate_system:i.coordinate_system||"world"})),"coordinate_system");t.world??(t.world=$e);const o={},n=i=>{const r=o[i];if(r)return r;const a=Lt(t,i);if(!a)throw new Error(`Unknown coordinate system ${i}. Known coordinate systems are: ${Object.keys(t).join(", ")}`);const c=a.reference_coordinate_system||"world";let d;if(c==="world")d=a;else{const h=n(c),u=x.Pose3.fromCoordinateSystem(h).multiply(x.Pose3.fromCoordinateSystem(a));d={...a,position:[u.position.x,u.position.y,u.position.z],orientation:[u.orientation.x,u.orientation.y,u.orientation.z],orientation_type:"ROTATION_VECTOR",reference_coordinate_system:h.reference_coordinate_system}}return o[i]=d,d};return Object.fromEntries(Object.keys(t).map(i=>[i,n(i)]))}function rt(e,t){const o=Lt(e,t||"world");if(!o)throw new Error(`Unknown coordinate system ${t}. Known coordinate systems are: ${Object.keys(e).join(", ")}`);return o}function Dt(e,t){return rt(Vt(t),e)}function K(e,t,o){if(e.coordinateSystemId===t)return e;const n=Vt(o),i=rt(n,e.coordinateSystemId||"world"),r=rt(n,t);if(i.coordinate_system===r.coordinate_system)return{...e,coordinateSystemId:r.coordinate_system};const a=x.Pose3.fromCoordinateSystem(r).inverse().multiply(x.Pose3.fromCoordinateSystem(i).multiply(x.Pose3.fromPose(e.pose)));return{...e,pose:{position:[a.position.x,a.position.y,a.position.z],orientation:[a.orientation.x,a.orientation.y,a.orientation.z]},coordinateSystemId:r.coordinate_system}}function Nt(e,t,o){const n=x.Pose3.fromPose(e).multiply(x.Pose3.fromRobotTcp(t).inverse()).multiply(x.Pose3.fromRobotTcp(o)),{position:i,orientation:r}=n;return{position:[i.x,i.y,i.z],orientation:[r.x,r.y,r.z]}}function jt(e,t){const o=e==null?void 0:e[t];if(!o)throw new Error(`Unknown TCP ${t}. Known TCPs are: ${Object.keys(e??{}).join(", ")}`);return{position:o.pose.position??[0,0,0],orientation:o.pose.orientation??[0,0,0],orientation_type:"ROTATION_VECTOR"}}function Fe({inputPose:e,selectedTcpId:t,selectedCoordinateSystemId:o,tcpOffsetsById:n,coordinateSystems:i}){const r=t&&t!==e.tcpId?{...e,pose:Nt(e.pose,jt(n,e.tcpId),jt(n,t)),tcpId:t}:e;return o?K(r,o,i):r}function $t(e){var t,o,n,i,r;if(typeof e=="string"){const a=_.tryParseJson(e);return a?$t(a):e}if(e&&typeof e=="object"){const a=e;return((t=a.error_feedback)==null?void 0:t.error_feedback_name)||((o=a.add_trajectory_error)==null?void 0:o.message)||a.message||((i=(n=a.result)==null?void 0:n.add_trajectory_error)==null?void 0:i.message)||((r=a.result)==null?void 0:r.message)||"Jogging motion failed"}return"Jogging motion failed"}const qe=[{pattern:/^FeedbackSingularity$/,translationKey:"Jogging.StreamStateSection.Error.Singularity.lb"},{pattern:/^FeedbackJointLimitExceeded$/,translationKey:"Jogging.StreamStateSection.Error.JointLimit.lb"},{pattern:/^FeedbackOutOfWorkspace$/,translationKey:"Jogging.StreamStateSection.Error.OutOfWorkspace.lb"},{pattern:/^FeedbackCollision$/,translationKey:"Jogging.StreamStateSection.Error.Collision.lb"},{pattern:/^FeedbackNoSolutionInCurrentConfiguration$/,translationKey:"Jogging.StreamStateSection.Error.NoSolutionInConfiguration.lb"},{pattern:/^Feedback\w+$/,translationKey:"Jogging.StreamStateSection.Error.PlanningFailed.lb"}];function Be(e){var t;return((t=qe.find(({pattern:o})=>o.test(e)))==null?void 0:t.translationKey)??null}const ze=5,Ue=250;function Ge(e){var n,i,r,a;const t=[(i=(n=e==null?void 0:e.manual_t1_limits)==null?void 0:n.tcp)==null?void 0:i.velocity,(a=(r=e==null?void 0:e.manual_limits)==null?void 0:r.tcp)==null?void 0:a.velocity].filter(c=>typeof c=="number"&&Number.isFinite(c)&&c>0);return Math.min(Ue,...t)/10}const st=[{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}],We=[{id:"continuous"},...st],He=["coordsys","tool"],bt="joggingToolStore",Ke=()=>typeof localStorage>"u"?void 0:localStorage;class Y{constructor(t,o,n,i,r,a={}){var d,h,u;this.jogger=t,this.coordSystems=o,this.motionGroupDescription=n,this.tcps=i,this.inverseSolverValue=r,this.selectedTabId="cartesian",this.locks=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=ze,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=V.JointTypeEnum.RevoluteJoint,this.storage=a.storage??Ke();for(const m of o)if(m.coordinate_system===""){m.coordinate_system="world";break}this.selectedCoordSystemId=((d=o[0])==null?void 0:d.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=Ge(n==null?void 0:n.operation_limits),this.jointType=((u=(h=n==null?void 0:n.dh_parameters)==null?void 0:h[0])==null?void 0:u.type)??V.JointTypeEnum.RevoluteJoint,y.makeAutoObservable(this,{storage:!1},{autoBind:!0}),this.jogger.onBlocked=()=>{this.block()};const c=this.jogger.onError;this.jogger.onError=m=>{this.setLastJogError($t(m)),c==null||c(m)},this.loadFromLocalStorage(),this.disposers.push(y.autorun(()=>this.saveToLocalStorage())),this.disposers.push(y.autorun(()=>{const m=this.jogger.motionStream.rapidlyChangingMotionState.tcp;m&&m!==this.selectedTcpId&&y.runInAction(()=>{this.selectedTcpId=m,this.tcpChangeInProgress=!1})}))}static async loadFor(t,o={}){const{nova:n,cellId:i}=t,[r,a]=await Promise.all([n.api.controller.listCoordinateSystems(i,t.motionStream.controllerId,"ROTATION_VECTOR"),n.api.motionGroup.getMotionGroupDescription(i,t.motionStream.controllerId,t.motionGroupId)]),c=await n.api.motionGroupModels.getMotionGroupKinematicModel(a.motion_group_model);return Y.create(t,{coordinateSystems:r||[],description:a,kinematicModel:c},o)}static create(t,o,n={}){const{coordinateSystems:i,description:r,kinematicModel:a}=o,c=Object.entries(r.tcps||{}).map(([d,h])=>({id:d,readable_name:h.name,position:h.pose.position,orientation:h.pose.orientation}));return new Y(t,i,r,c,a.inverse_solver,n)}dispose(){for(const t of this.disposers)t();this.jogger.dispose()}get coordSystemCountByName(){return wt.countBy(this.coordSystems,t=>t.name)}async deactivate(){this.jogger.mode==="jogging"&&await this.jogger.setJoggingMode("off")}async activate(){var t;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({tcp:this.selectedTcpId||void 0,orientation:this.selectedOrientation}),this.jogger.coordinateSystem=this.jogCoordSystem,this.activeDiscreteIncrement?await this.jogger.setJoggingMode("trajectory"):await this.jogger.setJoggingMode("jogging")):await this.jogger.setJoggingMode("jogging"),this.jogger}loadFromLocalStorage(){var n;const t=(n=this.storage)==null?void 0:n.getItem(bt),o=t?_.tryParseJson(t):void 0;o&&(this.tabsById[o.selectedTabId]&&(this.selectedTabId=o.selectedTabId),this.coordSystemsById[o.selectedCoordSystemId]&&(this.selectedCoordSystemId=o.selectedCoordSystemId),this.coordSystemsById[o.jogCoordSystemId]&&(this.jogCoordSystemId=o.jogCoordSystemId),this.incrementOptionsById[o.selectedIncrementId]&&(this.selectedIncrementId=o.selectedIncrementId),["translate","rotate"].includes(o.selectedCartesianMotionType)&&(this.selectedCartesianMotionType=o.selectedCartesianMotionType),["coordsys","tool"].includes(o.selectedOrientation)&&(this.selectedOrientation=o.selectedOrientation))}saveToLocalStorage(){var t;(t=this.storage)==null||t.setItem(bt,JSON.stringify(this.localStorageSave))}get isLocked(){return this.locks.size>0}get lastJogErrorTranslationKey(){return this.lastJogError?Be(this.lastJogError):null}get localStorageSave(){return{selectedTabId:this.selectedTabId,selectedCoordSystemId:this.selectedCoordSystemId,jogCoordSystemId:this.jogCoordSystemId,selectedOrientation:this.selectedOrientation,selectedIncrementId:this.selectedIncrementId,selectedCartesianMotionType:this.selectedCartesianMotionType}}get canJogCartesian(){return this.inverseSolver!==null}get tabs(){const t=[{id:"joint",label:"Joints"}];return this.canJogCartesian&&t.unshift({id:"cartesian",label:"Cartesian"}),t}get incrementOptions(){return We}get discreteIncrementOptions(){return st}get incrementOptionsById(){return H(this.incrementOptions,t=>t.id)}get tabsById(){return H(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 H(this.coordSystems,t=>t.coordinate_system)}get activeCoordSystemId(){return this.selectedOrientation==="tool"?"tool":this.selectedCoordSystemId}get jogCoordSystem(){return Dt(this.jogCoordSystemId,this.coordSystems)}get tcpPoseInSelectedCoordSystem(){const{tcp_pose:t,coordinate_system:o}=this.jogger.motionStream.readoutState;return!(t!=null&&t.position)||!t.orientation?t:K({pose:{position:t.position,orientation:t.orientation},coordinateSystemId:o||"world"},this.selectedCoordSystemId,this.coordSystems).pose}get tcpsById(){return H(this.tcps,t=>t.id)}tcpPoseIn(t,o){const{tcp_pose:n,tcp:i,coordinate_system:r}=this.jogger.motionStream.readoutState,a=this.tcpsById[i||this.selectedTcpId],c=this.tcpsById[t];if(!(!(n!=null&&n.position)||!n.orientation)&&!(!a||!c))try{return K({pose:Nt(n,a,c),coordinateSystemId:r||"world"},o,this.coordSystems).pose}catch{return}}get activeDiscreteIncrement(){return st.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 i=await this.waitForTcpConfirmation(t,1e3);n&&await this.jogger.setJoggingMode("off"),i||(i=await this.waitForTcpConfirmation(t,2e3)),y.runInAction(()=>{i?this.selectedTcpId=t:(this.jogger.tcp=o,this.selectedTcpId=this.jogger.motionStream.rapidlyChangingMotionState.tcp??"")})}catch(i){throw n&&await this.jogger.setJoggingMode("off").catch(()=>{}),y.runInAction(()=>{this.jogger.tcp=o,this.selectedTcpId=this.jogger.motionStream.rapidlyChangingMotionState.tcp??""}),i}finally{y.runInAction(()=>{this.tcpChangeInProgress=!1})}}waitForTcpConfirmation(t,o){return new Promise(n=>{const i=setTimeout(()=>{r(),n(!1)},o),r=y.when(()=>this.jogger.motionStream.rapidlyChangingMotionState.tcp===t,()=>{clearTimeout(i),n(!0)})})}setSelectedOrientation(t){this.selectedOrientation=t}setMoveRelativeToSelectedTcp(){this.selectedOrientation="tool"}setMoveRelativeToCoordSystem(t){this.selectedOrientation="coordsys",this.jogCoordSystemId=t}setSelectedIncrementId(t){this.selectedIncrementId=t}setCurrentIncrementJog(t){this.incrementJogInProgress=t}setLastJogError(t){this.lastJogError=t}setVelocityFromSlider(t,o){!Number.isFinite(t)||t<this.minVelocityInDisplayUnits(o)||t>this.maxVelocityInDisplayUnits(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=le();this.lock(o);try{return await t()}finally{this.unlock(o)}}}const Ye=E.observer(({store:e,useDegree:t})=>{var a;const{t:o}=P.useTranslation(),n=C.useId(),i=[];function r(c){switch(c){case"coordsys":return o("Jogging.Orientation.coordsys");case"tool":return o("Jogging.Orientation.tool");default:return c}}return e.showCoordSystemSelect&&i.push(s.jsx(Z,{labelId:`jogging-coord-select-${n}`,labelValue:o("Jogging.CoordinateSystem.hlb"),value:e.selectedCoordSystemId,size:"small",variant:"filled",displayEmpty:!0,onChange:c=>e.setSelectedCoordSystemId(c.target.value),children:e.coordSystems.map(c=>s.jsx(F,{value:c.coordinate_system,children:c.name&&e.coordSystemCountByName[c.name]>1?`${c.name} / ${c.coordinate_system}`:c.name||c.coordinate_system},c.coordinate_system))},"coord")),e.showTcpSelect&&i.push(s.jsx(Z,{labelId:`jogging-tcp-select-${n}`,labelValue:"TCP",value:e.selectedTcpId,size:"small",variant:"filled",displayEmpty:e.tcpChangeInProgress,onChange:c=>{e.requestTcpChange(c.target.value).catch(d=>{console.error("Failed to change TCP:",d)})},disabled:e.tcpChangeInProgress,endAdornment:e.tcpChangeInProgress?s.jsx(re,{position:"end",children:s.jsx(_t,{size:16})}):void 0,children:e.tcps.map(c=>s.jsx(F,{value:c.id,children:c.id},c.id))},"tcp")),e.showOrientationSelect&&i.push(s.jsx(Z,{labelValue:o("Jogging.Cartesian.Orientation.lb"),labelId:`orientation-select-${n}`,value:e.selectedOrientation,onChange:c=>e.setSelectedOrientation(c.target.value),children:He.map(c=>s.jsx(F,{value:c,children:r(c)},c))},"orientation")),e.showIncrementSelect&&i.push(s.jsxs(Z,{labelValue:o("Jogging.Increment.hlb"),labelId:`jogging-increment-select-${n}`,size:"small",variant:"filled",value:((a=e.activeDiscreteIncrement)==null?void 0:a.id)||"continuous",onChange:c=>e.setSelectedIncrementId(c.target.value),children:[s.jsx(F,{value:"continuous",children:o("Jogging.Increment.Continuous.dd")},"continuous"),e.discreteIncrementOptions.map(c=>s.jsx(F,{value:c.id,children:t?`${c.degrees}°`:`${c.mm}mm`},c.id))]},"increment")),s.jsx(D,{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:i.map((c,d)=>s.jsx(D,{sx:{gridColumn:i.length%2===1&&d===i.length-1?"span 2":"auto"},children:c},d))})}),Qe=N.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=Q.externalizeComponent(E.observer(e=>{const{store:t}=e,{t:o}=P.useTranslation();function n(i,r){r===e.velocity||!ge(r)||e.onVelocityChange(r,e.useDegree)}return s.jsxs(v,{direction:"row",gap:2,alignItems:"center","data-testid":"velocity-slider","aria-label":"velocity-slider",children:[t.showVelocityLegend&&s.jsx(w,{sx:{color:B.velocitySliderLegendColor,fontSize:"14px"},children:o("Jogging.Velocity.bt")}),s.jsx(Mt,{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):s.jsx(ht,{value:e.velocity.toString()}))]})}));function ht({value:e,sx:t}){var n;const o=N.useTheme();return s.jsx(v,{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:s.jsx(w,{component:"span",sx:{textAlign:"right",fontSize:"14px",opacity:.8,color:o.palette.text.primary,whiteSpace:"nowrap"},children:e})})}const qt=E.observer(({store:e,useDegree:t})=>{const{t:o}=P.useTranslation();function n(i,r){return r?`ω = ${o("Jogging.Cartesian.Rotation.velocityDegPerSec.lb",{amount:i})}`:`v = ${o("Jogging.Cartesian.Translation.velocityMmPerSec.lb",{amount:i})}`}return s.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:i=>s.jsx(ht,{value:n(i,t),sx:{minWidth:"111px",span:{transform:"translateY(-1.5px)"}}})})}),Bt=E.observer(({store:e})=>{var a,c,d;const{t}=P.useTranslation(),o=N.useTheme(),n=((d=(c=(a=e.jogger.motionStream.rapidlyChangingMotionState.execute)==null?void 0:a.details)==null?void 0:c.state)==null?void 0:d.kind)??"KIND_UNKNOWN",i=e.lastJogError,r=e.lastJogErrorTranslationKey;return s.jsxs(D,{sx:{display:"flex",flexDirection:"row",justifyContent:"space-between",color:o.palette.text.primary},children:[s.jsx(w,{variant:"body2",sx:{fontSize:"0.75rem",lineHeight:1.2},children:t("Jogging.StreamStateSection.lb")}),s.jsx(w,{variant:"body2",color:i?"error":void 0,sx:{fontSize:"0.75rem",lineHeight:1.2,textAlign:"right"},"data-testid":i?"JOG_ERROR":n,children:i?r?t(r):i:t(`Jogging.StreamStateSection.${n}.lb`)})]})}),Ze=E.observer(({store:e,children:t})=>{const{t:o}=P.useTranslation(),n=N.useTheme(),i=C.useRef(0);function r(g,l){(l==="translate"||l==="rotate")&&e.setSelectedCartesianMotionType(l)}async function a(g,l){const f=await e.activate(),p=f.motionStream.rapidlyChangingMotionState.tcp_pose,j=f.motionStream.rapidlyChangingMotionState.joint_position;p&&await e.withMotionLock(async()=>{try{e.setCurrentIncrementJog({axis:g.axis,direction:g.direction}),await e.jogger.runIncrementalCartesianMotion({currentTcpPose:p,currentJoints:j,coordSystemId:e.activeCoordSystemId,velocityInRelevantUnits:e.selectedCartesianMotionType==="translate"?e.translationVelocityMmPerSec:e.rotationVelocityRadsPerSec,axis:g.axis,direction:g.direction,motion:e.selectedCartesianMotionType==="translate"?{type:"translate",distanceMm:l.mm}:{type:"rotate",distanceRads:_.degreesToRadians(l.degrees)}})}finally{e.setCurrentIncrementJog(null),await e.deactivate()}})}async function c(g){if(e.isLocked)return;const l=++i.current;try{if(await e.activate(),l!==i.current)return;if(e.activeDiscreteIncrement)return await a(g,e.activeDiscreteIncrement);g.motionType==="translate"?await e.jogger.translateTCP({axis:g.axis,direction:g.direction,velocityMmPerSec:e.translationVelocityMmPerSec}):await e.jogger.rotateTCP({axis:g.axis,direction:g.direction,velocityRadsPerSec:e.rotationVelocityRadsPerSec})}catch(f){console.error("Jogging failed:",f)}}async function d(){e.isLocked||e.activeDiscreteIncrement||(i.current++,await e.deactivate())}const h=[{id:"x",icon:s.jsx(Je,{}),colors:B.cartesianAxisColors.X},{id:"y",icon:s.jsx(Ae,{}),colors:B.cartesianAxisColors.Y},{id:"z",icon:s.jsx(Le,{}),colors:B.cartesianAxisColors.Z}];function u(g){return o("General.mm.variable",{amount:g.toFixed(1)})}function m(g){return o("General.degree.variable",{amount:_.radiansToDegrees(g).toFixed(1)})}return s.jsxs(v,{"data-testid":"jogging-cartesian-tab","aria-label":"jogging-cartesian-tab",flexGrow:1,gap:2,sx:{padding:"18px 24px"},children:[s.jsxs(v,{gap:2,children:[s.jsx(Ye,{store:e,useDegree:e.selectedCartesianMotionType==="rotate"}),s.jsx(qt,{store:e,useDegree:e.selectedCartesianMotionType==="rotate"}),s.jsx(q,{})]}),s.jsx(v,{marginLeft:"auto",marginRight:"auto",gap:"24px",justifyContent:"center",sx:{flexGrow:"1"},children:s.jsxs(v,{alignItems:"center",justifyContent:"center",gap:"24px",sx:{flexGrow:1},children:[s.jsxs(Qe,{value:e.selectedCartesianMotionType,onChange:r,exclusive:!0,"aria-label":o("Jogging.Cartesian.MotionType.lb"),sx:{justifyContent:"center"},children:[s.jsx(pt,{value:"translate",children:o("Jogging.Cartesian.Translation.bt")}),s.jsx(pt,{value:"rotate",children:o("Jogging.Cartesian.Rotation.bt")})]}),e.selectedCartesianMotionType==="translate"&&h.map(g=>{var l,f;return s.jsx(it,{"data-testid":`jogging-cartesian-axis-control-${g.id}`,"aria-label":`jogging-cartesian-axis-control-${g.id}`,colors:g.colors,disabled:e.isLocked,activeJoggingDirection:((l=e.incrementJogInProgress)==null?void 0:l.axis)===g.id?e.incrementJogInProgress.direction:void 0,label:s.jsxs(s.Fragment,{children:[g.icon,s.jsx(w,{sx:{fontSize:"24px",color:((f=g.colors)==null?void 0:f.labelColor)??n.palette.text.primary},children:g.id.toUpperCase()})]}),getDisplayedValue:()=>{var p,j;return u(((j=(p=e.jogger.motionStream.rapidlyChangingMotionState.tcp_pose)==null?void 0:p.position)==null?void 0:j[_.XYZ_TO_VECTOR[g.id]])||0)},startJogging:p=>c({axis:g.id,motionType:"translate",direction:p}),stopJogging:d},g.id)}),e.selectedCartesianMotionType==="rotate"&&h.map(g=>{var l,f;return s.jsx(it,{"data-testid":`jogging-cartesian-axis-control-${g.id}`,"aria-label":`jogging-cartesian-axis-control-${g.id}`,colors:g.colors,disabled:e.isLocked,activeJoggingDirection:((l=e.incrementJogInProgress)==null?void 0:l.axis)===g.id?e.incrementJogInProgress.direction:void 0,label:s.jsxs(s.Fragment,{children:[s.jsx(De,{}),s.jsx(w,{sx:{fontSize:"24px",color:((f=g.colors)==null?void 0:f.labelColor)??n.palette.text.primary},children:g.id.toUpperCase()})]}),getDisplayedValue:()=>{var p,j;return m(((j=(p=e.jogger.motionStream.rapidlyChangingMotionState.tcp_pose)==null?void 0:p.orientation)==null?void 0:j[_.XYZ_TO_VECTOR[g.id]])||0)},startJogging:p=>c({axis:g.id,motionType:"rotate",direction:p}),stopJogging:d},g.id)})]})}),s.jsx(Pt,{store:e}),s.jsx(q,{}),s.jsx(Bt,{store:e}),t&&s.jsx(q,{}),t]})}),Xe=E.observer(({store:e,children:t})=>{const o=N.useTheme(),n=C.useRef(0);async function i(a){const c=++n.current;try{if(await e.activate(),c!==n.current)return;await e.jogger.rotateJoints({joint:a.joint,direction:a.direction,velocityUnit:e.jointType===V.JointTypeEnum.PrismaticJoint?"mm/s":"rad/s",velocityValue:e.jointType===V.JointTypeEnum.PrismaticJoint?e.translationVelocityMmPerSec:e.rotationVelocityRadsPerSec})}catch(d){console.error("Jogging failed:",d)}}async function r(){n.current++,await e.jogger.stop(),await e.deactivate()}return s.jsxs(v,{"data-testid":"jogging-joint-tab","aria-label":"jogging-joint-tab",flexGrow:1,gap:2,sx:{padding:"18px 24px"},children:[s.jsx(qt,{store:e,useDegree:e.jointType===V.JointTypeEnum.RevoluteJoint}),s.jsx(q,{}),s.jsx(v,{justifyContent:"center",alignItems:"stretch",sx:{flexGrow:"1"},children:s.jsx(v,{"data-testid":"jogging-joint-value-controls-wrapper","aria-label":"jogging-joint-value-controls-wrapper",alignItems:"center",gap:"24px",children:e.jogger.motionStream.joints.map(a=>{var d,h,u;const c=(u=(h=(d=e.motionGroupDescription.operation_limits.auto_limits)==null?void 0:d.joints)==null?void 0:h[a.index])==null?void 0:u.position;return s.jsxs(v,{"data-testid":`jogging-joint-value-control-${a.index}`,"aria-label":`jogging-joint-value-control-${a.index}`,direction:"row",alignItems:"center",justifyContent:"center",spacing:1.5,width:"100%",children:[e.showJointsLegend&&s.jsx(w,{color:e.isLocked?o.palette.text.disabled:o.palette.text.secondary,children:`G${a.index+1}`}),s.jsx(kt,{disabled:e.isLocked,lowerLimit:c==null?void 0:c.lower_limit,upperLimit:c==null?void 0:c.upper_limit,useDegree:e.jointType===V.JointTypeEnum.RevoluteJoint,getValue:()=>{const m=e.jogger.motionStream.rapidlyChangingMotionState.joint_position[a.index];return m!==void 0?m:void 0},startJogging:m=>i({joint:a.index,direction:m}),stopJogging:r})]},`joint-${a.index}`)})})}),s.jsx(Pt,{store:e}),s.jsx(q,{}),s.jsx(Bt,{store:e}),t&&s.jsx(q,{}),t]})}),to=Q.externalizeComponent(E.observer(e=>{const t=E.useLocalObservable(()=>({joggingStore:null,loadingError:null}));return C.useEffect(()=>{let o=!1,n;async function i(){y.runInAction(()=>{t.loadingError=null,t.joggingStore=null});try{let r=e.store;if(!r){const a=await ot.open(e.nova,e.motionGroupId,{cellId:e.cellId});if(o){a.dispose();return}try{r=await Y.loadFor(a)}catch(c){throw a.dispose(),c}if(n=r,o){r.dispose();return}}y.runInAction(()=>{t.joggingStore=r}),e.onSetup&&e.onSetup(r)}catch(r){if(o)return;y.runInAction(()=>{t.loadingError=r})}}return i(),()=>{o=!0,n==null||n.dispose()}},[e.store,e.nova,e.motionGroupId,e.cellId]),C.useEffect(()=>{const o=t.joggingStore;o&&(e.locked?o.lock("external"):o.unlock("external"))},[t.joggingStore,e.locked]),s.jsx(v,{"data-testid":"jogging-panel","aria-label":"jogging-panel",sx:{maxWidth:"460px",minWidth:"320px",position:"relative",...e.sx},children:t.joggingStore?s.jsx(eo,{store:t.joggingStore,children:e.children}):s.jsx(Rt,{message:"Loading jogging",error:t.loadingError})})})),eo=E.observer(({store:e,children:t})=>{const{t:o}=P.useTranslation();function n(){if(e.currentTab.id==="cartesian")return s.jsx(Ze,{store:e,children:t});if(e.currentTab.id==="joint")return s.jsx(Xe,{store:e,children:t})}return s.jsxs(v,{flexGrow:1,sx:{overflow:"hidden"},children:[s.jsx(te,{"data-testid":"jogging-tabs","aria-label":"jogging-tabs",value:e.tabIndex,onChange:e.onTabChange,variant:"fullWidth",children:e.tabs.map(i=>{const r=i.label==="Cartesian"?o("Jogging.Cartesian.bt"):o("Jogging.Joints.bt"),a=i.label==="cartesian"?s.jsx(Qt,{fontSize:"small",sx:{mr:1}}):s.jsx(Zt,{fontSize:"small",sx:{mr:1}});return s.jsx(Xt,{"data-testid":`jogging-tab-${i.id}`,"aria-label":`jogging-tab-${i.id}`,label:e.showTabIcons?s.jsxs(v,{direction:"row",alignItems:"center",children:[a,r]}):r,id:`jogging-tab-${i.id}`,"aria-controls":`jogging-tab-${i.id}`},i.id)})}),s.jsx(v,{flexGrow:1,position:"relative",sx:{overflowY:"auto",overflowX:"hidden"},children:n()}),e.blocked&&s.jsx(ke,{store:e})]})});function oo(){const e=window.location.href;return e.substring(0,e.indexOf("/",e.indexOf("//")+2))}function no({baseUrl:e=oo(),...t}){return s.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:[s.jsx(Se,{id:"no-motion-group-modal-title",children:"No motion group found"}),s.jsxs(ye,{sx:{marginTop:"3rem",marginBottom:"1.5rem",textAlign:"center"},children:[s.jsx(w,{color:"#fff",children:"Found no devices to connect to."}),s.jsx(w,{color:"#fff",children:"Please ensure a motion group has been created."})]}),s.jsx(fe,{children:s.jsxs(v,{width:"100%",maxWidth:"300px",margin:"auto",marginBottom:"2rem",children:[s.jsx(nt,{href:`${e}/settings`,variant:"contained",sx:{borderRadius:"8px",width:"100%"},children:"Go to settings app"}),s.jsx(nt,{href:`${e}`,variant:"text",sx:{marginTop:"1rem",color:"#fff",textDecoration:"underline",fontSize:"0.75rem"},children:"Back to Homescreen"})]})})]})}const vt=1e-4,io={a:0,d:0,alpha:0,theta:0,reverse_rotation_direction:!1};class tt{constructor(t,o,n,i,r,a,c,d,h,u,m="cell"){this.controller=o,this.motionGroup=n,this.initialMotionState=i,this.motionStateSocket=r,this.isVirtual=a,this.tcps=c,this.description=d,this.initialControllerState=h,this.controllerStateSocket=u,this.cellId=m,this.connectedJoggingSocket=null,this.joggingVelocity=10,this.activationState="inactive",this.nova=x.createNovaClient(t),this.rapidlyChangingMotionState=i,this.controllerState=h,u.addEventListener("message",g=>{var f;const l=(f=_.tryParseJson(g.data))==null?void 0:f.result;l&&y.runInAction(()=>{this.controllerState=l})}),r.addEventListener("message",g=>{var f;const l=(f=_.tryParseJson(g.data))==null?void 0:f.result;if(!l)throw new Error(`Failed to get motion state for ${this.motionGroupId}: ${g.data}`);ct(this.rapidlyChangingMotionState.joint_position,l.joint_position,vt)||y.runInAction(()=>{this.rapidlyChangingMotionState.joint_position=l.joint_position}),lt(this.rapidlyChangingMotionState,l,vt)||y.runInAction(()=>{this.rapidlyChangingMotionState.tcp_pose=l.tcp_pose}),l.tcp!==void 0&&this.rapidlyChangingMotionState.tcp!==l.tcp&&y.runInAction(()=>{this.rapidlyChangingMotionState.tcp=l.tcp}),this.rapidlyChangingMotionState.standstill!==l.standstill&&y.runInAction(()=>{this.rapidlyChangingMotionState.standstill=l.standstill})}),y.makeAutoObservable(this)}static async connectMultiple(t,o,n={}){const i=x.createNovaClient(t),r=n.cellId??x.cellIdOf(t);return Promise.all(o.map(a=>tt.connect(i,a,{...n,cellId:r})))}static async connect(t,o,n={}){var O,J;const i=x.createNovaClient(t),r=n.cellId??x.cellIdOf(t)??"cell",[a,c]=o.split("@"),d=await i.api.controller.getCurrentRobotControllerState(r,c),h=d==null?void 0:d.motion_groups.find(I=>I.motion_group===o);if(!d||!h)throw new Error(`Controller ${c} or motion group ${o} not found`);const u=i.openReconnectingWebsocket(`/cells/${r}/controllers/${c}/motion-groups/${o}/state-stream`),m=await u.firstMessage(),g=(O=_.tryParseJson(m.data))==null?void 0:O.result;if(!g)throw new Error(`Unable to parse initial motion state message ${m.data}`);console.log(`Connected motion state websocket to motion group ${h.motion_group}. Initial state:
|
|
2
|
-
`,g);const f=(await i.api.controller.getRobotController(r,d.controller)).configuration.kind==="VirtualController",p=await i.api.motionGroup.getMotionGroupDescription(r,c,h.motion_group),j=Object.entries(p.tcps||{}).map(([I,R])=>({id:I,readable_name:R.name,position:R.pose.position,orientation:R.pose.orientation})),T=i.openReconnectingWebsocket(`/cells/${r}/controllers/${d.controller}/state-stream?response_rate=1000`),M=await T.firstMessage(),k=(J=_.tryParseJson(M.data))==null?void 0:J.result;if(!k)throw new Error(`Unable to parse initial controller state message ${M.data}`);return console.log(`Connected controller state websocket to controller ${d.controller}. Initial state:
|
|
3
|
-
`,k),new tt(i,d,h,g,u,f,j,p,k,T,r)}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=>({...io,...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 i,r,a,c,d,h;const t=new ft.Vector3(((r=(i=this.description.mounting)==null?void 0:i.orientation)==null?void 0:r[0])||0,((c=(a=this.description.mounting)==null?void 0:a.orientation)==null?void 0:c[1])||0,((h=(d=this.description.mounting)==null?void 0:d.orientation)==null?void 0:h[2])||0),o=t.length(),n=t.normalize();return new ft.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}y.runInAction(()=>{this.activationState="deactivating"});try{await this.nova.api.controller.setDefaultMode(this.cellId,this.controllerId,"ROBOT_SYSTEM_MODE_MONITOR"),y.runInAction(()=>{this.activationState="inactive"})}catch(t){throw y.runInAction(()=>{this.activationState="active"}),t}}async activate(){if(this.activationState!=="inactive"){console.error("Tried to activate while already activating");return}y.runInAction(()=>{this.activationState="activating"});try{await this.nova.api.controller.setDefaultMode(this.cellId,this.controllerId,"ROBOT_SYSTEM_MODE_CONTROL"),y.runInAction(()=>{this.activationState="active"})}catch(t){throw y.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}}const zt=1e-4,ro=new Set(["timestamp","sequence_number","joint_position","joint_torque","joint_current","flange_pose","tcp_pose","flange_velocity","tcp_velocity"]),so=1,Ct=e=>Array.isArray(e)&&e.length===3&&e.every(t=>typeof t=="number");class ao{constructor(t,o,n,i={}){this.source=t,this.motionGroupId=o,this.lastMessageReceivedAt=Date.now(),this.lastInvalidStateMessage=null,this.connectionQuality="good";const r=n.motion_groups.find(a=>a.motion_group===o);if(!r)throw new Error(`Motion group ${o} not found in initial controller state`);this.isVirtual=i.isVirtual??!1,this.onError=i.onError,this.reconnectsOnFocus=(i.reconnectOnFocus??!0)&&typeof window<"u",this.rapidlyChangingMotionState=r,this.lastValidStateMessage={receivedAt:Date.now(),data:n},y.makeAutoObservable(this,{source:!1,lastMessageReceivedAt:!1,connectionQualityInterval:!1,isVirtual:!1,onError:!1,reconnectsOnFocus:!1,readoutState:y.computed({equals:ut,keepAlive:!0})},{autoBind:!0}),this.source.addEventListener("message",this.handleMessage),this.connectionQualityInterval=setInterval(this.updateConnectionQuality,500),this.reconnectsOnFocus&&window.addEventListener("focus",this.handleWindowFocus)}get controllerState(){return this.lastValidStateMessage.data}get readoutState(){return gt(this.rapidlyChangingMotionState)}async nextMotionState(){var n,i;const t=await this.source.nextMessage(),o=(i=(n=this.source.parse(t.data))==null?void 0:n.motion_groups)==null?void 0:i.find(r=>r.motion_group===this.motionGroupId);if(!o)throw new Error(`Failed to get motion state for ${this.motionGroupId}: ${t.data}`);return o}setLastInvalidStateMessage(t){this.lastInvalidStateMessage={receivedAt:Date.now(),data:t}}setLastValidStateMessage(t){this.lastValidStateMessage={receivedAt:Date.now(),data:t}}updateRapidlyChangingMotionState(t,o){const n=this.rapidlyChangingMotionState,i=t;for(const r of Object.keys(i))o!=null&&o.has(r)||Et(n[r],i[r])||(n[r]=i[r]);for(const r of Object.keys(n))o!=null&&o.has(r)||r in i||delete n[r]}setConnectionQuality(t){this.connectionQuality=t}handleWindowFocus(){this.source.reconnect()}updateConnectionQuality(){const t=Date.now()-this.lastMessageReceivedAt,o=this.isVirtual?3e3:1e3,n=this.isVirtual?6e3:3e3;if(t>n){this.source.readyState===so&&this.source.reconnect(),this.setConnectionQuality("critical");return}if(t>o){this.setConnectionQuality("struggling");return}this.setConnectionQuality("good")}dispose(){this.source.removeEventListener("message",this.handleMessage),clearInterval(this.connectionQualityInterval),this.reconnectsOnFocus&&window.removeEventListener("focus",this.handleWindowFocus)}handleMessage(t){var h,u;const o=this.source.parse(t.data);if(!(o!=null&&o.motion_groups)){(h=this.onError)==null||h.call(this,{message:_.makeErrorMessage(t.data),url:this.source.url}),this.setLastInvalidStateMessage(t.data);return}this.lastMessageReceivedAt=Date.now();const n=this.lastValidStateMessage.data;(n.safety_state!==o.safety_state||n.operation_mode!==o.operation_mode||n.mode!==o.mode)&&this.setLastValidStateMessage(o);const i=o.motion_groups.find(m=>m.motion_group===this.motionGroupId);if(!i){(u=this.onError)==null||u.call(this,{message:`Motion group ${this.motionGroupId} not found in controller state: ${JSON.stringify(t.data)}`,url:this.source.url}),this.setLastInvalidStateMessage(t.data);return}const r=!at(this.rapidlyChangingMotionState.joint_position,i.joint_position,zt),a=this.rapidlyChangingMotionState.tcp!==i.tcp;if(!r&&!a){this.updateRapidlyChangingMotionState(i,ro);return}const c=this.rapidlyChangingMotionState.flange_pose,d=i.flange_pose;if((d==null?void 0:d.orientation)==null||!Ct(d.orientation)){const m=d==null?void 0:d.orientation;throw new Error(`Invalid newFlangePose.orientation: expected [number, number, number] (got ${m==null?"null":m.length})`)}if((c==null?void 0:c.orientation)==null||!Ct(c.orientation)){const m=c==null?void 0:c.orientation;throw new Error(`Invalid oldFlangePose.orientation: expected [number, number, number] (got ${m==null?"null":m.length})`)}d.orientation=dt(d.orientation,c.orientation),this.updateRapidlyChangingMotionState(i)}}function co(e){return{get url(){return e.url},get readyState(){return e.readyState},addEventListener:(t,o)=>e.addEventListener(t,o),removeEventListener:(t,o)=>e.removeEventListener(t,o),nextMessage:()=>e.nextMessage(),reconnect:()=>e.reconnect(),close:()=>e.close(),parse:t=>{var o;return(o=xe.tryParseJson(t))==null?void 0:o.result}}}function lo(e,{controllerId:t,cellId:o,responseRateMs:n}){const i=x.createNovaClient(e),r=o??x.cellIdOf(e)??"cell",a=n===void 0?"":`?response_rate=${n}`;return co(i.openReconnectingWebsocket(`/cells/${r}/controllers/${t}/state-stream${a}`))}const go=["FeedbackOutOfWorkspace","FeedbackJointLimitExceeded","FeedbackAxisRangeExceeded","FeedbackNoSolutionInCurrentConfiguration"];function uo(e){return e==="FeedbackSingularity"?"Jogging.TargetPose.Error.Singularity.lb":e==="FeedbackCollision"?"Jogging.TargetPose.Error.Collision.lb":go.includes(e)?"Jogging.TargetPose.Error.NotReachable.lb":"Jogging.TargetPose.Error.PlanningFailed.lb"}class ho{constructor(t){this.options=t,this.plannedTrajectory=null,this.trajectoryState="idle",this.lastError=null,this.disposers=[],this.logger=t.logger??console,y.makeAutoObservable(this,{socket:!1,disposers:!1,logger:!1,options:!1},{autoBind:!0}),this.socket=this.openSocket(),this.disposers.push(y.reaction(()=>this.executionState,o=>{o==="END_OF_TRAJECTORY"&&this.reset()}))}get joggingStore(){return this.options.joggingStore}get jogger(){return this.options.joggingStore.jogger}get motionStream(){return this.options.joggingStore.jogger.motionStream}get executionState(){var t,o;return(o=(t=this.motionStream.rapidlyChangingMotionState.execute)==null?void 0:t.details)==null?void 0:o.state.kind}async planTrajectory(t){var T,M,k,O,J;if((M=(T=this.options).isLocked)!=null&&M.call(T))throw this.reset(),new Error("Cannot plan trajectory: the robot is locked");await this.ensureMovementOwnership();const o=this.motionStream.rapidlyChangingMotionState.joint_position??[],{cycle_time:n,mounting:i,motion_group_model:r,tcps:a}=this.motionStream.description,c=this.joggingStore.selectedTcpId,d=c?(k=a==null?void 0:a[c])==null?void 0:k.pose:void 0,h={motion_group_model:((O=this.jogger.options)==null?void 0:O.motionGroupModel)??r,cycle_time:n??0,mounting:i,...d&&{tcp_offset:d}};let u;if(t.type==="cartesian"){let I=t.pose;const R=t.coordinateSystemId||"world";if(R!=="world")try{I=K({pose:{position:I.position??[0,0,0],orientation:I.orientation??[0,0,0]},coordinateSystemId:R},"world",this.joggingStore.coordSystems).pose}catch{return this.reset(),{ok:!1,errorFeedbackName:"FeedbackUnknown"}}u={limits_override:{tcp_velocity_limit:this.joggingStore.translationVelocityMmPerSec},path:{target_pose:I,path_definition_name:"PathCartesianPTP"}}}else u={limits_override:{joint_velocity_limits:Array(o.length).fill(this.joggingStore.rotationVelocityRadsPerSec)},path:{target_joint_position:t.joints,path_definition_name:"PathJointPTP"}};y.runInAction(()=>{this.lastError=null,this.trajectoryState="planning"});let m;try{m=await this.jogger.nova.api.trajectoryPlanning.planTrajectory(this.jogger.cellId,{motion_group_setup:h,start_joint_position:o,motion_commands:[u]})}catch(I){throw this.reset(),I}const g=m.response;if("error_feedback"in g){const I=((J=g.error_feedback)==null?void 0:J.error_feedback_name)??"FeedbackUnknown";return this.reset(),{ok:!1,errorFeedbackName:I}}const l=g.joint_positions,f=l[0],p=l[l.length-1];if(!f||!p)throw this.reset(),new Error("Trajectory returned invalid joint positions");const j={message_type:"InitializeMovementRequest",trajectory:{message_type:"TrajectoryData",motion_group:this.jogger.motionGroupId,tcp:c||void 0,data:g}};return this.socket.sendJson(j),y.runInAction(()=>{this.plannedTrajectory={startJoints:f,endJoints:p}}),{ok:!0}}start(){if(!this.plannedTrajectory)throw new Error("Cannot start trajectory: no planned trajectory exists");if(this.trajectoryState!=="planned")throw new Error(`Cannot start trajectory: expected state "planned", got "${this.trajectoryState}"`);if(this.executionState==="RUNNING")throw new Error("Cannot start trajectory: robot is already running");const t={message_type:"StartMovementRequest",direction:"DIRECTION_FORWARD"};this.socket.sendJson(t)}async pause(){if(this.trajectoryState!=="moving")throw new Error(`Cannot pause trajectory: expected state "moving", got "${this.trajectoryState}"`);if(this.executionState==="PAUSED_BY_USER")throw new Error("Cannot pause trajectory: robot is already paused");const t={message_type:"PauseMovementRequest"};this.socket.sendJson(t),await this.waitUntilStopped(),y.runInAction(()=>{this.trajectoryState=this.plannedTrajectory?"planned":"idle"})}async stopAndReset(){try{if(this.executionState==="RUNNING"||this.trajectoryState==="moving"){const t={message_type:"PauseMovementRequest"};this.socket.sendJson(t),await this.waitUntilStopped()}}catch(t){this.logger.warn("Failed to stop trajectory execution cleanly",t)}finally{this.reset(),this.closeSocket(),this.socket=this.openSocket()}}reset(){this.plannedTrajectory=null,this.trajectoryState="idle"}clearError(){this.lastError=null}dispose(){for(const t of this.disposers)t();this.closeSocket()}async ensureMovementOwnership(){if(this.options.ensureMovementOwnership){await this.options.ensureMovementOwnership();return}this.jogger.mode!=="trajectory"&&(await this.joggingStore.deactivate(),await this.jogger.setJoggingMode("trajectory"))}async waitUntilStopped(){await y.when(()=>this.motionStream.rapidlyChangingMotionState.standstill)}handleMessage(t){var n,i;const o=(n=_.tryParseJson(t.data))==null?void 0:n.result;if(o)switch(o.kind){case"INITIALIZE_RECEIVED":o.add_trajectory_error||o.message?(this.lastError=((i=o.add_trajectory_error)==null?void 0:i.message)??o.message??"NOVA refused the trajectory",this.reset()):this.trajectoryState="planned";break;case"START_RECEIVED":this.trajectoryState="moving";break;case"PAUSE_RECEIVED":this.trajectoryState==="moving"&&(this.trajectoryState="stopping");break;case"MOTION_ERROR":this.lastError=o.message,this.reset();break}}openSocket(){const t=this.jogger.nova.openReconnectingWebsocket(`/cells/${this.jogger.cellId}/controllers/${this.motionStream.controllerId}/execution/trajectory`);return t.addEventListener("message",this.handleMessage),t}closeSocket(){this.socket.removeEventListener("message",this.handleMessage),this.socket.dispose()}}exports.AppHeader=je;exports.ConnectedMotionGroup=tt;exports.ControllerStateStream=ao;exports.JoggerConnection=ot;exports.JoggingCartesianAxisControl=it;exports.JoggingJointValueControl=kt;exports.JoggingPanel=to;exports.JoggingStore=Y;exports.LoadingCover=Rt;exports.LoadingErrorMessage=At;exports.MOTION_DELTA_THRESHOLD=zt;exports.MotionStreamConnection=et;exports.NoMotionGroupModal=no;exports.TrajectoryExecutionStore=ho;exports.VelocitySlider=Ft;exports.VelocitySliderLabel=ht;exports.controllerStateWebsocket=lo;exports.deriveSelectedTcpPose=Fe;exports.jointValuesEqual=at;exports.jointValuesUnchanged=ct;exports.planErrorTranslationKey=uo;exports.poseEqual=Jt;exports.readoutOf=gt;exports.readoutsEqual=ut;exports.resolveCoordinateSystemInWorld=Dt;exports.tcpMotionEqual=lt;exports.transformPoseToCoordinateSystem=K;exports.unwrapRotationVector=dt;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";const d=require("three");function y(n){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(n){for(const t in n)if(t!=="default"){const o=Object.getOwnPropertyDescriptor(n,t);Object.defineProperty(e,t,o.get?o:{enumerable:!0,get:()=>n[t]})}}return e.default=n,Object.freeze(e)}const r=y(d);function g(n){try{return JSON.parse(n)}catch{return}}function b(n){try{return JSON.stringify(n)}catch{return}}function h(n){const e=n.length(),t=new r.Quaternion;if(e>1e-6){const o=n.clone().normalize();t.setFromAxisAngle(o,e)}return t}function p(n){if(!n||n.length===0)return 5;const o=n.reduce((s,c)=>s+Math.abs(c.a??0)/1e3+Math.abs(c.d??0)/1e3,0)*2;return!Number.isFinite(o)||o<=0?5:o}function z(n){if(n.length<3)return console.log("Not enough vertices to define a plane"),{isCoplanar:!1};const e=new r.Vector3(n[0].x,n[0].y,n[0].z),t=new r.Vector3(n[1].x,n[1].y,n[1].z),o=new r.Vector3(n[2].x,n[2].y,n[2].z),s=new r.Vector3().subVectors(t,e),c=new r.Vector3().subVectors(o,e),i=new r.Vector3().crossVectors(s,c).normalize();for(let a=3;a<n.length;a++){const u=new r.Vector3(n[a].x,n[a].y,n[a].z),l=new r.Vector3().subVectors(u,e),f=i.dot(l);if(Math.abs(f)>1e-6)return console.log("Vertices are not on the same plane"),{isCoplanar:!1}}return{isCoplanar:!0,normal:i}}exports.dhParametersToPlaneSize=p;exports.orientationToQuaternion=h;exports.tryParseJson=g;exports.tryStringifyJson=b;exports.verticesToCoplanarity=z;
|
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
import type { MotionGroupState, RobotControllerState } from "@wandelbots/nova-js/v2";
|
|
2
|
-
import type { ControllerStateSource } from "./controllerStateSource";
|
|
3
|
-
import { type MotionStateReadout } from "./motionStateUpdate";
|
|
4
|
-
/** Joints that moved less than this (rad, or mm) count as standing still */
|
|
5
|
-
export declare const MOTION_DELTA_THRESHOLD = 0.0001;
|
|
6
|
-
/** A message from the source that the stream could not use */
|
|
7
|
-
export type ControllerStateStreamError = {
|
|
8
|
-
message: string;
|
|
9
|
-
/** The source's URL */
|
|
10
|
-
url?: string;
|
|
11
|
-
};
|
|
12
|
-
/** What an app can give a {@link ControllerStateStream} besides its source */
|
|
13
|
-
export type ControllerStateStreamOptions = {
|
|
14
|
-
/**
|
|
15
|
-
* A virtual robot: its stream can come more slowly, depending on the speed
|
|
16
|
-
* of the simulation, so the stream waits longer before it calls the
|
|
17
|
-
* connection struggling (3 s instead of 1 s) or critical (6 s instead of 3 s)
|
|
18
|
-
*/
|
|
19
|
-
isVirtual?: boolean;
|
|
20
|
-
/** Reports a message that the stream could not use */
|
|
21
|
-
onError?: (error: ControllerStateStreamError) => void;
|
|
22
|
-
/**
|
|
23
|
-
* Reconnect the source when the window gets the focus back, e.g. after the
|
|
24
|
-
* computer slept. Defaults to true where there is a window.
|
|
25
|
-
*/
|
|
26
|
-
reconnectOnFocus?: boolean;
|
|
27
|
-
};
|
|
28
|
-
/**
|
|
29
|
-
* The live state of one motion group and its controller, from a
|
|
30
|
-
* {@link ControllerStateSource}: the safety state, operation mode and mode of
|
|
31
|
-
* the controller, and the motion group's state, updated in place as the
|
|
32
|
-
* messages come. Tells how good the connection is, and reconnects the source
|
|
33
|
-
* when its messages stop.
|
|
34
|
-
*/
|
|
35
|
-
export declare class ControllerStateStream {
|
|
36
|
-
/** Where the controller state comes from; its owner closes it */
|
|
37
|
-
readonly source: ControllerStateSource;
|
|
38
|
-
/** The motion group whose state the stream keeps */
|
|
39
|
-
readonly motionGroupId: string;
|
|
40
|
-
/**
|
|
41
|
-
* The motion group's state as the last message had it. It stays the same
|
|
42
|
-
* object for as long as the stream lives, updated field by field, so that
|
|
43
|
-
* observers of one of its fields keep working. While the robot stands
|
|
44
|
-
* still, the jittering pose readings are not written.
|
|
45
|
-
*/
|
|
46
|
-
rapidlyChangingMotionState: MotionGroupState;
|
|
47
|
-
/**
|
|
48
|
-
* The last message that changed the controller's safety state, operation
|
|
49
|
-
* mode or mode, and when it came
|
|
50
|
-
*/
|
|
51
|
-
lastValidStateMessage: {
|
|
52
|
-
receivedAt: number;
|
|
53
|
-
data: RobotControllerState;
|
|
54
|
-
};
|
|
55
|
-
/** Non-observable timestamp for connection quality tracking only */
|
|
56
|
-
private lastMessageReceivedAt;
|
|
57
|
-
/** The last message that held no state of the motion group, if any */
|
|
58
|
-
lastInvalidStateMessage: {
|
|
59
|
-
receivedAt: number;
|
|
60
|
-
data: unknown;
|
|
61
|
-
} | null;
|
|
62
|
-
/**
|
|
63
|
-
* How the messages come: "struggling" after 1 s without one (3 s for a
|
|
64
|
-
* virtual robot), "critical" after 3 s (6 s), when the source is reconnected
|
|
65
|
-
*/
|
|
66
|
-
connectionQuality: "good" | "struggling" | "critical";
|
|
67
|
-
private readonly connectionQualityInterval;
|
|
68
|
-
private readonly isVirtual;
|
|
69
|
-
private readonly onError?;
|
|
70
|
-
private readonly reconnectsOnFocus;
|
|
71
|
-
constructor(
|
|
72
|
-
/** Where the controller state comes from; its owner closes it */
|
|
73
|
-
source: ControllerStateSource,
|
|
74
|
-
/** The motion group whose state the stream keeps */
|
|
75
|
-
motionGroupId: string, initialControllerState: RobotControllerState, options?: ControllerStateStreamOptions);
|
|
76
|
-
/** The controller's state as of the last message that changed it */
|
|
77
|
-
get controllerState(): RobotControllerState;
|
|
78
|
-
/**
|
|
79
|
-
* What pose and joint readouts show. Holds the previous reading while the
|
|
80
|
-
* joints only jitter, see {@link readoutsEqual}; kept alive so it also holds
|
|
81
|
-
* for untracked reads.
|
|
82
|
-
*/
|
|
83
|
-
get readoutState(): MotionStateReadout;
|
|
84
|
-
/** The motion group's state in the next message of the source */
|
|
85
|
-
nextMotionState(): Promise<MotionGroupState>;
|
|
86
|
-
private setLastInvalidStateMessage;
|
|
87
|
-
private setLastValidStateMessage;
|
|
88
|
-
/**
|
|
89
|
-
* Merge the latest motion state onto the existing object instead of replacing
|
|
90
|
-
* it, so this stream owns exactly one live motion state object for the whole
|
|
91
|
-
* time it is connected.
|
|
92
|
-
*
|
|
93
|
-
* Consumers subscribe to *properties* of the object they are holding — the 3D
|
|
94
|
-
* animators keep it in a ref and read `joint_position` inside a MobX
|
|
95
|
-
* reaction. Replacing the object leaves those reactions subscribed to an
|
|
96
|
-
* orphan that never changes again, so the robot model stopped getting joint
|
|
97
|
-
* targets from the stream and only moved when React happened to re-render it
|
|
98
|
-
* (~5 updates/s against a ~134/s stream).
|
|
99
|
-
*
|
|
100
|
-
* Only fields whose value actually changed are written. A blanket
|
|
101
|
-
* `Object.assign` puts a fresh object into every nested field, and MobX
|
|
102
|
-
* compares with `===`, so each of `flange_pose`, `tcp_pose` and
|
|
103
|
-
* `joint_limit_reached` would notify its observers on every message of a
|
|
104
|
-
* ~134/s stream even while standing still. This mirrors how
|
|
105
|
-
* MotionStreamConnection guards each of its own field writes.
|
|
106
|
-
*
|
|
107
|
-
* Fields the message does not carry are removed rather than left behind: a
|
|
108
|
-
* merge must not make a stale pose read as the current one, which replacing
|
|
109
|
-
* the whole object never did.
|
|
110
|
-
*
|
|
111
|
-
* Runs as a MobX action (see `makeAutoObservable` with `autoBind` above), so
|
|
112
|
-
* the per-field writes notify observers once, as a single batch.
|
|
113
|
-
*
|
|
114
|
-
* `skipFields` leaves the named fields exactly as they are — neither updated
|
|
115
|
-
* nor removed — which is how a standstill message updates the discrete state
|
|
116
|
-
* without churning the jittery pose readings.
|
|
117
|
-
*/
|
|
118
|
-
private updateRapidlyChangingMotionState;
|
|
119
|
-
private setConnectionQuality;
|
|
120
|
-
private handleWindowFocus;
|
|
121
|
-
private updateConnectionQuality;
|
|
122
|
-
/** Stops listening to the source; the source's owner closes it */
|
|
123
|
-
dispose(): void;
|
|
124
|
-
private handleMessage;
|
|
125
|
-
}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import type { RobotControllerState } from "@wandelbots/nova-js/v2";
|
|
2
|
-
import { type NovaConnection } from "./novaConnection";
|
|
3
|
-
/**
|
|
4
|
-
* Where a robot's live controller state comes from: NOVA's websocket
|
|
5
|
-
* ({@link controllerStateWebsocket}), NATS (the `/nats` entry point), or a
|
|
6
|
-
* source of the app's own. It works like a WebSocket that reconnects itself:
|
|
7
|
-
* a {@link ControllerStateStream} listens to its messages and asks it to
|
|
8
|
-
* reconnect when they stop coming.
|
|
9
|
-
*/
|
|
10
|
-
export type ControllerStateSource = {
|
|
11
|
-
/** Where it connects, for error reports */
|
|
12
|
-
readonly url: string;
|
|
13
|
-
/** 1 (`WebSocket.OPEN`) while it is connected */
|
|
14
|
-
readonly readyState: number;
|
|
15
|
-
addEventListener(type: "message", listener: (event: MessageEvent) => void): void;
|
|
16
|
-
removeEventListener(type: "message", listener: (event: MessageEvent) => void): void;
|
|
17
|
-
/** Resolves with the next message */
|
|
18
|
-
nextMessage(): Promise<MessageEvent>;
|
|
19
|
-
reconnect(): void;
|
|
20
|
-
close(): void;
|
|
21
|
-
/** The controller state that a message's data holds, if any */
|
|
22
|
-
parse(data: unknown): RobotControllerState | undefined;
|
|
23
|
-
};
|
|
24
|
-
/**
|
|
25
|
-
* The live state of a controller from NOVA's websocket
|
|
26
|
-
* (`/cells/{cell}/controllers/{controller}/state-stream`): safety state,
|
|
27
|
-
* operation mode, mode, and the state of each of its motion groups
|
|
28
|
-
*/
|
|
29
|
-
export declare function controllerStateWebsocket(connection: NovaConnection, { controllerId, cellId, responseRateMs, }: {
|
|
30
|
-
controllerId: string;
|
|
31
|
-
/** Defaults to the cell of an older nova-js client, or "cell" */
|
|
32
|
-
cellId?: string;
|
|
33
|
-
/** How often NOVA sends the state, in ms; NOVA's own default without it */
|
|
34
|
-
responseRateMs?: number;
|
|
35
|
-
}): ControllerStateSource;
|