@viamrobotics/motion-tools 0.14.7 → 0.14.9

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.
@@ -4,24 +4,23 @@ import { getContext, setContext } from 'svelte';
4
4
  const key = Symbol('arm-client-context');
5
5
  export const provideArmClient = (partID) => {
6
6
  const arms = useResourceNames(partID, 'arm');
7
- const clients = $state({});
8
7
  const options = { refetchInterval: 500 };
9
- const jointPositionsQueries = $state({});
10
8
  const names = $derived(arms.current.map((arm) => arm.name));
11
- const currentPositions = $derived(Object.fromEntries(Object.entries(jointPositionsQueries).map(([name, query]) => [name, query.data?.values])));
12
- $effect(() => {
13
- for (const arm of arms.current) {
14
- const client = createResourceClient(ArmClient, partID, () => arm.name);
15
- if (client.current && !clients[arm.name])
16
- clients[arm.name] = { current: client.current };
17
- }
18
- });
19
- $effect(() => {
20
- for (const client of Object.values(clients)) {
9
+ const clients = $derived(arms.current.map((arm) => createResourceClient(ArmClient, partID, () => arm.name)));
10
+ const jointPositionsQueries = $derived.by(() => {
11
+ const results = {};
12
+ for (const client of clients) {
13
+ if (!client.current)
14
+ continue;
21
15
  const query = createResourceQuery(client, 'getJointPositions', options);
22
- jointPositionsQueries[client.current.name] = query.current;
16
+ results[client.current.name] = query;
23
17
  }
18
+ return results;
24
19
  });
20
+ const currentPositions = $derived(Object.fromEntries(Object.entries(jointPositionsQueries).map(([name, query]) => [
21
+ name,
22
+ query.current.data?.values,
23
+ ])));
25
24
  setContext(key, {
26
25
  get names() {
27
26
  return names;
package/dist/transform.js CHANGED
@@ -3,6 +3,8 @@ import { Euler, MathUtils, Matrix4, Quaternion, Vector3 } from 'three';
3
3
  const quaternion = new Quaternion();
4
4
  const euler = new Euler();
5
5
  const ov = new OrientationVector();
6
+ const translation = new Vector3();
7
+ const scale = new Vector3();
6
8
  export const createPose = (pose) => {
7
9
  return {
8
10
  x: pose?.x ?? 0,
@@ -90,32 +92,23 @@ export const scaleToDimensions = (scale, geometry) => {
90
92
  }
91
93
  };
92
94
  export const poseToMatrix = (pose) => {
95
+ ov.set(pose.oX, pose.oY, pose.oZ, MathUtils.degToRad(pose.theta));
96
+ ov.toQuaternion(quaternion);
93
97
  const matrix = new Matrix4();
94
- const poseQuaternion = new Quaternion().setFromAxisAngle(new Vector3(pose.oX, pose.oY, pose.oZ), pose.theta * (Math.PI / 180));
95
- matrix.makeRotationFromQuaternion(poseQuaternion);
96
- matrix.setPosition(new Vector3(pose.x, pose.y, pose.z));
98
+ matrix.makeRotationFromQuaternion(quaternion);
99
+ matrix.setPosition(pose.x, pose.y, pose.z);
97
100
  return matrix;
98
101
  };
99
102
  export const matrixToPose = (matrix) => {
100
103
  const pose = createPose();
101
- const translation = new Vector3();
102
- const quaternion = new Quaternion();
103
- matrix.decompose(translation, quaternion, new Vector3());
104
+ matrix.decompose(translation, quaternion, scale);
104
105
  pose.x = translation.x;
105
106
  pose.y = translation.y;
106
107
  pose.z = translation.z;
107
- const s = Math.sqrt(1 - quaternion.w * quaternion.w);
108
- if (s < 0.000001) {
109
- pose.oX = 0;
110
- pose.oY = 0;
111
- pose.oZ = 1;
112
- pose.theta = 0;
113
- }
114
- else {
115
- pose.oX = quaternion.x / s;
116
- pose.oY = quaternion.y / s;
117
- pose.oZ = quaternion.z / s;
118
- pose.theta = Math.acos(quaternion.w) * 2 * (180 / Math.PI);
119
- }
108
+ ov.setFromQuaternion(quaternion);
109
+ pose.oX = ov.x;
110
+ pose.oY = ov.y;
111
+ pose.oZ = ov.z;
112
+ pose.theta = MathUtils.radToDeg(ov.th);
120
113
  return pose;
121
114
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@viamrobotics/motion-tools",
3
- "version": "0.14.7",
3
+ "version": "0.14.9",
4
4
  "description": "Motion visualization with Viam",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",