@viamrobotics/test-widgets 0.15.1 → 0.17.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 (200) 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 +58 -49
  5. package/dist/components/api-section.svelte.d.ts +24 -10
  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 +10 -5
  11. package/dist/components/content-rect.svelte.d.ts +3 -1
  12. package/dist/components/error.svelte +15 -5
  13. package/dist/components/error.svelte.d.ts +8 -1
  14. package/dist/components/index.d.ts +4 -3
  15. package/dist/components/index.js +4 -3
  16. package/dist/components/is-moving.svelte +29 -35
  17. package/dist/components/is-moving.svelte.d.ts +6 -6
  18. package/dist/components/maplibre/index.svelte +5 -6
  19. package/dist/components/maplibre/index.svelte.d.ts +3 -1
  20. package/dist/components/pose-editor.svelte +83 -15
  21. package/dist/components/pose-editor.svelte.d.ts +11 -4
  22. package/dist/components/progress.svelte +1 -0
  23. package/dist/components/queries.svelte +14 -4
  24. package/dist/components/queries.svelte.d.ts +6 -1
  25. package/dist/components/query.svelte +11 -3
  26. package/dist/components/query.svelte.d.ts +6 -1
  27. package/dist/components/section/error-key.d.ts +2 -0
  28. package/dist/components/section/error-key.js +2 -0
  29. package/dist/components/section/index.d.ts +21 -0
  30. package/dist/components/section/index.js +21 -0
  31. package/dist/components/section/section-body.svelte +36 -0
  32. package/dist/components/section/section-body.svelte.d.ts +13 -0
  33. package/dist/components/section/section-error-reporter.d.ts +8 -0
  34. package/dist/components/section/section-error-reporter.js +7 -0
  35. package/dist/components/section/section-error.svelte +36 -0
  36. package/dist/components/section/section-error.svelte.d.ts +9 -0
  37. package/dist/components/section/section-errors.svelte +145 -0
  38. package/dist/components/section/section-errors.svelte.d.ts +6 -0
  39. package/dist/components/section/section-heading.svelte +21 -0
  40. package/dist/components/section/section-heading.svelte.d.ts +9 -0
  41. package/dist/components/section/section-loading.d.ts +4 -0
  42. package/dist/components/section/section-loading.js +10 -0
  43. package/dist/components/section/section-method.svelte +29 -0
  44. package/dist/components/section/section-method.svelte.d.ts +9 -0
  45. package/dist/components/section/section-placeholder.svelte +29 -0
  46. package/dist/components/section/section-placeholder.svelte.d.ts +7 -0
  47. package/dist/components/section/section-text.svelte +17 -0
  48. package/dist/components/section/section-text.svelte.d.ts +8 -0
  49. package/dist/components/section/section-tooltip.svelte +25 -0
  50. package/dist/components/section/section-tooltip.svelte.d.ts +7 -0
  51. package/dist/components/section/section.svelte +23 -0
  52. package/dist/components/section/section.svelte.d.ts +11 -0
  53. package/dist/components/section/use-section-errors.svelte.d.ts +19 -0
  54. package/dist/components/section/use-section-errors.svelte.js +49 -0
  55. package/dist/components/stop-button.svelte +1 -5
  56. package/dist/components/stop-button.svelte.d.ts +0 -1
  57. package/dist/components/stop.svelte +31 -14
  58. package/dist/components/stop.svelte.d.ts +6 -1
  59. package/dist/components/widgets/arm/arm.svelte +43 -40
  60. package/dist/components/widgets/arm/get-joint-positions-widget.svelte +10 -9
  61. package/dist/components/widgets/arm/joint-position-editor.svelte +105 -27
  62. package/dist/components/widgets/arm/joint-position-editor.svelte.d.ts +4 -3
  63. package/dist/components/widgets/arm/joint-position-slider.svelte +6 -2
  64. package/dist/components/widgets/arm/joint-position-slider.svelte.d.ts +2 -1
  65. package/dist/components/widgets/arm/manual-mode-widget.svelte +16 -6
  66. package/dist/components/widgets/arm/manual-mode.svelte +1 -5
  67. package/dist/components/widgets/arm/manual-mode.svelte.d.ts +0 -1
  68. package/dist/components/widgets/arm/move-to-joint-positions-widget.svelte +22 -8
  69. package/dist/components/widgets/arm/move-to-joint-positions.svelte +15 -17
  70. package/dist/components/widgets/arm/move-to-joint-positions.svelte.d.ts +0 -1
  71. package/dist/components/widgets/arm/move-to-position-control.svelte +45 -33
  72. package/dist/components/widgets/arm/move-to-position.svelte +97 -34
  73. package/dist/components/widgets/arm/move-to-position.svelte.d.ts +3 -2
  74. package/dist/components/widgets/arm/quick-move-widget.svelte +10 -4
  75. package/dist/components/widgets/arm/quick-move.svelte +1 -4
  76. package/dist/components/widgets/arm/quick-move.svelte.d.ts +0 -1
  77. package/dist/components/widgets/arm/use-arm-motion-tracking.svelte.d.ts +16 -0
  78. package/dist/components/widgets/arm/use-arm-motion-tracking.svelte.js +37 -0
  79. package/dist/components/widgets/arm/use-edited-targets.svelte.d.ts +9 -0
  80. package/dist/components/widgets/arm/use-edited-targets.svelte.js +24 -0
  81. package/dist/components/widgets/audio-input/audio-input.svelte +80 -77
  82. package/dist/components/widgets/audio-input/get-properties-widget.svelte +16 -16
  83. package/dist/components/widgets/audio-output/audio-output.svelte +87 -84
  84. package/dist/components/widgets/audio-output/get-properties-widget.svelte +16 -16
  85. package/dist/components/widgets/base/base.svelte +78 -43
  86. package/dist/components/widgets/base/move-straight-widget.svelte +16 -4
  87. package/dist/components/widgets/base/quick-move-widget.svelte +25 -9
  88. package/dist/components/widgets/base/quick-move.svelte +5 -6
  89. package/dist/components/widgets/base/set-power-widget.svelte +20 -8
  90. package/dist/components/widgets/base/set-power.svelte +6 -4
  91. package/dist/components/widgets/base/set-velocity-widget.svelte +20 -8
  92. package/dist/components/widgets/base/set-velocity.svelte +6 -4
  93. package/dist/components/widgets/base/spin-widget.svelte +20 -8
  94. package/dist/components/widgets/base/vec3-builder.svelte +3 -2
  95. package/dist/components/widgets/base/vec3-builder.svelte.d.ts +2 -1
  96. package/dist/components/widgets/board/analog-read.svelte +2 -4
  97. package/dist/components/widgets/board/analog-write.svelte +2 -4
  98. package/dist/components/widgets/board/gpio-read.svelte +2 -1
  99. package/dist/components/widgets/board/gpio-write.svelte +2 -1
  100. package/dist/components/widgets/board/pin-section.svelte +5 -6
  101. package/dist/components/widgets/board/pin-section.svelte.d.ts +3 -2
  102. package/dist/components/widgets/board/read-write-pins.svelte +2 -2
  103. package/dist/components/widgets/button/push.svelte +2 -2
  104. package/dist/components/widgets/camera/camera.svelte +17 -24
  105. package/dist/components/widgets/camera/live-or-polling-video.svelte +33 -30
  106. package/dist/components/widgets/custom-control/__tests__/__fixtures__/with-sibling.svelte +10 -0
  107. package/dist/components/widgets/custom-control/control-frame.svelte +60 -0
  108. package/dist/components/widgets/custom-control/control-frame.svelte.d.ts +10 -0
  109. package/dist/components/widgets/custom-control/create-control-host.svelte.d.ts +19 -0
  110. package/dist/components/widgets/custom-control/create-control-host.svelte.js +26 -0
  111. package/dist/components/widgets/custom-control/custom-control.d.ts +35 -0
  112. package/dist/components/widgets/custom-control/custom-control.js +85 -0
  113. package/dist/components/widgets/custom-control/custom-control.svelte +45 -0
  114. package/dist/components/widgets/custom-control/custom-control.svelte.d.ts +14 -0
  115. package/dist/components/widgets/discovery/discovery.svelte +13 -17
  116. package/dist/components/widgets/encoder/encoder.svelte +25 -21
  117. package/dist/components/widgets/encoder/get-position-widget.svelte +19 -16
  118. package/dist/components/widgets/gantry/gantry.svelte +58 -76
  119. package/dist/components/widgets/gantry/get-position-widget.svelte +15 -14
  120. package/dist/components/widgets/gantry/home.svelte +21 -10
  121. package/dist/components/widgets/gantry/move-to-position-widget.svelte +2 -1
  122. package/dist/components/widgets/gantry/move-to-position.svelte +1 -4
  123. package/dist/components/widgets/gantry/move-to-position.svelte.d.ts +0 -1
  124. package/dist/components/widgets/gantry/quick-move-widget.svelte +3 -2
  125. package/dist/components/widgets/gantry/quick-move.svelte +1 -5
  126. package/dist/components/widgets/gantry/quick-move.svelte.d.ts +0 -1
  127. package/dist/components/widgets/generic/generic.svelte +11 -6
  128. package/dist/components/widgets/gripper/grab-widget.svelte +26 -0
  129. package/dist/components/widgets/gripper/grab-widget.svelte.d.ts +7 -0
  130. package/dist/components/widgets/gripper/grab.svelte +3 -19
  131. package/dist/components/widgets/gripper/grab.svelte.d.ts +1 -2
  132. package/dist/components/widgets/gripper/gripper.svelte +18 -18
  133. package/dist/components/widgets/gripper/is-holding-something.svelte +21 -21
  134. package/dist/components/widgets/gripper/open-widget.svelte +26 -0
  135. package/dist/components/widgets/gripper/open-widget.svelte.d.ts +7 -0
  136. package/dist/components/widgets/gripper/open.svelte +3 -19
  137. package/dist/components/widgets/gripper/open.svelte.d.ts +1 -2
  138. package/dist/components/widgets/input-controller/input-controller.svelte +10 -16
  139. package/dist/components/widgets/input-controller/webgamepad.svelte +2 -2
  140. package/dist/components/widgets/ml-model-service/ml-model-service.svelte +1 -1
  141. package/dist/components/widgets/motion/frame-select.svelte +4 -2
  142. package/dist/components/widgets/motion/frame-select.svelte.d.ts +2 -1
  143. package/dist/components/widgets/motion/motion.svelte +27 -31
  144. package/dist/components/widgets/motion/move-widget.svelte +32 -12
  145. package/dist/components/widgets/motion/move-widget.svelte.d.ts +6 -0
  146. package/dist/components/widgets/motion/move.svelte +6 -16
  147. package/dist/components/widgets/motion/move.svelte.d.ts +0 -1
  148. package/dist/components/widgets/motor/go-for-view.svelte +16 -8
  149. package/dist/components/widgets/motor/go-to-view.svelte +12 -4
  150. package/dist/components/widgets/motor/motor.svelte +100 -64
  151. package/dist/components/widgets/motor/quick-move-widget.svelte +16 -8
  152. package/dist/components/widgets/motor/set-power-widget.svelte +12 -4
  153. package/dist/components/widgets/motor/set-rpm-widget.svelte +12 -4
  154. package/dist/components/widgets/movement-sensor/get-accuracy-widget.svelte +8 -11
  155. package/dist/components/widgets/movement-sensor/get-compass-heading-widget.svelte +8 -11
  156. package/dist/components/widgets/movement-sensor/get-orientation-widget.svelte +8 -11
  157. package/dist/components/widgets/movement-sensor/get-position-widget.svelte +8 -11
  158. package/dist/components/widgets/movement-sensor/movement-sensor.svelte +64 -66
  159. package/dist/components/widgets/operations-and-sessions/operations-and-sessions.svelte +2 -1
  160. package/dist/components/widgets/power-sensor/get-current-widget.svelte +8 -11
  161. package/dist/components/widgets/power-sensor/get-power-widget.svelte +8 -11
  162. package/dist/components/widgets/power-sensor/get-voltage-widget.svelte +8 -11
  163. package/dist/components/widgets/power-sensor/power-sensor.svelte +35 -45
  164. package/dist/components/widgets/sensor/sensor.svelte +8 -12
  165. package/dist/components/widgets/servo/move-widget.svelte +2 -1
  166. package/dist/components/widgets/servo/move.svelte +1 -4
  167. package/dist/components/widgets/servo/move.svelte.d.ts +0 -1
  168. package/dist/components/widgets/servo/quick-move-widget.svelte +2 -1
  169. package/dist/components/widgets/servo/quick-move.svelte +1 -5
  170. package/dist/components/widgets/servo/quick-move.svelte.d.ts +0 -1
  171. package/dist/components/widgets/servo/servo.svelte +53 -37
  172. package/dist/components/widgets/slam/get-position-widget.svelte +8 -11
  173. package/dist/components/widgets/slam/move-on-map.svelte +9 -6
  174. package/dist/components/widgets/slam/move-on-map.svelte.d.ts +2 -1
  175. package/dist/components/widgets/slam/slam.svelte +65 -75
  176. package/dist/components/widgets/switch/position-view.svelte +1 -1
  177. package/dist/components/widgets/switch/position.svelte +2 -2
  178. package/dist/components/widgets/switch/switch.svelte +1 -1
  179. package/dist/components/widgets/vision-service/detection-row.svelte +4 -2
  180. package/dist/components/widgets/vision-service/detection-row.svelte.d.ts +2 -1
  181. package/dist/components/widgets/vision-service/fonts/public-sans.json +1 -0
  182. package/dist/components/widgets/vision-service/fonts/public-sans.png +0 -0
  183. package/dist/components/widgets/vision-service/image.svelte +4 -4
  184. package/dist/components/widgets/vision-service/legend.svelte +4 -4
  185. package/dist/components/widgets/vision-service/public-sans-font.d.ts +5 -0
  186. package/dist/components/widgets/vision-service/public-sans-font.js +14 -0
  187. package/dist/components/widgets/vision-service/vision-service.svelte +2 -2
  188. package/dist/index.d.ts +1 -1
  189. package/dist/index.js +0 -1
  190. package/package.json +19 -5
  191. package/dist/components/board/pin-section.svelte +0 -28
  192. package/dist/components/board/pin-section.svelte.d.ts +0 -9
  193. package/dist/components/mutation-section.svelte +0 -73
  194. package/dist/components/mutation-section.svelte.d.ts +0 -16
  195. package/dist/components/mutation-view.svelte +0 -29
  196. package/dist/components/mutation-view.svelte.d.ts +0 -10
  197. package/dist/components/section-group.svelte +0 -64
  198. package/dist/components/section-group.svelte.d.ts +0 -14
  199. package/dist/components/section-title.svelte +0 -63
  200. package/dist/components/section-title.svelte.d.ts +0 -14
