added machine actions
This commit is contained in:
parent
f888c2798c
commit
ec4d3db70e
|
@ -38,10 +38,18 @@ const SimulationPlayer: React.FC = () => {
|
||||||
const { isReset, setReset } = useResetButtonStore();
|
const { isReset, setReset } = useResetButtonStore();
|
||||||
const { subModule } = useSubModuleStore();
|
const { subModule } = useSubModuleStore();
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (isReset) {
|
||||||
|
setTimeout(() => {
|
||||||
|
setReset(false);
|
||||||
|
}, 0)
|
||||||
|
}
|
||||||
|
}, [isReset])
|
||||||
|
|
||||||
// Button functions
|
// Button functions
|
||||||
const handleReset = () => {
|
const handleReset = () => {
|
||||||
setReset(!isReset);
|
setReset(true);
|
||||||
setSpeed(1);
|
// setSpeed(1);
|
||||||
};
|
};
|
||||||
const handlePlayStop = () => {
|
const handlePlayStop = () => {
|
||||||
setIsPaused(!isPaused);
|
setIsPaused(!isPaused);
|
||||||
|
@ -271,8 +279,7 @@ const SimulationPlayer: React.FC = () => {
|
||||||
</div>
|
</div>
|
||||||
{index < intervals.length - 1 && (
|
{index < intervals.length - 1 && (
|
||||||
<div
|
<div
|
||||||
className={`line ${
|
className={`line ${progress >= ((index + 1) / totalSegments) * 100
|
||||||
progress >= ((index + 1) / totalSegments) * 100
|
|
||||||
? "filled"
|
? "filled"
|
||||||
: ""
|
: ""
|
||||||
}`}
|
}`}
|
||||||
|
@ -314,8 +321,7 @@ const SimulationPlayer: React.FC = () => {
|
||||||
<div className="custom-slider-wrapper">
|
<div className="custom-slider-wrapper">
|
||||||
<div className="custom-slider">
|
<div className="custom-slider">
|
||||||
<button
|
<button
|
||||||
className={`slider-handle ${
|
className={`slider-handle ${isDragging ? "dragging" : ""
|
||||||
isDragging ? "dragging" : ""
|
|
||||||
}`}
|
}`}
|
||||||
style={{ left: `${calculateHandlePosition()}%` }}
|
style={{ left: `${calculateHandlePosition()}%` }}
|
||||||
onMouseDown={handleMouseDown}
|
onMouseDown={handleMouseDown}
|
||||||
|
|
|
@ -6,20 +6,20 @@ import { useVehicleActions } from "./vehicle/useVehicleActions";
|
||||||
|
|
||||||
// Master hook that selects the appropriate action handler
|
// Master hook that selects the appropriate action handler
|
||||||
export function useActionHandler(point: PointsScheme) {
|
export function useActionHandler(point: PointsScheme) {
|
||||||
if ('actions' in point) {
|
// if ('actions' in point) {
|
||||||
// Robotic Arm
|
// // Robotic Arm
|
||||||
useRoboticArmActions(point);
|
// useRoboticArmActions(point);
|
||||||
} else if (point.action.actionType === 'travel') {
|
// } else if (point.action.actionType === 'travel') {
|
||||||
// Vehicle
|
// // Vehicle
|
||||||
useVehicleActions(point as VehiclePointSchema);
|
// useVehicleActions(point as VehiclePointSchema);
|
||||||
} else if (point.action.actionType === 'process') {
|
// } else if (point.action.actionType === 'process') {
|
||||||
// Machine
|
// // Machine
|
||||||
useMachineActions(point as MachinePointSchema);
|
// useMachineActions(point as MachinePointSchema);
|
||||||
} else if (point.action.actionType === 'store') {
|
// } else if (point.action.actionType === 'store') {
|
||||||
// Storage
|
// // Storage
|
||||||
useStorageActions(point as StoragePointSchema);
|
// useStorageActions(point as StoragePointSchema);
|
||||||
} else {
|
// } else {
|
||||||
// Conveyor
|
// // Conveyor
|
||||||
useConveyorActions(point as ConveyorPointSchema);
|
// useConveyorActions(point as ConveyorPointSchema);
|
||||||
}
|
// }
|
||||||
}
|
}
|
|
@ -34,16 +34,12 @@ const MachineAnimator = ({ currentPhase, handleCallBack, processingTime, machine
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
isPlayingRef.current = isPlaying;
|
isPlayingRef.current = isPlaying;
|
||||||
}, [isPlaying]);
|
}, [isPlaying]);
|
||||||
useEffect(() => {
|
|
||||||
isResetRef.current = isReset;
|
|
||||||
}, [isReset]);
|
|
||||||
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|
||||||
if (isReset || !isPlaying) {
|
if (isReset || !isPlaying) {
|
||||||
reset();
|
reset();
|
||||||
setReset(false);
|
|
||||||
startTimeRef.current = 0;
|
startTimeRef.current = 0;
|
||||||
isPausedRef.current = false;
|
isPausedRef.current = false;
|
||||||
pauseTimeRef.current = 0;
|
pauseTimeRef.current = 0;
|
||||||
|
@ -53,20 +49,19 @@ const MachineAnimator = ({ currentPhase, handleCallBack, processingTime, machine
|
||||||
}
|
}
|
||||||
}, [isReset, isPlaying])
|
}, [isReset, isPlaying])
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (currentPhase === 'processing' && !animationStarted.current && machineUuid) {
|
if (currentPhase === 'processing' && !animationStarted.current && machineUuid) {
|
||||||
animationStarted.current = true;
|
animationStarted.current = true;
|
||||||
startTimeRef.current = performance.now();
|
startTimeRef.current = performance.now();
|
||||||
animationFrameId.current = requestAnimationFrame(step);
|
animationFrameId.current = requestAnimationFrame(step);
|
||||||
}
|
}
|
||||||
|
|
||||||
}, [currentPhase]);
|
}, [currentPhase]);
|
||||||
|
|
||||||
function step(time: number) {
|
function step(time: number) {
|
||||||
if (!isPausedRef.current || !isResetRef.current) {
|
|
||||||
if (animationFrameId.current) {
|
|
||||||
cancelAnimationFrame(animationFrameId.current);
|
|
||||||
animationFrameId.current = null;
|
|
||||||
}
|
|
||||||
if (isPausedRef.current) {
|
if (isPausedRef.current) {
|
||||||
if (!pauseTimeRef.current) {
|
if (!pauseTimeRef.current) {
|
||||||
pauseTimeRef.current = performance.now();
|
pauseTimeRef.current = performance.now();
|
||||||
|
@ -82,18 +77,23 @@ const MachineAnimator = ({ currentPhase, handleCallBack, processingTime, machine
|
||||||
}
|
}
|
||||||
|
|
||||||
const elapsed = time - startTimeRef.current;
|
const elapsed = time - startTimeRef.current;
|
||||||
const processedTime = processingTime * 1000;
|
const processedTime = (processingTime * 1000) / speed;
|
||||||
|
|
||||||
if (elapsed < processedTime) {
|
if (elapsed < processedTime) {
|
||||||
machineStatus(machineUuid, "Machine is currently processing the task");
|
machineStatus(machineUuid, "Machine is currently processing the task");
|
||||||
animationFrameId.current = requestAnimationFrame(step);
|
animationFrameId.current = requestAnimationFrame(step);
|
||||||
} else {
|
} else {
|
||||||
removeCurrentAction(machineUuid);
|
|
||||||
animationStarted.current = false;
|
animationStarted.current = false;
|
||||||
|
if (animationFrameId.current !== null) {
|
||||||
|
removeCurrentAction(machineUuid);
|
||||||
|
cancelAnimationFrame(animationFrameId.current);
|
||||||
|
animationFrameId.current = null;
|
||||||
handleCallBack();
|
handleCallBack();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
|
|
|
@ -10,10 +10,10 @@ function MachineInstance({ machineDetail }: any) {
|
||||||
const { machines, addCurrentAction, setMachineState, setMachineActive } = useMachineStore();
|
const { machines, addCurrentAction, setMachineState, setMachineActive } = useMachineStore();
|
||||||
|
|
||||||
const reset = () => {
|
const reset = () => {
|
||||||
|
setCurrentPhase("idle");
|
||||||
setMachineState(machineDetail.modelUuid, 'idle');
|
setMachineState(machineDetail.modelUuid, 'idle');
|
||||||
setMachineActive(machineDetail.modelUuid, false);
|
setMachineActive(machineDetail.modelUuid, false);
|
||||||
isIncrememtable.current = true;
|
isIncrememtable.current = true;
|
||||||
setCurrentPhase("idle");
|
|
||||||
}
|
}
|
||||||
const increment = () => {
|
const increment = () => {
|
||||||
if (isIncrememtable.current) {
|
if (isIncrememtable.current) {
|
||||||
|
@ -31,7 +31,7 @@ function MachineInstance({ machineDetail }: any) {
|
||||||
if (!machineDetail.isActive && machineDetail.state === "idle" && currentPhase == "idle" && !machineDetail.currentAction) {
|
if (!machineDetail.isActive && machineDetail.state === "idle" && currentPhase == "idle" && !machineDetail.currentAction) {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
increment();
|
increment();
|
||||||
}, 2000);
|
}, 5000);
|
||||||
machineStatus(machineDetail.modelUuid, 'Machine is idle and waiting for next instruction.')
|
machineStatus(machineDetail.modelUuid, 'Machine is idle and waiting for next instruction.')
|
||||||
} else if (!machineDetail.isActive && machineDetail.state === "idle" && currentPhase == "idle" && machineDetail.currentAction) {
|
} else if (!machineDetail.isActive && machineDetail.state === "idle" && currentPhase == "idle" && machineDetail.currentAction) {
|
||||||
setCurrentPhase("processing");
|
setCurrentPhase("processing");
|
||||||
|
@ -39,8 +39,6 @@ function MachineInstance({ machineDetail }: any) {
|
||||||
setMachineActive(machineDetail.modelUuid, true);
|
setMachineActive(machineDetail.modelUuid, true);
|
||||||
machineStatus(machineDetail.modelUuid, "Machine started processing")
|
machineStatus(machineDetail.modelUuid, "Machine started processing")
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
reset();
|
|
||||||
}
|
}
|
||||||
}, [currentPhase, isPlaying, machines])
|
}, [currentPhase, isPlaying, machines])
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,7 @@ function Simulator() {
|
||||||
const executionOrder = determineExecutionOrder(products);
|
const executionOrder = determineExecutionOrder(products);
|
||||||
|
|
||||||
executionOrder.forEach(point => {
|
executionOrder.forEach(point => {
|
||||||
useActionHandler(point);
|
// useActionHandler(point);
|
||||||
});
|
});
|
||||||
|
|
||||||
function determineExecutionSequences(products: productsSchema): PointsScheme[][] {
|
function determineExecutionSequences(products: productsSchema): PointsScheme[][] {
|
||||||
|
|
Loading…
Reference in New Issue