feat: implement instance components for various simulation entities including human, machine, robotic arm, storage unit, vehicle, conveyor, and crane.

This commit is contained in:
2025-12-22 12:36:24 +05:30
parent bd79b36e8e
commit 1f881c488d
7 changed files with 126 additions and 116 deletions

View File

@@ -39,13 +39,21 @@ function ConveyorInstance({ conveyor }: { readonly conveyor: ConveyorStatus }) {
const deltaTime = (currentTime - previousTimeRef.current) / 1000;
previousTimeRef.current = currentTime;
if (!conveyor.isPaused) {
if (!isPausedRef.current) {
if (!isPausedRef.current) {
if (!conveyor.isPaused) {
activeTimeRef.current += deltaTime * isSpeedRef.current;
}
} else {
if (!isPausedRef.current) {
if (activeTimeRef.current >= 1) {
const inc = Math.floor(activeTimeRef.current);
incrementActiveTime(conveyor.modelUuid, inc);
activeTimeRef.current -= inc;
}
} else {
idleTimeRef.current += deltaTime * isSpeedRef.current;
if (idleTimeRef.current >= 1) {
const inc = Math.floor(idleTimeRef.current);
incrementIdleTime(conveyor.modelUuid, inc);
idleTimeRef.current -= inc;
}
}
}
animationFrameIdRef.current = requestAnimationFrame(animate);
@@ -53,15 +61,6 @@ function ConveyorInstance({ conveyor }: { readonly conveyor: ConveyorStatus }) {
useEffect(() => {
if (!isPlaying) return;
if (!conveyor.isPaused) {
const roundedActiveTime = Math.round(activeTimeRef.current);
incrementActiveTime(conveyor.modelUuid, roundedActiveTime);
activeTimeRef.current = 0;
} else {
const roundedIdleTime = Math.round(idleTimeRef.current);
incrementIdleTime(conveyor.modelUuid, roundedIdleTime);
idleTimeRef.current = 0;
}
if (animationFrameIdRef.current === null) {
animationFrameIdRef.current = requestAnimationFrame(animate);

View File

@@ -50,13 +50,21 @@ function PillarJibInstance({ crane }: { readonly crane: CraneStatus }) {
const deltaTime = (currentTime - previousTimeRef.current) / 1000;
previousTimeRef.current = currentTime;
if (crane.isActive) {
if (!isPausedRef.current) {
if (!isPausedRef.current) {
if (crane.isActive) {
activeTimeRef.current += deltaTime * isSpeedRef.current;
}
} else {
if (!isPausedRef.current) {
if (activeTimeRef.current >= 1) {
const inc = Math.floor(activeTimeRef.current);
incrementActiveTime(crane.modelUuid, inc);
activeTimeRef.current -= inc;
}
} else {
idleTimeRef.current += deltaTime * isSpeedRef.current;
if (idleTimeRef.current >= 1) {
const inc = Math.floor(idleTimeRef.current);
incrementIdleTime(crane.modelUuid, inc);
idleTimeRef.current -= inc;
}
}
}
animationFrameIdRef.current = requestAnimationFrame(animate);
@@ -64,15 +72,6 @@ function PillarJibInstance({ crane }: { readonly crane: CraneStatus }) {
useEffect(() => {
if (!isPlaying) return;
if (crane.isActive) {
const roundedActiveTime = Math.round(activeTimeRef.current);
incrementActiveTime(crane.modelUuid, roundedActiveTime);
activeTimeRef.current = 0;
} else {
const roundedIdleTime = Math.round(idleTimeRef.current);
incrementIdleTime(crane.modelUuid, roundedIdleTime);
idleTimeRef.current = 0;
}
if (animationFrameIdRef.current === null) {
animationFrameIdRef.current = requestAnimationFrame(animate);

View File

@@ -39,13 +39,21 @@ function HumanInstance({ human }: { readonly human: HumanStatus }) {
const deltaTime = (currentTime - previousTimeRef.current) / 1000;
previousTimeRef.current = currentTime;
if (human.isActive) {
if (!isPausedRef.current) {
if (!isPausedRef.current) {
if (human.isActive) {
activeTimeRef.current += deltaTime * isSpeedRef.current;
}
} else {
if (!isPausedRef.current) {
if (activeTimeRef.current >= 1) {
const inc = Math.floor(activeTimeRef.current);
incrementActiveTime(human.modelUuid, inc);
activeTimeRef.current -= inc;
}
} else {
idleTimeRef.current += deltaTime * isSpeedRef.current;
if (idleTimeRef.current >= 1) {
const inc = Math.floor(idleTimeRef.current);
incrementIdleTime(human.modelUuid, inc);
idleTimeRef.current -= inc;
}
}
}
animationFrameIdRef.current = requestAnimationFrame(animate);
@@ -53,15 +61,6 @@ function HumanInstance({ human }: { readonly human: HumanStatus }) {
useEffect(() => {
if (!isPlaying) return;
if (!human.isActive) {
const roundedActiveTime = Math.round(activeTimeRef.current);
incrementActiveTime(human.modelUuid, roundedActiveTime);
activeTimeRef.current = 0;
} else {
const roundedIdleTime = Math.round(idleTimeRef.current);
incrementIdleTime(human.modelUuid, roundedIdleTime);
idleTimeRef.current = 0;
}
if (animationFrameIdRef.current === null) {
animationFrameIdRef.current = requestAnimationFrame(animate);

View File

@@ -57,15 +57,21 @@ function MachineInstance({ machineDetail }: { readonly machineDetail: MachineSta
const deltaTime = (currentTime - previousTimeRef.current) / 1000;
previousTimeRef.current = currentTime;
if (machineDetail.isActive) {
if (!isPausedRef.current) {
if (!isPausedRef.current) {
if (machineDetail.isActive) {
activeTimeRef.current += deltaTime * isSpeedRef.current;
// console.log(' activeTimeRef.current: ', activeTimeRef.current);
}
} else {
if (!isPausedRef.current) {
if (activeTimeRef.current >= 1) {
const inc = Math.floor(activeTimeRef.current);
incrementActiveTime(machineDetail.modelUuid, inc);
activeTimeRef.current -= inc;
}
} else {
idleTimeRef.current += deltaTime * isSpeedRef.current;
// console.log('idleTimeRef.curre: ', idleTimeRef.current);
if (idleTimeRef.current >= 1) {
const inc = Math.floor(idleTimeRef.current);
incrementIdleTime(machineDetail.modelUuid, inc);
idleTimeRef.current -= inc;
}
}
}
animationFrameIdRef.current = requestAnimationFrame(animate);
@@ -73,17 +79,6 @@ function MachineInstance({ machineDetail }: { readonly machineDetail: MachineSta
useEffect(() => {
if (!isPlaying) return;
if (!machineDetail.isActive) {
const roundedActiveTime = Math.round(activeTimeRef.current);
// console.log('Final Active Time:', roundedActiveTime, 'seconds');
incrementActiveTime(machineDetail.modelUuid, roundedActiveTime);
activeTimeRef.current = 0;
} else {
const roundedIdleTime = Math.round(idleTimeRef.current);
// console.log('Final Idle Time:', roundedIdleTime, 'seconds');
incrementIdleTime(machineDetail.modelUuid, roundedIdleTime);
idleTimeRef.current = 0;
}
if (animationFrameIdRef.current === null) {
animationFrameIdRef.current = requestAnimationFrame(animate);
@@ -127,7 +122,16 @@ function MachineInstance({ machineDetail }: { readonly machineDetail: MachineSta
}
}
return <MachineAnimator processingTime={machineDetail.point.action.processTime} handleCallBack={handleCallBack} currentPhase={currentPhase} machineUuid={machineDetail.modelUuid} machineStatus={machineStatus} reset={reset} />;
return (
<MachineAnimator
processingTime={machineDetail.point.action.processTime}
handleCallBack={handleCallBack}
currentPhase={currentPhase}
machineUuid={machineDetail.modelUuid}
machineStatus={machineStatus}
reset={reset}
/>
);
}
export default MachineInstance;

View File

@@ -144,15 +144,21 @@ function RoboticArmInstance({ armBot }: { readonly armBot: ArmBotStatus }) {
}
const deltaTime = (currentTime - previousTimeRef.current) / 1000;
previousTimeRef.current = currentTime;
if (armBot.isActive) {
if (!isPausedRef.current) {
if (!isPausedRef.current) {
if (armBot.isActive) {
activeSecondsElapsed.current += deltaTime * isSpeedRef.current;
// console.log(' activeSecondsElapsed.current: ', activeSecondsElapsed.current);
}
} else {
if (!isPausedRef.current) {
if (activeSecondsElapsed.current >= 1) {
const inc = Math.floor(activeSecondsElapsed.current);
incrementActiveTime(armBot.modelUuid, inc);
activeSecondsElapsed.current -= inc;
}
} else {
idleSecondsElapsed.current += deltaTime * isSpeedRef.current;
// console.log('idleSecondsElapsed.current: ', idleSecondsElapsed.current);
if (idleSecondsElapsed.current >= 1) {
const inc = Math.floor(idleSecondsElapsed.current);
incrementIdleTime(armBot.modelUuid, inc);
idleSecondsElapsed.current -= inc;
}
}
}
animationFrameIdRef.current = requestAnimationFrame(animate);
@@ -161,21 +167,6 @@ function RoboticArmInstance({ armBot }: { readonly armBot: ArmBotStatus }) {
useEffect(() => {
if (!isPlaying) return;
if (!armBot.isActive && armBot.state === "idle" && (currentPhase === "rest" || currentPhase === "init")) {
cancelAnimationFrame(animationFrameIdRef.current!);
animationFrameIdRef.current = null;
const roundedActiveTime = Math.round(activeSecondsElapsed.current); // Get the final rounded active time
// console.log('🚨Final Active Time:',armBot.modelUuid, roundedActiveTime, 'seconds');
incrementActiveTime(armBot.modelUuid, roundedActiveTime);
activeSecondsElapsed.current = 0;
} else if (armBot.isActive && armBot.state !== "idle" && currentPhase !== "rest" && armBot.currentAction) {
cancelAnimationFrame(animationFrameIdRef.current!);
animationFrameIdRef.current = null;
const roundedIdleTime = Math.round(idleSecondsElapsed.current); // Get the final rounded idle time
// console.log('🕒 Final Idle Time:', armBot.modelUuid,roundedIdleTime, 'seconds');
incrementIdleTime(armBot.modelUuid, roundedIdleTime);
idleSecondsElapsed.current = 0;
}
if (animationFrameIdRef.current === null) {
animationFrameIdRef.current = requestAnimationFrame(animate);
}

View File

@@ -38,13 +38,21 @@ function StorageUnitInstance({ storageUnit }: Readonly<{ storageUnit: StorageUni
const deltaTime = (currentTime - previousTimeRef.current) / 1000;
previousTimeRef.current = currentTime;
if (storageUnit.isActive) {
if (!isPausedRef.current) {
if (!isPausedRef.current) {
if (storageUnit.isActive) {
activeTimeRef.current += deltaTime * isSpeedRef.current;
}
} else {
if (!isPausedRef.current) {
if (activeTimeRef.current >= 1) {
const inc = Math.floor(activeTimeRef.current);
incrementActiveTime(storageUnit.modelUuid, inc);
activeTimeRef.current -= inc;
}
} else {
idleTimeRef.current += deltaTime * isSpeedRef.current;
if (idleTimeRef.current >= 1) {
const inc = Math.floor(idleTimeRef.current);
incrementIdleTime(storageUnit.modelUuid, inc);
idleTimeRef.current -= inc;
}
}
}
animationFrameIdRef.current = requestAnimationFrame(animate);
@@ -52,15 +60,6 @@ function StorageUnitInstance({ storageUnit }: Readonly<{ storageUnit: StorageUni
useEffect(() => {
if (!isPlaying) return;
if (storageUnit.isActive) {
const roundedActiveTime = Math.round(activeTimeRef.current);
incrementActiveTime(storageUnit.modelUuid, roundedActiveTime);
activeTimeRef.current = 0;
} else {
const roundedIdleTime = Math.round(idleTimeRef.current);
incrementIdleTime(storageUnit.modelUuid, roundedIdleTime);
idleTimeRef.current = 0;
}
if (animationFrameIdRef.current === null) {
animationFrameIdRef.current = requestAnimationFrame(animate);

View File

@@ -28,7 +28,21 @@ function VehicleInstance({ agvDetail }: Readonly<{ agvDetail: VehicleStatus }>)
const { addHumanToMonitor } = useHumanEventManager();
const { addCraneToMonitor } = useCraneEventManager();
const { getActionByUuid, getEventByModelUuid, getTriggerByUuid, selectedProduct } = productStore();
const { vehicles, setCurrentPhase, setVehicleActive, setVehicleState, setVehiclePicking, clearCurrentMaterials, setVehicleLoad, decrementVehicleLoad, removeLastMaterial, getLastMaterial, incrementIdleTime, incrementActiveTime, resetTime } = vehicleStore();
const {
vehicles,
setCurrentPhase,
setVehicleActive,
setVehicleState,
setVehiclePicking,
clearCurrentMaterials,
setVehicleLoad,
decrementVehicleLoad,
removeLastMaterial,
getLastMaterial,
incrementIdleTime,
incrementActiveTime,
resetTime,
} = vehicleStore();
const [path, setPath] = useState<[number, number, number][]>([]);
const pauseTimeRef = useRef<number | null>(null);
const idleTimeRef = useRef<number>(0);
@@ -145,13 +159,21 @@ function VehicleInstance({ agvDetail }: Readonly<{ agvDetail: VehicleStatus }>)
const deltaTime = (currentTime - previousTimeRef.current) / 1000;
previousTimeRef.current = currentTime;
if (agvDetail.isActive) {
if (!isPausedRef.current) {
if (!isPausedRef.current) {
if (agvDetail.isActive) {
activeTimeRef.current += deltaTime * isSpeedRef.current;
}
} else {
if (!isPausedRef.current) {
idleTimeRef.current += deltaTime * isSpeedRef.current; // Scale idle time by speed
if (activeTimeRef.current >= 1) {
const inc = Math.floor(activeTimeRef.current);
incrementActiveTime(agvDetail.modelUuid, inc);
activeTimeRef.current -= inc;
}
} else {
idleTimeRef.current += deltaTime * isSpeedRef.current;
if (idleTimeRef.current >= 1) {
const inc = Math.floor(idleTimeRef.current);
incrementIdleTime(agvDetail.modelUuid, inc);
idleTimeRef.current -= inc;
}
}
}
animationFrameIdRef.current = requestAnimationFrame(animate);
@@ -159,17 +181,6 @@ function VehicleInstance({ agvDetail }: Readonly<{ agvDetail: VehicleStatus }>)
useEffect(() => {
if (!isPlaying) return;
if (!agvDetail.isActive) {
const roundedActiveTime = Math.round(activeTimeRef.current);
// console.log('Final Active Time:', roundedActiveTime, 'seconds');
incrementActiveTime(agvDetail.modelUuid, roundedActiveTime);
activeTimeRef.current = 0;
} else {
const roundedIdleTime = Math.round(idleTimeRef.current);
// console.log('Final Idle Time:', roundedIdleTime, 'seconds');
incrementIdleTime(agvDetail.modelUuid, roundedIdleTime);
idleTimeRef.current = 0;
}
if (animationFrameIdRef.current === null) {
animationFrameIdRef.current = requestAnimationFrame(animate);
@@ -569,7 +580,15 @@ function VehicleInstance({ agvDetail }: Readonly<{ agvDetail: VehicleStatus }>)
return (
<>
<VehicleAnimator path={path} handleCallBack={handleCallBack} currentPhase={agvDetail.currentPhase} agvUuid={agvDetail?.modelUuid} agvDetail={agvDetail} reset={reset} startUnloadingProcess={startUnloadingProcess} />
<VehicleAnimator
path={path}
handleCallBack={handleCallBack}
currentPhase={agvDetail.currentPhase}
agvUuid={agvDetail?.modelUuid}
agvDetail={agvDetail}
reset={reset}
startUnloadingProcess={startUnloadingProcess}
/>
{selectedPath === "manual" && <InteractivePoints agvUuid={agvDetail?.modelUuid} />}
<MaterialAnimator agvDetail={agvDetail} />
</>