@@ -10,7 +10,8 @@
10
10
  useRobotClient,
11
11
  } from '@viamrobotics/svelte-sdk'
12
12
 
13
- import Queries from '../../queries.svelte'
13
+ import ApiSection from '../../api-section.svelte'
14
+ import { ResourceTriplets } from '../../../resource-triplet'
14
15
 
15
16
  import {
16
17
  canPlanMotion,
@@ -19,6 +20,7 @@
19
20
  moveMotionServiceName,
20
21
  } from './move-control-mode'
21
22
  import MoveToPosition from './move-to-position.svelte'
23
+ import { useArmMotionTracking } from './use-arm-motion-tracking.svelte'
22
24
 
23
25
  interface Props {
24
26
  partID: string
@@ -27,8 +29,6 @@
27
29
 
28
30
  const { partID, resourceName }: Props = $props()
29
31
 
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
32
  const FRAME_SYSTEM_REFETCH_INTERVAL_MS = 5000
33
33
 
34
34
  const motionServices = useResourceStatuses(() => partID, 'motion')
@@ -77,32 +77,31 @@
77
77
  () => activeMotionServiceName ?? ''
78
78
  )
79
79
 
80
- // Pre-fill the editor with the arm's current pose, in the frame the active mode sends to.
81
- const poseArgs = $derived<Parameters<RobotClient['getPose']>>([resourceName, 'world', []])
80
+ const moveMutation = createResourceMutation(motionClient, 'move')
81
+ const moveToPosMutation = createResourceMutation(armClient, 'moveToPosition')
82
+ const activeMutation = $derived(mode === 'motion' ? moveMutation : moveToPosMutation)
83
+
84
+ const motionTracking = useArmMotionTracking(armClient, {
85
+ isMovePending: () => moveMutation.isPending || moveToPosMutation.isPending,
86
+ refetchPosition: () => activeQuery.refetch(),
87
+ })
88
+ const refetchInterval = $derived(motionTracking.refetchInterval)
89
+
82
90
  const poseQuery = createRobotQuery(
83
91
  robotClient,
84
92
  'getPose',
85
- () => poseArgs,
86
- () => ({ refetchInterval: POSE_REFETCH_INTERVAL_MS, enabled: mode === 'motion' })
93
+ () => [resourceName, 'world', []] satisfies Parameters<RobotClient['getPose']>,
94
+ () => ({ refetchInterval, enabled: mode === 'motion' })
87
95
  )
