added machine actions

This commit is contained in:
Poovizhi99 2025-05-05 12:20:55 +05:30
parent f888c2798c
commit ec4d3db70e
5 changed files with 66 additions and 62 deletions

View File

@ -38,10 +38,18 @@ const SimulationPlayer: React.FC = () => {
const { isReset, setReset } = useResetButtonStore();
const { subModule } = useSubModuleStore();
useEffect(() => {
if (isReset) {
setTimeout(() => {
setReset(false);
}, 0)
}
}, [isReset])
// Button functions
const handleReset = () => {
setReset(!isReset);
setSpeed(1);
setReset(true);
// setSpeed(1);
};
const handlePlayStop = () => {
setIsPaused(!isPaused);
@ -271,11 +279,10 @@ const SimulationPlayer: React.FC = () => {
</div>
{index < intervals.length - 1 && (
<div
className={`line ${
progress >= ((index + 1) / totalSegments) * 100
? "filled"
: ""
}`}
className={`line ${progress >= ((index + 1) / totalSegments) * 100
? "filled"
: ""
}`}
></div>
)}
</React.Fragment>
@ -314,9 +321,8 @@ const SimulationPlayer: React.FC = () => {
<div className="custom-slider-wrapper">
<div className="custom-slider">
<button
className={`slider-handle ${
isDragging ? "dragging" : ""
}`}
className={`slider-handle ${isDragging ? "dragging" : ""
}`}
style={{ left: `${calculateHandlePosition()}%` }}
onMouseDown={handleMouseDown}
>

View File

@ -6,20 +6,20 @@ import { useVehicleActions } from "./vehicle/useVehicleActions";
// Master hook that selects the appropriate action handler
export function useActionHandler(point: PointsScheme) {
if ('actions' in point) {
// Robotic Arm
useRoboticArmActions(point);
} else if (point.action.actionType === 'travel') {
// Vehicle
useVehicleActions(point as VehiclePointSchema);
} else if (point.action.actionType === 'process') {
// Machine
useMachineActions(point as MachinePointSchema);
} else if (point.action.actionType === 'store') {
// Storage
useStorageActions(point as StoragePointSchema);
} else {
// Conveyor
useConveyorActions(point as ConveyorPointSchema);
}
// if ('actions' in point) {
// // Robotic Arm
// useRoboticArmActions(point);
// } else if (point.action.actionType === 'travel') {
// // Vehicle
// useVehicleActions(point as VehiclePointSchema);
// } else if (point.action.actionType === 'process') {
// // Machine
// useMachineActions(point as MachinePointSchema);
// } else if (point.action.actionType === 'store') {
// // Storage
// useStorageActions(point as StoragePointSchema);
// } else {
// // Conveyor
// useConveyorActions(point as ConveyorPointSchema);
// }
}

View File

@ -34,16 +34,12 @@ const MachineAnimator = ({ currentPhase, handleCallBack, processingTime, machine
useEffect(() => {
isPlayingRef.current = isPlaying;
}, [isPlaying]);
useEffect(() => {
isResetRef.current = isReset;
}, [isReset]);
useEffect(() => {
if (isReset || !isPlaying) {
reset();
setReset(false);
startTimeRef.current = 0;
isPausedRef.current = false;
pauseTimeRef.current = 0;
@ -53,49 +49,53 @@ const MachineAnimator = ({ currentPhase, handleCallBack, processingTime, machine
}
}, [isReset, isPlaying])
useEffect(() => {
if (currentPhase === 'processing' && !animationStarted.current && machineUuid) {
animationStarted.current = true;
startTimeRef.current = performance.now();
animationFrameId.current = requestAnimationFrame(step);
}
}, [currentPhase]);
function step(time: number) {
if (!isPausedRef.current || !isResetRef.current) {
if (animationFrameId.current) {
if (isPausedRef.current) {
if (!pauseTimeRef.current) {
pauseTimeRef.current = performance.now();
}
animationFrameId.current = requestAnimationFrame(step);
return;
}
if (pauseTimeRef.current) {
const pauseDuration = performance.now() - pauseTimeRef.current;
startTimeRef.current += pauseDuration;
pauseTimeRef.current = null;
}
const elapsed = time - startTimeRef.current;
const processedTime = (processingTime * 1000) / speed;
if (elapsed < processedTime) {
machineStatus(machineUuid, "Machine is currently processing the task");
animationFrameId.current = requestAnimationFrame(step);
} else {
animationStarted.current = false;
if (animationFrameId.current !== null) {
removeCurrentAction(machineUuid);
cancelAnimationFrame(animationFrameId.current);
animationFrameId.current = null;
}
if (isPausedRef.current) {
if (!pauseTimeRef.current) {
pauseTimeRef.current = performance.now();
}
animationFrameId.current = requestAnimationFrame(step);
return;
}
if (pauseTimeRef.current) {
const pauseDuration = performance.now() - pauseTimeRef.current;
startTimeRef.current += pauseDuration;
pauseTimeRef.current = null;
}
const elapsed = time - startTimeRef.current;
const processedTime = processingTime * 1000;
if (elapsed < processedTime) {
machineStatus(machineUuid, "Machine is currently processing the task");
animationFrameId.current = requestAnimationFrame(step);
} else {
removeCurrentAction(machineUuid);
animationStarted.current = false;
handleCallBack();
}
}
}
return null;
}

View File

@ -10,10 +10,10 @@ function MachineInstance({ machineDetail }: any) {
const { machines, addCurrentAction, setMachineState, setMachineActive } = useMachineStore();
const reset = () => {
setCurrentPhase("idle");
setMachineState(machineDetail.modelUuid, 'idle');
setMachineActive(machineDetail.modelUuid, false);
isIncrememtable.current = true;
setCurrentPhase("idle");
}
const increment = () => {
if (isIncrememtable.current) {
@ -31,7 +31,7 @@ function MachineInstance({ machineDetail }: any) {
if (!machineDetail.isActive && machineDetail.state === "idle" && currentPhase == "idle" && !machineDetail.currentAction) {
setTimeout(() => {
increment();
}, 2000);
}, 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");
@ -39,8 +39,6 @@ function MachineInstance({ machineDetail }: any) {
setMachineActive(machineDetail.modelUuid, true);
machineStatus(machineDetail.modelUuid, "Machine started processing")
}
} else {
reset();
}
}, [currentPhase, isPlaying, machines])

View File

@ -7,7 +7,7 @@ function Simulator() {
const executionOrder = determineExecutionOrder(products);
executionOrder.forEach(point => {
useActionHandler(point);
// useActionHandler(point);
});
function determineExecutionSequences(products: productsSchema): PointsScheme[][] {