2025-04-24 04:17:44 +00:00
|
|
|
import React, { useEffect, useState } from 'react'
|
2025-04-23 06:59:16 +00:00
|
|
|
import IKInstance from '../ikInstance/ikInstance';
|
|
|
|
import RoboticArmAnimator from '../animator/roboticArmAnimator';
|
2025-04-24 04:17:44 +00:00
|
|
|
import { usePlayButtonStore } from '../../../../../store/usePlayButtonStore';
|
|
|
|
import { useArmBotStore } from '../../../../../store/simulation/useArmBotStore';
|
|
|
|
|
|
|
|
function RoboticArmInstance({ armBot }: any) {
|
|
|
|
const { isPlaying } = usePlayButtonStore();
|
|
|
|
const [currentPhase, setCurrentPhase] = useState<(string)>("init");
|
|
|
|
console.log('currentPhase: ', currentPhase);
|
|
|
|
const { armBots, addArmBot, addCurrentAction } = useArmBotStore();
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
|
|
|
console.log('isPlaying: ', isPlaying);
|
|
|
|
if (isPlaying) {
|
|
|
|
//Moving armBot from initial point to rest position.
|
|
|
|
|
|
|
|
if (armBot?.isActive && armBot?.state == "idle" && currentPhase == "init") {
|
|
|
|
addCurrentAction(armBot.modelUuid, 'action-001');
|
|
|
|
setCurrentPhase("moving-to-rest");
|
|
|
|
|
|
|
|
}
|
|
|
|
//Waiting for trigger.
|
|
|
|
if (!armBot?.isActive && armBot?.state == "idle" && currentPhase == "moving-to-rest") {
|
|
|
|
setCurrentPhase("rest");
|
|
|
|
}
|
|
|
|
// Moving armBot from rest position to pick up point.
|
|
|
|
if (!armBot?.isActive && armBot?.state == "idle" && currentPhase == "rest") {
|
|
|
|
|
|
|
|
}
|
|
|
|
//Moving arm from start point to end point.
|
|
|
|
if (armBot?.isActive && armBot?.state == "running " && currentPhase == "rest-to-start ") {
|
|
|
|
|
|
|
|
}
|
|
|
|
//Moving arm from end point to idle.
|
|
|
|
if (armBot?.isActive && armBot?.state == "running" && currentPhase == "end-to-start") {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}, [currentPhase, armBot, isPlaying])
|
|
|
|
|
|
|
|
const HandleCallback = () => {
|
|
|
|
if (armBot.isActive && armBot.state == "idle" && currentPhase == "init") {
|
|
|
|
addCurrentAction('armbot-xyz-001', 'action-001');
|
|
|
|
}
|
|
|
|
}
|
2025-04-23 06:59:16 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
|
|
|
|
<IKInstance />
|
2025-04-24 04:17:44 +00:00
|
|
|
<RoboticArmAnimator armUuid={armBot?.modelUuid} HandleCallback={HandleCallback} currentPhase={currentPhase} />
|
2025-04-23 06:59:16 +00:00
|
|
|
|
|
|
|
</>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
export default RoboticArmInstance;
|