Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Removed jogging activation gating in favor of short-lived websockets #154

Merged
merged 8 commits into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 15 additions & 17 deletions src/components/3d-viewport/SafetyZonesRenderer.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { SafetySetupSafetyZone } from "@wandelbots/wandelbots-js"
import { type GroupProps } from "@react-three/fiber"
import type { Geometry } from "@wandelbots/wandelbots-api-client"
import type { SafetySetupSafetyZone } from "@wandelbots/wandelbots-js"
import * as THREE from "three"
import { ConvexGeometry } from "three-stdlib"
import { type GroupProps } from "@react-three/fiber"

export type SafetyZonesRendererProps = {
safetyZones: SafetySetupSafetyZone[]
Expand Down Expand Up @@ -89,21 +89,19 @@ export function SafetyZonesRenderer({
return null
}
return (
<>
<mesh key={`${index}-${i}`} geometry={convexGeometry}>
<meshStandardMaterial
key={index}
attach="material"
color="#009f4d"
opacity={0.2}
depthTest={false}
depthWrite={false}
transparent
polygonOffset
polygonOffsetFactor={-i}
/>
</mesh>
</>
<mesh key={`${index}-${i}`} geometry={convexGeometry}>
<meshStandardMaterial
key={index}
attach="material"
color="#009f4d"
opacity={0.2}
depthTest={false}
depthWrite={false}
transparent
polygonOffset
polygonOffsetFactor={-i}
/>
</mesh>
)
})
})}
Expand Down
56 changes: 0 additions & 56 deletions src/components/jogging/JoggingActivationRequired.tsx

This file was deleted.

216 changes: 110 additions & 106 deletions src/components/jogging/JoggingCartesianTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import YAxisIcon from "../../icons/axis-y.svg"
import ZAxisIcon from "../../icons/axis-z.svg"
import RotationIcon from "../../icons/rotation.svg"
import { useReaction } from "../utils/hooks"
import { JoggingActivationRequired } from "./JoggingActivationRequired"
import { JoggingCartesianAxisControl } from "./JoggingCartesianAxisControl"
import { JoggingJointLimitDetector } from "./JoggingJointLimitDetector"
import { JoggingOptions } from "./JoggingOptions"
Expand Down Expand Up @@ -67,11 +66,11 @@ export const JoggingCartesianTab = observer(
opts: JoggingCartesianOpts,
increment: DiscreteIncrementOption,
) {
const tcpPose =
store.jogger.motionStream.rapidlyChangingMotionState.tcp_pose
const jogger = await store.activate()

const tcpPose = jogger.motionStream.rapidlyChangingMotionState.tcp_pose
const jointPosition =
store.jogger.motionStream.rapidlyChangingMotionState.state
.joint_position
jogger.motionStream.rapidlyChangingMotionState.state.joint_position
if (!tcpPose) return

await store.withMotionLock(async () => {
Expand Down Expand Up @@ -100,13 +99,15 @@ export const JoggingCartesianTab = observer(
})
} finally {
store.setCurrentIncrementJog(null)
await store.deactivate()
}
})
}

async function startCartesianJogging(opts: JoggingCartesianOpts) {
if (store.isLocked) return

const jogger = await store.activate()
if (store.activeDiscreteIncrement) {
return runIncrementalCartesianJog(opts, store.activeDiscreteIncrement)
}
Expand All @@ -133,7 +134,7 @@ export const JoggingCartesianTab = observer(
return
}

await store.jogger.stop()
await store.deactivate()
}

