From 25b168a543bc50a98bfd436bd170dc55cd7e2a8a Mon Sep 17 00:00:00 2001 From: jugglingcats Date: Wed, 3 Jul 2024 13:52:35 +0100 Subject: [PATCH] feat(#210): support QUICKSTOP feat(#212): set safety douts for current mode (if configured) --- src/hooks.ts | 16 ------- src/modes/InnoboticsJogTileWrapper.tsx | 22 +++++---- src/modes/InnoboticsModeProvider.tsx | 66 ++++++++++++++++---------- 3 files changed, 54 insertions(+), 50 deletions(-) diff --git a/src/hooks.ts b/src/hooks.ts index 269b746..061f564 100644 --- a/src/hooks.ts +++ b/src/hooks.ts @@ -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) -} diff --git a/src/modes/InnoboticsJogTileWrapper.tsx b/src/modes/InnoboticsJogTileWrapper.tsx index 6bcc5d6..c5821e0 100644 --- a/src/modes/InnoboticsJogTileWrapper.tsx +++ b/src/modes/InnoboticsJogTileWrapper.tsx @@ -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) { @@ -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() @@ -33,7 +37,7 @@ export const InnoboticsJogTileWrapper = ({ children }) => { return } - const message = get_message(op, keyswitch, mode, deadman) + const message = get_message(op, autoMode, mode as ManualMode, motionAllowed) if (message) { return } diff --git a/src/modes/InnoboticsModeProvider.tsx b/src/modes/InnoboticsModeProvider.tsx index 417cedd..f0504de 100644 --- a/src/modes/InnoboticsModeProvider.tsx +++ b/src/modes/InnoboticsModeProvider.tsx @@ -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 {children}