feat: Enhance Robotic Arm functionality with state management and action handling
This commit is contained in:
@@ -1,14 +1,58 @@
|
||||
import React from 'react'
|
||||
import React, { useEffect, useState } from 'react'
|
||||
import IKInstance from '../ikInstance/ikInstance';
|
||||
import RoboticArmAnimator from '../animator/roboticArmAnimator';
|
||||
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');
|
||||
}
|
||||
}
|
||||
|
||||
function RoboticArmInstance() {
|
||||
return (
|
||||
<>
|
||||
|
||||
<IKInstance />
|
||||
|
||||
<RoboticArmAnimator />
|
||||
<RoboticArmAnimator armUuid={armBot?.modelUuid} HandleCallback={HandleCallback} currentPhase={currentPhase} />
|
||||
|
||||
</>
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user