@wandelbots/wandelbots-js-react-components 2.27.1 → 2.28.0-pr.feature-add-program-control-component.367.28afd72

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 (53) hide show
  1. package/README.md +1 -1
  2. package/dist/Setup.d.ts +1 -1
  3. package/dist/Setup.d.ts.map +1 -1
  4. package/dist/components/3d-viewport/SafetyZonesRenderer.d.ts +2 -2
  5. package/dist/components/3d-viewport/SafetyZonesRenderer.d.ts.map +1 -1
  6. package/dist/components/3d-viewport/TrajectoryRenderer.d.ts +1 -1
  7. package/dist/components/3d-viewport/TrajectoryRenderer.d.ts.map +1 -1
  8. package/dist/components/ProgramControl.d.ts +43 -0
  9. package/dist/components/ProgramControl.d.ts.map +1 -0
  10. package/dist/components/robots/DHRobot.d.ts.map +1 -1
  11. package/dist/components/robots/GenericRobot.d.ts +2 -2
  12. package/dist/components/robots/GenericRobot.d.ts.map +1 -1
  13. package/dist/components/robots/Robot.d.ts +2 -2
  14. package/dist/components/robots/Robot.d.ts.map +1 -1
  15. package/dist/components/robots/RobotAnimator.d.ts.map +1 -1
  16. package/dist/components/robots/RobotAnimator.test.d.ts +2 -0
  17. package/dist/components/robots/RobotAnimator.test.d.ts.map +1 -0
  18. package/dist/components/robots/SupportedRobot.d.ts +3 -3
  19. package/dist/components/robots/SupportedRobot.d.ts.map +1 -1
  20. package/dist/components/utils/interpolation.d.ts +159 -0
  21. package/dist/components/utils/interpolation.d.ts.map +1 -0
  22. package/dist/components/utils/interpolation.test.d.ts +2 -0
  23. package/dist/components/utils/interpolation.test.d.ts.map +1 -0
  24. package/dist/externalizeComponent.d.ts +1 -1
  25. package/dist/externalizeComponent.d.ts.map +1 -1
  26. package/dist/index.cjs +39 -47
  27. package/dist/index.cjs.map +1 -1
  28. package/dist/index.d.ts +2 -0
  29. package/dist/index.d.ts.map +1 -1
  30. package/dist/index.js +8283 -9714
  31. package/dist/index.js.map +1 -1
  32. package/dist/test/setup.d.ts +2 -0
  33. package/dist/test/setup.d.ts.map +1 -0
  34. package/package.json +33 -32
  35. package/src/Setup.tsx +1 -1
  36. package/src/components/3d-viewport/SafetyZonesRenderer.tsx +2 -2
  37. package/src/components/3d-viewport/TrajectoryRenderer.tsx +1 -1
  38. package/src/components/ProgramControl.tsx +217 -0
  39. package/src/components/jogging/JoggingOptions.tsx +1 -1
  40. package/src/components/robots/DHRobot.tsx +37 -10
  41. package/src/components/robots/GenericRobot.tsx +4 -5
  42. package/src/components/robots/Robot.tsx +2 -2
  43. package/src/components/robots/RobotAnimator.test.tsx +113 -0
  44. package/src/components/robots/RobotAnimator.tsx +38 -23
  45. package/src/components/robots/SupportedRobot.tsx +3 -3
  46. package/src/components/utils/converters.ts +1 -1
  47. package/src/components/utils/interpolation.test.ts +1123 -0
  48. package/src/components/utils/interpolation.ts +379 -0
  49. package/src/externalizeComponent.tsx +1 -1
  50. package/src/i18n/locales/de/translations.json +5 -1
  51. package/src/i18n/locales/en/translations.json +5 -1
  52. package/src/index.ts +2 -0
  53. package/src/test/setup.ts +111 -0
@@ -1,12 +1,12 @@
1
- import { Globals, useSpring } from "@react-spring/three"
2
- import { useThree } from "@react-three/fiber"
1
+ import { useFrame, useThree } from "@react-three/fiber"
3
2
  import type {
4
3
  DHParameter,
5
4
  MotionGroupStateResponse,
6
5
  } from "@wandelbots/nova-api/v1"
7
- import React, { useRef } from "react"
6
+ import React, { useEffect, useRef } from "react"
8
7
  import type { Group, Object3D } from "three"
9
8
  import { useAutorun } from "../utils/hooks"
9
+ import { ValueInterpolator } from "../utils/interpolation"
10
10
  import { collectJoints } from "./robotModelLogic"
11
11
 
