Enhance machine and robotic arm interactions: update action handling, integrate material management, and improve state management across components.
This commit is contained in:
@@ -1,13 +1,19 @@
|
||||
import React, { useEffect, useRef, useState } from 'react'
|
||||
import { useEffect, useRef, useState } from 'react'
|
||||
import { useMachineStore } from '../../../../../store/simulation/useMachineStore';
|
||||
import { usePlayButtonStore } from '../../../../../store/usePlayButtonStore';
|
||||
import MachineAnimator from '../animator/machineAnimator';
|
||||
import { useProductStore } from '../../../../../store/simulation/useProductStore';
|
||||
import { useSelectedProduct } from '../../../../../store/simulation/useSimulationStore';
|
||||
import { useTriggerHandler } from '../../../triggers/triggerHandler/useTriggerHandler';
|
||||
|
||||
function MachineInstance({ machineDetail }: any) {
|
||||
function MachineInstance({ machineDetail }: { machineDetail: MachineStatus }) {
|
||||
const [currentPhase, setCurrentPhase] = useState<string>('idle');
|
||||
let isIncrememtable = useRef<boolean>(true);
|
||||
const { isPlaying } = usePlayButtonStore();
|
||||
const { machines, addCurrentAction, setMachineState, setMachineActive } = useMachineStore();
|
||||
const { machines, setMachineState, setMachineActive } = useMachineStore();
|
||||
const { selectedProduct } = useSelectedProduct();
|
||||
const { getActionByUuid } = useProductStore();
|
||||
const { triggerPointActions } = useTriggerHandler();
|
||||
|
||||
const reset = () => {
|
||||
setCurrentPhase("idle");
|
||||
@@ -15,23 +21,14 @@ function MachineInstance({ machineDetail }: any) {
|
||||
setMachineActive(machineDetail.modelUuid, false);
|
||||
isIncrememtable.current = true;
|
||||
}
|
||||
const increment = () => {
|
||||
if (isIncrememtable.current) {
|
||||
addCurrentAction(machineDetail.modelUuid, "machine-action-2468-1357-8024")
|
||||
isIncrememtable.current = false;
|
||||
}
|
||||
}
|
||||
|
||||
function machineStatus(modelId: string, status: string) {
|
||||
// console.log(`${modelId} , ${status}`);
|
||||
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
if (isPlaying) {
|
||||
if (!machineDetail.isActive && machineDetail.state === "idle" && currentPhase == "idle" && !machineDetail.currentAction) {
|
||||
setTimeout(() => {
|
||||
increment();
|
||||
}, 5000);
|
||||
machineStatus(machineDetail.modelUuid, 'Machine is idle and waiting for next instruction.')
|
||||
} else if (!machineDetail.isActive && machineDetail.state === "idle" && currentPhase == "idle" && machineDetail.currentAction) {
|
||||
setCurrentPhase("processing");
|
||||
@@ -49,11 +46,15 @@ function MachineInstance({ machineDetail }: any) {
|
||||
setCurrentPhase("idle")
|
||||
isIncrememtable.current = true;
|
||||
machineStatus(machineDetail.modelUuid, "Machine has completed the processing")
|
||||
|
||||
if (machineDetail.currentAction) {
|
||||
const action = getActionByUuid(selectedProduct.productId, machineDetail.currentAction.actionUuid);
|
||||
if (action && machineDetail.currentAction.materialId) {
|
||||
triggerPointActions(action, machineDetail.currentAction.materialId)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// console.log('currentPhase: ', currentPhase);
|
||||
|
||||
|
||||
|
||||
return (
|
||||
<>
|
||||
|
||||
Reference in New Issue
Block a user