Skip to content

Commit

Permalink
feat(#210): support QUICKSTOP
Browse files Browse the repository at this point in the history
feat(#212): set safety douts for current mode (if configured)
  • Loading branch information
jugglingcats committed Jul 3, 2024
1 parent 04bf995 commit 25b168a
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 50 deletions.
16 changes: 0 additions & 16 deletions src/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,19 +101,3 @@ export function useLoadedRobotPartsWithEmbeddedAssets(

return loaded
}

export function useManualKeyswitch() {
const safety_inputs = useSafetyDigitalInputList()
const keyswitch_index = safety_inputs.findIndex(
c => c.type === DIN_SAFETY_TYPE.DIN_SAFETY_TYPE_KEYSWITCH
)
return useSafetyDigitalInputState(keyswitch_index)
}

export function useDeadman() {
const safety_inputs = useSafetyDigitalInputList()
const deadman_index = safety_inputs.findIndex(
c => c.type === DIN_SAFETY_TYPE.DIN_SAFETY_TYPE_DEAD_MAN
)
return useSafetyDigitalInputState(deadman_index)
}
22 changes: 13 additions & 9 deletions src/modes/InnoboticsJogTileWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,22 @@
*/

import * as React from "react"
import { useDeadman, useManualKeyswitch } from "@glowbuzzer/awlib"
import { useConnection } from "@glowbuzzer/store"
import {
ManualMode,
useAutoModeActiveInput,
useConnection,
useMotionEnabledInput
} from "@glowbuzzer/store"
import { DockTileDisabled, useGlowbuzzerMode, useOperationEnabled } from "@glowbuzzer/controls"

function get_message(op: boolean, keyswitch: boolean, mode: string, deadman: boolean) {
function get_message(op: boolean, autoMode: boolean, mode: ManualMode, deadman: boolean) {
if (!op) {
return "Operation Not Enabled"
}
if (!keyswitch) {
return "Manual Keyswitch Not Engaged"
if (autoMode) {
return "Manual Mode Not Selected"
}
if (mode !== "jog") {
if (mode !== ManualMode.JOG) {
return "Jog Mode Not Selected"
}
if (!deadman) {
Expand All @@ -23,8 +27,8 @@ function get_message(op: boolean, keyswitch: boolean, mode: string, deadman: boo
}

export const InnoboticsJogTileWrapper = ({ children }) => {
const [{ actValue: keyswitch }] = useManualKeyswitch()
const [{ actValue: deadman }] = useDeadman()
const autoMode = useAutoModeActiveInput()
const motionAllowed = useMotionEnabledInput()
const { connected } = useConnection()
const op = useOperationEnabled()
const { mode } = useGlowbuzzerMode()
Expand All @@ -33,7 +37,7 @@ export const InnoboticsJogTileWrapper = ({ children }) => {
return <DockTileDisabled children={children} />
}

const message = get_message(op, keyswitch, mode, deadman)
const message = get_message(op, autoMode, mode as ManualMode, motionAllowed)
if (message) {
return <DockTileDisabled children={children} content={message} />
}
Expand Down
66 changes: 41 additions & 25 deletions src/modes/InnoboticsModeProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,44 +3,60 @@
*/

import * as React from "react"
import { GlowbuzzerModeProvider } from "@glowbuzzer/controls"
import {
DIN_SAFETY_TYPE,
useSafetyDigitalInputList,
useSafetyDigitalInputState
} from "@glowbuzzer/store"
import { useEffect } from "react"
import { GlowbuzzerModeContextType, GlowbuzzerModeProvider } from "@glowbuzzer/controls"
import { ManualMode, useAutoModeActiveInput, useManualMode } from "@glowbuzzer/store"

export const InnoboticsModeProvider = ({ children }) => {
const [requestedMode, setRequestedMode] = React.useState("auto")
const safety_inputs = useSafetyDigitalInputList()
const keyswitch_index = safety_inputs.findIndex(
c => c.type === DIN_SAFETY_TYPE.DIN_SAFETY_TYPE_KEYSWITCH
)
const switched = useSafetyDigitalInputState(keyswitch_index)
const autoModeEnabled = useAutoModeActiveInput()
const [manualMode, setManualMode] = useManualMode()

const mode = switched ? (requestedMode === "auto" ? "jog" : requestedMode) : "auto"
useEffect(() => {
// whenever we switch between auto/manual, ensure we revert to disabled mode
// (applies equally to auto and manual mode, even though this doesn't affect auto mode)
setManualMode(ManualMode.DISABLED)
}, [autoModeEnabled])

const context = {
function setMode(mode: ManualMode | "auto") {
if (mode === "auto") {
setManualMode(ManualMode.DISABLED)
} else {
setManualMode(mode)
}
}

const mode = autoModeEnabled ? "auto" : manualMode

const context: GlowbuzzerModeContextType = {
mode,
setMode: setRequestedMode,
modes: {
auto: {
setMode,
modes: [
{
value: "auto",
name: "Auto",
disabled: switched
disabled: !autoModeEnabled
},
{
value: ManualMode.DISABLED,
name: "Disabled",
disabled: autoModeEnabled
},
jog: {
{
value: ManualMode.JOG,
name: "Jog",
disabled: !switched
disabled: autoModeEnabled
},
["test-program"]: {
{
value: ManualMode.TEST_PROGRAM,
name: "Test Program",
disabled: !switched
disabled: autoModeEnabled
},
["hand-guided"]: {
{
value: ManualMode.HAND_GUIDED,
name: "Hand Guided",
disabled: !switched || keyswitch_index < 0
disabled: autoModeEnabled
}
}
]
}

return <GlowbuzzerModeProvider context={context}>{children}</GlowbuzzerModeProvider>
Expand Down

0 comments on commit 25b168a

Please sign in to comment.