12
12
  type RobotAnimatorProps = {
@@ -22,11 +22,42 @@ export default function RobotAnimator({
22
22
  onRotationChanged,
23
23
  children,
24
24
  }: RobotAnimatorProps) {
25
- Globals.assign({ frameLoop: "always" })
26
25
  const jointValues = useRef<number[]>([])
27
26
  const jointObjects = useRef<Object3D[]>([])
27
+ const interpolatorRef = useRef<ValueInterpolator | null>(null)
28
28
  const { invalidate } = useThree()
29
29
 
30
+ // Initialize interpolator
31
+ useEffect(() => {
32
+ const initialJointValues =
33
+ rapidlyChangingMotionState.state.joint_position.joints.filter(
34
+ (item) => item !== undefined,
35
+ )
36
+
37
+ interpolatorRef.current = new ValueInterpolator(initialJointValues, {
38
+ tension: 120, // Controls spring stiffness - higher values create faster, more responsive motion
39
+ friction: 20, // Controls damping - higher values reduce oscillation and create smoother settling
40
+ threshold: 0.001,
41
+ })
42
+
43
+ return () => {
44
+ interpolatorRef.current?.destroy()
45
+ }
46
+ }, [])
47
+
48
+ // Animation loop that runs at the display's refresh rate
49
+ useFrame((state, delta) => {
50
+ if (interpolatorRef.current) {
51
+ const isComplete = interpolatorRef.current.update(delta)
52
+ setRotation()
53
+
54
+ // Trigger a re-render only if the animation is still running
55
+ if (!isComplete) {
56
+ invalidate()
57
+ }
58
+ }
59
+ })
60
+
30
61
  function setGroupRef(group: Group | null) {
31
62
  if (!group) return
32
63
 
@@ -39,13 +70,11 @@ export default function RobotAnimator({
39
70
 
40
71
  function updateJoints(newJointValues: number[]) {
41
72
  jointValues.current = newJointValues
42
- setSpring.start(Object.assign({}, jointValues.current) as any)
73
+ interpolatorRef.current?.setTarget(newJointValues)
43
74
  }
44
75
 
45
76
  function setRotation() {
46
- const updatedJointValues = jointObjects.current.map((_, objectIndex) =>
47
- (axisValues as any)[objectIndex].get(),
48
- )
77
+ const updatedJointValues = interpolatorRef.current?.getCurrentValues() || []
49
78
 
50
79
  if (onRotationChanged) {
51
80
  onRotationChanged(jointObjects.current, updatedJointValues)
@@ -56,7 +85,7 @@ export default function RobotAnimator({
56
85
  const rotationSign = dhParam.reverse_rotation_direction ? -1 : 1
57
86
 
58
87
  object.rotation.y =
59
- rotationSign * updatedJointValues[index]! + rotationOffset
88
+ rotationSign * (updatedJointValues[index] || 0) + rotationOffset
60
89
  }
61
90
  }
62
91
  }
@@ -70,19 +99,5 @@ export default function RobotAnimator({
70
99
  requestAnimationFrame(() => updateJoints(newJointValues))
71
100
  })
72
101
 
73
- const [axisValues, setSpring] = useSpring(() => ({
74
- ...Object.assign(
75
- {},
76
- rapidlyChangingMotionState.state.joint_position.joints,
77
- ),
78
- onChange: () => {
79
- setRotation()
80
- invalidate()
81
- },
82
- onResolve: () => {
83
- setRotation()
84
- },
85
- }))
86
-
87
102
  return <group ref={setGroupRef}>{children}</group>
88
103
  }
@@ -1,4 +1,4 @@
1
- import type { GroupProps } from "@react-three/fiber"
1
+ import type { ThreeElements } from "@react-three/fiber"
2
2
  import type {
3
3
  DHParameter,
4
4
  MotionGroupStateResponse,
@@ -18,7 +18,7 @@ import { defaultGetModel } from "./robotModelLogic"
18
18
  export type DHRobotProps = {
19
19
  rapidlyChangingMotionState: MotionGroupStateResponse
20
20
  dhParameters: Array<DHParameter>
21
- } & GroupProps
21
+ } & ThreeElements["group"]
22
22
 
23
23
  export type SupportedRobotProps = {
24
24
  rapidlyChangingMotionState: MotionGroupStateResponse
@@ -28,7 +28,7 @@ export type SupportedRobotProps = {
28
28
  getModel?: (modelFromController: string) => string
29
29
  postModelRender?: () => void
30
30
  transparentColor?: string
31
- } & GroupProps
31
+ } & ThreeElements["group"]
32
32
 
33
33
  export const SupportedRobot = externalizeComponent(
34
34
  ({
@@ -20,4 +20,4 @@ export function tryStringifyJson(json: unknown): string | undefined {
20
20
  } catch {
21
21
  return undefined
22
22
  }
23
- }
23
+ }