Skip to content

Commit

Permalink
fix: Jogging websocket is now only open when mouse is inside panel
Browse files Browse the repository at this point in the history
  • Loading branch information
evrys committed Aug 19, 2024
1 parent 70e3315 commit 1612b15
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 7 deletions.
30 changes: 29 additions & 1 deletion src/components/jogging/JoggingCartesianTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { JoggingVelocitySlider } from "./JoggingVelocitySlider"
import { useReaction } from "../utils/hooks"
import { JoggingCartesianValues } from "./JoggingCartesianValues"
import { JoggingJointLimitDetector } from "./JoggingJointLimitDetector"
import { useEffect } from "react"

type JoggingCartesianOpts = {
axis: "x" | "y" | "z"
Expand Down Expand Up @@ -49,6 +50,31 @@ export const JoggingCartesianTab = observer(
{ fireImmediately: true } as any,
)

useEffect(() => {
// Start in increment mode with no websockets open
store.jogger.setJoggingMode("increment")

window.addEventListener("blur", disconnectJogger)

return () => {
window.removeEventListener("blur", disconnectJogger)
}
}, [])

async function connectJogger() {
store.jogger.setJoggingMode(
store.selectedDiscreteIncrement ? "increment" : "cartesian",
{
tcpId: store.selectedTcpId,
coordSystemId: store.selectedCoordSystemId,
},
)
}

async function disconnectJogger() {
store.jogger.setJoggingMode("increment")
}

async function runIncrementalCartesianJog(
opts: JoggingCartesianOpts,
increment: DiscreteIncrementOption,
Expand Down Expand Up @@ -85,6 +111,8 @@ export const JoggingCartesianTab = observer(
async function startCartesianJogging(opts: JoggingCartesianOpts) {
if (store.isLocked) return

connectJogger()

if (store.selectedDiscreteIncrement) {
return runIncrementalCartesianJog(opts, store.selectedDiscreteIncrement)
}
Expand Down Expand Up @@ -143,7 +171,7 @@ export const JoggingCartesianTab = observer(
}

return (
<Stack>
<Stack onMouseEnter={connectJogger} onMouseLeave={disconnectJogger}>
{/* Show Wandelscript string for the current coords */}
<JoggingCartesianValues store={store} />

Expand Down
30 changes: 24 additions & 6 deletions src/components/jogging/JoggingJointTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,29 @@ import type { JoggingStore } from "./JoggingStore"
import { JoggingVelocitySlider } from "./JoggingVelocitySlider"
import { JoggingJointRotationControl } from "./JoggingJointRotationControl"
import { JoggingJointValues } from "./JoggingJointValues"
import { useEffect } from "react"

export const JoggingJointTab = observer(
({ store }: { store: JoggingStore; }) => {
({ store }: { store: JoggingStore }) => {
useEffect(() => {
// Start in increment mode with no websockets open
store.jogger.setJoggingMode("increment")

window.addEventListener("blur", disconnectJogger)

return () => {
window.removeEventListener("blur", disconnectJogger)
}
}, [])

async function connectJogger() {
store.jogger.setJoggingMode("joint")
}

async function disconnectJogger() {
store.jogger.setJoggingMode("increment")
}

async function startJointJogging(opts: {
joint: number
direction: "-" | "+"
Expand All @@ -22,16 +42,14 @@ export const JoggingJointTab = observer(
async function stopJointJogging() {
await store.jogger.stop()
}

return (
<Stack>
<Stack onMouseEnter={connectJogger} onMouseLeave={disconnectJogger}>
<JoggingJointValues store={store} />
<Stack>
{store.jogger.motionStream.joints.map((joint) => {
const jointLimits =
store.motionGroupSpec.mechanical_joint_limits?.[
joint.index
]
store.motionGroupSpec.mechanical_joint_limits?.[joint.index]
const lowerLimitDegs =
jointLimits?.lower_limit !== undefined
? radiansToDegrees(jointLimits.lower_limit)
Expand Down

0 comments on commit 1612b15

Please sign in to comment.