@viamrobotics/test-widgets 0.15.0 → 0.16.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.
Files changed (139) hide show
  1. package/README.md +15 -1
  2. package/dist/api-docs-href.d.ts +2 -2
  3. package/dist/api-docs-href.js +0 -1
  4. package/dist/components/api-section.svelte +7 -6
  5. package/dist/components/api-section.svelte.d.ts +4 -3
  6. package/dist/components/boundary.svelte +51 -0
  7. package/dist/components/boundary.svelte.d.ts +5 -0
  8. package/dist/components/connection-status.svelte +57 -61
  9. package/dist/components/connection-status.svelte.d.ts +5 -5
  10. package/dist/components/content-rect.svelte +4 -5
  11. package/dist/components/content-rect.svelte.d.ts +2 -1
  12. package/dist/components/error.svelte +6 -5
  13. package/dist/components/error.svelte.d.ts +2 -1
  14. package/dist/components/index.d.ts +0 -1
  15. package/dist/components/index.js +0 -1
  16. package/dist/components/is-moving.svelte +4 -2
  17. package/dist/components/is-moving.svelte.d.ts +2 -1
  18. package/dist/components/maplibre/index.svelte +5 -6
  19. package/dist/components/maplibre/index.svelte.d.ts +3 -1
  20. package/dist/components/mutation-section.svelte +7 -5
  21. package/dist/components/mutation-section.svelte.d.ts +4 -2
  22. package/dist/components/pose-editor.svelte +83 -15
  23. package/dist/components/pose-editor.svelte.d.ts +11 -4
  24. package/dist/components/queries.svelte +7 -4
  25. package/dist/components/queries.svelte.d.ts +2 -1
  26. package/dist/components/query.svelte +4 -3
  27. package/dist/components/query.svelte.d.ts +2 -1
  28. package/dist/components/section/error-key.d.ts +2 -0
  29. package/dist/components/section/error-key.js +2 -0
  30. package/dist/components/section/index.d.ts +19 -0
  31. package/dist/components/section/index.js +19 -0
  32. package/dist/components/section/section-body.svelte +36 -0
  33. package/dist/components/section/section-body.svelte.d.ts +13 -0
  34. package/dist/components/section/section-errors.svelte +18 -0
  35. package/dist/components/section/section-errors.svelte.d.ts +6 -0
  36. package/dist/components/section/section-heading.svelte +21 -0
  37. package/dist/components/section/section-heading.svelte.d.ts +9 -0
  38. package/dist/components/section/section-loading.d.ts +4 -0
  39. package/dist/components/section/section-loading.js +10 -0
  40. package/dist/components/section/section-method.svelte +29 -0
  41. package/dist/components/section/section-method.svelte.d.ts +9 -0
  42. package/dist/components/section/section-placeholder.svelte +29 -0
  43. package/dist/components/section/section-placeholder.svelte.d.ts +7 -0
  44. package/dist/components/section/section-text.svelte +17 -0
  45. package/dist/components/section/section-text.svelte.d.ts +8 -0
  46. package/dist/components/section/section-tooltip.svelte +25 -0
  47. package/dist/components/section/section-tooltip.svelte.d.ts +7 -0
  48. package/dist/components/section/section.svelte +17 -0
  49. package/dist/components/section/section.svelte.d.ts +8 -0
  50. package/dist/components/section/use-section-errors.svelte.d.ts +18 -0
  51. package/dist/components/section/use-section-errors.svelte.js +39 -0
  52. package/dist/components/section-title.svelte +3 -1
  53. package/dist/components/section-title.svelte.d.ts +2 -1
  54. package/dist/components/stop.svelte +31 -14
  55. package/dist/components/stop.svelte.d.ts +6 -1
  56. package/dist/components/widgets/arm/arm.svelte +22 -11
  57. package/dist/components/widgets/arm/get-joint-positions-widget.svelte +1 -1
  58. package/dist/components/widgets/arm/joint-position-editor.svelte +105 -27
  59. package/dist/components/widgets/arm/joint-position-editor.svelte.d.ts +4 -3
  60. package/dist/components/widgets/arm/joint-position-slider.svelte +6 -2
  61. package/dist/components/widgets/arm/joint-position-slider.svelte.d.ts +2 -1
  62. package/dist/components/widgets/arm/manual-mode-widget.svelte +3 -2
  63. package/dist/components/widgets/arm/manual-mode.svelte +2 -2
  64. package/dist/components/widgets/arm/manual-mode.svelte.d.ts +1 -1
  65. package/dist/components/widgets/arm/move-to-joint-positions-widget.svelte +12 -4
  66. package/dist/components/widgets/arm/move-to-joint-positions.svelte +14 -6
  67. package/dist/components/widgets/arm/move-to-position-control.svelte +25 -17
  68. package/dist/components/widgets/arm/move-to-position.svelte +97 -30
  69. package/dist/components/widgets/arm/move-to-position.svelte.d.ts +3 -1
  70. package/dist/components/widgets/arm/use-arm-motion-tracking.svelte.d.ts +16 -0
  71. package/dist/components/widgets/arm/use-arm-motion-tracking.svelte.js +37 -0
  72. package/dist/components/widgets/arm/use-edited-targets.svelte.d.ts +9 -0
  73. package/dist/components/widgets/arm/use-edited-targets.svelte.js +24 -0
  74. package/dist/components/widgets/audio-input/audio-input.svelte +5 -4
  75. package/dist/components/widgets/audio-input/get-properties-widget.svelte +2 -2
  76. package/dist/components/widgets/audio-output/audio-output.svelte +5 -4
  77. package/dist/components/widgets/audio-output/get-properties-widget.svelte +2 -2
  78. package/dist/components/widgets/base/base.svelte +8 -6
  79. package/dist/components/widgets/base/quick-move.svelte +5 -6
  80. package/dist/components/widgets/base/set-power.svelte +6 -4
  81. package/dist/components/widgets/base/set-velocity.svelte +6 -4
  82. package/dist/components/widgets/base/vec3-builder.svelte +3 -2
  83. package/dist/components/widgets/base/vec3-builder.svelte.d.ts +2 -1
  84. package/dist/components/widgets/board/analog-read.svelte +2 -4
  85. package/dist/components/widgets/board/analog-write.svelte +2 -4
  86. package/dist/components/widgets/board/gpio-read.svelte +2 -1
  87. package/dist/components/widgets/board/gpio-write.svelte +2 -1
  88. package/dist/components/widgets/board/pin-section.svelte +5 -6
  89. package/dist/components/widgets/board/pin-section.svelte.d.ts +3 -2
  90. package/dist/components/widgets/camera/camera.svelte +4 -3
  91. package/dist/components/widgets/camera/live-or-polling-video.svelte +22 -22
  92. package/dist/components/widgets/discovery/discovery.svelte +4 -3
  93. package/dist/components/widgets/encoder/encoder.svelte +5 -3
  94. package/dist/components/widgets/encoder/get-position-widget.svelte +1 -1
  95. package/dist/components/widgets/gantry/gantry.svelte +13 -7
  96. package/dist/components/widgets/gantry/get-position-widget.svelte +1 -1
  97. package/dist/components/widgets/gantry/quick-move-widget.svelte +1 -1
  98. package/dist/components/widgets/generic/generic.svelte +4 -1
  99. package/dist/components/widgets/gripper/gripper.svelte +8 -6
  100. package/dist/components/widgets/gripper/is-holding-something.svelte +3 -2
  101. package/dist/components/widgets/input-controller/input-controller.svelte +4 -3
  102. package/dist/components/widgets/ml-model-service/ml-model-service.svelte +1 -1
  103. package/dist/components/widgets/motion/frame-select.svelte +4 -2
  104. package/dist/components/widgets/motion/frame-select.svelte.d.ts +2 -1
  105. package/dist/components/widgets/motion/motion.svelte +9 -5
  106. package/dist/components/widgets/motion/move.svelte +5 -3
  107. package/dist/components/widgets/motor/motor.svelte +12 -10
  108. package/dist/components/widgets/movement-sensor/get-accuracy-widget.svelte +2 -2
  109. package/dist/components/widgets/movement-sensor/get-compass-heading-widget.svelte +2 -2
  110. package/dist/components/widgets/movement-sensor/get-orientation-widget.svelte +2 -2
  111. package/dist/components/widgets/movement-sensor/get-position-widget.svelte +2 -2
  112. package/dist/components/widgets/movement-sensor/movement-sensor.svelte +17 -18
  113. package/dist/components/widgets/power-sensor/get-current-widget.svelte +2 -2
  114. package/dist/components/widgets/power-sensor/get-power-widget.svelte +2 -2
  115. package/dist/components/widgets/power-sensor/get-voltage-widget.svelte +2 -2
  116. package/dist/components/widgets/power-sensor/power-sensor.svelte +13 -11
  117. package/dist/components/widgets/sensor/sensor.svelte +4 -3
  118. package/dist/components/widgets/servo/servo.svelte +9 -4
  119. package/dist/components/widgets/slam/get-position-widget.svelte +2 -2
  120. package/dist/components/widgets/slam/move-on-map.svelte +3 -1
  121. package/dist/components/widgets/slam/slam.svelte +10 -5
  122. package/dist/components/widgets/switch/position-view.svelte +1 -1
  123. package/dist/components/widgets/switch/switch.svelte +1 -1
  124. package/dist/components/widgets/vision-service/detection-row.svelte +4 -2
  125. package/dist/components/widgets/vision-service/detection-row.svelte.d.ts +2 -1
  126. package/dist/components/widgets/vision-service/fonts/public-sans.json +1 -0
  127. package/dist/components/widgets/vision-service/fonts/public-sans.png +0 -0
  128. package/dist/components/widgets/vision-service/image.svelte +4 -4
  129. package/dist/components/widgets/vision-service/legend.svelte +4 -4
  130. package/dist/components/widgets/vision-service/public-sans-font.d.ts +5 -0
  131. package/dist/components/widgets/vision-service/public-sans-font.js +14 -0
  132. package/dist/components/widgets/vision-service/vision-service.svelte +2 -2
  133. package/dist/index.d.ts +1 -1
  134. package/dist/index.js +0 -1
  135. package/package.json +24 -11
  136. package/dist/components/board/pin-section.svelte +0 -28
  137. package/dist/components/board/pin-section.svelte.d.ts +0 -9
  138. package/dist/components/section-group.svelte +0 -64
  139. package/dist/components/section-group.svelte.d.ts +0 -14