96
+
88
97
  const endPositionQuery = createResourceQuery(armClient, 'getEndPosition', () => ({
89
- refetchInterval: POSE_REFETCH_INTERVAL_MS,
98
+ refetchInterval,
90
99
  enabled: mode === 'direct',
91
100
  }))
92
101
 
93
102
  const activeQuery = $derived(mode === 'motion' ? poseQuery : endPositionQuery)
94
103
  const endPosition = $derived(mode === 'motion' ? poseQuery.data?.pose : endPositionQuery.data)
95
104
 
96
- const moveMutation = createResourceMutation(motionClient, 'move')
97
- const moveToPosMutation = createResourceMutation(armClient, 'moveToPosition')
98
- const lastError = $derived(mode === 'motion' ? moveMutation.error : moveToPosMutation.error)
99
-
100
- const description = $derived(
101
- mode === 'motion'
102
- ? 'Pose is in the world frame, as required by the motion service.'
103
- : 'Pose is with respect to the arm origin and does not take into account the motion service or frame system.'
104
- )
105
-
106
105
  const handleModeInput = (event: CustomEvent<string>) => {
107
106
  userChoice = event.detail === 'Motion service' ? 'motion' : 'direct'
108
107
  }
@@ -122,7 +121,22 @@
122
121
  }
