@viamrobotics/test-widgets 0.11.3 → 0.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/refetch-controller.svelte +5 -2
- package/dist/components/refetch-interval-store.svelte.d.ts +1 -1
- package/dist/components/widgets/arm/arm.svelte +7 -20
- package/dist/components/widgets/arm/joint-position-editor.svelte +8 -3
- package/dist/components/widgets/arm/joint-position-editor.svelte.d.ts +2 -1
- package/dist/components/widgets/arm/joint-position-jogging.svelte +216 -0
- package/dist/components/widgets/arm/joint-position-jogging.svelte.d.ts +13 -0
- package/dist/components/widgets/arm/move-control-mode.d.ts +23 -0
- package/dist/components/widgets/arm/move-control-mode.js +26 -0
- package/dist/components/widgets/arm/move-to-joint-positions-widget.svelte +2 -2
- package/dist/components/widgets/arm/move-to-joint-positions.svelte +11 -9
- package/dist/components/widgets/arm/move-to-joint-positions.svelte.d.ts +2 -1
- package/dist/components/widgets/arm/move-to-position-control.svelte +184 -0
- package/dist/components/widgets/arm/move-to-position-control.svelte.d.ts +7 -0
- package/dist/components/widgets/arm/move-to-position-widget.svelte +5 -33
- package/dist/components/widgets/arm/move-to-position.svelte +8 -2
- package/dist/components/widgets/arm/move-to-position.svelte.d.ts +1 -0
- package/dist/components/widgets/arm/useJogQueue.svelte.d.ts +51 -0
- package/dist/components/widgets/arm/useJogQueue.svelte.js +143 -0
- package/dist/components/widgets/camera/camera.svelte +122 -124
- package/dist/components/widgets/camera/export-screenshot.svelte +12 -8
- package/dist/components/widgets/camera/picture-in-picture-button.svelte +13 -12
- package/dist/components/widgets/do-command/create-do-command-client.svelte.d.ts +2 -3
- package/dist/components/widgets/do-command/create-do-command-client.svelte.js +7 -1
- package/dist/components/widgets/do-command/resource-do-command.svelte +3 -3
- package/dist/components/widgets/vision-service/vision-service.svelte +11 -5
- package/dist/registry.js +1 -1
- package/package.json +2 -2
- package/dist/components/widgets/arm/joint-position-quick-move.svelte +0 -85
- package/dist/components/widgets/arm/joint-position-quick-move.svelte.d.ts +0 -9
|
@@ -91,9 +91,12 @@
|
|
|
91
91
|
})
|
|
92
92
|
</script>
|
|
93
93
|
|
|
94
|
-
<div class="text-default flex
|
|
94
|
+
<div class="text-default flex text-xs">
|
|
95
95
|
<div class="w-50 max-w-full">
|
|
96
|
-
<Select
|
|
96
|
+
<Select
|
|
97
|
+
on:change={onChange}
|
|
98
|
+
cx="border-r-0"
|
|
99
|
+
>
|
|
97
100
|
{#each refetchOptions as option (option)}
|
|
98
101
|
<option selected={selectedOption === option}>{option}</option>
|
|
99
102
|
{/each}
|
|
@@ -14,5 +14,5 @@ export declare const RefetchIntervals: {
|
|
|
14
14
|
};
|
|
15
15
|
export type RefetchRate = ValueOf<typeof RefetchRates>;
|
|
16
16
|
export type RefetchInterval = ValueOf<typeof RefetchIntervals>;
|
|
17
|
-
export declare const RefetchRateToInterval: ["Live" | "Refresh every second" | "Refresh every 5 seconds" | "Manual refresh", false | 1000 | 33.3333
|
|
17
|
+
export declare const RefetchRateToInterval: ["Live" | "Refresh every second" | "Refresh every 5 seconds" | "Manual refresh", false | 1000 | 5000 | 33.3333][];
|
|
18
18
|
export declare const createRefetchIntervalStore: (partID: () => string, resourceName: () => string, scope: string, defaultInterval?: RefetchInterval) => PersistedState<RefetchInterval>;
|
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
|
-
import type { Pose } from '@viamrobotics/sdk'
|
|
3
|
-
|
|
4
2
|
import { ArmClient } from '@viamrobotics/sdk'
|
|
5
3
|
import {
|
|
6
4
|
createResourceClient,
|
|
@@ -17,7 +15,7 @@
|
|
|
17
15
|
import GetJointPositions from './get-joint-positions.svelte'
|
|
18
16
|
import { getJointPositionLimits, type KinematicsJSON } from './joint-position-limits'
|
|
19
17
|
import MoveToJointPositions from './move-to-joint-positions.svelte'
|
|
20
|
-
import
|
|
18
|
+
import MoveToPositionControl from './move-to-position-control.svelte'
|
|
21
19
|
|
|
22
20
|
interface Props {
|
|
23
21
|
partID: string
|
|
@@ -34,20 +32,14 @@
|
|
|
34
32
|
|
|
35
33
|
const options = { refetchInterval: 500 }
|
|
36
34
|
const jointPositionsQuery = createResourceQuery(client, 'getJointPositions', options)
|
|
37
|
-
const endPositionQuery = createResourceQuery(client, 'getEndPosition', options)
|
|
38
35
|
const kinematicsQuery = createResourceQuery(client, 'getKinematics', options)
|
|
39
36
|
const isMovingQuery = createResourceQuery(client, 'isMoving', options)
|
|
40
37
|
|
|
41
38
|
const moveToJointPosMutation = createResourceMutation(client, 'moveToJointPositions')
|
|
42
39
|
const stopMutation = createResourceMutation(client, 'stop')
|
|
43
|
-
const moveToPosMutation = createResourceMutation(client, 'moveToPosition')
|
|
44
|
-
|
|
45
|
-
const moveToJointPositions = (jointPositionsList: number[]) => {
|
|
46
|
-
moveToJointPosMutation.mutate([jointPositionsList], {})
|
|
47
|
-
}
|
|
48
40
|
|
|
49
|
-
const
|
|
50
|
-
|
|
41
|
+
const moveToJointPositions = async (jointPositionsList: number[]) => {
|
|
42
|
+
await moveToJointPosMutation.mutateAsync([jointPositionsList])
|
|
51
43
|
}
|
|
52
44
|
|
|
53
45
|
const jointLimitsDegrees = $derived(
|
|
@@ -94,15 +86,10 @@
|
|
|
94
86
|
title="MoveToPosition"
|
|
95
87
|
api="rdk:component:arm"
|
|
96
88
|
>
|
|
97
|
-
<
|
|
98
|
-
{
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
{moveToPosition}
|
|
102
|
-
lastError={moveToPosMutation.error}
|
|
103
|
-
/>
|
|
104
|
-
{/if}
|
|
105
|
-
</Query>
|
|
89
|
+
<MoveToPositionControl
|
|
90
|
+
{partID}
|
|
91
|
+
{resourceName}
|
|
92
|
+
/>
|
|
106
93
|
</ApiSection>
|
|
107
94
|
</div>
|
|
108
95
|
|
|
@@ -11,7 +11,8 @@
|
|
|
11
11
|
positions: number[]
|
|
12
12
|
jointLimitsDegrees: JointLimit[]
|
|
13
13
|
useRadians: boolean
|
|
14
|
-
|
|
14
|
+
/** Sends the move. Rejects when it fails. */
|
|
15
|
+
moveToJointPositions: (jointPositions: number[]) => Promise<void>
|
|
15
16
|
}
|
|
16
17
|
|
|
17
18
|
let {
|
|
@@ -25,8 +26,12 @@
|
|
|
25
26
|
const getSliderMin = (index: number): number => jointLimitsDegrees[index]?.minDegrees ?? -180
|
|
26
27
|
const getSliderMax = (index: number): number => jointLimitsDegrees[index]?.maxDegrees ?? 180
|
|
27
28
|
|
|
28
|
-
const execute = () => {
|
|
29
|
-
|
|
29
|
+
const execute = async () => {
|
|
30
|
+
try {
|
|
31
|
+
await moveToJointPositions([...desiredPositions])
|
|
32
|
+
} catch {
|
|
33
|
+
// The parent renders the failure from the mutation's error state.
|
|
34
|
+
}
|
|
30
35
|
}
|
|
31
36
|
|
|
32
37
|
const resetToZero = () => {
|
|
@@ -4,7 +4,8 @@ interface Props {
|
|
|
4
4
|
positions: number[];
|
|
5
5
|
jointLimitsDegrees: JointLimit[];
|
|
6
6
|
useRadians: boolean;
|
|
7
|
-
|
|
7
|
+
/** Sends the move. Rejects when it fails. */
|
|
8
|
+
moveToJointPositions: (jointPositions: number[]) => Promise<void>;
|
|
8
9
|
}
|
|
9
10
|
declare const JointPositionEditor: import("svelte").Component<Props, {}, "desiredPositions">;
|
|
10
11
|
type JointPositionEditor = ReturnType<typeof JointPositionEditor>;
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import {
|
|
3
|
+
Badge,
|
|
4
|
+
Button,
|
|
5
|
+
Icon,
|
|
6
|
+
type IconName,
|
|
7
|
+
Label,
|
|
8
|
+
Select,
|
|
9
|
+
Tooltip,
|
|
10
|
+
} from '@viamrobotics/prime-core'
|
|
11
|
+
|
|
12
|
+
import { degreesToRadians, formatNumeric } from '../../../format'
|
|
13
|
+
|
|
14
|
+
import type { JointLimit } from './joint-position-limits'
|
|
15
|
+
|
|
16
|
+
import {
|
|
17
|
+
type JogJointRange,
|
|
18
|
+
type JogQueueEntry,
|
|
19
|
+
type JogQueueStatus,
|
|
20
|
+
jogTargetDegrees,
|
|
21
|
+
useJogQueue,
|
|
22
|
+
} from './useJogQueue.svelte'
|
|
23
|
+
|
|
24
|
+
const JOG_STEP_OPTIONS_DEGREES = [1, 5, 10, 15] as const
|
|
25
|
+
type JogStepDegrees = (typeof JOG_STEP_OPTIONS_DEGREES)[number]
|
|
26
|
+
const DEFAULT_JOG_STEP_DEGREES: JogStepDegrees = 5
|
|
27
|
+
|
|
28
|
+
type JogDirection = 'decrease' | 'increase'
|
|
29
|
+
|
|
30
|
+
interface StatusBadge {
|
|
31
|
+
variant: 'pending' | 'progress' | 'success' | 'danger'
|
|
32
|
+
icon?: IconName
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const STATUS_BADGES: Record<JogQueueStatus, StatusBadge> = {
|
|
36
|
+
queuing: { variant: 'pending' },
|
|
37
|
+
sending: { variant: 'progress' },
|
|
38
|
+
sent: { variant: 'success' },
|
|
39
|
+
failed: { variant: 'danger' },
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
interface Props {
|
|
43
|
+
positions: number[]
|
|
44
|
+
/** Per-joint limits a jog target is clamped to. A joint with no entry is not clamped. */
|
|
45
|
+
jointLimitsDegrees: JointLimit[]
|
|
46
|
+
useRadians: boolean
|
|
47
|
+
isMoving: boolean
|
|
48
|
+
/** Sends the move. Rejects when it fails. */
|
|
49
|
+
moveToJointPositions: (jointPositions: number[]) => Promise<void>
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const { positions, jointLimitsDegrees, useRadians, isMoving, moveToJointPositions }: Props =
|
|
53
|
+
$props()
|
|
54
|
+
|
|
55
|
+
let jogStepDegrees = $state<JogStepDegrees>(DEFAULT_JOG_STEP_DEGREES)
|
|
56
|
+
|
|
57
|
+
const queue = useJogQueue({
|
|
58
|
+
send: (targetsByJoint) =>
|
|
59
|
+
moveToJointPositions(
|
|
60
|
+
positions.map((position, index) => targetsByJoint.get(index) ?? position)
|
|
61
|
+
),
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
$effect(() => queue.dispose)
|
|
65
|
+
|
|
66
|
+
const isJointDisabled = (jointIndex: number) =>
|
|
67
|
+
isMoving || queue.entryFor(jointIndex)?.status === 'sending'
|
|
68
|
+
|
|
69
|
+
const formatAngle = (degrees: number) =>
|
|
70
|
+
useRadians ? `${formatNumeric(degreesToRadians(degrees))} rad` : `${formatNumeric(degrees)}°`
|
|
71
|
+
|
|
72
|
+
const rangeFor = (jointIndex: number): JogJointRange => ({
|
|
73
|
+
startDegrees: positions[jointIndex] ?? 0,
|
|
74
|
+
minDegrees: jointLimitsDegrees[jointIndex]?.minDegrees ?? Number.NEGATIVE_INFINITY,
|
|
75
|
+
maxDegrees: jointLimitsDegrees[jointIndex]?.maxDegrees ?? Number.POSITIVE_INFINITY,
|
|
76
|
+
})
|
|
77
|
+
|
|
78
|
+
const stepFor = (direction: JogDirection) =>
|
|
79
|
+
direction === 'decrease' ? -jogStepDegrees : jogStepDegrees
|
|
80
|
+
|
|
81
|
+
const handleStepChange = (event: Event) => {
|
|
82
|
+
if (!(event.target instanceof HTMLSelectElement)) return
|
|
83
|
+
|
|
84
|
+
const selected = Number(event.target.value)
|
|
85
|
+
const step = JOG_STEP_OPTIONS_DEGREES.find((option) => option === selected)
|
|
86
|
+
if (step !== undefined) jogStepDegrees = step
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const handlePointerDown = (event: PointerEvent, jointIndex: number, direction: JogDirection) => {
|
|
90
|
+
if (isJointDisabled(jointIndex) || event.button !== 0) return
|
|
91
|
+
|
|
92
|
+
queue.beginHold(jointIndex, stepFor(direction), rangeFor(jointIndex))
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// Keyboard and assistive-technology activation arrive as a click with `detail` 0. Pointer
|
|
96
|
+
// clicks are already counted by the pointer handlers, so they are skipped here.
|
|
97
|
+
const handleClick = (event: MouseEvent, jointIndex: number, direction: JogDirection) => {
|
|
98
|
+
if (isJointDisabled(jointIndex) || event.detail !== 0) return
|
|
99
|
+
|
|
100
|
+
queue.tap(jointIndex, stepFor(direction), rangeFor(jointIndex))
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const formatTarget = (entry: JogQueueEntry) => formatAngle(jogTargetDegrees(entry))
|
|
104
|
+
|
|
105
|
+
const describeEntry = (entry: JogQueueEntry) => {
|
|
106
|
+
const target = formatTarget(entry)
|
|
107
|
+
switch (entry.status) {
|
|
108
|
+
case 'queuing': {
|
|
109
|
+
return `Joint ${entry.jointIndex} will move to ${target}`
|
|
110
|
+
}
|
|
111
|
+
case 'sending': {
|
|
112
|
+
return `Moving joint ${entry.jointIndex} to ${target}`
|
|
113
|
+
}
|
|
114
|
+
case 'sent': {
|
|
115
|
+
return `Joint ${entry.jointIndex} moved to ${target}`
|
|
116
|
+
}
|
|
117
|
+
case 'failed': {
|
|
118
|
+
return `Move of joint ${entry.jointIndex} to ${target} failed`
|
|
119
|
+
}
|
|
120
|
+
default: {
|
|
121
|
+
const exhaustive: never = entry.status
|
|
122
|
+
return exhaustive
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
</script>
|
|
127
|
+
|
|
128
|
+
{#snippet jogButton(jointIndex: number, direction: JogDirection)}
|
|
129
|
+
<Tooltip
|
|
130
|
+
hoverDelayMS={400}
|
|
131
|
+
targetClass="inline-flex"
|
|
132
|
+
>
|
|
133
|
+
<Button
|
|
134
|
+
aria-label="{direction === 'decrease'
|
|
135
|
+
? 'Decrease'
|
|
136
|
+
: 'Increase'} joint {jointIndex} by {jogStepDegrees} degrees"
|
|
137
|
+
disabled={isJointDisabled(jointIndex)}
|
|
138
|
+
onpointerdown={(event) => handlePointerDown(event, jointIndex, direction)}
|
|
139
|
+
onpointerup={queue.endHold}
|
|
140
|
+
onpointerleave={queue.endHold}
|
|
141
|
+
onpointercancel={queue.endHold}
|
|
142
|
+
onclick={(event) => handleClick(event, jointIndex, direction)}
|
|
143
|
+
>
|
|
144
|
+
{direction === 'decrease' ? '−' : '+'}{jogStepDegrees}°
|
|
145
|
+
</Button>
|
|
146
|
+
<span slot="description">
|
|
147
|
+
Tap or hold to {direction === 'decrease' ? 'subtract' : 'add'}
|
|
148
|
+
{jogStepDegrees}°
|
|
149
|
+
</span>
|
|
150
|
+
</Tooltip>
|
|
151
|
+
{/snippet}
|
|
152
|
+
|
|
153
|
+
<div class="flex flex-col gap-x-4 gap-y-2">
|
|
154
|
+
<Label position="left">
|
|
155
|
+
<span class="w-12"> Jog step</span>
|
|
156
|
+
<Select
|
|
157
|
+
slot="input"
|
|
158
|
+
value={String(jogStepDegrees)}
|
|
159
|
+
on:change={handleStepChange}
|
|
160
|
+
>
|
|
161
|
+
{#each JOG_STEP_OPTIONS_DEGREES as step (step)}
|
|
162
|
+
<option value={String(step)}>{step}°</option>
|
|
163
|
+
{/each}
|
|
164
|
+
</Select>
|
|
165
|
+
</Label>
|
|
166
|
+
<Tooltip>
|
|
167
|
+
<span class="flex items-center gap-1 text-xs text-amber-600">
|
|
168
|
+
<Icon
|
|
169
|
+
name="alert"
|
|
170
|
+
size="sm"
|
|
171
|
+
cx="text-amber-600"
|
|
172
|
+
/>
|
|
173
|
+
Jogging executes immediately on release
|
|
174
|
+
</span>
|
|
175
|
+
<span slot="description">
|
|
176
|
+
Jog buttons send a move to the arm as soon as you release them. There is no confirm step.
|
|
177
|
+
Buttons are disabled while the arm is moving.
|
|
178
|
+
</span>
|
|
179
|
+
</Tooltip>
|
|
180
|
+
</div>
|
|
181
|
+
|
|
182
|
+
<ul class="flex flex-col divide-y">
|
|
183
|
+
{#each positions as position, index (index)}
|
|
184
|
+
{@const entry = queue.entryFor(index)}
|
|
185
|
+
<!-- flex-wrap with a stepper that keeps its min-content width: it drops under the label only when the row is too narrow for both. -->
|
|
186
|
+
<li class="flex flex-wrap items-center gap-x-3 gap-y-1.5 py-1.5">
|
|
187
|
+
<span class="font-roboto-mono text-subtle-1 w-14 shrink-0 text-xs">Joint {index}</span>
|
|
188
|
+
<div class="flex flex-1 items-center gap-1.5">
|
|
189
|
+
{@render jogButton(index, 'decrease')}
|
|
190
|
+
<!-- The badge overlays the readout so the row keeps one width in the narrow three-column card. -->
|
|
191
|
+
<span class="grid min-w-20 flex-1 items-center justify-center">
|
|
192
|
+
{#if entry}
|
|
193
|
+
<span
|
|
194
|
+
role="status"
|
|
195
|
+
class="row-start-1l col-start-1"
|
|
196
|
+
>
|
|
197
|
+
<span aria-hidden="true">
|
|
198
|
+
<Badge
|
|
199
|
+
label={formatTarget(entry)}
|
|
200
|
+
cx="font-roboto-mono tabular-nums"
|
|
201
|
+
{...STATUS_BADGES[entry.status]}
|
|
202
|
+
/>
|
|
203
|
+
</span>
|
|
204
|
+
<span class="sr-only">{describeEntry(entry)}</span>
|
|
205
|
+
</span>
|
|
206
|
+
{:else}
|
|
207
|
+
<span class="font-roboto-mono col-start-1 row-start-1 text-xs tabular-nums">
|
|
208
|
+
{formatAngle(position)}
|
|
209
|
+
</span>
|
|
210
|
+
{/if}
|
|
211
|
+
</span>
|
|
212
|
+
{@render jogButton(index, 'increase')}
|
|
213
|
+
</div>
|
|
214
|
+
</li>
|
|
215
|
+
{/each}
|
|
216
|
+
</ul>
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { JointLimit } from './joint-position-limits';
|
|
2
|
+
interface Props {
|
|
3
|
+
positions: number[];
|
|
4
|
+
/** Per-joint limits a jog target is clamped to. A joint with no entry is not clamped. */
|
|
5
|
+
jointLimitsDegrees: JointLimit[];
|
|
6
|
+
useRadians: boolean;
|
|
7
|
+
isMoving: boolean;
|
|
8
|
+
/** Sends the move. Rejects when it fails. */
|
|
9
|
+
moveToJointPositions: (jointPositions: number[]) => Promise<void>;
|
|
10
|
+
}
|
|
11
|
+
declare const JointPositionJogging: import("svelte").Component<Props, {}, "">;
|
|
12
|
+
type JointPositionJogging = ReturnType<typeof JointPositionJogging>;
|
|
13
|
+
export default JointPositionJogging;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { type FrameConfigEntry } from '../motion/frame-system-config';
|
|
2
|
+
/** How the arm MoveToPosition widget executes a move. */
|
|
3
|
+
export type MoveControlMode = 'motion' | 'direct';
|
|
4
|
+
/**
|
|
5
|
+
* Whether the widget can offer motion planning for `resourceName`.
|
|
6
|
+
*
|
|
7
|
+
* The machine needs a motion service, and the arm needs a frame in the machine's frame system.
|
|
8
|
+
* rdk leaves a component configured without a `frame` out of the frame system entirely, and
|
|
9
|
+
* neither `GetPose` nor a motion `Move` can resolve an arm it cannot find there.
|
|
10
|
+
*/
|
|
11
|
+
export declare const canPlanMotion: (motionServiceNames: string[], frameSystem: FrameConfigEntry[], resourceName: string) => boolean;
|
|
12
|
+
/**
|
|
13
|
+
* The motion service a `Move` call targets: `builtin` when present, otherwise
|
|
14
|
+
* the first discovered service.
|
|
15
|
+
*
|
|
16
|
+
* @returns The service name, or `undefined` when the machine has no motion service.
|
|
17
|
+
*/
|
|
18
|
+
export declare const moveMotionServiceName: (motionServiceNames: string[]) => string | undefined;
|
|
19
|
+
/**
|
|
20
|
+
* The selectable motion services for the service select: `builtin` first when
|
|
21
|
+
* present, the rest alphabetical.
|
|
22
|
+
*/
|
|
23
|
+
export declare const motionServiceOptions: (motionServiceNames: string[]) => string[];
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { movableFrameNames } from '../motion/frame-system-config';
|
|
2
|
+
/**
|
|
3
|
+
* Whether the widget can offer motion planning for `resourceName`.
|
|
4
|
+
*
|
|
5
|
+
* The machine needs a motion service, and the arm needs a frame in the machine's frame system.
|
|
6
|
+
* rdk leaves a component configured without a `frame` out of the frame system entirely, and
|
|
7
|
+
* neither `GetPose` nor a motion `Move` can resolve an arm it cannot find there.
|
|
8
|
+
*/
|
|
9
|
+
export const canPlanMotion = (motionServiceNames, frameSystem, resourceName) => motionServiceNames.length > 0 && movableFrameNames(frameSystem).includes(resourceName);
|
|
10
|
+
/**
|
|
11
|
+
* The motion service a `Move` call targets: `builtin` when present, otherwise
|
|
12
|
+
* the first discovered service.
|
|
13
|
+
*
|
|
14
|
+
* @returns The service name, or `undefined` when the machine has no motion service.
|
|
15
|
+
*/
|
|
16
|
+
export const moveMotionServiceName = (motionServiceNames) => motionServiceNames.includes('builtin') ? 'builtin' : motionServiceNames[0];
|
|
17
|
+
/**
|
|
18
|
+
* The selectable motion services for the service select: `builtin` first when
|
|
19
|
+
* present, the rest alphabetical.
|
|
20
|
+
*/
|
|
21
|
+
export const motionServiceOptions = (motionServiceNames) => {
|
|
22
|
+
const others = motionServiceNames
|
|
23
|
+
.filter((name) => name !== 'builtin')
|
|
24
|
+
.toSorted((a, b) => a.localeCompare(b));
|
|
25
|
+
return motionServiceNames.includes('builtin') ? ['builtin', ...others] : others;
|
|
26
|
+
};
|
|
@@ -33,8 +33,8 @@
|
|
|
33
33
|
|
|
34
34
|
const moveToJointPosMutation = createResourceMutation(client, 'moveToJointPositions')
|
|
35
35
|
|
|
36
|
-
const moveToJointPositions = (jointPositionsList: number[]) => {
|
|
37
|
-
moveToJointPosMutation.
|
|
36
|
+
const moveToJointPositions = async (jointPositionsList: number[]) => {
|
|
37
|
+
await moveToJointPosMutation.mutateAsync([jointPositionsList])
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
const jointLimitsDegrees = $derived(
|
|
@@ -8,16 +8,17 @@
|
|
|
8
8
|
import { degreesToRadians, formatNumeric, radiansToDegrees } from '../../../format'
|
|
9
9
|
|
|
10
10
|
import JointPositionEditor from './joint-position-editor.svelte'
|
|
11
|
+
import JointPositionJogging from './joint-position-jogging.svelte'
|
|
11
12
|
import { type JointLimit } from './joint-position-limits'
|
|
12
|
-
import JointPositionQuickMove from './joint-position-quick-move.svelte'
|
|
13
13
|
|
|
14
|
-
type ControlMode = '
|
|
14
|
+
type ControlMode = 'Jogging' | 'Joint Positions'
|
|
15
15
|
|
|
16
|
-
const CONTROL_MODES: ControlMode[] = ['
|
|
16
|
+
const CONTROL_MODES: ControlMode[] = ['Jogging', 'Joint Positions']
|
|
17
17
|
|
|
18
18
|
interface Props {
|
|
19
19
|
positions: number[]
|
|
20
|
-
|
|
20
|
+
/** Sends the move. Rejects when it fails. */
|
|
21
|
+
moveToJointPositions: (jointPositions: number[]) => Promise<void>
|
|
21
22
|
lastError: Error | null
|
|
22
23
|
jointLimitsDegrees: JointLimit[]
|
|
23
24
|
isMoving?: boolean
|
|
@@ -34,9 +35,9 @@
|
|
|
34
35
|
// svelte-ignore state_referenced_locally
|
|
35
36
|
let desiredPositions = $state([...positions]) // in degrees
|
|
36
37
|
let useRadians = $state(false)
|
|
37
|
-
let controlMode = $state<ControlMode>('
|
|
38
|
+
let controlMode = $state<ControlMode>('Jogging')
|
|
38
39
|
|
|
39
|
-
const
|
|
40
|
+
const isJoggingMode = $derived(controlMode === 'Jogging')
|
|
40
41
|
|
|
41
42
|
const getJointMin = (index: number): number => jointLimitsDegrees[index]?.minDegrees ?? -180
|
|
42
43
|
const getJointMax = (index: number): number => jointLimitsDegrees[index]?.maxDegrees ?? 180
|
|
@@ -77,7 +78,7 @@
|
|
|
77
78
|
on:input={handleModeChange}
|
|
78
79
|
/>
|
|
79
80
|
<div class="flex items-center gap-1">
|
|
80
|
-
{#if !
|
|
81
|
+
{#if !isJoggingMode}
|
|
81
82
|
<Tooltip>
|
|
82
83
|
<Icon
|
|
83
84
|
name="information-outline"
|
|
@@ -100,10 +101,11 @@
|
|
|
100
101
|
</div>
|
|
101
102
|
</div>
|
|
102
103
|
|
|
103
|
-
{#if
|
|
104
|
-
<
|
|
104
|
+
{#if isJoggingMode}
|
|
105
|
+
<JointPositionJogging
|
|
105
106
|
{positions}
|
|
106
107
|
{moveToJointPositions}
|
|
108
|
+
{jointLimitsDegrees}
|
|
107
109
|
{useRadians}
|
|
108
110
|
{isMoving}
|
|
109
111
|
/>
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { type JointLimit } from './joint-position-limits';
|
|
2
2
|
interface Props {
|
|
3
3
|
positions: number[];
|
|
4
|
-
|
|
4
|
+
/** Sends the move. Rejects when it fails. */
|
|
5
|
+
moveToJointPositions: (jointPositions: number[]) => Promise<void>;
|
|
5
6
|
lastError: Error | null;
|
|
6
7
|
jointLimitsDegrees: JointLimit[];
|
|
7
8
|
isMoving?: boolean;
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { Banner, Icon, Label, Select, ToggleButtons, Tooltip } from '@viamrobotics/prime-core'
|
|
3
|
+
import { ArmClient, MotionClient, type Pose, type RobotClient } from '@viamrobotics/sdk'
|
|
4
|
+
import {
|
|
5
|
+
createResourceClient,
|
|
6
|
+
createResourceMutation,
|
|
7
|
+
createResourceQuery,
|
|
8
|
+
createRobotQuery,
|
|
9
|
+
useResourceStatuses,
|
|
10
|
+
useRobotClient,
|
|
11
|
+
} from '@viamrobotics/svelte-sdk'
|
|
12
|
+
|
|
13
|
+
import Queries from '../../queries.svelte'
|
|
14
|
+
|
|
15
|
+
import {
|
|
16
|
+
canPlanMotion,
|
|
17
|
+
motionServiceOptions,
|
|
18
|
+
type MoveControlMode,
|
|
19
|
+
moveMotionServiceName,
|
|
20
|
+
} from './move-control-mode'
|
|
21
|
+
import MoveToPosition from './move-to-position.svelte'
|
|
22
|
+
|
|
23
|
+
interface Props {
|
|
24
|
+
partID: string
|
|
25
|
+
resourceName: string
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const { partID, resourceName }: Props = $props()
|
|
29
|
+
|
|
30
|
+
// Both modes read the live pose back at this rate, so `Current position` is never stale.
|
|
31
|
+
const POSE_REFETCH_INTERVAL_MS = 500
|
|
32
|
+
const FRAME_SYSTEM_REFETCH_INTERVAL_MS = 5000
|
|
33
|
+
|
|
34
|
+
const motionServices = useResourceStatuses(() => partID, 'motion')
|
|
35
|
+
const motionServiceNames = $derived(
|
|
36
|
+
motionServices.current
|
|
37
|
+
.map((service) => service.name?.name)
|
|
38
|
+
.filter((name): name is string => name !== undefined)
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
const robotClient = useRobotClient(() => partID)
|
|
42
|
+
const frameSystemQuery = createRobotQuery(robotClient, 'frameSystemConfig', () => ({
|
|
43
|
+
refetchInterval: FRAME_SYSTEM_REFETCH_INTERVAL_MS,
|
|
44
|
+
}))
|
|
45
|
+
const frameSystem = $derived(frameSystemQuery.data)
|
|
46
|
+
const hasMotionService = $derived(motionServiceNames.length > 0)
|
|
47
|
+
const motionAvailable = $derived(
|
|
48
|
+
frameSystem !== undefined && canPlanMotion(motionServiceNames, frameSystem, resourceName)
|
|
49
|
+
)
|
|
50
|
+
|
|
51
|
+
let userChoice = $state<MoveControlMode>()
|
|
52
|
+
const mode = $derived<MoveControlMode>(motionAvailable ? (userChoice ?? 'motion') : 'direct')
|
|
53
|
+
|
|
54
|
+
let userServiceChoice = $state<string>()
|
|
55
|
+
const activeMotionServiceName = $derived(
|
|
56
|
+
userServiceChoice ?? moveMotionServiceName(motionServiceNames)
|
|
57
|
+
)
|
|
58
|
+
const serviceOptions = $derived(motionServiceOptions(motionServiceNames))
|
|
59
|
+
const showServiceSelect = $derived(mode === 'motion' && serviceOptions.length > 1)
|
|
60
|
+
|
|
61
|
+
const armClient = createResourceClient(
|
|
62
|
+
ArmClient,
|
|
63
|
+
() => partID,
|
|
64
|
+
() => resourceName
|
|
65
|
+
)
|
|
66
|
+
const motionClient = createResourceClient(
|
|
67
|
+
MotionClient,
|
|
68
|
+
() => partID,
|
|
69
|
+
() => activeMotionServiceName ?? ''
|
|
70
|
+
)
|
|
71
|
+
|
|
72
|
+
// Pre-fill the editor with the arm's current pose, in the frame the active mode sends to.
|
|
73
|
+
const poseArgs = $derived<Parameters<RobotClient['getPose']>>([resourceName, 'world', []])
|
|
74
|
+
const poseQuery = createRobotQuery(
|
|
75
|
+
robotClient,
|
|
76
|
+
'getPose',
|
|
77
|
+
() => poseArgs,
|
|
78
|
+
() => ({ refetchInterval: POSE_REFETCH_INTERVAL_MS, enabled: mode === 'motion' })
|
|
79
|
+
)
|
|
80
|
+
const endPositionQuery = createResourceQuery(armClient, 'getEndPosition', () => ({
|
|
81
|
+
refetchInterval: POSE_REFETCH_INTERVAL_MS,
|
|
82
|
+
enabled: mode === 'direct',
|
|
83
|
+
}))
|
|
84
|
+
|
|
85
|
+
const activeQuery = $derived(mode === 'motion' ? poseQuery : endPositionQuery)
|
|
86
|
+
const endPosition = $derived(mode === 'motion' ? poseQuery.data?.pose : endPositionQuery.data)
|
|
87
|
+
|
|
88
|
+
const moveMutation = createResourceMutation(motionClient, 'move')
|
|
89
|
+
const moveToPosMutation = createResourceMutation(armClient, 'moveToPosition')
|
|
90
|
+
const lastError = $derived(mode === 'motion' ? moveMutation.error : moveToPosMutation.error)
|
|
91
|
+
|
|
92
|
+
const description = $derived(
|
|
93
|
+
mode === 'motion'
|
|
94
|
+
? 'Pose is in the world frame, as required by the motion service.'
|
|
95
|
+
: 'Pose is with respect to the arm origin and does not take into account the motion service or frame system.'
|
|
96
|
+
)
|
|
97
|
+
|
|
98
|
+
const handleModeInput = (event: CustomEvent<string>) => {
|
|
99
|
+
userChoice = event.detail === 'Motion service' ? 'motion' : 'direct'
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
const handleServiceChange = (event: Event) => {
|
|
103
|
+
if (event.target instanceof HTMLSelectElement) {
|
|
104
|
+
userServiceChoice = event.target.value
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
const moveToPosition = (position: Pose) => {
|
|
109
|
+
if (mode === 'motion') {
|
|
110
|
+
moveMutation.mutate([{ referenceFrame: 'world', pose: position }, resourceName], {})
|
|
111
|
+
} else {
|
|
112
|
+
moveToPosMutation.mutate([position], {})
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
</script>
|
|
116
|
+
|
|
117
|
+
<div class="flex flex-col gap-4">
|
|
118
|
+
{#if motionAvailable}
|
|
119
|
+
<Label position="top">
|
|
120
|
+
<span class="flex items-center gap-1 text-xs">
|
|
121
|
+
Control mode
|
|
122
|
+
<Tooltip>
|
|
123
|
+
<Icon
|
|
124
|
+
name="information-outline"
|
|
125
|
+
size="sm"
|
|
126
|
+
/>
|
|
127
|
+
<span slot="description">
|
|
128
|
+
Using a motion service will include motion planning and obstacle avoidance. Direct arm
|
|
129
|
+
control will move the arm without any planning and regardless of obstacles.
|
|
130
|
+
</span>
|
|
131
|
+
</Tooltip>
|
|
132
|
+
</span>
|
|
133
|
+
|
|
134
|
+
<ToggleButtons
|
|
135
|
+
slot="input"
|
|
136
|
+
options={['Motion service', 'Arm']}
|
|
137
|
+
selected={mode === 'motion' ? 'Motion service' : 'Arm'}
|
|
138
|
+
on:input={handleModeInput}
|
|
139
|
+
/>
|
|
140
|
+
</Label>
|
|
141
|
+
{/if}
|
|
142
|
+
{#if showServiceSelect}
|
|
143
|
+
<Label>
|
|
144
|
+
Motion service name
|
|
145
|
+
|
|
146
|
+
<Select
|
|
147
|
+
slot="input"
|
|
148
|
+
value={activeMotionServiceName ?? ''}
|
|
149
|
+
on:change={handleServiceChange}
|
|
150
|
+
>
|
|
151
|
+
{#each serviceOptions as name (name)}
|
|
152
|
+
<option value={name}>{name}</option>
|
|
153
|
+
{/each}
|
|
154
|
+
</Select>
|
|
155
|
+
</Label>
|
|
156
|
+
{/if}
|
|
157
|
+
{#if frameSystem !== undefined}
|
|
158
|
+
<Banner variant={mode === 'motion' ? 'info' : 'danger'}>
|
|
159
|
+
{#snippet subtitle()}
|
|
160
|
+
{#if mode === 'motion'}
|
|
161
|
+
Movement goes through motion planning and attempts to avoid obstacles.
|
|
162
|
+
{:else if hasMotionService && !motionAvailable}
|
|
163
|
+
{resourceName} has no frame, so the motion service cannot plan for it. The arm will not avoid
|
|
164
|
+
obstacles when moving. Use with caution.
|
|
165
|
+
{:else}
|
|
166
|
+
The arm will not avoid obstacles when moving. Use with caution.
|
|
167
|
+
{/if}
|
|
168
|
+
{/snippet}
|
|
169
|
+
</Banner>
|
|
170
|
+
{/if}
|
|
171
|
+
<Queries queries={[frameSystemQuery, activeQuery]}>
|
|
172
|
+
<!-- Re-seed the editor on a mode change: the two modes report the pose in different frames. -->
|
|
173
|
+
{#key mode}
|
|
174
|
+
{#if endPosition}
|
|
175
|
+
<MoveToPosition
|
|
176
|
+
{endPosition}
|
|
177
|
+
{moveToPosition}
|
|
178
|
+
{lastError}
|
|
179
|
+
{description}
|
|
180
|
+
/>
|
|
181
|
+
{/if}
|
|
182
|
+
{/key}
|
|
183
|
+
</Queries>
|
|
184
|
+
</div>
|