@@ -0,0 +1,39 @@
1
+ import { errorKey } from './error-key';
2
+ export const dedupeErrors = (errors) => {
3
+ const present = errors.filter((error) => error !== null);
4
+ return present.filter((error, index) => present.findIndex((seen) => errorKey(seen) === errorKey(error)) === index);
5
+ };
6
+ const serializeErrors = (errors) => errors.map((error) => errorKey(error)).join('\0\0');
7
+ /**
8
+ * A section's distinct errors across its queries and mutations, and whether its first load is
9
+ * still running.
10
+ */
11
+ export const useSectionErrors = (getSources) => {
12
+ let held = [];
13
+ const queryErrors = $derived.by(() => {
14
+ const queries = getSources().queries ?? [];
15
+ const next = dedupeErrors(queries.map((query) => query.error));
16
+ if (next.length > 0) {
17
+ if (serializeErrors(next) !== serializeErrors(held)) {
18
+ held = next;
19
+ }
20
+ }
21
+ else if (queries.every((query) => query.fetchStatus === 'idle')) {
22
+ held = [];
23
+ }
24
+ return held;
25
+ });
26
+ const errors = $derived.by(() => {
27
+ const mutationErrors = (getSources().mutations ?? []).map((mutation) => mutation.error);
28
+ return dedupeErrors([...queryErrors, ...mutationErrors]);
29
+ });
30
+ const isLoading = $derived(errors.length === 0 && (getSources().queries ?? []).some((query) => query.isLoading));
31
+ return {
32
+ get errors() {
33
+ return errors;
34
+ },
35
+ get isLoading() {
36
+ return isLoading;
37
+ },
38
+ };
39
+ };
@@ -3,13 +3,15 @@
3
3
 