const axisList = [
Expand Down Expand Up @@ -183,109 +184,112 @@ export const JoggingCartesianTab = observer(
justifyContent="center"
sx={{ flexGrow: "1" }}
>
{/* Translate or rotate toggle */}
<JoggingToggleButtonGroup
value={store.selectedCartesianMotionType}
onChange={onMotionTypeChange}
exclusive
aria-label={t("Jogging.Cartesian.MotionType.lb")}
sx={{ justifyContent: "center" }}
<Stack
alignItems="center"
justifyContent="center"
gap="24px"
sx={{ flexGrow: 1 }}
>
<ToggleButton value="translate">
{t("Jogging.Cartesian.Translation.bt")}
</ToggleButton>
<ToggleButton value="rotate">
{t("Jogging.Cartesian.Rotation.bt")}
</ToggleButton>
</JoggingToggleButtonGroup>
{/* Translate or rotate toggle */}
<JoggingToggleButtonGroup
value={store.selectedCartesianMotionType}
onChange={onMotionTypeChange}
exclusive
aria-label={t("Jogging.Cartesian.MotionType.lb")}
sx={{ justifyContent: "center" }}
>
<ToggleButton value="translate">
{t("Jogging.Cartesian.Translation.bt")}
</ToggleButton>
<ToggleButton value="rotate">
{t("Jogging.Cartesian.Rotation.bt")}
</ToggleButton>
</JoggingToggleButtonGroup>

<JoggingActivationRequired store={store}>
<Stack alignItems="center" gap="24px" sx={{ flexGrow: 1 }}>
{/* Cartesian translate jogging */}
{store.selectedCartesianMotionType === "translate" &&
axisList.map((axis) => (
<JoggingCartesianAxisControl
key={axis.id}
colors={axis.colors}
disabled={store.isLocked}
activeJoggingDirection={
store.incrementJogInProgress?.axis === axis.id
? store.incrementJogInProgress.direction
: undefined
}
label={
<>
{axis.icon}
<Typography
sx={{
fontSize: "24px",
color: theme.palette.text.primary,
}}
>
{axis.id.toUpperCase()}
</Typography>
</>
}
getDisplayedValue={() =>
formatMM(
store.jogger.motionStream.rapidlyChangingMotionState
.tcp_pose?.position[axis.id] || 0,
)
}
startJogging={(direction: "-" | "+") =>
startCartesianJogging({
axis: axis.id,
motionType: "translate",
direction,
})
}
stopJogging={stopJogging}
/>
))}
{/* Cartesian translate jogging */}
{store.selectedCartesianMotionType === "translate" &&
axisList.map((axis) => (
<JoggingCartesianAxisControl
key={axis.id}
colors={axis.colors}
disabled={store.isLocked}
activeJoggingDirection={
store.incrementJogInProgress?.axis === axis.id
? store.incrementJogInProgress.direction
: undefined
}
label={
<>
{axis.icon}
<Typography
sx={{
fontSize: "24px",
color: theme.palette.text.primary,
}}
>
{axis.id.toUpperCase()}
</Typography>
</>
}
getDisplayedValue={() =>
formatMM(
store.jogger.motionStream.rapidlyChangingMotionState
.tcp_pose?.position[axis.id] || 0,
)
}
startJogging={(direction: "-" | "+") =>
startCartesianJogging({
axis: axis.id,
motionType: "translate",
direction,
})
}
stopJogging={stopJogging}
/>
))}

{/* Cartesian rotate jogging */}
{store.selectedCartesianMotionType === "rotate" &&
axisList.map((axis) => (
<JoggingCartesianAxisControl
key={axis.id}
colors={axis.colors}
disabled={store.isLocked}
activeJoggingDirection={
store.incrementJogInProgress?.axis === axis.id
? store.incrementJogInProgress.direction
: undefined
}
label={
<>
<RotationIcon />
<Typography
sx={{
fontSize: "24px",
color: theme.palette.text.primary,
}}
>
{axis.id.toUpperCase()}
</Typography>
</>
}
getDisplayedValue={() =>
formatDegrees(
store.jogger.motionStream.rapidlyChangingMotionState
.tcp_pose?.orientation?.[axis.id] || 0,
)
}
startJogging={(direction: "-" | "+") =>
startCartesianJogging({
axis: axis.id,
motionType: "rotate",
direction,
})
}
stopJogging={stopJogging}
/>
))}
</Stack>
</JoggingActivationRequired>
{/* Cartesian rotate jogging */}
{store.selectedCartesianMotionType === "rotate" &&
axisList.map((axis) => (
<JoggingCartesianAxisControl
key={axis.id}
colors={axis.colors}
disabled={store.isLocked}
activeJoggingDirection={
store.incrementJogInProgress?.axis === axis.id
? store.incrementJogInProgress.direction
: undefined
}
label={
<>
<RotationIcon />
<Typography
sx={{
fontSize: "24px",
color: theme.palette.text.primary,
}}
>
{axis.id.toUpperCase()}
</Typography>
</>
}
getDisplayedValue={() =>
formatDegrees(
store.jogger.motionStream.rapidlyChangingMotionState
.tcp_pose?.orientation?.[axis.id] || 0,
)
}
startJogging={(direction: "-" | "+") =>
startCartesianJogging({
axis: axis.id,
motionType: "rotate",
direction,
})
}
stopJogging={stopJogging}
/>
))}
</Stack>
</Stack>

{/* Show message if joint limits reached */}
Expand Down
4 changes: 2 additions & 2 deletions src/components/jogging/JoggingJointRotationControl.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ export const JoggingJointRotationControl = externalizeComponent(
>
<ChevronLeft
sx={{
"pointer-events": "none",
pointerEvents: "none",
}}
/>
</IconButton>
Expand Down Expand Up @@ -231,7 +231,7 @@ export const JoggingJointRotationControl = externalizeComponent(
>
<ChevronRight
sx={{
"pointer-events": "none",
pointerEvents: "none",
}}
/>
</IconButton>
Expand Down
Loading