@wandelbots/wandelbots-js-react-components 4.1.0 → 4.1.1-pr.feat-RB-3107-motion-group-visualizer.510.3add2c2
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/3d.cjs.js +1 -1
- package/dist/3d.es.js +1 -1
- package/dist/components/robots/LinearAxisAnimator.d.ts.map +1 -1
- package/dist/components/robots/MotionGroupVisualizer.d.ts +8 -0
- package/dist/components/robots/MotionGroupVisualizer.d.ts.map +1 -0
- package/dist/index.cjs.js +1 -1
- package/dist/index.es.js +1 -1
- package/dist/{manufacturerHomePositions-B_nLYNzG.cjs → manufacturerHomePositions-5E6JP4Zd.cjs} +2 -2
- package/dist/{manufacturerHomePositions-B_nLYNzG.cjs.map → manufacturerHomePositions-5E6JP4Zd.cjs.map} +1 -1
- package/dist/{manufacturerHomePositions-BCgn-SCy.js → manufacturerHomePositions-DAaWLJKB.js} +2 -2
- package/dist/{manufacturerHomePositions-BCgn-SCy.js.map → manufacturerHomePositions-DAaWLJKB.js.map} +1 -1
- package/package.json +1 -1
- package/src/components/robots/LinearAxisAnimator.tsx +2 -3
- package/src/components/robots/MotionGroupVisualizer.tsx +73 -0
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import React, { useCallback, useEffect, useMemo, useState } from "react"
|
|
2
|
+
import { NovaClient } from "@wandelbots/nova-js/v2"
|
|
3
|
+
import type { KinematicModel } from "@wandelbots/nova-api/v2"
|
|
4
|
+
|
|
5
|
+
import { externalizeComponent } from "../../externalizeComponent"
|
|
6
|
+
import { SupportedRobot, type SupportedRobotProps } from "./SupportedRobot"
|
|
7
|
+
import { SupportedLinearAxis, type SupportedLinearAxisProps } from "./SupportedLinearAxis"
|
|
8
|
+
|
|
9
|
+
export type MotionGroupVisualizerProps = {
|
|
10
|
+
inverseSolver?: string | null
|
|
11
|
+
} & (SupportedRobotProps | SupportedLinearAxisProps)
|
|
12
|
+
|
|
13
|
+
export const MotionGroupVisualizer: React.FC<MotionGroupVisualizerProps> = externalizeComponent((props: MotionGroupVisualizerProps) => {
|
|
14
|
+
const { inverseSolver: inverseSolverProp, modelFromController, ...rest } = props
|
|
15
|
+
|
|
16
|
+
const [inverseSolver, setInverseSolver] = useState<string | null | undefined>(inverseSolverProp)
|
|
17
|
+
|
|
18
|
+
const instanceUrl = import.meta.env.WANDELAPI_BASE_URL
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Fetches the kinematic model from the API and saved the inverse_solver property, which defined
|
|
22
|
+
* whether the motion group should be displayed as a robot or linear axis
|
|
23
|
+
*/
|
|
24
|
+
const fetchKinematicModel = useCallback(async () => {
|
|
25
|
+
const nova = new NovaClient({ instanceUrl })
|
|
26
|
+
try {
|
|
27
|
+
const kinematicModel: KinematicModel = await nova.api.motionGroupModels.getMotionGroupKinematicModel(
|
|
28
|
+
modelFromController,
|
|
29
|
+
)
|
|
30
|
+
|
|
31
|
+
setInverseSolver(kinematicModel.inverse_solver)
|
|
32
|
+
} catch (err) {
|
|
33
|
+
console.warn(`Failed to fetch kinematic model from API for ${modelFromController}, falling back to local config`)
|
|
34
|
+
}
|
|
35
|
+
}, [modelFromController, instanceUrl])
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Checks the delivered inverseSolver property from the consumer
|
|
39
|
+
* Defined, Null - carry on with the delivered value - the inverseSolver was fetched via consumer app
|
|
40
|
+
* Undefined - carry out a request to fetch the inverseSolver value
|
|
41
|
+
*/
|
|
42
|
+
useEffect(() => {
|
|
43
|
+
if (inverseSolverProp === undefined && modelFromController && instanceUrl) {
|
|
44
|
+
fetchKinematicModel()
|
|
45
|
+
}
|
|
46
|
+
}, [inverseSolverProp, modelFromController, fetchKinematicModel, instanceUrl])
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* The turntable models return inverseSolver = null - however these models
|
|
50
|
+
* should be rendered with SupportedRobot instead of SupportedLinearAxis
|
|
51
|
+
*
|
|
52
|
+
* In the future - this hard coded check would be replaced with a new "type" property
|
|
53
|
+
* from dh parameters
|
|
54
|
+
*/
|
|
55
|
+
const isTurnTable = useMemo(() => {
|
|
56
|
+
return ["KUKA_DK250", "KUKA_DK500", "YASKAWA_TURN1", "YASKAWA_TURN2", "YASKAWA_TURN3"]
|
|
57
|
+
.includes(modelFromController)
|
|
58
|
+
}, [modelFromController])
|
|
59
|
+
|
|
60
|
+
if (inverseSolver || isTurnTable) {
|
|
61
|
+
return (
|
|
62
|
+
<SupportedRobot modelFromController={modelFromController} {...rest} />
|
|
63
|
+
)
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
if (inverseSolver === null) {
|
|
67
|
+
return (
|
|
68
|
+
<SupportedLinearAxis modelFromController={modelFromController} {...rest} />
|
|
69
|
+
)
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
return null
|
|
73
|
+
})
|