From 0d18c85e4e921a6af11f445b4934eaec02babb6e Mon Sep 17 00:00:00 2001 From: jugglingcats Date: Thu, 27 Jun 2024 08:26:54 +0100 Subject: [PATCH] chore: refactor dock tile definitions plus other changes --- examples/applications/cnc/src/App.tsx | 12 ++-- .../applications/drives-fsoe/src/tiles.ts | 1 + examples/applications/drives/src/tiles.ts | 1 + .../applications/pick-and-place/src/main.tsx | 1 + .../applications/staubli-dance/src/tiles.ts | 1 + examples/machines/igus/src/main.tsx | 1 + examples/machines/liquid-handler/src/tiles.ts | 1 + examples/misc/path-planning/src/main.tsx | 1 - examples/react-native/SimpleConnectView.tsx | 3 +- .../src/SimpleOscillatingMoveTile.tsx | 1 + .../tutorials/set-digital-out/src/main.tsx | 1 + .../tutorials/three-tutorial/src/main.tsx | 57 +++++---------- examples/util/OscillatingMoveTile.tsx | 1 + examples/util/drives/DrivesTileDefinition.ts | 1 - .../src/config/ConfigEditTileDefinition.ts | 3 +- .../src/connect/ConnectTileDefinition.ts | 29 +++----- .../dev/StateMachineToolsTileDefinition.ts | 21 +++--- libs/controls/src/dock/DockLayout.tsx | 23 +----- libs/controls/src/dock/DockLayoutContext.ts | 3 - libs/controls/src/dock/DockTileDefinition.ts | 5 +- .../src/dock/DockTileDefinitionBuilder.ts | 70 +++++++++--------- .../src/dock/DockTileStandardWrapper.tsx | 19 +++++ libs/controls/src/dock/DockTileWrapper.tsx | 34 --------- libs/controls/src/dock/hooks.ts | 17 +++-- .../src/dro/JointDroTileDefinition.ts | 21 +++--- .../src/emstat/EmStatTileDefinition.ts | 3 +- libs/controls/src/flow/FlowTileDefinition.ts | 3 +- .../src/frames/FramesTileDefinition.ts | 3 +- .../controls/src/gcode/GCodeTileDefinition.ts | 23 +++--- .../src/io/AnalogInputsTileDefinition.ts | 21 +++--- .../src/io/AnalogOutputsTileDefinition.ts | 21 +++--- libs/controls/src/io/DigitalInputsTile.tsx | 44 +----------- .../src/io/DigitalInputsTileDefinition.ts | 21 +++--- .../src/io/DigitalOutputsTileDefinition.ts | 21 +++--- .../src/io/IntegerInputsTileDefinition.ts | 21 +++--- .../src/io/IntegerOutputsTileDefinition.ts | 21 +++--- .../io/ModbusDigitalInputsTileDefinition.ts | 21 +++--- .../io/ModbusDigitalOutputsTileDefinition.ts | 21 +++--- .../io/ModbusIntegerInputsTileDefinition.ts | 21 +++--- .../io/ModbusIntegerOutputsTileDefinition.ts | 21 +++--- .../src/io/SafetyDigitalInputsTile.tsx | 72 ++++++++++++------- .../io/SafetyDigitalInputsTileDefinition.ts | 21 +++--- .../io/SafetyDigitalOutputsTileDefinition.ts | 22 +++--- libs/controls/src/io/SafetyTileDefinition.ts | 21 +++--- .../DevInputOverridesTileDefinition.ts | 17 ++--- .../cartesian/CartesianJogTileDefinition.ts | 7 +- .../jogging/joint/JointJogTileDefinition.ts | 18 ++--- .../joints/JointTorqueModesTileDefinition.ts | 18 +++-- .../src/monitor/MonitorTileDefinition.ts | 4 +- .../src/payload/PayloadTileDefinition.ts | 1 + .../src/points/PointsTileDefinition.ts | 3 +- .../ThreeDimensionalSceneTileDefinition.ts | 1 - .../SerialCommunicationsTileDefinition.ts | 1 + .../src/spindle/SpindleTileDefinition.ts | 17 +++-- .../controls/src/tasks/TasksTileDefinition.ts | 21 +++--- .../src/telemetry/TelemetryTileDefinition.ts | 20 +++--- .../controls/src/tools/ToolsTileDefinition.ts | 3 +- libs/controls/src/util/index.ts | 1 + test/src/all_tests.ts | 1 + test/src/framework.ts | 14 ++-- test/src/tests/activity.ts | 18 ----- test/src/tests/blending.ts | 3 + test/src/tests/feedrate.ts | 66 +++++++++++++++++ test/src/tests/io.ts | 2 +- test/src/tests/robot.ts | 2 +- .../apps/awtube-envelope/src/EnvelopeTile.tsx | 1 - .../apps/awtube-l2/src/SimpleMoveTile.tsx | 1 + .../automationware/apps/awtube-l2/src/app.tsx | 17 +++-- .../apps/awtube-l2/src/main.tsx | 2 + .../apps/awtube-urdfviz/src/app.tsx | 1 - .../apps/awtube-variable/src/app.tsx | 1 - .../apps/awtube-variable/tsconfig.json | 8 +-- .../apps/stewart-aw-piattaforma/src/main.tsx | 2 - .../apps/stewart-aw-piattaforma/tsconfig.json | 8 +-- vendors/automationware/awlib | 2 +- 75 files changed, 499 insertions(+), 532 deletions(-) create mode 100644 libs/controls/src/dock/DockTileStandardWrapper.tsx delete mode 100644 libs/controls/src/dock/DockTileWrapper.tsx create mode 100644 test/src/tests/feedrate.ts diff --git a/examples/applications/cnc/src/App.tsx b/examples/applications/cnc/src/App.tsx index cd1bf978..d750ab2d 100644 --- a/examples/applications/cnc/src/App.tsx +++ b/examples/applications/cnc/src/App.tsx @@ -36,16 +36,16 @@ import { } from "@glowbuzzer/store" import { ToolHolderConstants } from "./constants" +const CustomThreeDimensionalSceneTileDefinition = DockTileDefinitionBuilder( + ThreeDimensionalSceneTileDefinition +) + .render(() => ) + .build() + export const App = () => { const toolList = useToolList() const toolHolderFrame = useFrame(ToolHolderConstants.frameIndex) - const CustomThreeDimensionalSceneTileDefinition = DockTileDefinitionBuilder( - ThreeDimensionalSceneTileDefinition - ) - .render(() => ) - .build() - const { spacing, holderToolOffset } = ToolHolderConstants const { x: originX, y: originY, z: originZ } = toolHolderFrame.translation const { x: holderToolOffsetX, y: holderToolOffsetY, z: holderToolOffsetZ } = holderToolOffset diff --git a/examples/applications/drives-fsoe/src/tiles.ts b/examples/applications/drives-fsoe/src/tiles.ts index bb6b901b..99482c2f 100644 --- a/examples/applications/drives-fsoe/src/tiles.ts +++ b/examples/applications/drives-fsoe/src/tiles.ts @@ -12,6 +12,7 @@ export const DrivesOscillatingMoveTileDefinition = DockTileDefinitionBuilder() .name("Move Drives") .placement(0, 1) .render(() => React.createElement(DrivesMoveTile)) + .requiresOperationEnabled() .build() export const VirtualHmiTileDefinition = DockTileDefinitionBuilder() diff --git a/examples/applications/drives/src/tiles.ts b/examples/applications/drives/src/tiles.ts index 75a2e8c1..c130ffee 100644 --- a/examples/applications/drives/src/tiles.ts +++ b/examples/applications/drives/src/tiles.ts @@ -11,4 +11,5 @@ export const DrivesOscillatingMoveTileDefinition = DockTileDefinitionBuilder() .name("Move Drives") .placement(0, 1) .render(() => React.createElement(DrivesMoveTile)) + .requiresOperationEnabled() .build() diff --git a/examples/applications/pick-and-place/src/main.tsx b/examples/applications/pick-and-place/src/main.tsx index 03fd3399..a93b86b8 100644 --- a/examples/applications/pick-and-place/src/main.tsx +++ b/examples/applications/pick-and-place/src/main.tsx @@ -41,6 +41,7 @@ const DemoTileDefinition = DockTileDefinitionBuilder() .name("Demo") .placement(1, 1) .render(() => React.createElement(DemoTile)) + .requiresConnection() .build() function App() { diff --git a/examples/applications/staubli-dance/src/tiles.ts b/examples/applications/staubli-dance/src/tiles.ts index a85472a8..4a248afa 100644 --- a/examples/applications/staubli-dance/src/tiles.ts +++ b/examples/applications/staubli-dance/src/tiles.ts @@ -7,4 +7,5 @@ export const DemoTileDefinition = DockTileDefinitionBuilder() .name("Demo") .placement(1, 1) .render(() => React.createElement(DemoTile)) + .requiresConnection() .build() diff --git a/examples/machines/igus/src/main.tsx b/examples/machines/igus/src/main.tsx index c2f18984..4cb22866 100644 --- a/examples/machines/igus/src/main.tsx +++ b/examples/machines/igus/src/main.tsx @@ -66,6 +66,7 @@ const demoMoveTile: DockTileDefinition = DockTileDefinitionBuilder() .name("Demo Move") .render(() => ) .placement(0, 1) + .requiresOperationEnabled() .build() export function App() { diff --git a/examples/machines/liquid-handler/src/tiles.ts b/examples/machines/liquid-handler/src/tiles.ts index a85472a8..4a248afa 100644 --- a/examples/machines/liquid-handler/src/tiles.ts +++ b/examples/machines/liquid-handler/src/tiles.ts @@ -7,4 +7,5 @@ export const DemoTileDefinition = DockTileDefinitionBuilder() .name("Demo") .placement(1, 1) .render(() => React.createElement(DemoTile)) + .requiresConnection() .build() diff --git a/examples/misc/path-planning/src/main.tsx b/examples/misc/path-planning/src/main.tsx index fcdbc9eb..dcde5356 100644 --- a/examples/misc/path-planning/src/main.tsx +++ b/examples/misc/path-planning/src/main.tsx @@ -52,7 +52,6 @@ const DemoTileDefinition = DockTileDefinitionBuilder() .name("Demo") .id("path-demo") .placement(1, 1) - .enableWithoutConnection() .build() const root = createRoot(document.getElementById("root")) diff --git a/examples/react-native/SimpleConnectView.tsx b/examples/react-native/SimpleConnectView.tsx index e941f937..0ee81be6 100644 --- a/examples/react-native/SimpleConnectView.tsx +++ b/examples/react-native/SimpleConnectView.tsx @@ -1,4 +1,5 @@ -import {Button, Text, View} from "react-native" +import * as React from "react" +import { Button, Text, View } from "react-native" import { DesiredState, determine_machine_state, diff --git a/examples/tutorials/oscillating-move/src/SimpleOscillatingMoveTile.tsx b/examples/tutorials/oscillating-move/src/SimpleOscillatingMoveTile.tsx index 94ff7e05..8da150b2 100644 --- a/examples/tutorials/oscillating-move/src/SimpleOscillatingMoveTile.tsx +++ b/examples/tutorials/oscillating-move/src/SimpleOscillatingMoveTile.tsx @@ -68,4 +68,5 @@ export const SimpleOscillatingMoveTileDefinition = DockTileDefinitionBuilder() .name("Oscillating Move") .placement(1, 0) .render(SimpleOscillatingMoveTile) + .requiresOperationEnabled() .build() diff --git a/examples/tutorials/set-digital-out/src/main.tsx b/examples/tutorials/set-digital-out/src/main.tsx index a0ac76ae..898c9f7a 100644 --- a/examples/tutorials/set-digital-out/src/main.tsx +++ b/examples/tutorials/set-digital-out/src/main.tsx @@ -23,6 +23,7 @@ const toggleDigitalOutputTileDefinition = DockTileDefinitionBuilder() .name("Toggle Digital Output") .placement(1, 0) .render(() => ) + .requiresOperationEnabled() .build() const config: GlowbuzzerConfig = { diff --git a/examples/tutorials/three-tutorial/src/main.tsx b/examples/tutorials/three-tutorial/src/main.tsx index ed29524d..4dbcd051 100644 --- a/examples/tutorials/three-tutorial/src/main.tsx +++ b/examples/tutorials/three-tutorial/src/main.tsx @@ -53,47 +53,26 @@ import { PlaybackTile } from "./playbackTile" import { DemoMoveTile } from "./demoMoveTile" import { DefaultEnvironment } from "../../../util/DefaultEnvironment" -const ChooseExampleTileDefinition: DockTileDefinition = { - id: "chooseExample", - name: "Choose Example", - defaultPlacement: { - column: 2, - row: 0 - }, - excludeByDefault: false, - config: { - enableWithoutConnection: true - }, - render: () => -} +const ChooseExampleTileDefinition = DockTileDefinitionBuilder() + .id("chooseExample") + .name("Choose Example") + .placement(2, 0) + .render(() => ) + .build() -const PlaybackTileDefinition: DockTileDefinition = { - id: "playback", - name: "Playback telemetry", - defaultPlacement: { - column: 2, - row: 0 - }, - excludeByDefault: false, - config: { - enableWithoutConnection: true - }, - render: () => -} +const PlaybackTileDefinition = DockTileDefinitionBuilder() + .id("playback") + .name("Playback telemetry") + .placement(2, 0) + .render(() => ) + .build() -const DemoMoveTileDefinition: DockTileDefinition = { - id: "demoMove", - name: "Demo move", - defaultPlacement: { - column: 2, - row: 0 - }, - excludeByDefault: false, - config: { - enableWithoutConnection: true - }, - render: () => -} +const DemoMoveTileDefinition = DockTileDefinitionBuilder() + .id("demoMove") + .name("Demo Move") + .placement(2, 0) + .render(() => ) + .build() const DEG90 = Math.PI / 2 diff --git a/examples/util/OscillatingMoveTile.tsx b/examples/util/OscillatingMoveTile.tsx index d1126d96..7ecb6894 100644 --- a/examples/util/OscillatingMoveTile.tsx +++ b/examples/util/OscillatingMoveTile.tsx @@ -129,4 +129,5 @@ export const OscillatingMoveTileDefinition = DockTileDefinitionBuilder() .name("Oscillating Move") .id("oscillating-move") .render(() => ) + .requiresOperationEnabled() .build() diff --git a/examples/util/drives/DrivesTileDefinition.ts b/examples/util/drives/DrivesTileDefinition.ts index b2b4c389..ef77bc77 100644 --- a/examples/util/drives/DrivesTileDefinition.ts +++ b/examples/util/drives/DrivesTileDefinition.ts @@ -11,5 +11,4 @@ export const DrivesTileDefinition = DockTileDefinitionBuilder() .name("Drives") .placement(1, 0) .render(() => React.createElement(DrivesTile)) - .enableWithoutConnection() .build() diff --git a/libs/controls/src/config/ConfigEditTileDefinition.ts b/libs/controls/src/config/ConfigEditTileDefinition.ts index 2d42d5bc..aa7455af 100644 --- a/libs/controls/src/config/ConfigEditTileDefinition.ts +++ b/libs/controls/src/config/ConfigEditTileDefinition.ts @@ -24,7 +24,6 @@ import { DockTileDefinitionBuilder } from "../dock" export const ConfigEditTileDefinition = DockTileDefinitionBuilder() .id(GlowbuzzerTileIdentifiers.CONFIG_EDIT) .name("Config Editor") - .placement(1, 0) - .enableWithoutConnection() .render(() => createElement(ConfigEditTile2, {}, null), null) + .placement(1, 0) .build() diff --git a/libs/controls/src/connect/ConnectTileDefinition.ts b/libs/controls/src/connect/ConnectTileDefinition.ts index 8b3e37df..7382822a 100644 --- a/libs/controls/src/connect/ConnectTileDefinition.ts +++ b/libs/controls/src/connect/ConnectTileDefinition.ts @@ -5,24 +5,17 @@ import { createElement } from "react" import { GlowbuzzerTileIdentifiers } from "../GlowbuzzerTileIdentifiers" import { ConnectTile } from "./ConnectTile" -import { ConnectSettings } from "./ConnectSettings" import { ConnectTabButtons } from "./ConnectTabButtons" import { ConnectTileHelp } from "./ConnectTileHelp" +import { DockTileDefinitionBuilder } from "../dock" -export const ConnectTileDefinition = { - id: GlowbuzzerTileIdentifiers.CONNECT, - name: "Connection", - enableDrag: false, // don't allow connect tile to be moved - enableClose: false, // or closed! - render: () => createElement(ConnectTile, {}, null), - renderSettings: () => ConnectSettings, - renderButtons: () => createElement(ConnectTabButtons, {}, null), - renderHelp: () => createElement(ConnectTileHelp, {}, null), - defaultPlacement: { - column: 0, - row: 0 - }, - config: { - enableWithoutConnection: true - } -} +export const ConnectTileDefinition = DockTileDefinitionBuilder() + .id(GlowbuzzerTileIdentifiers.CONNECT) + .name("Connection") + .render( + () => createElement(ConnectTile, {}, null), + () => createElement(ConnectTileHelp, {}, null), + () => createElement(ConnectTabButtons, {}, null) + ) + .placement(0, 0) + .build() diff --git a/libs/controls/src/dev/StateMachineToolsTileDefinition.ts b/libs/controls/src/dev/StateMachineToolsTileDefinition.ts index 5cdc261b..35056001 100644 --- a/libs/controls/src/dev/StateMachineToolsTileDefinition.ts +++ b/libs/controls/src/dev/StateMachineToolsTileDefinition.ts @@ -6,15 +6,14 @@ import { GlowbuzzerTileIdentifiers } from "../GlowbuzzerTileIdentifiers" import { createElement } from "react" import { StateMachineToolsTile } from "./StateMachineToolsTile" import { StateMachineToolsTileHelp } from "./StateMachineToolsTileHelp" +import { DockTileDefinitionBuilder } from "../dock" -export const StateMachineToolsTileDefinition = { - id: GlowbuzzerTileIdentifiers.STATE_MACHINE_TOOLS, - name: "State Machine Tools", - defaultPlacement: { - column: 0, - row: 2 - }, - render: () => createElement(StateMachineToolsTile, {}, null), - renderHelp: () => createElement(StateMachineToolsTileHelp, {}, null), - excludeByDefault: true -} +export const StateMachineToolsTileDefinition = DockTileDefinitionBuilder() + .id(GlowbuzzerTileIdentifiers.STATE_MACHINE_TOOLS) + .name("State Machine Tools") + .render( + () => createElement(StateMachineToolsTile, {}, null), + () => createElement(StateMachineToolsTileHelp, {}, null) + ) + .placement(0, 2) + .build() diff --git a/libs/controls/src/dock/DockLayout.tsx b/libs/controls/src/dock/DockLayout.tsx index 6a224ba0..237a1bdf 100644 --- a/libs/controls/src/dock/DockLayout.tsx +++ b/libs/controls/src/dock/DockLayout.tsx @@ -3,7 +3,7 @@ */ import * as React from "react" -import { createElement, useContext, useState } from "react" +import { useContext, useState } from "react" import { Popover } from "antd" import { DockLayoutContext } from "./DockLayoutContext" import { Layout, TabNode } from "flexlayout-react" @@ -13,7 +13,6 @@ import { QuestionCircleOutlined } from "@ant-design/icons" import { MachineState, useConnection, useMachineState } from "@glowbuzzer/store" import { is_touch_device } from "./util" import { useGlowbuzzerMode } from "../modes" -import { DockTileDisabled } from "./DockTileDisabled" const DockTileSettingsModal = ({ Component }: { Component }) => { const [visible, setVisible] = useState(false) @@ -46,7 +45,6 @@ export const DockLayout = () => { settingsFactory, helpFactory, headerFactory, - wrapperFactory, updateModel } = useContext(DockLayoutContext) @@ -55,23 +53,6 @@ export const DockLayout = () => { const machineState = useMachineState() const op = machineState === MachineState.OPERATION_ENABLED - function tile_factory(node: TabNode) { - // create the tile itself unadorned - const tile = factory(node) - // has a wrapper factory been defined for this tile? - // this is used to handle overlaying the tile with a dimmer when it is disabled, - // and to handle other mode-specific behaviours - const elemFactory = wrapperFactory?.(node) - return elemFactory - ? // factory exists, so use it to wrap the tile - elemFactory(tile, connection.connected, op, mode) - : // no factory, so implement the default behaviour which - // is to dim the tile if we're not connected - connection.connected - ? tile // no dimming - : createElement(DockTileDisabled, null, tile) - } - function render_tab_set(node, renderValues) { const selectedNode = node.getSelectedNode() if (selectedNode?.getType() === "tab") { @@ -113,7 +94,7 @@ export const DockLayout = () => { return ( factory(node)} font={{ size: "12px" }} realtimeResize={!is_touch_device()} onModelChange={updateModel} diff --git a/libs/controls/src/dock/DockLayoutContext.ts b/libs/controls/src/dock/DockLayoutContext.ts index 463c317d..2a97dee7 100644 --- a/libs/controls/src/dock/DockLayoutContext.ts +++ b/libs/controls/src/dock/DockLayoutContext.ts @@ -8,8 +8,6 @@ import { createContext } from "react" import { DockTileDefinition } from "./DockTileDefinition" import { DockPerspective } from "./types" -import { TileWrapperFactory } from "./DockTileDefinitionBuilder" - export type DockLayoutContextType = { appName: string model: Model @@ -18,7 +16,6 @@ export type DockLayoutContextType = { headerFactory: (node: TabNode) => React.ReactNode buttonsFactory: (node: TabNode) => React.ReactNode helpFactory: (node: TabNode) => React.ReactNode - wrapperFactory: (node: TabNode) => TileWrapperFactory tiles: (Partial & { id: string })[] perspectives: DockPerspective[] currentPerspective: string diff --git a/libs/controls/src/dock/DockTileDefinition.ts b/libs/controls/src/dock/DockTileDefinition.ts index 0c73b74f..b199c32f 100644 --- a/libs/controls/src/dock/DockTileDefinition.ts +++ b/libs/controls/src/dock/DockTileDefinition.ts @@ -5,8 +5,6 @@ import { IJsonTabNode } from "flexlayout-react" import { ReactNode } from "react" -import { TileWrapperFactory } from "./DockTileDefinitionBuilder" - type DockTilePlacement = { column: number row: number @@ -14,6 +12,7 @@ type DockTilePlacement = { export interface DockTileDefinition extends IJsonTabNode { id: string + tile?: () => ReactNode render(props?): ReactNode @@ -25,8 +24,6 @@ export interface DockTileDefinition extends IJsonTabNode { renderHelp?(): ReactNode - renderWrapper?: TileWrapperFactory - defaultPlacement?: DockTilePlacement excludeByDefault?: boolean diff --git a/libs/controls/src/dock/DockTileDefinitionBuilder.ts b/libs/controls/src/dock/DockTileDefinitionBuilder.ts index e42d4a51..f7a353d9 100644 --- a/libs/controls/src/dock/DockTileDefinitionBuilder.ts +++ b/libs/controls/src/dock/DockTileDefinitionBuilder.ts @@ -2,35 +2,14 @@ * Copyright (c) 2022. Glowbuzzer. All rights reserved */ -import * as React from "react" -import { createElement, isValidElement, ReactNode } from "react" +import { createElement, FunctionComponent, ReactNode } from "react" import { DockTileDefinition } from "./DockTileDefinition" -import { DockTileDisabled } from "./DockTileDisabled" - -function convertToReactElement(tile: ReactNode) { - if (isValidElement(tile)) { - return tile - } - return createElement(React.Fragment, { children: tile }) -} - -export type TileWrapperFactory = ( - tile: React.ReactNode, - connected: boolean, - op: boolean, - mode: string -) => React.ReactElement +import { DockTileStandardWrapper } from "./DockTileStandardWrapper" +import Element = React.JSX.Element export function DockTileDefinitionBuilder(template?: DockTileDefinition) { return new (class { public definition: DockTileDefinition = { - renderWrapper(tile: ReactNode, connected: boolean, _op: boolean, _mode: string) { - return connected - ? convertToReactElement(tile) - : createElement(DockTileDisabled, { - children: tile - }) - }, ...template } @@ -49,12 +28,20 @@ export function DockTileDefinitionBuilder(template?: DockTileDefinition) { renderHelpFn?: () => ReactNode, renderButtonsFn?: () => ReactNode ) { + this.definition.tile = template?.tile || renderFn this.definition.render = renderFn this.definition.renderHelp = renderHelpFn this.definition.renderButtons = renderButtonsFn return this } + wrap(element: FunctionComponent<{ children: ReactNode }>) { + this.definition.render = () => + createElement(element, { children: this.definition.tile() }) + + return this + } + placement(column: number, row: number) { this.definition.defaultPlacement = { column, row } return this @@ -64,26 +51,37 @@ export function DockTileDefinitionBuilder(template?: DockTileDefinition) { return this.definition } - wrapper(wrapperFactory: TileWrapperFactory) { - this.definition.renderWrapper = wrapperFactory + /** @deprecated */ + enableWithoutConnection() { + console.warn("enableWithoutConnection is deprecated, use requiresConnection instead") return this } - enableWithoutConnection() { - this.definition.renderWrapper = convertToReactElement + requiresConnection() { + if (!this.definition.tile) { + throw new Error("render function must be set before calling requiresConnection") + } + this.definition.render = () => + createElement(DockTileStandardWrapper, { + children: this.definition.tile(), + requireOpEnabled: false + }) + return this } requiresOperationEnabled() { - this.definition.renderWrapper = (tile, connected, op) => { - if (!connected || !op) { - return createElement(DockTileDisabled, { - children: tile, - disabledOnly: connected - }) - } - return convertToReactElement(tile) + if (!this.definition.tile) { + throw new Error( + "render function must be set before calling requiresOperationEnabled" + ) } + this.definition.render = () => + createElement(DockTileStandardWrapper, { + children: this.definition.tile(), + requireOpEnabled: true + }) + return this } })() diff --git a/libs/controls/src/dock/DockTileStandardWrapper.tsx b/libs/controls/src/dock/DockTileStandardWrapper.tsx new file mode 100644 index 00000000..32302bcc --- /dev/null +++ b/libs/controls/src/dock/DockTileStandardWrapper.tsx @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2024. Glowbuzzer. All rights reserved + */ + +import * as React from "react" +import { useConnection } from "@glowbuzzer/store" +import { useOperationEnabled } from "../util" +import { DockTileDisabled } from "./DockTileDisabled" + +export const DockTileStandardWrapper = ({ children, requireOpEnabled }) => { + const { connected } = useConnection() + const op = useOperationEnabled() + + if (!connected || (requireOpEnabled && !op)) { + return + } + + return <>{children} +} diff --git a/libs/controls/src/dock/DockTileWrapper.tsx b/libs/controls/src/dock/DockTileWrapper.tsx deleted file mode 100644 index abd5ad6f..00000000 --- a/libs/controls/src/dock/DockTileWrapper.tsx +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (c) 2023. Glowbuzzer. All rights reserved - */ - -import React, { useEffect, useRef } from "react" - -export const DockTileWrapper = ({ children }) => { - const ref = useRef(null) - - useEffect(() => { - // register keyboard event handlers - const elm = ref.current - - const onKeyDown = (e: KeyboardEvent) => { - e.stopPropagation() - } - const onKeyUp = (e: KeyboardEvent) => { - e.stopPropagation() - } - - elm.addEventListener("keydown", onKeyDown) - elm.addEventListener("keyup", onKeyUp) - return () => { - elm.removeEventListener("keydown", onKeyDown) - elm.removeEventListener("keyup", onKeyUp) - } - }) - - return ( -
- {children} -
- ) -} diff --git a/libs/controls/src/dock/hooks.ts b/libs/controls/src/dock/hooks.ts index e427893f..355f498d 100644 --- a/libs/controls/src/dock/hooks.ts +++ b/libs/controls/src/dock/hooks.ts @@ -142,7 +142,8 @@ export function useDockContext( } function tileFor(id: string): DockTileDefinition { - const definition = availableTiles.find(c => c.id === id) + const definition: DockTileDefinition = availableTiles.find(c => c.id === id) + if (!definition) { console.warn("No tile definition found for id", id, availableTiles) return { @@ -152,6 +153,17 @@ export function useDockContext( } } } + + if (!definition.tile) { + console.log("Tile did not use DockTileDefinitionBuilder to create definition", id) + return { + id, + render() { + return "Tile does not use DockTileDefinitionBuilder " + id + } + } + } + return definition // use this for testing to render simple content in every tile // return { @@ -187,9 +199,6 @@ export function useDockContext( helpFactory: (node: TabNode) => { return tileFor(node.getId()).renderHelp?.() }, - wrapperFactory: (node: TabNode) => { - return tileFor(node.getId()).renderWrapper - }, updateModel: new_model => { // model object is not changed, so we need to force a re-render updateModel(Model.fromJson(new_model.toJson())) diff --git a/libs/controls/src/dro/JointDroTileDefinition.ts b/libs/controls/src/dro/JointDroTileDefinition.ts index fe7a89ab..ef248265 100644 --- a/libs/controls/src/dro/JointDroTileDefinition.ts +++ b/libs/controls/src/dro/JointDroTileDefinition.ts @@ -6,14 +6,15 @@ import { GlowbuzzerTileIdentifiers } from "../GlowbuzzerTileIdentifiers" import { createElement } from "react" import { JointDroTile } from "./JointDroTile" import { JointDroTileHelp } from "./JointDroTileHelp" +import { DockTileDefinitionBuilder } from "../dock" -export const JointDroTileDefinition = { - id: GlowbuzzerTileIdentifiers.JOINT_DRO, - name: "Joint DRO", - defaultPlacement: { - column: 0, - row: 2 - }, - render: () => createElement(JointDroTile, {}, null), - renderHelp: () => createElement(JointDroTileHelp, {}, null) -} +export const JointDroTileDefinition = DockTileDefinitionBuilder() + .id(GlowbuzzerTileIdentifiers.JOINT_DRO) + .name("Joint DRO") + .render( + () => createElement(JointDroTile, {}, null), + () => createElement(JointDroTileHelp, {}, null) + ) + .placement(0, 2) + .requiresConnection() + .build() diff --git a/libs/controls/src/emstat/EmStatTileDefinition.ts b/libs/controls/src/emstat/EmStatTileDefinition.ts index bbec4d0f..1b7e83c1 100644 --- a/libs/controls/src/emstat/EmStatTileDefinition.ts +++ b/libs/controls/src/emstat/EmStatTileDefinition.ts @@ -10,7 +10,6 @@ import { DockTileDefinition, DockTileDefinitionBuilder } from "../dock" export const EmStatTileDefinition: DockTileDefinition = DockTileDefinitionBuilder() .id(GlowbuzzerTileIdentifiers.EMSTAT) .name("EtherCAT Master Status") - .placement(1, 0) - .enableWithoutConnection() .render(() => createElement(EmStatTile, {}, null)) + .placement(1, 0) .build() diff --git a/libs/controls/src/flow/FlowTileDefinition.ts b/libs/controls/src/flow/FlowTileDefinition.ts index 39e91d54..41e8471e 100644 --- a/libs/controls/src/flow/FlowTileDefinition.ts +++ b/libs/controls/src/flow/FlowTileDefinition.ts @@ -12,11 +12,10 @@ import { gbdbFacetIndicatorFactory } from "../gbdb/util" export const FlowTileDefinition = DockTileDefinitionBuilder() .id("flow") .name("Flow Maker") - .placement(1, 1) .render( () => createElement(FlowContextProvider, { children: createElement(FlowTile) }), undefined, gbdbFacetIndicatorFactory("flow") ) - .enableWithoutConnection() + .placement(1, 1) .build() diff --git a/libs/controls/src/frames/FramesTileDefinition.ts b/libs/controls/src/frames/FramesTileDefinition.ts index 9fc67c14..ecf7c115 100644 --- a/libs/controls/src/frames/FramesTileDefinition.ts +++ b/libs/controls/src/frames/FramesTileDefinition.ts @@ -11,11 +11,10 @@ import { gbdbFacetIndicatorFactory } from "../gbdb/util" export const FramesTileDefinition = DockTileDefinitionBuilder() .id(GlowbuzzerTileIdentifiers.FRAMES) .name("Frames") - .placement(2, 0) - .enableWithoutConnection() .render( () => createElement(FramesTile, {}, null), null, gbdbFacetIndicatorFactory("config", "frames") ) + .placement(2, 0) .build() diff --git a/libs/controls/src/gcode/GCodeTileDefinition.ts b/libs/controls/src/gcode/GCodeTileDefinition.ts index 842888bb..46ed5acb 100644 --- a/libs/controls/src/gcode/GCodeTileDefinition.ts +++ b/libs/controls/src/gcode/GCodeTileDefinition.ts @@ -6,17 +6,14 @@ import { GlowbuzzerTileIdentifiers } from "../GlowbuzzerTileIdentifiers" import { createElement } from "react" import { GCodeTile } from "./GCodeTile" import { GCodeTileHelp } from "./GCodeTileHelp" +import { DockTileDefinitionBuilder } from "../dock" -export const GCodeTileDefinition = { - id: GlowbuzzerTileIdentifiers.GCODE, - name: "GCode", - defaultPlacement: { - column: 1, - row: 1 - }, - render: () => createElement(GCodeTile, {}, null), - renderHelp: () => createElement(GCodeTileHelp, {}, null), - config: { - enableWithoutConnection: true - } -} +export const GCodeTileDefinition = DockTileDefinitionBuilder() + .id(GlowbuzzerTileIdentifiers.GCODE) + .name("GCode") + .placement(1, 1) + .render( + () => createElement(GCodeTile, {}, null), + () => createElement(GCodeTileHelp, {}, null) + ) + .build() diff --git a/libs/controls/src/io/AnalogInputsTileDefinition.ts b/libs/controls/src/io/AnalogInputsTileDefinition.ts index 04e56314..374a1516 100644 --- a/libs/controls/src/io/AnalogInputsTileDefinition.ts +++ b/libs/controls/src/io/AnalogInputsTileDefinition.ts @@ -6,14 +6,15 @@ import { GlowbuzzerTileIdentifiers } from "../GlowbuzzerTileIdentifiers" import { createElement } from "react" import { AnalogInputsTile } from "./AnalogInputsTile" import { AnalogInputsTileHelp } from "./AnalogInputsTileHelp" +import { DockTileDefinitionBuilder } from "../dock" -export const AnalogInputsTileDefinition = { - id: GlowbuzzerTileIdentifiers.ANALOG_INPUTS, - name: "Analog Inputs", - defaultPlacement: { - column: 2, - row: 1 - }, - render: () => createElement(AnalogInputsTile, {}, null), - renderHelp: () => createElement(AnalogInputsTileHelp, {}, null) -} +export const AnalogInputsTileDefinition = DockTileDefinitionBuilder() + .id(GlowbuzzerTileIdentifiers.ANALOG_INPUTS) + .name("Analog Inputs") + .placement(2, 1) + .render( + () => createElement(AnalogInputsTile, {}, null), + () => createElement(AnalogInputsTileHelp, {}, null) + ) + .requiresConnection() + .build() diff --git a/libs/controls/src/io/AnalogOutputsTileDefinition.ts b/libs/controls/src/io/AnalogOutputsTileDefinition.ts index 9172e132..adf96f56 100644 --- a/libs/controls/src/io/AnalogOutputsTileDefinition.ts +++ b/libs/controls/src/io/AnalogOutputsTileDefinition.ts @@ -6,14 +6,15 @@ import { GlowbuzzerTileIdentifiers } from "../GlowbuzzerTileIdentifiers" import { createElement } from "react" import { AnalogOutputsTile } from "./AnalogOutputsTile" import { AnalogOutputsTileHelp } from "./AnalogOutputsTileHelp" +import { DockTileDefinitionBuilder } from "../dock" -export const AnalogOutputsTileDefinition = { - id: GlowbuzzerTileIdentifiers.ANALOG_OUTPUTS, - name: "Analog Outputs", - defaultPlacement: { - column: 2, - row: 2 - }, - render: () => createElement(AnalogOutputsTile, {}, null), - renderHelp: () => createElement(AnalogOutputsTileHelp, {}, null) -} +export const AnalogOutputsTileDefinition = DockTileDefinitionBuilder() + .id(GlowbuzzerTileIdentifiers.ANALOG_OUTPUTS) + .name("Analog Outputs") + .placement(2, 2) + .render( + () => createElement(AnalogOutputsTile, {}, null), + () => createElement(AnalogOutputsTileHelp, {}, null) + ) + .requiresOperationEnabled() + .build() diff --git a/libs/controls/src/io/DigitalInputsTile.tsx b/libs/controls/src/io/DigitalInputsTile.tsx index de648f5b..0c24d5d0 100644 --- a/libs/controls/src/io/DigitalInputsTile.tsx +++ b/libs/controls/src/io/DigitalInputsTile.tsx @@ -16,9 +16,7 @@ import styled from "styled-components" const { Option } = Select -const StyledDiv = styled.div` - //padding-top: 20px; - +export const StyledDigitalInputs = styled.div` > div { display: flex; gap: 10px; @@ -34,36 +32,6 @@ const StyledDiv = styled.div` } ` -const StyledDigitalInput = styled.div` - display: flex; - padding: 1px 0; - - justify-content: space-between; // Add this line - align-items: center; // Optional: Align items to center vertically - - .label { - flex-grow: 1; - } - - .ant-tag { - width: 40px; - text-align: center; - } -` - -export const TooltipWrapper = ({ title, children }) => ( - - triggerNode} - > - {children} - - -) - const DigitalInputItem = ({ index, label }: { index: number; label?: string }) => { const [din, setDin] = useDigitalInputState(index) @@ -114,16 +82,10 @@ type DigitalInputsTileProps = { */ export const DigitalInputsTile = ({ labels = [] }: DigitalInputsTileProps) => { const dins = useDigitalInputList() - const values = useDigitalInputs() - - // label fallbacks if no name provided - const normalised_labels = dins?.map( - (config, index) => labels[index] || config.name || index.toString() - ) return ( - + {dins?.map((config, index) => ( { label={labels[index] || config.name || index.toString()} /> ))} - + ) } diff --git a/libs/controls/src/io/DigitalInputsTileDefinition.ts b/libs/controls/src/io/DigitalInputsTileDefinition.ts index a4cf2c11..d8b6b728 100644 --- a/libs/controls/src/io/DigitalInputsTileDefinition.ts +++ b/libs/controls/src/io/DigitalInputsTileDefinition.ts @@ -6,14 +6,15 @@ import { GlowbuzzerTileIdentifiers } from "../GlowbuzzerTileIdentifiers" import { createElement } from "react" import { DigitalInputsTile } from "./DigitalInputsTile" import { DigitalInputsTileHelp } from "./DigitalInputsTileHelp" +import { DockTileDefinitionBuilder } from "../dock" -export const DigitalInputsTileDefinition = { - id: GlowbuzzerTileIdentifiers.DIGITAL_INPUTS, - name: "Digital Inputs", - defaultPlacement: { - column: 2, - row: 1 - }, - render: () => createElement(DigitalInputsTile, {}, null), - renderHelp: () => createElement(DigitalInputsTileHelp, {}, null) -} +export const DigitalInputsTileDefinition = DockTileDefinitionBuilder() + .id(GlowbuzzerTileIdentifiers.DIGITAL_INPUTS) + .name("Digital Inputs") + .placement(2, 1) + .render( + () => createElement(DigitalInputsTile, {}, null), + () => createElement(DigitalInputsTileHelp, {}, null) + ) + .requiresConnection() + .build() diff --git a/libs/controls/src/io/DigitalOutputsTileDefinition.ts b/libs/controls/src/io/DigitalOutputsTileDefinition.ts index e023ca90..123e3c44 100644 --- a/libs/controls/src/io/DigitalOutputsTileDefinition.ts +++ b/libs/controls/src/io/DigitalOutputsTileDefinition.ts @@ -6,14 +6,15 @@ import { GlowbuzzerTileIdentifiers } from "../GlowbuzzerTileIdentifiers" import { createElement } from "react" import { DigitalOutputsTile } from "./DigitalOutputsTile" import { DigitalOutputsTileHelp } from "./DigitalOutputsTileHelp" +import { DockTileDefinitionBuilder } from "../dock" -export const DigitalOutputsTileDefinition = { - id: GlowbuzzerTileIdentifiers.DIGITAL_OUTPUTS, - name: "Digital Outputs", - defaultPlacement: { - column: 2, - row: 2 - }, - render: () => createElement(DigitalOutputsTile, {}, null), - renderHelp: () => createElement(DigitalOutputsTileHelp, {}, null) -} +export const DigitalOutputsTileDefinition = DockTileDefinitionBuilder() + .id(GlowbuzzerTileIdentifiers.DIGITAL_OUTPUTS) + .name("Digital Outputs") + .placement(2, 2) + .render( + () => createElement(DigitalOutputsTile, {}, null), + () => createElement(DigitalOutputsTileHelp, {}, null) + ) + .requiresOperationEnabled() + .build() diff --git a/libs/controls/src/io/IntegerInputsTileDefinition.ts b/libs/controls/src/io/IntegerInputsTileDefinition.ts index ed17aca6..bec2bbf9 100644 --- a/libs/controls/src/io/IntegerInputsTileDefinition.ts +++ b/libs/controls/src/io/IntegerInputsTileDefinition.ts @@ -6,14 +6,15 @@ import { GlowbuzzerTileIdentifiers } from "../GlowbuzzerTileIdentifiers" import { createElement } from "react" import { IntegerInputsTile } from "./IntegerInputsTile" import { IntegerInputsTileHelp } from "./IntegerInputsTileHelp" +import { DockTileDefinitionBuilder } from "../dock" -export const IntegerInputsTileDefinition = { - id: GlowbuzzerTileIdentifiers.INTEGER_INPUTS, - name: "Integer Inputs", - defaultPlacement: { - column: 2, - row: 1 - }, - render: () => createElement(IntegerInputsTile, {}, null), - renderHelp: () => createElement(IntegerInputsTileHelp, {}, null) -} +export const IntegerInputsTileDefinition = DockTileDefinitionBuilder() + .id(GlowbuzzerTileIdentifiers.INTEGER_INPUTS) + .name("Integer Inputs") + .placement(2, 1) + .render( + () => createElement(IntegerInputsTile, {}, null), + () => createElement(IntegerInputsTileHelp, {}, null) + ) + .requiresConnection() + .build() diff --git a/libs/controls/src/io/IntegerOutputsTileDefinition.ts b/libs/controls/src/io/IntegerOutputsTileDefinition.ts index c126ab3f..4fe59831 100644 --- a/libs/controls/src/io/IntegerOutputsTileDefinition.ts +++ b/libs/controls/src/io/IntegerOutputsTileDefinition.ts @@ -6,14 +6,15 @@ import { GlowbuzzerTileIdentifiers } from "../GlowbuzzerTileIdentifiers" import { createElement } from "react" import { IntegerOutputsTile } from "./IntegerOutputsTile" import { IntegerOutputsTileHelp } from "./IntegerOutputsTileHelp" +import { DockTileDefinitionBuilder } from "../dock" -export const IntegerOutputsTileDefinition = { - id: GlowbuzzerTileIdentifiers.INTEGER_OUTPUTS, - name: "Integer Outputs", - defaultPlacement: { - column: 2, - row: 2 - }, - render: () => createElement(IntegerOutputsTile, {}, null), - renderHelp: () => createElement(IntegerOutputsTileHelp, {}, null) -} +export const IntegerOutputsTileDefinition = DockTileDefinitionBuilder() + .id(GlowbuzzerTileIdentifiers.INTEGER_OUTPUTS) + .name("Integer Outputs") + .placement(2, 2) + .render( + () => createElement(IntegerOutputsTile, {}, null), + () => createElement(IntegerOutputsTileHelp, {}, null) + ) + .requiresOperationEnabled() + .build() diff --git a/libs/controls/src/io/ModbusDigitalInputsTileDefinition.ts b/libs/controls/src/io/ModbusDigitalInputsTileDefinition.ts index 4074d573..aa1b3ef2 100644 --- a/libs/controls/src/io/ModbusDigitalInputsTileDefinition.ts +++ b/libs/controls/src/io/ModbusDigitalInputsTileDefinition.ts @@ -6,14 +6,15 @@ import { GlowbuzzerTileIdentifiers } from "../GlowbuzzerTileIdentifiers" import { createElement } from "react" import { ModbusDigitalInputsTile } from "./ModbusDigitalInputsTile" import { ModbusDigitalInputsTileHelp } from "./ModbusDigitalInputsTileHelp" +import { DockTileDefinitionBuilder } from "../dock" -export const ModbusDigitalInputsTileDefinition = { - id: GlowbuzzerTileIdentifiers.MODBUS_DIGITAL_INPUTS, - name: "Modbus Digital Inputs", - defaultPlacement: { - column: 2, - row: 1 - }, - render: () => createElement(ModbusDigitalInputsTile, {}, null), - renderHelp: () => createElement(ModbusDigitalInputsTileHelp, {}, null) -} +export const ModbusDigitalInputsTileDefinition = DockTileDefinitionBuilder() + .id(GlowbuzzerTileIdentifiers.MODBUS_DIGITAL_INPUTS) + .name("Modbus Digital Inputs") + .placement(2, 1) + .render( + () => createElement(ModbusDigitalInputsTile, {}, null), + () => createElement(ModbusDigitalInputsTileHelp, {}, null) + ) + .requiresConnection() + .build() diff --git a/libs/controls/src/io/ModbusDigitalOutputsTileDefinition.ts b/libs/controls/src/io/ModbusDigitalOutputsTileDefinition.ts index 976066a5..6d70cf13 100644 --- a/libs/controls/src/io/ModbusDigitalOutputsTileDefinition.ts +++ b/libs/controls/src/io/ModbusDigitalOutputsTileDefinition.ts @@ -6,14 +6,15 @@ import { GlowbuzzerTileIdentifiers } from "../GlowbuzzerTileIdentifiers" import { createElement } from "react" import { ModbusDigitalOutputsTile } from "./ModbusDigitalOutputsTile" import { ModbusDigitalOutputsTileHelp } from "./ModbusDigitalOutputsTileHelp" +import { DockTileDefinitionBuilder } from "../dock" -export const ModbusDigitalOutputsTileDefinition = { - id: GlowbuzzerTileIdentifiers.MODBUS_DIGITAL_OUTPUTS, - name: "Modbus Digital Outputs", - defaultPlacement: { - column: 2, - row: 2 - }, - render: () => createElement(ModbusDigitalOutputsTile, {}, null), - renderHelp: () => createElement(ModbusDigitalOutputsTileHelp, {}, null) -} +export const ModbusDigitalOutputsTileDefinition = DockTileDefinitionBuilder() + .id(GlowbuzzerTileIdentifiers.MODBUS_DIGITAL_OUTPUTS) + .name("Modbus Digital Outputs") + .placement(2, 2) + .render( + () => createElement(ModbusDigitalOutputsTile, {}, null), + () => createElement(ModbusDigitalOutputsTileHelp, {}, null) + ) + .requiresOperationEnabled() + .build() diff --git a/libs/controls/src/io/ModbusIntegerInputsTileDefinition.ts b/libs/controls/src/io/ModbusIntegerInputsTileDefinition.ts index 907cb8e7..f647ddcd 100644 --- a/libs/controls/src/io/ModbusIntegerInputsTileDefinition.ts +++ b/libs/controls/src/io/ModbusIntegerInputsTileDefinition.ts @@ -6,14 +6,15 @@ import { GlowbuzzerTileIdentifiers } from "../GlowbuzzerTileIdentifiers" import { createElement } from "react" import { ModbusIntegerInputsTile } from "./ModbusIntegerInputsTile" import { ModbusIntegerInputsTileHelp } from "./ModbusIntegerInputsTileHelp" +import { DockTileDefinitionBuilder } from "../dock" -export const ModbusIntegerInputsTileDefinition = { - id: GlowbuzzerTileIdentifiers.MODBUS_INTEGER_INPUTS, - name: "Modbus Integer Inputs", - defaultPlacement: { - column: 2, - row: 1 - }, - render: () => createElement(ModbusIntegerInputsTile, {}, null), - renderHelp: () => createElement(ModbusIntegerInputsTileHelp, {}, null) -} +export const ModbusIntegerInputsTileDefinition = DockTileDefinitionBuilder() + .id(GlowbuzzerTileIdentifiers.MODBUS_INTEGER_INPUTS) + .name("Modbus Integer Inputs") + .placement(2, 1) + .render( + () => createElement(ModbusIntegerInputsTile, {}, null), + () => createElement(ModbusIntegerInputsTileHelp, {}, null) + ) + .requiresConnection() + .build() diff --git a/libs/controls/src/io/ModbusIntegerOutputsTileDefinition.ts b/libs/controls/src/io/ModbusIntegerOutputsTileDefinition.ts index 9f77c455..e29f5b45 100644 --- a/libs/controls/src/io/ModbusIntegerOutputsTileDefinition.ts +++ b/libs/controls/src/io/ModbusIntegerOutputsTileDefinition.ts @@ -6,14 +6,15 @@ import { GlowbuzzerTileIdentifiers } from "../GlowbuzzerTileIdentifiers" import { createElement } from "react" import { ModbusIntegerOutputsTile } from "./ModbusIntegerOutputsTile" import { ModbusIntegerOutputsTileHelp } from "./ModbusIntegerOutputsTileHelp" +import { DockTileDefinitionBuilder } from "../dock" -export const ModbusIntegerOutputsTileDefinition = { - id: GlowbuzzerTileIdentifiers.MODBUS_INTEGER_OUTPUTS, - name: "Modbus Integer Outputs", - defaultPlacement: { - column: 2, - row: 2 - }, - render: () => createElement(ModbusIntegerOutputsTile, {}, null), - renderHelp: () => createElement(ModbusIntegerOutputsTileHelp, {}, null) -} +export const ModbusIntegerOutputsTileDefinition = DockTileDefinitionBuilder() + .id(GlowbuzzerTileIdentifiers.MODBUS_INTEGER_OUTPUTS) + .name("Modbus Integer Outputs") + .placement(2, 2) + .render( + () => createElement(ModbusIntegerOutputsTile, {}, null), + () => createElement(ModbusIntegerOutputsTileHelp, {}, null) + ) + .requiresOperationEnabled() + .build() diff --git a/libs/controls/src/io/SafetyDigitalInputsTile.tsx b/libs/controls/src/io/SafetyDigitalInputsTile.tsx index 74f6038e..b22aa337 100644 --- a/libs/controls/src/io/SafetyDigitalInputsTile.tsx +++ b/libs/controls/src/io/SafetyDigitalInputsTile.tsx @@ -2,26 +2,51 @@ * Copyright (c) 2022. Glowbuzzer. All rights reserved */ -import React from "react" -import { useSafetyDigitalInputList, useSafetyDigitalInputs } from "@glowbuzzer/store" +import * as React from "react" +import { useSafetyDigitalInputList, useSafetyDigitalInputState } from "@glowbuzzer/store" import { StyledSafetyTileContent } from "../util/styles/StyledTileContent" -import { Tag } from "antd" +import { Select, Switch, Tag } from "antd" +import { StyledDigitalInputs } from "./DigitalInputsTile" -import styled from "styled-components" +const { Option } = Select -const StyledSafetyDigitalInput = styled.div` - display: flex; - padding: 1px 0; +const SafetyDigitalInputItem = ({ index, label }: { index: number; label?: string }) => { + const [din, setDin] = useSafetyDigitalInputState(index) - .label { - flex-grow: 1; + function handle_override_change(value) { + setDin(din.override, value) } - .ant-tag { - width: 40px; - text-align: center; + function handle_state_change() { + const new_state = !din.setValue + setDin(new_state, din.override) } -` + + return ( +
+
{label || "Unknown"}
+
+ +
+ +
+ {din.actValue ? "ON" : "OFF"} +
+
+ ) +} type SafetyDigitalInputsTileProps = { /** @@ -35,23 +60,18 @@ type SafetyDigitalInputsTileProps = { */ export const SafetyDigitalInputsTile = ({ labels = [] }: SafetyDigitalInputsTileProps) => { const dins = useSafetyDigitalInputList() - const values = useSafetyDigitalInputs() - - const normalised_labels = dins?.map( - (config, index) => labels[index] || config.name || index.toString() - ) return ( - {dins && - dins.map((config, index) => ( - - {normalised_labels[index]} - - {values[index] ? "ON" : "OFF"} - - + + {dins?.map((config, index) => ( + ))} + ) } diff --git a/libs/controls/src/io/SafetyDigitalInputsTileDefinition.ts b/libs/controls/src/io/SafetyDigitalInputsTileDefinition.ts index 32592ca5..e12a06d9 100644 --- a/libs/controls/src/io/SafetyDigitalInputsTileDefinition.ts +++ b/libs/controls/src/io/SafetyDigitalInputsTileDefinition.ts @@ -6,14 +6,15 @@ import { GlowbuzzerTileIdentifiers } from "../GlowbuzzerTileIdentifiers" import { createElement } from "react" import { SafetyDigitalInputsTile } from "./SafetyDigitalInputsTile" import { SafetyDigitalInputsTileHelp } from "./SafetyDigitalInputsTileHelp" +import { DockTileDefinitionBuilder } from "../dock" -export const SafetyDigitalInputsTileDefinition = { - id: GlowbuzzerTileIdentifiers.SAFETY_DIGITAL_INPUTS, - name: "Safety Digital Inputs", - defaultPlacement: { - column: 2, - row: 1 - }, - render: () => createElement(SafetyDigitalInputsTile, {}, null), - renderHelp: () => createElement(SafetyDigitalInputsTileHelp, {}, null) -} +export const SafetyDigitalInputsTileDefinition = DockTileDefinitionBuilder() + .id(GlowbuzzerTileIdentifiers.SAFETY_DIGITAL_INPUTS) + .name("Safety Digital Inputs") + .placement(2, 1) + .render( + () => createElement(SafetyDigitalInputsTile, {}, null), + () => createElement(SafetyDigitalInputsTileHelp, {}, null) + ) + .requiresConnection() + .build() diff --git a/libs/controls/src/io/SafetyDigitalOutputsTileDefinition.ts b/libs/controls/src/io/SafetyDigitalOutputsTileDefinition.ts index 7b7dd28d..85931c1f 100644 --- a/libs/controls/src/io/SafetyDigitalOutputsTileDefinition.ts +++ b/libs/controls/src/io/SafetyDigitalOutputsTileDefinition.ts @@ -6,15 +6,15 @@ import { GlowbuzzerTileIdentifiers } from "../GlowbuzzerTileIdentifiers" import { createElement } from "react" import { SafetyDigitalOutputsTile } from "./SafetyDigitalOutputsTile" import { SafetyDigitalOutputsTileHelp } from "./SafetyDigitalOutputsTileHelp" +import { DockTileDefinitionBuilder } from "../dock" -export const SafetyDigitalOutputsTileDefinition = { - id: GlowbuzzerTileIdentifiers.SAFETY_DIGITAL_OUTPUTS, - name: "Safety Digital Outputs", - defaultPlacement: { - column: 2, - row: 2 - }, - enableWithoutConnection: true, - render: () => createElement(SafetyDigitalOutputsTile, {}, null), - renderHelp: () => createElement(SafetyDigitalOutputsTileHelp, {}, null) -} +export const SafetyDigitalOutputsTileDefinition = DockTileDefinitionBuilder() + .id(GlowbuzzerTileIdentifiers.SAFETY_DIGITAL_OUTPUTS) + .name("Safety Digital Outputs") + .placement(2, 2) + .render( + () => createElement(SafetyDigitalOutputsTile, {}, null), + () => createElement(SafetyDigitalOutputsTileHelp, {}, null) + ) + .requiresOperationEnabled() + .build() diff --git a/libs/controls/src/io/SafetyTileDefinition.ts b/libs/controls/src/io/SafetyTileDefinition.ts index 773f7c90..5078bdb6 100644 --- a/libs/controls/src/io/SafetyTileDefinition.ts +++ b/libs/controls/src/io/SafetyTileDefinition.ts @@ -6,14 +6,15 @@ import { GlowbuzzerTileIdentifiers } from "../GlowbuzzerTileIdentifiers" import { createElement } from "react" import { SafetyTile } from "./SafetyTile" import { SafetyTileHelp } from "./SafetyTileHelp" +import { DockTileDefinitionBuilder } from "../dock" -export const SafetyTileDefinition = { - id: GlowbuzzerTileIdentifiers.SAFETY, - name: "Safety", - defaultPlacement: { - column: 2, - row: 1 - }, - render: () => createElement(SafetyTile, {}, null), - renderHelp: () => createElement(SafetyTileHelp, {}, null) -} +export const SafetyTileDefinition = DockTileDefinitionBuilder() + .id(GlowbuzzerTileIdentifiers.SAFETY) + .name("Safety") + .placement(2, 1) + .render( + () => createElement(SafetyTile, {}, null), + () => createElement(SafetyTileHelp, {}, null) + ) + .requiresConnection() + .build() diff --git a/libs/controls/src/io/overrides/DevInputOverridesTileDefinition.ts b/libs/controls/src/io/overrides/DevInputOverridesTileDefinition.ts index a188c193..86f4bd89 100644 --- a/libs/controls/src/io/overrides/DevInputOverridesTileDefinition.ts +++ b/libs/controls/src/io/overrides/DevInputOverridesTileDefinition.ts @@ -2,16 +2,13 @@ * Copyright (c) 2024. Glowbuzzer. All rights reserved */ -import { GlowbuzzerTileIdentifiers } from "../.." +import { DockTileDefinitionBuilder, GlowbuzzerTileIdentifiers } from "../.." import { createElement } from "react" import { DevInputOverridesTile } from "./DevInputOverridesTile" -export const DevInputOverridesTileDefinition = { - id: GlowbuzzerTileIdentifiers.DEV_INPUT_OVERRIDES, - name: "Developer Input Overrides", - defaultPlacement: { - column: 2, - row: 1 - }, - render: () => createElement(DevInputOverridesTile, {}, null) -} +export const DevInputOverridesTileDefinition = DockTileDefinitionBuilder() + .id(GlowbuzzerTileIdentifiers.DEV_INPUT_OVERRIDES) + .name("Developer Input Overrides") + .placement(2, 1) + .render(() => createElement(DevInputOverridesTile, {}, null)) + .build() diff --git a/libs/controls/src/jogging/cartesian/CartesianJogTileDefinition.ts b/libs/controls/src/jogging/cartesian/CartesianJogTileDefinition.ts index 6bd32743..2bcff152 100644 --- a/libs/controls/src/jogging/cartesian/CartesianJogTileDefinition.ts +++ b/libs/controls/src/jogging/cartesian/CartesianJogTileDefinition.ts @@ -12,10 +12,5 @@ export const CartesianJogTileDefinition = DockTileDefinitionBuilder() .name("Cartesian Jog") .placement(0, 1) .render(() => createElement(CartesianJogTile, {}, null)) - // .modeBehaviour((connected, op) => { - // return { - // disabled: !connected || !op, - // overlay: null - // } - // }) + .requiresOperationEnabled() .build() diff --git a/libs/controls/src/jogging/joint/JointJogTileDefinition.ts b/libs/controls/src/jogging/joint/JointJogTileDefinition.ts index 8ee066bd..2df7aacc 100644 --- a/libs/controls/src/jogging/joint/JointJogTileDefinition.ts +++ b/libs/controls/src/jogging/joint/JointJogTileDefinition.ts @@ -5,13 +5,13 @@ import { GlowbuzzerTileIdentifiers } from "../../GlowbuzzerTileIdentifiers" import { createElement } from "react" import { JointJogTile } from "./JointJogTile" +import { DockTileDefinitionBuilder } from "../../dock" +import { CartesianJogTile } from "../cartesian/CartesianJogTile" -export const JointJogTileDefinition = { - id: GlowbuzzerTileIdentifiers.JOG_JOINT, - name: "Joint Jog", - defaultPlacement: { - column: 0, - row: 1 - }, - render: () => createElement(JointJogTile, {}, null) -} +export const JointJogTileDefinition = DockTileDefinitionBuilder() + .id(GlowbuzzerTileIdentifiers.JOG_JOINT) + .name("Joint Jog") + .placement(0, 1) + .render(() => createElement(JointJogTile, {}, null)) + .requiresOperationEnabled() + .build() diff --git a/libs/controls/src/joints/JointTorqueModesTileDefinition.ts b/libs/controls/src/joints/JointTorqueModesTileDefinition.ts index d2e62c81..b14fb05b 100644 --- a/libs/controls/src/joints/JointTorqueModesTileDefinition.ts +++ b/libs/controls/src/joints/JointTorqueModesTileDefinition.ts @@ -3,15 +3,13 @@ */ import { createElement } from "react" -import { GlowbuzzerTileIdentifiers } from ".." +import { DockTileDefinitionBuilder, GlowbuzzerTileIdentifiers } from ".." import { JointTorqueModesTile } from "./JointTorqueModesTile" -export const JointTorqueModesTileDefinition = { - id: GlowbuzzerTileIdentifiers.JOINT_TORQUE_MODES, - name: "Joint Torque Mode", - defaultPlacement: { - column: 0, - row: 1 - }, - render: () => createElement(JointTorqueModesTile, {}, null) -} +export const JointTorqueModesTileDefinition = DockTileDefinitionBuilder() + .id(GlowbuzzerTileIdentifiers.JOINT_TORQUE_MODES) + .name("Joint Torque Mode") + .placement(0, 1) + .render(() => createElement(JointTorqueModesTile, {}, null)) + .requiresOperationEnabled() + .build() diff --git a/libs/controls/src/monitor/MonitorTileDefinition.ts b/libs/controls/src/monitor/MonitorTileDefinition.ts index 7a896a55..bb690ea5 100644 --- a/libs/controls/src/monitor/MonitorTileDefinition.ts +++ b/libs/controls/src/monitor/MonitorTileDefinition.ts @@ -9,7 +9,7 @@ import { MonitorTile } from "./MonitorTile" export const MonitorTileDefinition = DockTileDefinitionBuilder() .name("Connection Monitoring") .id("monitor") - .enableWithoutConnection() - .placement(2, 2) .render(() => React.createElement(MonitorTile)) + .placement(2, 2) + .requiresConnection() .build() diff --git a/libs/controls/src/payload/PayloadTileDefinition.ts b/libs/controls/src/payload/PayloadTileDefinition.ts index 17a9623d..34d4e44a 100644 --- a/libs/controls/src/payload/PayloadTileDefinition.ts +++ b/libs/controls/src/payload/PayloadTileDefinition.ts @@ -11,4 +11,5 @@ export const PayloadTileDefinition = DockTileDefinitionBuilder() .name("Payload Tile") .placement(2, 1) .render(() => React.createElement(PayloadTile)) + .requiresConnection() .build() diff --git a/libs/controls/src/points/PointsTileDefinition.ts b/libs/controls/src/points/PointsTileDefinition.ts index fe225127..130e424a 100644 --- a/libs/controls/src/points/PointsTileDefinition.ts +++ b/libs/controls/src/points/PointsTileDefinition.ts @@ -11,11 +11,10 @@ import { gbdbFacetIndicatorFactory } from "../gbdb/util" export const PointsTileDefinition = DockTileDefinitionBuilder() .id(GlowbuzzerTileIdentifiers.POINTS) .name("Points") - .placement(2, 0) - .enableWithoutConnection() .render( () => createElement(PointsTile, {}, null), null, gbdbFacetIndicatorFactory("config", "points") ) + .placement(2, 0) .build() diff --git a/libs/controls/src/scene/ThreeDimensionalSceneTileDefinition.ts b/libs/controls/src/scene/ThreeDimensionalSceneTileDefinition.ts index e5210470..9e6f755b 100644 --- a/libs/controls/src/scene/ThreeDimensionalSceneTileDefinition.ts +++ b/libs/controls/src/scene/ThreeDimensionalSceneTileDefinition.ts @@ -26,5 +26,4 @@ export const ThreeDimensionalSceneTileDefinition = DockTileDefinitionBuilder() () => renderThreeDimensionalSceneWithFrustum(), () => createElement(ThreeDimensionalSceneTileHelp, {}, null) ) - .enableWithoutConnection() .build() diff --git a/libs/controls/src/serial/SerialCommunicationsTileDefinition.ts b/libs/controls/src/serial/SerialCommunicationsTileDefinition.ts index c5476645..dcadcfb2 100644 --- a/libs/controls/src/serial/SerialCommunicationsTileDefinition.ts +++ b/libs/controls/src/serial/SerialCommunicationsTileDefinition.ts @@ -11,4 +11,5 @@ export const SerialCommunicationsTileDefinition = DockTileDefinitionBuilder() .name("Serial Comms") .placement(2, 2) .render(() => React.createElement(SerialCommunicationsTile)) + .requiresOperationEnabled() .build() diff --git a/libs/controls/src/spindle/SpindleTileDefinition.ts b/libs/controls/src/spindle/SpindleTileDefinition.ts index c61d3e36..5dd080bb 100644 --- a/libs/controls/src/spindle/SpindleTileDefinition.ts +++ b/libs/controls/src/spindle/SpindleTileDefinition.ts @@ -5,13 +5,12 @@ import { GlowbuzzerTileIdentifiers } from "../GlowbuzzerTileIdentifiers" import { createElement } from "react" import { SpindleTile } from "./SpindleTile" +import { DockTileDefinitionBuilder } from "../dock" -export const SpindleTileDefinition = { - id: GlowbuzzerTileIdentifiers.SPINDLE, - name: "Spindle", - defaultPlacement: { - column: 2, - row: 0 - }, - render: () => createElement(SpindleTile, {}, null) -} +export const SpindleTileDefinition = DockTileDefinitionBuilder() + .id(GlowbuzzerTileIdentifiers.SPINDLE) + .name("Spindle") + .placement(2, 0) + .render(() => createElement(SpindleTile, {}, null)) + .requiresConnection() + .build() diff --git a/libs/controls/src/tasks/TasksTileDefinition.ts b/libs/controls/src/tasks/TasksTileDefinition.ts index eb203d7f..95fbe2ec 100644 --- a/libs/controls/src/tasks/TasksTileDefinition.ts +++ b/libs/controls/src/tasks/TasksTileDefinition.ts @@ -6,14 +6,15 @@ import { GlowbuzzerTileIdentifiers } from "../GlowbuzzerTileIdentifiers" import { createElement } from "react" import { TasksTile } from "./TasksTile" import { TasksTileHelp } from "./TasksTileHelp" +import { DockTileDefinitionBuilder } from "../dock" -export const TasksTileDefinition = { - id: GlowbuzzerTileIdentifiers.TASKS, - name: "Tasks", - defaultPlacement: { - column: 0, - row: 2 - }, - render: () => createElement(TasksTile, {}, null), - renderHelp: () => createElement(TasksTileHelp, {}, null) -} +export const TasksTileDefinition = DockTileDefinitionBuilder() + .id(GlowbuzzerTileIdentifiers.TASKS) + .name("Tasks") + .placement(0, 2) + .render( + () => createElement(TasksTile, {}, null), + () => createElement(TasksTileHelp, {}, null) + ) + .requiresConnection() + .build() diff --git a/libs/controls/src/telemetry/TelemetryTileDefinition.ts b/libs/controls/src/telemetry/TelemetryTileDefinition.ts index 380c52a6..9f8f2b8a 100644 --- a/libs/controls/src/telemetry/TelemetryTileDefinition.ts +++ b/libs/controls/src/telemetry/TelemetryTileDefinition.ts @@ -5,16 +5,12 @@ import { GlowbuzzerTileIdentifiers } from "../GlowbuzzerTileIdentifiers" import { createElement } from "react" import { TelemetryTile } from "./TelemetryTile" +import { DockTileDefinitionBuilder } from "../dock" -export const TelemetryTileDefinition = { - id: GlowbuzzerTileIdentifiers.TELEMETRY, - name: "Telemetry", - defaultPlacement: { - column: 0, - row: 2 - }, - config: { - enableWithoutConnection: true - }, - render: () => createElement(TelemetryTile, {}, null) -} +export const TelemetryTileDefinition = DockTileDefinitionBuilder() + .id(GlowbuzzerTileIdentifiers.TELEMETRY) + .name("Telemetry") + .placement(1, 2) + .render(() => createElement(TelemetryTile, {}, null)) + .requiresConnection() + .build() diff --git a/libs/controls/src/tools/ToolsTileDefinition.ts b/libs/controls/src/tools/ToolsTileDefinition.ts index ca1fe3aa..b8d7e017 100644 --- a/libs/controls/src/tools/ToolsTileDefinition.ts +++ b/libs/controls/src/tools/ToolsTileDefinition.ts @@ -11,7 +11,6 @@ import { ToolsTile } from "./ToolsTile" export const ToolsTileDefinition = DockTileDefinitionBuilder() .id(GlowbuzzerTileIdentifiers.TOOLS) .name("Tools") - .placement(2, 2) .render(() => createElement(ToolsTile), undefined, gbdbFacetIndicatorFactory("config", "tools")) - .enableWithoutConnection() + .placement(2, 2) .build() diff --git a/libs/controls/src/util/index.ts b/libs/controls/src/util/index.ts index 7f4b60aa..49d0a002 100644 --- a/libs/controls/src/util/index.ts +++ b/libs/controls/src/util/index.ts @@ -3,3 +3,4 @@ */ export * from "./components" +export * from "./hooks" diff --git a/test/src/all_tests.ts b/test/src/all_tests.ts index 78d6a556..4516ad11 100644 --- a/test/src/all_tests.ts +++ b/test/src/all_tests.ts @@ -29,3 +29,4 @@ export * from "./tests/config_load" export * from "./tests/move_vector" export * from "./tests/move_joints_interpolated" export * from "./tests/moves" +export * from "./tests/feedrate" diff --git a/test/src/framework.ts b/test/src/framework.ts index 496e4345..7e575d95 100644 --- a/test/src/framework.ts +++ b/test/src/framework.ts @@ -76,7 +76,7 @@ export class GbcTest { activity: { tag: number; streamState: number; activityState: number } }[] | undefined - private check_limits = true + private valid_limits_factor = 1 private readonly gbc: any private store: EnhancedStore private activity_api: SoloActivityApi @@ -278,12 +278,12 @@ export class GbcTest { } disable_limit_check() { - this.check_limits = false + this.valid_limits_factor = 0 return this } - enable_limit_check() { - this.check_limits = true + enable_limit_check(factor = 1) { + this.valid_limits_factor = factor return this } @@ -309,7 +309,7 @@ export class GbcTest { this.send(updateFroMsg(0, 1)) this.exec_double_cycle() - this.check_limits = true + this.valid_limits_factor = 1 return this } @@ -406,7 +406,7 @@ export class GbcTest { exec(count = 1, single_cycle = false) { if (this.capture_state) { for (let n = 0; n < count; n++) { - this.gbc.run(1, single_cycle, this.check_limits) + this.gbc.run(1, single_cycle, this.valid_limits_factor) // get the joint status const msg = this.status_msg const status = msg.status @@ -437,7 +437,7 @@ export class GbcTest { }) } } else { - this.gbc.run(count, single_cycle, this.check_limits) + this.gbc.run(count, single_cycle, this.valid_limits_factor) } const status = this.status_msg.status const { activity } = status diff --git a/test/src/tests/activity.ts b/test/src/tests/activity.ts index 581eff96..9d55b3cc 100644 --- a/test/src/tests/activity.ts +++ b/test/src/tests/activity.ts @@ -136,22 +136,4 @@ test("will normalise move vector at velocity", async () => { await do_cancel(move, 1, 50) }) -test("move vector at velocity respects feedrate", async () => { - const pos = joint => state => state.status.joint[joint].actPos - - const move1 = gbc.wrap(gbc.activity.moveVectorAtVelocity(100, 0, 0).promise) - await do_cancel(move1, 1, 50) - gbc.assert.gt(pos(0), 10) - - gbc.reset() - gbc.enable_operation() - gbc.set_fro(0, 0.5) - - const move2 = gbc.wrap(gbc.activity.moveVectorAtVelocity(100, 0, 0).promise) - await do_cancel(move2, 1, 50) - gbc.assert.lt(pos(0), 10) - - gbc.plot("test") -}) - export const activity = test diff --git a/test/src/tests/blending.ts b/test/src/tests/blending.ts index 8b3ce6ca..c61e8358 100644 --- a/test/src/tests/blending.ts +++ b/test/src/tests/blending.ts @@ -12,6 +12,9 @@ test.before.each(ctx => { console.log(ctx.__test__) gbc.reset() gbc.enable_operation() + // we increase the factor used to check limits, + // because blending can increase vmax and amax + gbc.enable_limit_check(2) }) const tag = state => state.stream[0].tag diff --git a/test/src/tests/feedrate.ts b/test/src/tests/feedrate.ts new file mode 100644 index 00000000..e35f6e58 --- /dev/null +++ b/test/src/tests/feedrate.ts @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2024. Glowbuzzer. All rights reserved + */ + +import * as uvu from "uvu" +import { gbc } from "../../gbc" +import { do_cancel } from "../util" + +const test = uvu.suite("feedrate") + +test.before.each(ctx => { + console.log(ctx.__test__) + gbc.config().joints(3).cartesianKinematics().finalize() + gbc.enable_operation() + // we want an unusual number here to ensure we don't fall on + // cycle boundary + gbc.set_fro(0, 1.321232) + gbc.exec(15) +}) + +test("should not exceed limits when ramping from stationary to regular fro", async () => { + try { + gbc.enable_limit_check(1.5) + gbc.set_fro(0, 0) + gbc.exec(40) + gbc.assert.selector(s => s.status.kc[0].froActual, 0) + + gbc.set_fro(0, 0) + const move = gbc.wrap(gbc.activity.moveVectorAtVelocity(0, 1, 0).promise) + move.start().iterations(40) + } finally { + gbc.plot("test") + } +}) + +test.only("moveVectorAtVelocity should not give velocity spike at higher fro when cancelling", async () => { + try { + // we allow slightly higher limit because of fro changes + gbc.enable_limit_check(25) + const move = gbc.wrap(gbc.activity.moveVectorAtVelocity(0, 1, 0).promise) + move.start().iterations(25) + gbc.set_fro(0, 0.1) + // gbc.exec(1) + const cancel = gbc.wrap(gbc.activity.cancel().promise) + cancel.start() + gbc.exec(35) + } finally { + gbc.plot("test") + } +}) + +test("moveJointsAtVelocity should not give velocity spike at higher fro when cancelling", async () => { + try { + const move = gbc.wrap(gbc.activity.moveJointsAtVelocity([1]).promise) + move.start().iterations(2) + gbc.set_fro(0, 2) + gbc.exec(25) // ensure fro change complete + + const cancel = gbc.wrap(gbc.activity.cancel().promise) + cancel.start().iterations(25) + } finally { + gbc.plot("test") + } +}) + +export const feedrate = test diff --git a/test/src/tests/io.ts b/test/src/tests/io.ts index 1a22cdae..361382c2 100644 --- a/test/src/tests/io.ts +++ b/test/src/tests/io.ts @@ -13,7 +13,7 @@ test.before.each(() => { test("can get digital input from fieldbus", async () => { const index = 2 - const selector = state => state.status.din[index] + const selector = state => state.status.din[index].actValue gbc.assert .selector(selector, false) .enable_operation() diff --git a/test/src/tests/robot.ts b/test/src/tests/robot.ts index b76c153d..ef0c5ec4 100644 --- a/test/src/tests/robot.ts +++ b/test/src/tests/robot.ts @@ -29,7 +29,7 @@ function init_robot_test() { gbc.set_joint_pos(5, 0) gbc.enable_operation() - gbc.enable_limit_check() + gbc.enable_limit_check(2) } test.before.each(() => { diff --git a/vendors/automationware/apps/awtube-envelope/src/EnvelopeTile.tsx b/vendors/automationware/apps/awtube-envelope/src/EnvelopeTile.tsx index c89704a9..bf5a2f4f 100644 --- a/vendors/automationware/apps/awtube-envelope/src/EnvelopeTile.tsx +++ b/vendors/automationware/apps/awtube-envelope/src/EnvelopeTile.tsx @@ -165,5 +165,4 @@ export const EnvelopeTileDefinition = DockTileDefinitionBuilder() .id("envelope") .name("Envelope") .render(() => ) - .enableWithoutConnection() .build() diff --git a/vendors/automationware/apps/awtube-l2/src/SimpleMoveTile.tsx b/vendors/automationware/apps/awtube-l2/src/SimpleMoveTile.tsx index ca76a719..176df215 100644 --- a/vendors/automationware/apps/awtube-l2/src/SimpleMoveTile.tsx +++ b/vendors/automationware/apps/awtube-l2/src/SimpleMoveTile.tsx @@ -87,4 +87,5 @@ export const SimpleMoveTileDefinition = DockTileDefinitionBuilder() .id("aw-simple-move") .name("Simple Move") .render(() => ) + .requiresOperationEnabled() .build() diff --git a/vendors/automationware/apps/awtube-l2/src/app.tsx b/vendors/automationware/apps/awtube-l2/src/app.tsx index 49ca5d29..645e4aa2 100644 --- a/vendors/automationware/apps/awtube-l2/src/app.tsx +++ b/vendors/automationware/apps/awtube-l2/src/app.tsx @@ -7,6 +7,7 @@ import { CartesianJogTileDefinition, ConfigEditTileDefinition, DevInputOverridesTileDefinition, + DigitalInputsTileDefinition, DigitalOutputsTileDefinition, DockLayout, DockLayoutProvider, @@ -21,6 +22,7 @@ import { MonitorTileDefinition, PayloadTileDefinition, PointsTileDefinition, + SafetyDigitalInputsTileDefinition, SerialCommunicationsTileDefinition, TelemetryTileDefinition, ThreeDimensionalSceneTile, @@ -36,6 +38,7 @@ import { AwTubeStatusTileDefinitionBuilder, Base, Clamp, + InnoboticsModeProvider, Joint, Link, Monobraccio, @@ -47,8 +50,7 @@ import { Environment, Sphere } from "@react-three/drei" import { SimpleMoveTileDefinition } from "./SimpleMoveTile" import { InterpolatedMoveTile } from "./InterpolatedMoveTile" import { AppStatusBar } from "./AppStatusBar" -import { InnoboticsModeProvider } from "@glowbuzzer/awlib" -import { InnoboticsJogModeTileHelper } from "../../../awlib/src/modes/InnoboticsJogModeTileHelper" +import { InnoboticsJogTileWrapper } from "../../../awlib/src/modes/InnoboticsJogTileWrapper" // construct the robot definition from the parts const definition_l2: AwTubeRobotParts = { @@ -121,6 +123,7 @@ const InterpolatedMoveTileDefinition = DockTileDefinitionBuilder() .id("aw-interpolated-move") .name("Interpolated Move") .render(() => ) + .requiresOperationEnabled() .build() export const App = () => { @@ -136,8 +139,12 @@ export const App = () => { }), SerialCommunicationsTileDefinition, ConfigEditTileDefinition, - InnoboticsJogModeTileHelper(CartesianJogTileDefinition), - InnoboticsJogModeTileHelper(JointJogTileDefinition), + DockTileDefinitionBuilder(CartesianJogTileDefinition) + .wrap(InnoboticsJogTileWrapper) + .build(), + DockTileDefinitionBuilder(JointJogTileDefinition) + .wrap(InnoboticsJogTileWrapper) + .build(), CartesianDroTileDefinition, JointDroTileDefinition, JointTorqueModesTileDefinition, @@ -153,6 +160,8 @@ export const App = () => { DevInputOverridesTileDefinition, PayloadTileDefinition, InterpolatedMoveTileDefinition, + DigitalInputsTileDefinition, + SafetyDigitalInputsTileDefinition, DigitalOutputsTileDefinition ]} statusBarExtra={} diff --git a/vendors/automationware/apps/awtube-l2/src/main.tsx b/vendors/automationware/apps/awtube-l2/src/main.tsx index 51ef5d95..f768a8b7 100644 --- a/vendors/automationware/apps/awtube-l2/src/main.tsx +++ b/vendors/automationware/apps/awtube-l2/src/main.tsx @@ -19,6 +19,8 @@ import { ToolsGbdbFacetSlice } from "@glowbuzzer/store" +console.log(config) + const persistence: GbdbConfiguration = { // remoteDb: "http://localhost:5984", facets: { diff --git a/vendors/automationware/apps/awtube-urdfviz/src/app.tsx b/vendors/automationware/apps/awtube-urdfviz/src/app.tsx index 273aa839..81129e00 100644 --- a/vendors/automationware/apps/awtube-urdfviz/src/app.tsx +++ b/vendors/automationware/apps/awtube-urdfviz/src/app.tsx @@ -99,7 +99,6 @@ const UrdfTileDefinition = DockTileDefinitionBuilder() .render(() => { return }) - .enableWithoutConnection() .build() export const App = () => { diff --git a/vendors/automationware/apps/awtube-variable/src/app.tsx b/vendors/automationware/apps/awtube-variable/src/app.tsx index fa090cb2..d1352501 100644 --- a/vendors/automationware/apps/awtube-variable/src/app.tsx +++ b/vendors/automationware/apps/awtube-variable/src/app.tsx @@ -64,7 +64,6 @@ const LinkLengthTileDefinition = DockTileDefinitionBuilder() .render(() => { return }) - .enableWithoutConnection() .build() export const App = () => { diff --git a/vendors/automationware/apps/awtube-variable/tsconfig.json b/vendors/automationware/apps/awtube-variable/tsconfig.json index 8c9b0df1..51eb932d 100644 --- a/vendors/automationware/apps/awtube-variable/tsconfig.json +++ b/vendors/automationware/apps/awtube-variable/tsconfig.json @@ -1,9 +1,3 @@ { - "extends": "../../../../tsconfig.base.json", - "compilerOptions": { - "jsx": "react-jsx", - "allowJs": true, - "esModuleInterop": true, - "allowSyntheticDefaultImports": true - } + "extends": "../../tsconfig.aw.json", } diff --git a/vendors/automationware/apps/stewart-aw-piattaforma/src/main.tsx b/vendors/automationware/apps/stewart-aw-piattaforma/src/main.tsx index f10c8ea0..205c52b2 100644 --- a/vendors/automationware/apps/stewart-aw-piattaforma/src/main.tsx +++ b/vendors/automationware/apps/stewart-aw-piattaforma/src/main.tsx @@ -49,7 +49,6 @@ const MechHumanTileDefinition = DockTileDefinitionBuilder() .id("mech-human") .name("Teeth Motion") .placement(2, 0) - .enableWithoutConnection() .render(() => ) .build() @@ -75,7 +74,6 @@ const PointsLoaderTileDefinition = DockTileDefinitionBuilder() .name("Points Loader") .placement(2, 1) .render(() => ) - .enableWithoutConnection() .build() const persistence: GbdbConfiguration = { diff --git a/vendors/automationware/apps/stewart-aw-piattaforma/tsconfig.json b/vendors/automationware/apps/stewart-aw-piattaforma/tsconfig.json index 8c9b0df1..14f13e87 100644 --- a/vendors/automationware/apps/stewart-aw-piattaforma/tsconfig.json +++ b/vendors/automationware/apps/stewart-aw-piattaforma/tsconfig.json @@ -1,9 +1,3 @@ { - "extends": "../../../../tsconfig.base.json", - "compilerOptions": { - "jsx": "react-jsx", - "allowJs": true, - "esModuleInterop": true, - "allowSyntheticDefaultImports": true - } + "extends": "../../tsconfig.aw.json" } diff --git a/vendors/automationware/awlib b/vendors/automationware/awlib index 2787f747..04bf995f 160000 --- a/vendors/automationware/awlib +++ b/vendors/automationware/awlib @@ -1 +1 @@ -Subproject commit 2787f7471c057fe7d403e8a205e3b8e7902c8203 +Subproject commit 04bf995faef27354b3cd699be38c4e44e761e0b6