4
4
  import { Icon, Tooltip } from '@viamrobotics/prime-core'
5
5
 
6
+ import type { ResourceTriplet } from '../resource-triplet'
7
+
6
8
  import { apiDocsHref } from '../api-docs-href'
7
9
 
8
10
  interface Props {
9
11
  title: string
10
12
  tooltip?: string | undefined
11
13
  /** RDK API string, e.g. "rdk:component:camera". Required — SectionTitle is only for headers that map to an API method; the docs link is built from this plus the title. */
12
- api: string
14
+ api: ResourceTriplet
13
15
  /** Optional external ID for the <h3>; generated internally if omitted */
14
16
  headingId?: string | undefined
15
17
  /** Inline content rendered after the title inside the <h3> (e.g. unit labels) */
@@ -1,9 +1,10 @@
1
1
  import type { Snippet } from 'svelte';
2
+ import type { ResourceTriplet } from '../resource-triplet';
2
3
  interface Props {
3
4
  title: string;
4
5
  tooltip?: string | undefined;
5
6
  /** RDK API string, e.g. "rdk:component:camera". Required — SectionTitle is only for headers that map to an API method; the docs link is built from this plus the title. */
6
- api: string;
7
+ api: ResourceTriplet;
7
8
  /** Optional external ID for the <h3>; generated internally if omitted */
8
9
  headingId?: string | undefined;
9
10
  /** Inline content rendered after the title inside the <h3> (e.g. unit labels) */
@@ -13,24 +13,32 @@
13
13
  Servo,
14
14
  ServoClient,
15
15
  } from '@viamrobotics/sdk'
16
+ import type { Snippet } from 'svelte'
16
17
 
17
18
  import { createResourceClient, createResourceMutation } from '@viamrobotics/svelte-sdk'
18
19
 
20
+ import type { ResourceTriplet } from '../resource-triplet'
21
+
22
+ import ApiSection from './api-section.svelte'
19
23
  import StopButton from './stop-button.svelte'
20
24
 
25
+ type Client =
26
+ | typeof ArmClient
27
+ | typeof BaseClient
28
+ | typeof GantryClient
29
+ | typeof GripperClient
30
+ | typeof MotorClient
31
+ | typeof ServoClient
32
+
21
33
  interface Props {
34
+ client: Client
22
35
  partID: string
23
36
  resourceName: string
24
- client:
25
- | typeof ArmClient
26
- | typeof BaseClient
27
- | typeof GantryClient
28
- | typeof GripperClient
29
- | typeof MotorClient
30
- | typeof ServoClient
37
+ api: ResourceTriplet
38
+ children?: Snippet
31
39
  }
32
40
 
33
- const { partID, resourceName, client: clientClass }: Props = $props()
41
+ const { client: clientClass, partID, resourceName, api, children }: Props = $props()
34
42
 
35
43
  const client = $derived(
36
44
  createResourceClient<Arm | Base | Gantry | Gripper | Motor | Servo>(
@@ -43,9 +51,18 @@
43
51
  const stopMutation = $derived(createResourceMutation(client, 'stop'))
44
52
  </script>
45
53
 
46
- <StopButton
47
- error={stopMutation.error}
48
- onStop={() => {
49
- stopMutation.mutate([])
50
- }}
51
- />
54
+ <ApiSection
55
+ class="grow flex-col gap-4"
56
+ title="Stop"
57
+ {api}
58
+ >
59
+ <StopButton
60
+ error={stopMutation.error}
61
+ onStop={() => {
62
+ stopMutation.mutate([])
63
+ }}
64
+ />
65
+
66
+ <!-- snippet for additional actuation info Ex: Motor's IsPowered & GetPosition -->
67
+ {@render children?.()}
68
+ </ApiSection>
@@ -1,8 +1,13 @@
1
1
  import type { ArmClient, BaseClient, GantryClient, GripperClient, MotorClient, ServoClient } from '@viamrobotics/sdk';
2
+ import type { Snippet } from 'svelte';
3
+ import type { ResourceTriplet } from '../resource-triplet';
4
+ type Client = typeof ArmClient | typeof BaseClient | typeof GantryClient | typeof GripperClient | typeof MotorClient | typeof ServoClient;
2
5
  interface Props {
6
+ client: Client;
3
7
  partID: string;
4
8
  resourceName: string;
5
- client: typeof ArmClient | typeof BaseClient | typeof GantryClient | typeof GripperClient | typeof MotorClient | typeof ServoClient;
9
+ api: ResourceTriplet;
10
+ children?: Snippet;
6
11
  }
7
12
  declare const Stop: import("svelte").Component<Props, {}, "">;
8
13
  type Stop = ReturnType<typeof Stop>;
@@ -11,12 +11,14 @@
11
11
  import IsMoving from '../../is-moving.svelte'
12
12
  import Query from '../../query.svelte'
13
13
  import StopButton from '../../stop-button.svelte'
14
+ import { ResourceTriplets } from '../../../resource-triplet'
14
15
 
15
16
  import GetJointPositions from './get-joint-positions.svelte'
16
17
  import { getJointPositionLimits, type KinematicsJSON } from './joint-position-limits'
17
18
  import ManualModeWidget from './manual-mode-widget.svelte'
18
19
  import MoveToJointPositions from './move-to-joint-positions.svelte'
19
20
  import MoveToPositionControl from './move-to-position-control.svelte'
21
+ import { useArmMotionTracking } from './use-arm-motion-tracking.svelte'
20
22
 
21
23
  interface Props {
22
24
  partID: string
@@ -31,12 +33,17 @@
31
33
  () => resourceName
32
34
  )
33
35
 
34
- const options = { refetchInterval: 500 }
35
- const jointPositionsQuery = createResourceQuery(client, 'getJointPositions', options)
36
- const kinematicsQuery = createResourceQuery(client, 'getKinematics', options)
37
- const isMovingQuery = createResourceQuery(client, 'isMoving', options)
38
-
39
36
  const moveToJointPosMutation = createResourceMutation(client, 'moveToJointPositions')
37
+
38
+ const motionTracking = useArmMotionTracking(client, {
39
+ isMovePending: () => moveToJointPosMutation.isPending,
40
+ refetchPosition: () => jointPositionsQuery.refetch(),
41
+ })
42
+
43
+ const jointPositionsQuery = createResourceQuery(client, 'getJointPositions', () => ({
44
+ refetchInterval: motionTracking.refetchInterval,
45
+ }))
46
+ const kinematicsQuery = createResourceQuery(client, 'getKinematics', { refetchInterval: 500 })
40
47
  const stopMutation = createResourceMutation(client, 'stop')
41
48
 
42
49
  const moveToJointPositions = async (jointPositionsList: number[]) => {
@@ -64,8 +71,9 @@
64
71
  class="flex flex-col gap-4 @2xl:grid @2xl:grow @2xl:grid-cols-2 @2xl:gap-0 @2xl:divide-x @4xl:grid-cols-3"
65
72
  >
66
73
  <ApiSection
74
+ class="grow flex-col gap-4"
67
75
  title="GetJointPositions"
68
- api="rdk:component:arm"
76
+ api={ResourceTriplets.Arm}
69
77
  bottomText="Updates automatically"
70
78
  >
71
79
  <Query query={jointPositionsQuery}>
@@ -75,8 +83,9 @@
75
83
  </Query>
76
84
  </ApiSection>
77
85
  <ApiSection
86
+ class="grow flex-col gap-4"
78
87
  title="MoveToJointPositions"
79
- api="rdk:component:arm"
88
+ api={ResourceTriplets.Arm}
80
89
  >
81
90
  <Query query={jointPositionsQuery}>
82
91
  {#if jointPositionsQuery.data}
@@ -85,14 +94,15 @@
85
94
  {moveToJointPositions}
86
95
  lastError={moveToJointPosMutation.error}
87
96
  {jointLimitsDegrees}
88
- isMoving={isMovingQuery.data ?? false}
97
+ isMoving={motionTracking.isTracking}
89
98
  />
90
99
  {/if}
91
100
  </Query>
92
101
  </ApiSection>
93
102
  <ApiSection
103
+ class="grow flex-col gap-4"
94
104
  title="MoveToPosition"
95
- api="rdk:component:arm"
105
+ api={ResourceTriplets.Arm}
96
106
  >
97
107
  <MoveToPositionControl
98
108
  {partID}
@@ -106,8 +116,9 @@
106
116
  class="flex flex-row gap-4 @2xl:ml-auto @2xl:w-full @2xl:max-w-40 @2xl:flex-col @2xl:gap-0 @2xl:divide-y"
107
117
  >
108
118
  <ApiSection
119
+ class="grow flex-col gap-4"
109
120
  title="Stop"
110
- api="rdk:component:arm"
121
+ api={ResourceTriplets.Arm}
111
122
  >
112
123
  <StopButton
113
124
  error={stopMutation.error}
@@ -118,7 +129,7 @@
118
129
  </ApiSection>
119
130
  <IsMoving
120
131
  client={ArmClient}
121
- api="rdk:component:arm"
132
+ api={ResourceTriplets.Arm}
122
133
  {partID}
123
134
  {resourceName}
124
135
  />
@@ -26,7 +26,7 @@
26
26
  <ApiSection
27
27
  title="GetJointPositions"
28
28
  bottomText="Updates automatically"
29
- class="grow"
29
+ class="grow flex-col gap-4"
30
30
  >
31
31
  <Query {query}>
32
32
  {#if query.data}
@@ -1,45 +1,70 @@
1
1
  <script lang="ts">
2
- import { Button, Icon, Tooltip } from '@viamrobotics/prime-core'
2
+ import { Button, Icon, IconButton, Tooltip } from '@viamrobotics/prime-core'
3
3
 
4
+ import StatusPill from '../../status-pill.svelte'
4
5
  import Table from '../../table.svelte'
6
+ import { degreesToRadians, formatNumeric } from '../../../format'
7
+
8
+ import type { EditedTargets } from './use-edited-targets.svelte'
5
9
 
6
10
  import { type JointLimit } from './joint-position-limits'
7
11
  import JointPositionSlider from './joint-position-slider.svelte'
8
12
 
9
13
  interface Props {
10
- desiredPositions: number[]
14
+ targets: EditedTargets<number>
11
15
  positions: number[]
12
16
  jointLimitsDegrees: JointLimit[]
13
17
  useRadians: boolean
14
- /** Sends the move. Rejects when it fails. */
15
18
  moveToJointPositions: (jointPositions: number[]) => Promise<void>
19
+ isMoving?: boolean
16
20
  }
17
21
 
18
- let {
19
- desiredPositions = $bindable(),
22
+ const {
23
+ targets,
20
24
  positions,
21
25
  jointLimitsDegrees,
22
26
  useRadians,
23
27
  moveToJointPositions,
28
+ isMoving = false,
24
29
  }: Props = $props()
25
30
 
31
+ interface StatusIndicator {
32
+ status: 'info' | 'warn'
33
+ message: string
34
+ }
35
+
26
36
  const getSliderMin = (index: number): number => jointLimitsDegrees[index]?.minDegrees ?? -180
27
37
  const getSliderMax = (index: number): number => jointLimitsDegrees[index]?.maxDegrees ?? 180
28
38
 
39
+ const formatAngle = (degrees: number) =>
40
+ useRadians ? `${formatNumeric(degreesToRadians(degrees))} rad` : `${formatNumeric(degrees)}°`
41
+
42
+ const statusIndicator = (index: number): StatusIndicator | undefined => {
43
+ const drift = targets.drift(index)
44
+ if (drift !== undefined) {
45
+ return {
46
+ status: 'warn',
47
+ message: `Arm moved ${formatAngle(drift)} since you edited joint ${index}.`,
48
+ }
49
+ }
50
+ if (isMoving && targets.isEdited(index)) {
51
+ return { status: 'info', message: 'The arm is moving. Your edit is kept.' }
52
+ }
53
+ return undefined
54
+ }
55
+
29
56
  const execute = async () => {
30
57
  try {
31
- await moveToJointPositions([...desiredPositions])
58
+ await moveToJointPositions(positions.map((_, index) => targets.target(index)))
32
59
  } catch {
33
60
  // The parent renders the failure from the mutation's error state.
34
61
  }
35
62
  }
36
63
 
37
64
  const resetToZero = () => {
38
- desiredPositions = positions.map(() => 0)
39
- }
40
-
41
- const resetToCurrent = () => {
42
- desiredPositions = [...positions]
65
+ for (const index of positions.keys()) {
66
+ targets.edit(index, 0)
67
+ }
43
68
  }
44
69
  </script>
45
70
 
@@ -51,16 +76,52 @@
51
76
  </tr>
52
77
  </thead>
53
78
  <tbody>
54
- {#each [...desiredPositions.keys()] as index (index)}
79
+ {#each [...positions.keys()] as index (index)}
80
+ {@const indicator = statusIndicator(index)}
55
81
  <tr>
56
82
  <th scope="row">{index}</th>
57
83
  <th>
58
- <JointPositionSlider
59
- bind:value={desiredPositions[index]}
60
- minDegrees={getSliderMin(index)}
61
- maxDegrees={getSliderMax(index)}
62
- {useRadians}
63
- />
84
+ <div class="flex flex-col gap-0.5">
85
+ <div class="flex items-center gap-1">
86
+ <div class="min-w-0 grow">
87
+ <JointPositionSlider
88
+ value={targets.target(index)}
89
+ onValueChange={(degrees) => {
90
+ targets.edit(index, degrees)
91
+ }}
92
+ minDegrees={getSliderMin(index)}
93
+ maxDegrees={getSliderMax(index)}
94
+ {useRadians}
95
+ />
96
+ </div>
97
+ {#if indicator}
98
+ <Tooltip>
99
+ <Icon
100
+ name={indicator.status === 'warn' ? 'alert' : 'information'}
101
+ cx={indicator.status === 'warn' ? 'text-warning-bright' : 'text-info-dark'}
102
+ />
103
+ <span slot="description">{indicator.message}</span>
104
+ </Tooltip>
105
+ <!-- The tweakpane slider takes no aria-describedby, so screen readers get the message here. -->
106
+ <span class="sr-only">{indicator.message}</span>
107
+ {/if}
108
+ {#if targets.isEdited(index)}
109
+ <Tooltip>
110
+ <IconButton
111
+ icon="backup-restore"
112
+ label="Reset joint {index} to current"
113
+ onclick={() => {
114
+ targets.reset(index)
115
+ }}
116
+ />
117
+ <span slot="description">Reset joint {index} to its current value</span>
118
+ </Tooltip>
119
+ {/if}
120
+ </div>
121
+ <span class="text-subtle-2 font-roboto-mono text-xs font-normal">
122
+ Current {formatAngle(positions[index] ?? 0)}
123
+ </span>
124
+ </div>
64
125
  </th>
65
126
  </tr>
66
127
  {/each}
@@ -80,15 +141,32 @@
80
141
  </span>
81
142
  <div class="flex flex-col gap-2 sm:flex-row">
82
143
  <Button onclick={resetToZero}>Zero</Button>
83
- <Button onclick={resetToCurrent}>Current position</Button>
144
+ <Button
145
+ onclick={() => {
146
+ targets.resetAll()
147
+ }}
148
+ >
149
+ Current position
150
+ </Button>
84
151
  </div>
85
152
  </div>
86
153
 
87
- <Button
88
- class="mt-auto w-fit"
89
- icon="play-circle-outline"
90
- variant="dark"
91
- onclick={execute}
92
- >
93
- Execute
94
- </Button>
154
+ <div class="mt-auto flex items-center gap-2">
155
+ <Button
156
+ class="w-fit"
157
+ icon="play-circle-outline"
158
+ variant="dark"
159
+ disabled={isMoving}
160
+ onclick={execute}
161
+ >
162
+ Execute
163
+ </Button>
164
+ <span role="status">
165
+ {#if isMoving}
166
+ <StatusPill
167
+ isActive
168
+ activeText="Arm is moving"
169
+ />
170
+ {/if}
171
+ </span>
172
+ </div>
@@ -1,12 +1,13 @@
1
+ import type { EditedTargets } from './use-edited-targets.svelte';
1
2
  import { type JointLimit } from './joint-position-limits';
2
3
  interface Props {
3
- desiredPositions: number[];
4
+ targets: EditedTargets<number>;
4
5
  positions: number[];
5
6
  jointLimitsDegrees: JointLimit[];
6
7
  useRadians: boolean;
7
- /** Sends the move. Rejects when it fails. */
8
8
  moveToJointPositions: (jointPositions: number[]) => Promise<void>;
9
+ isMoving?: boolean;
9
10
  }
10
- declare const JointPositionEditor: import("svelte").Component<Props, {}, "desiredPositions">;
11
+ declare const JointPositionEditor: import("svelte").Component<Props, {}, "">;
11
12
  type JointPositionEditor = ReturnType<typeof JointPositionEditor>;
12
13
  export default JointPositionEditor;
@@ -5,12 +5,13 @@
5
5
 
6
6
  interface Props {
7
7
  value: number
8
+ onValueChange: (degrees: number) => void
8
9
  minDegrees: number
9
10
  maxDegrees: number
10
11
  useRadians: boolean
11
12
  }
12
13
 
13
- let { value = $bindable(), minDegrees, maxDegrees, useRadians }: Props = $props()
14
+ const { value, onValueChange, minDegrees, maxDegrees, useRadians }: Props = $props()
14
15
 
15
16
  const min = $derived(useRadians ? degreesToRadians(minDegrees) : minDegrees)
16
17
  const max = $derived(useRadians ? degreesToRadians(maxDegrees) : maxDegrees)
@@ -25,7 +26,10 @@
25
26
  <Slider
26
27
  value={toDisplay(value)}
27
28
  on:change={(event) => {
28
- value = toDegrees(event.detail.value)
29
+ // The slider also reports changes to `value` from outside, such as a live reading arriving.
30
+ if (event.detail.origin === 'internal') {
31
+ onValueChange(toDegrees(event.detail.value))
32
+ }
29
33
  }}
30
34
  {min}
31
35
  {max}
@@ -1,9 +1,10 @@
1
1
  interface Props {
2
2
  value: number;
3
+ onValueChange: (degrees: number) => void;
3
4
  minDegrees: number;
4
5
  maxDegrees: number;
5
6
  useRadians: boolean;
6
7
  }
7
- declare const JointPositionSlider: import("svelte").Component<Props, {}, "value">;
8
+ declare const JointPositionSlider: import("svelte").Component<Props, {}, "">;
8
9
  type JointPositionSlider = ReturnType<typeof JointPositionSlider>;
9
10
  export default JointPositionSlider;
@@ -7,6 +7,7 @@
7
7
  } from '@viamrobotics/svelte-sdk'
8
8
 
9
9
  import ApiSection from '../../api-section.svelte'
10
+ import { ResourceTriplets } from '../../../resource-triplet'
10
11
 
11
12
  import ManualMode from './manual-mode.svelte'
12
13
 
@@ -57,8 +58,8 @@
57
58
  {:else}
58
59
  <ApiSection
59
60
  title="SetManualMode"
60
- api="rdk:component:arm"
61
- class="grow"
61
+ api={ResourceTriplets.Arm}
62
+ class="grow flex-col gap-4"
62
63
  >
63
64
  <ManualMode
64
65
  isManualMode={manualModeQuery.data ?? false}
@@ -12,14 +12,14 @@
12
12
  title?: string
13
13
  isManualMode: boolean
14
14
  isPending: boolean
15
- setManualMode: (manualMode: boolean, enabledFor: number) => void
16
15
  lastError: Error | null
16
+ setManualMode: (manualMode: boolean, enabledFor: number) => void
17
17
  }
18
18
 
19
19
  const { title, isManualMode, isPending, setManualMode, lastError }: Props = $props()
20
20
 
21
21
  let enabledFor = $state(90)
22
- let enableAfter = $state(20)
22
+ let enableAfter = $state(5)
23
23
  let lastAction = $state<'enter' | 'exit' | undefined>()
24
24
 
25
25
  const countdown = useCountdown(() => {
@@ -3,8 +3,8 @@ interface Props {
3
3
  title?: string;
4
4
  isManualMode: boolean;
5
5
  isPending: boolean;
6
- setManualMode: (manualMode: boolean, enabledFor: number) => void;
7
6
  lastError: Error | null;
7
+ setManualMode: (manualMode: boolean, enabledFor: number) => void;
8
8
  }
9
9
  declare const ManualMode: import("svelte").Component<Props, {}, "">;
10
10
  type ManualMode = ReturnType<typeof ManualMode>;
@@ -10,6 +10,7 @@
10
10
 
11
11
  import { getJointPositionLimits, type KinematicsJSON } from './joint-position-limits'
12
12
  import MoveToJointPositions from './move-to-joint-positions.svelte'
13
+ import { useArmMotionTracking } from './use-arm-motion-tracking.svelte'
13
14
 
14
15
  interface Props {
15
16
  partID: string
@@ -24,15 +25,21 @@
24
25
  () => resourceName
25
26
  )
26
27
 
27
- const jointPositionsQuery = createResourceQuery(client, 'getJointPositions', {
28
- refetchInterval: 500,
28
+ const moveToJointPosMutation = createResourceMutation(client, 'moveToJointPositions')
29
+
30
+ const motionTracking = useArmMotionTracking(client, {
31
+ isMovePending: () => moveToJointPosMutation.isPending,
32
+ refetchPosition: () => jointPositionsQuery.refetch(),
29
33
  })
34
+
35
+ const jointPositionsQuery = createResourceQuery(client, 'getJointPositions', () => ({
36
+ refetchInterval: motionTracking.refetchInterval,
37
+ }))
38
+
30
39
  const kinematicsQuery = createResourceQuery(client, 'getKinematics', {
31
40
  refetchInterval: 500,
32
41
  })
33
42
 
34
- const moveToJointPosMutation = createResourceMutation(client, 'moveToJointPositions')
35
-
36
43
  const moveToJointPositions = async (jointPositionsList: number[]) => {
37
44
  await moveToJointPosMutation.mutateAsync([jointPositionsList])
38
45
  }
@@ -49,6 +56,7 @@
49
56
  {moveToJointPositions}
50
57
  lastError={moveToJointPosMutation.error}
51
58
  {jointLimitsDegrees}
59
+ isMoving={motionTracking.isTracking}
52
60
  />
53
61
  {/if}
54
62
  </Query>
@@ -10,11 +10,15 @@
10
10
  import JointPositionEditor from './joint-position-editor.svelte'
11
11
  import JointPositionJogging from './joint-position-jogging.svelte'
12
12
  import { type JointLimit } from './joint-position-limits'
13
+ import { useEditedTargets } from './use-edited-targets.svelte'
13
14
 
14
15
  type ControlMode = 'Jogging' | 'Joint Positions'
15
16
 
16
17
  const CONTROL_MODES: ControlMode[] = ['Jogging', 'Joint Positions']
17
18
 
19
+ // Tight enough to catch a real move, loose enough to ignore encoder noise.
20
+ const JOINT_DRIFT_DEGREES = 0.5
21
+
18
22
  interface Props {
19
23
  positions: number[]
20
24
  /** Sends the move. Rejects when it fails. */
@@ -32,8 +36,11 @@
32
36
  isMoving = false,
33
37
  }: Props = $props()
34
38
 
35
- // svelte-ignore state_referenced_locally
36
- let desiredPositions = $state([...positions]) // in degrees
39
+ const targets = useEditedTargets<number>(
40
+ (index) => positions[index] ?? 0,
41
+ () => JOINT_DRIFT_DEGREES
42
+ )
43
+ const desiredPositions = $derived(positions.map((_, index) => targets.target(index))) // in degrees
37
44
  let useRadians = $state(false)
38
45
  let controlMode = $state<ControlMode>('Jogging')
39
46
 
@@ -57,10 +64,10 @@
57
64
  const handlePaste = (data: string): boolean => {
58
65
  try {
59
66
  const parsed = JSON.parse(data) as number[]
60
- desiredPositions = parsed.map((pos, i) => {
67
+ for (const [index, pos] of parsed.slice(0, positions.length).entries()) {
61
68
  const degrees = useRadians ? radiansToDegrees(pos) : pos
62
- return Math.min(Math.max(degrees, getJointMin(i)), getJointMax(i))
63
- })
69
+ targets.edit(index, Math.min(Math.max(degrees, getJointMin(index)), getJointMax(index)))
70
+ }
64
71
  } catch {
65
72
  return false
66
73
  }
@@ -111,11 +118,12 @@
111
118
  />
112
119
  {:else}
113
120
  <JointPositionEditor
114
- bind:desiredPositions
121
+ {targets}
115
122
  {positions}
116
123
  {moveToJointPositions}
117
124
  {useRadians}
118
125
  {jointLimitsDegrees}
126
+ {isMoving}
119
127
  />
120
128
  {/if}
121
129