123
122
  </script>
124
123
 
125
- <div class="flex flex-col gap-4">
124
+ {#snippet description()}
125
+ {#if mode === 'motion'}
126
+ Pose is in the world frame, as required by the motion service.
127
+ {:else}
128
+ Pose is with respect to the arm origin and does not take into account the motion service or
129
+ frame system.
130
+ {/if}
131
+ {/snippet}
132
+
133
+ <ApiSection
134
+ method="MoveToPosition"
135
+ api={ResourceTriplets.Arm}
136
+ queries={[frameSystemQuery, activeQuery]}
137
+ mutations={[activeMutation]}
138
+ class="grow flex-col gap-4"
139
+ >
126
140
  {#if motionAvailable}
127
141
  <Label position="top">
128
142
  <span class="flex items-center gap-1 text-xs">
@@ -177,17 +191,15 @@
177
191
  {/snippet}
178
192
  </Banner>
179
193
  {/if}
180
- <Queries queries={[frameSystemQuery, activeQuery]}>
181
- <!-- Re-seed the editor on a mode change: the two modes report the pose in different frames. -->
182
- {#key mode}
183
- {#if endPosition}
184
- <MoveToPosition
185
- {endPosition}
186
- {moveToPosition}
187
- {lastError}
188
- {description}
189
- />
190
- {/if}
191
- {/key}
192
- </Queries>
193
- </div>
194
+ <!-- Re-seed the editor on a mode change: the two modes report the pose in different frames. -->
195
+ {#key mode}
196
+ {#if endPosition}
197
+ <MoveToPosition
198
+ {endPosition}
199
+ {moveToPosition}
200
+ isMoving={motionTracking.isTracking}
201
+ {description}
202
+ />
203
+ {/if}
204
+ {/key}
205
+ </ApiSection>
@@ -1,54 +1,101 @@
1
- <script lang="ts">
1
+ <script
2
+ lang="ts"
3
+ module
4
+ >
2
5
  import type { Pose } from '@viamrobotics/sdk'
3
6
 
7
+ type PoseKey = keyof Pose
8
+
9
+ const POSE_KEYS: PoseKey[] = ['x', 'y', 'z', 'oX', 'oY', 'oZ', 'theta']
10
+
11
+ // Tight enough to catch a real move, loose enough to ignore encoder noise. Theta is in degrees.
12
+ const DRIFT_THRESHOLDS: Record<PoseKey, number> = {
13
+ x: 1,
14
+ y: 1,
15
+ z: 1,
16
+ oX: 0.01,
17
+ oY: 0.01,
18
+ oZ: 0.01,
19
+ theta: 0.5,
20
+ }
21
+ </script>
22
+
23
+ <script lang="ts">
24
+ import type { Snippet } from 'svelte'
25
+
4
26
  import { Button, Icon, Tooltip } from '@viamrobotics/prime-core'
5
27
 
6
- import ErrorDisplay from '../../error.svelte'
7
28
  import PoseEditor from '../../pose-editor.svelte'
29
+ import StatusPill from '../../status-pill.svelte'
30
+
31
+ import { useEditedTargets } from './use-edited-targets.svelte'
8
32
 
9
33
  interface Props {
10
34
  endPosition: Pose
11
35
  moveToPosition: (position: Pose) => void
12
- lastError: Error | null
13
- description?: string
36
+ isMoving?: boolean
37
+ description?: Snippet
14
38
  }
15
39
 
16
40
  const {
17
41
  endPosition,
18
42
  moveToPosition,
19
- lastError,
20
- description = 'Pose is with respect to the arm origin and does not take into account the motion service or frame system.',
43
+ isMoving = false,
44
+ description: customDescription,
21
45
  }: Props = $props()
22
46
 
23
- // svelte-ignore state_referenced_locally
24
- let desiredPosition = $state({ ...endPosition })
47
+ const targets = useEditedTargets<PoseKey>(
48
+ (key) => endPosition[key],
49
+ (key) => DRIFT_THRESHOLDS[key]
50
+ )
25
51
 
26
- const resetToZero = () => {
27
- desiredPosition = {
28
- x: 0,
29
- y: 0,
30
- z: 0,
31
- oX: 0,
32
- oY: 0,
33
- oZ: 0,
34
- theta: 0,
52
+ const desiredPosition = $derived<Pose>({
53
+ x: targets.target('x'),
54
+ y: targets.target('y'),
55
+ z: targets.target('z'),
56
+ oX: targets.target('oX'),
57
+ oY: targets.target('oY'),
58
+ oZ: targets.target('oZ'),
59
+ theta: targets.target('theta'),
60
+ })
61
+
62
+ const handlePoseChange = (next: Pose) => {
63
+ for (const key of POSE_KEYS) {
64
+ if (next[key] !== desiredPosition[key]) {
65
+ targets.edit(key, next[key])
66
+ }
35
67
  }
36
68
  }
37
69
 
38
- const resetToCurrent = () => {
39
- desiredPosition = { ...endPosition }
70
+ const resetToZero = () => {
71
+ for (const key of POSE_KEYS) {
72
+ targets.edit(key, 0)
73
+ }
40
74
  }
41
75
  </script>
42
76
 
77
+ {#snippet poseDescription()}
78
+ Pose is with respect to the arm origin and does not take into account the motion service or frame
79
+ system.
80
+ {/snippet}
81
+
43
82
  <div class="flex min-w-0 flex-col gap-4">
44
83
  <PoseEditor
45
84
  pose={desiredPosition}
46
- onPoseChange={(next) => {
47
- desiredPosition = next
85
+ onPoseChange={handlePoseChange}
86
+ fieldStatus={(key) => ({
87
+ current: endPosition[key],
88
+ isEdited: targets.isEdited(key),
89
+ drift: targets.drift(key),
90
+ isMoving,
91
+ })}
92
+ onFieldReset={(key) => {
93
+ targets.reset(key)
48
94
  }}
49
- title="Pose Values"
50
- {description}
51
- />
95
+ description={customDescription ?? poseDescription}
96
+ >
97
+ {#snippet heading()}Pose Values{/snippet}
98
+ </PoseEditor>
52
99
 
53
100
  <div class="mb-2 flex flex-col gap-2">
54
101
  <span class="flex flex-row gap-2">
@@ -64,16 +111,32 @@
64
111
  </span>
65
112
  <div class="flex flex-col gap-2 sm:flex-row">
66
113
  <Button onclick={resetToZero}>Zero</Button>
67
- <Button onclick={resetToCurrent}>Current position</Button>
114
+ <Button
115
+ onclick={() => {
116
+ targets.resetAll()
117
+ }}
118
+ >
119
+ Current position
120
+ </Button>
68
121
  </div>
69
122
  </div>
70
- <Button
71
- class="mt-auto w-fit"
72
- icon="play-circle-outline"
73
- variant="dark"
74
- onclick={() => moveToPosition(desiredPosition)}
75
- >
76
- Execute
77
- </Button>
78
- <ErrorDisplay {lastError} />
123
+ <div class="mt-auto flex items-center gap-2">
124
+ <Button
125
+ class="w-fit"
126
+ icon="play-circle-outline"
127
+ variant="dark"
128
+ disabled={isMoving}
129
+ onclick={() => moveToPosition(desiredPosition)}
130
+ >
131
+ Execute
132
+ </Button>
133
+ <span role="status">
134
+ {#if isMoving}
135
+ <StatusPill
136
+ isActive
137
+ activeText="Arm is moving"
138
+ />
139
+ {/if}
140
+ </span>
141
+ </div>
79
142
  </div>
@@ -1,9 +1,10 @@
1
1
  import type { Pose } from '@viamrobotics/sdk';
2
+ import type { Snippet } from 'svelte';
2
3
  interface Props {
3
4
  endPosition: Pose;
4
5
  moveToPosition: (position: Pose) => void;
5
- lastError: Error | null;
6
- description?: string;
6
+ isMoving?: boolean;
7
+ description?: Snippet;
7
8
  }
8
9
  declare const MoveToPosition: import("svelte").Component<Props, {}, "">;
9
10
  type MoveToPosition = ReturnType<typeof MoveToPosition>;
@@ -6,7 +6,8 @@
6
6
  createResourceQuery,
7
7
  } from '@viamrobotics/svelte-sdk'
8
8
 
9
- import Query from '../../query.svelte'
9
+ import ApiSection from '../../api-section.svelte'
10
+ import { ResourceTriplets } from '../../../resource-triplet'
10
11
 
11
12
  import QuickMove from './quick-move.svelte'
12
13
 
@@ -34,12 +35,17 @@
34
35
  }
35
36
  </script>
36
37
 
37
- <Query query={jointPositionsQuery}>
38
+ <ApiSection
39
+ method="MoveToJointPositions"
40
+ api={ResourceTriplets.Arm}
41
+ queries={[jointPositionsQuery]}
42
+ mutations={[quickMoveToJointPosMutation]}
43
+ class="grow flex-col gap-4"
44
+ >
38
45
  {#if jointPositionsQuery.data}
39
46
  <QuickMove
40
47
  positions={jointPositionsQuery.data.values}
41
48
  moveToJointPositions={quickMoveToJointPositions}
42
- lastError={quickMoveToJointPosMutation.error}
43
49
  />
44
50
  {/if}
45
- </Query>
51
+ </ApiSection>
@@ -1,16 +1,14 @@
1
1
  <script lang="ts">
2
2
  import { Button } from '@viamrobotics/prime-core'
3
3
 
4
- import ErrorDisplay from '../../error.svelte'
5
4
  import Table from '../../table.svelte'
6
5
 
7
6
  interface Props {
8
7
  positions: number[]
9
8
  moveToJointPositions: (jointPositions: number[]) => void
10
- lastError: Error | null
11
9
  }
12
10
 
13
- const { positions, moveToJointPositions, lastError }: Props = $props()
11
+ const { positions, moveToJointPositions }: Props = $props()
14
12
 
15
13
  const quickMove = (index: number, increment: number) => {
16
14
  const clonedPositions = positions.map((position, positionIndex) =>
@@ -59,4 +57,3 @@
59
57
  {/each}
60
58
  </tbody>
61
59
  </Table>
62
- <ErrorDisplay {lastError} />
@@ -1,7 +1,6 @@
1
1
  interface Props {
2
2
  positions: number[];
3
3
  moveToJointPositions: (jointPositions: number[]) => void;
4
- lastError: Error | null;
5
4
  }
6
5
  declare const QuickMove: import("svelte").Component<Props, {}, "">;
7
6
  type QuickMove = ReturnType<typeof QuickMove>;
@@ -0,0 +1,16 @@
1
+ import type { ArmClient } from '@viamrobotics/sdk';
2
+ import { type ResourceClientContext } from '@viamrobotics/svelte-sdk';
3
+ interface ArmMotionTrackingOptions {
4
+ /** A move this widget sent is still in flight. */
5
+ isMovePending: () => boolean;
6
+ /** Re-reads the arm's position. Called once each time the arm stops. */
7
+ refetchPosition: () => Promise<unknown>;
8
+ }
9
+ /** Allows an editor to track the arm's live position. */
10
+ export declare const useArmMotionTracking: (client: ResourceClientContext<ArmClient>, { isMovePending, refetchPosition }: ArmMotionTrackingOptions) => {
11
+ /** The arm is moving or has just stopped, so the editor follows the live position. */
12
+ readonly isTracking: boolean;
13
+ /** How often to poll the arm's position. Faster while tracking. */
14
+ readonly refetchInterval: 500 | 250;
15
+ };
16
+ export {};
@@ -0,0 +1,37 @@
1
+ import { createResourceQuery } from '@viamrobotics/svelte-sdk';
2
+ import { untrack } from 'svelte';
3
+ const IDLE_REFETCH_INTERVAL_MS = 500;
4
+ const MOVING_REFETCH_INTERVAL_MS = 250;
5
+ /** Allows an editor to track the arm's live position. */
6
+ export const useArmMotionTracking = (client, { isMovePending, refetchPosition }) => {
7
+ const isMovingQuery = createResourceQuery(client, 'isMoving', {
8
+ refetchInterval: IDLE_REFETCH_INTERVAL_MS,
9
+ });
10
+ const isMoving = $derived(isMovingQuery.data === true || isMovePending());
11
+ let isSettling = $state(false);
12
+ let wasMoving = false;
13
+ $effect(() => {
14
+ if (isMoving) {
15
+ wasMoving = true;
16
+ return;
17
+ }
18
+ if (!wasMoving)
19
+ return;
20
+ wasMoving = false;
21
+ isSettling = true;
22
+ void untrack(refetchPosition).finally(() => {
23
+ isSettling = false;
24
+ });
25
+ });
26
+ const isTracking = $derived(isMoving || isSettling);
27
+ return {
28
+ /** The arm is moving or has just stopped, so the editor follows the live position. */
29
+ get isTracking() {
30
+ return isTracking;
31
+ },
32
+ /** How often to poll the arm's position. Faster while tracking. */
33
+ get refetchInterval() {
34
+ return isTracking ? MOVING_REFETCH_INTERVAL_MS : IDLE_REFETCH_INTERVAL_MS;
35
+ },
36
+ };
37
+ };
@@ -0,0 +1,9 @@
1
+ export interface EditedTargets<TKey> {
2
+ target: (key: TKey) => number;
3
+ isEdited: (key: TKey) => boolean;
4
+ drift: (key: TKey) => number | undefined;
5
+ edit: (key: TKey, value: number) => void;
6
+ reset: (key: TKey) => void;
7
+ resetAll: () => void;
8
+ }
9
+ export declare const useEditedTargets: <TKey>(readLive: (key: TKey) => number, driftThreshold: (key: TKey) => number) => EditedTargets<TKey>;
@@ -0,0 +1,24 @@
1
+ import { SvelteMap } from 'svelte/reactivity';
2
+ export const useEditedTargets = (readLive, driftThreshold) => {
3
+ const edits = new SvelteMap();
4
+ return {
5
+ target: (key) => edits.get(key)?.value ?? readLive(key),
6
+ isEdited: (key) => edits.has(key),
7
+ drift: (key) => {
8
+ const edit = edits.get(key);
9
+ if (!edit)
10
+ return undefined;
11
+ const distance = Math.abs(readLive(key) - edit.baseline);
12
+ return distance > driftThreshold(key) ? distance : undefined;
13
+ },
14
+ edit: (key, value) => {
15
+ edits.set(key, { value, baseline: readLive(key) });
16
+ },
17
+ reset: (key) => {
18
+ edits.delete(key);
19
+ },
20
+ resetAll: () => {
21
+ edits.clear();
22
+ },
23
+ };
24
+ };
@@ -6,11 +6,11 @@
6
6
  import ApiSection from '../../api-section.svelte'
7
7
  import Properties from '../../audio-properties.svelte'
8
8
  import ConnectionStatus from '../../connection-status.svelte'
9
- import MutationSection from '../../mutation-section.svelte'
10
- import Query from '../../query.svelte'
11
9
  import RefetchController from '../../refetch-controller.svelte'
12
10
  import { createRefetchIntervalStore } from '../../refetch-interval-store.svelte'
11
+ import { Section } from '../../section'
13
12
  import { numberValueFromEvent } from '../../../event-handlers'
13
+ import { ResourceTriplets } from '../../../resource-triplet'
14
14
 
15
15
  import { createAudioCapturer } from './create-audio-capturer.svelte.js'
16
16
 
@@ -61,94 +61,97 @@
61
61
  <div class="@container">
62
62
  <div class="flex flex-col divide-y @2xl:flex-row @2xl:divide-x @2xl:divide-y-0">
63
63
  <div class="flex w-full flex-col divide-y">
64
- <MutationSection
65
- title="GetAudio"
66
- api="rdk:component:audio_input"
67
- description="Capture audio from the device"
68
- lastError={capture.error}
64
+ <ApiSection
65
+ method="GetAudio"
66
+ api={ResourceTriplets.AudioInput}
67
+ mutations={[capture]}
68
+ class="flex-row flex-wrap gap-2"
69
69
  >
70
- <div class="flex flex-col gap-2">
71
- <Label cx="gap-1 text-xs">
72
- Codec
73
- <Select
74
- slot="input"
75
- value={selectedCodec}
76
- on:change={(e) => {
77
- captureCodec = (e.target as HTMLSelectElement).value
78
- }}
79
- >
80
- {#each availableCodecs as codec (codec)}
81
- <option value={codec}>{codec}</option>
82
- {/each}
83
- </Select>
84
- </Label>
85
- <Label cx="gap-1 text-xs">
86
- Duration (seconds, 0 = stream until stopped)
87
- <NumericInput
88
- slot="input"
89
- value={captureDuration}
90
- on:change={(e) => {
91
- captureDuration = numberValueFromEvent(e) ?? 3
92
- }}
93
- />
94
- </Label>
95
- </div>
70
+ {#snippet subheading()}
71
+ <Section.Text>Capture audio from the device</Section.Text>
72
+ {/snippet}
73
+ <div class="flex grow flex-wrap justify-between gap-2">
74
+ <div class="flex flex-col gap-2">
75
+ <Label cx="gap-1 text-xs">
76
+ Codec
77
+ <Select
78
+ slot="input"
79
+ value={selectedCodec}
80
+ on:change={(e) => {
81
+ captureCodec = (e.target as HTMLSelectElement).value
82
+ }}
83
+ >
84
+ {#each availableCodecs as codec (codec)}
85
+ <option value={codec}>{codec}</option>
86
+ {/each}
87
+ </Select>
88
+ </Label>
89
+ <Label cx="gap-1 text-xs">
90
+ Duration (seconds, 0 = stream until stopped)
91
+ <NumericInput
92
+ slot="input"
93
+ value={captureDuration}
94
+ on:change={(e) => {
95
+ captureDuration = numberValueFromEvent(e) ?? 3
96
+ }}
97
+ />
98
+ </Label>
99
+ </div>
96
100
 
97
- <div class="mt-auto flex flex-col items-start gap-2">
98
- {#if capture.status === 'recording'}
99
- <p class="font-roboto-mono text-subtle-1 text-xs">
100
- {(capture.totalBytes / 1024).toFixed(1)} kB captured
101
- </p>
102
- <Button
103
- icon="stop-circle-outline"
104
- onclick={capture.stop}
105
- >
106
- Stop
107
- </Button>
108
- {:else}
109
- {#if capture.downloadUrl}
101
+ <div class="mt-auto flex flex-col items-start gap-2">
102
+ {#if capture.status === 'recording'}
110
103
  <p class="font-roboto-mono text-subtle-1 text-xs">
111
104
  {(capture.totalBytes / 1024).toFixed(1)} kB captured
112
105
  </p>
113
- <a
114
- href={capture.downloadUrl}
115
- download="audio-capture.{selectedCodec}"
116
- rel="external"
106
+ <Button
107
+ icon="stop-circle-outline"
108
+ onclick={capture.stop}
117
109
  >
118
- <Button icon="download">Download</Button>
119
- </a>
110
+ Stop
111
+ </Button>
112
+ {:else}
113
+ {#if capture.downloadUrl}
114
+ <p class="font-roboto-mono text-subtle-1 text-xs">
115
+ {(capture.totalBytes / 1024).toFixed(1)} kB captured
116
+ </p>
117
+ <a
118
+ href={capture.downloadUrl}
119
+ download="audio-capture.{selectedCodec}"
120
+ rel="external"
121
+ >
122
+ <Button icon="download">Download</Button>
123
+ </a>
124
+ {/if}
125
+ <Button
126
+ icon="play-circle-outline"
127
+ onclick={() => capture.start(selectedCodec, captureDuration)}
128
+ disabled={!client.current}
129
+ >
130
+ {capture.status === 'done' ? 'Capture Again' : 'Start Capture'}
131
+ </Button>
120
132
  {/if}
121
- <Button
122
- icon="play-circle-outline"
123
- onclick={() => capture.start(selectedCodec, captureDuration)}
124
- disabled={!client.current}
125
- >
126
- {capture.status === 'done' ? 'Capture Again' : 'Start Capture'}
127
- </Button>
128
- {/if}
133
+ </div>
129
134
  </div>
130
- </MutationSection>
135
+ </ApiSection>
131
136
  </div>
132
137
 
133
138
  <div class="flex w-full flex-col divide-y @2xl:ml-auto @2xl:max-w-1/2 @4xl:max-w-1/3">
134
139
  <ApiSection
135
- title="GetProperties"
136
- api="rdk:component:audio_input"
137
- description="Audio input properties"
138
- class="relative"
140
+ method="GetProperties"
141
+ api={ResourceTriplets.AudioInput}
142
+ queries={[propertiesQuery]}
143
+ class="relative grow flex-col gap-4"
139
144
  >
140
- <Query
141
- query={propertiesQuery}
142
- contentCx="h-6"
143
- >
144
- {#if propertiesQuery.data !== undefined}
145
- <Properties
146
- supportedCodecs={propertiesQuery.data.supportedCodecs}
147
- sampleRateHz={propertiesQuery.data.sampleRateHz}
148
- numChannels={propertiesQuery.data.numChannels}
149
- />
150
- {/if}
151
- </Query>
145
+ {#snippet subheading()}
146
+ <Section.Text>Audio input properties</Section.Text>
147
+ {/snippet}
148
+ {#if propertiesQuery.data !== undefined}
149
+ <Properties
150
+ supportedCodecs={propertiesQuery.data.supportedCodecs}
151
+ sampleRateHz={propertiesQuery.data.sampleRateHz}
152
+ numChannels={propertiesQuery.data.numChannels}
153
+ />
154
+ {/if}
152
155
  </ApiSection>
153
156
  </div>
154
157
  </div>