Refactor vehicle simulation components for improved path handling and state management
- Updated PointsCreator component to enhance event data selection and keyboard handling. - Refactored VehicleAnimator to streamline animation logic and reset handling. - Simplified VehicleInstance logic for better clarity and maintainability. - Modified vehicle data structure to include rotation information for pick-up and unload points. - Adjusted TypeScript types to reflect new vehicle point schema with nested position and rotation properties.
This commit is contained in:
parent
ccc7a1d954
commit
ea53af62c4
|
@ -15,9 +15,7 @@ function VehicleMechanics() {
|
||||||
const [activeOption, setActiveOption] = useState<"default" | "travel">(
|
const [activeOption, setActiveOption] = useState<"default" | "travel">(
|
||||||
"default"
|
"default"
|
||||||
);
|
);
|
||||||
const [selectedPointData, setSelectedPointData] = useState<
|
const [selectedPointData, setSelectedPointData] = useState<VehiclePointSchema | undefined>();
|
||||||
VehiclePointSchema | undefined
|
|
||||||
>();
|
|
||||||
const { selectedEventData } = useSelectedEventData();
|
const { selectedEventData } = useSelectedEventData();
|
||||||
const { getPointByUuid, updateEvent, updateAction } = useProductStore();
|
const { getPointByUuid, updateEvent, updateAction } = useProductStore();
|
||||||
const { selectedProduct } = useSelectedProduct();
|
const { selectedProduct } = useSelectedProduct();
|
||||||
|
@ -75,18 +73,10 @@ function VehicleMechanics() {
|
||||||
|
|
||||||
const handlePickPointChange = (value: string) => {
|
const handlePickPointChange = (value: string) => {
|
||||||
if (!selectedPointData) return;
|
if (!selectedPointData) return;
|
||||||
const [x, y, z] = value.split(",").map(Number);
|
|
||||||
updateAction(selectedPointData.action.actionUuid, {
|
|
||||||
pickUpPoint: { x, y, z },
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleUnloadPointChange = (value: string) => {
|
const handleUnloadPointChange = (value: string) => {
|
||||||
if (!selectedPointData) return;
|
if (!selectedPointData) return;
|
||||||
const [x, y, z] = value.split(",").map(Number);
|
|
||||||
updateAction(selectedPointData.action.actionUuid, {
|
|
||||||
unLoadPoint: { x, y, z },
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Get current values from store
|
// Get current values from store
|
||||||
|
@ -107,13 +97,9 @@ function VehicleMechanics() {
|
||||||
? selectedPointData.action.unLoadDuration.toString()
|
? selectedPointData.action.unLoadDuration.toString()
|
||||||
: "1";
|
: "1";
|
||||||
|
|
||||||
const currentPickPoint = selectedPointData?.action.pickUpPoint
|
const currentPickPoint = selectedPointData?.action.pickUpPoint;
|
||||||
? `${selectedPointData.action.pickUpPoint.x},${selectedPointData.action.pickUpPoint.y},${selectedPointData.action.pickUpPoint.z}`
|
|
||||||
: "";
|
|
||||||
|
|
||||||
const currentUnloadPoint = selectedPointData?.action.unLoadPoint
|
const currentUnloadPoint = selectedPointData?.action.unLoadPoint;
|
||||||
? `${selectedPointData.action.unLoadPoint.x},${selectedPointData.action.unLoadPoint.y},${selectedPointData.action.unLoadPoint.z}`
|
|
||||||
: "";
|
|
||||||
|
|
||||||
const availableActions = {
|
const availableActions = {
|
||||||
defaultOption: "travel",
|
defaultOption: "travel",
|
||||||
|
|
|
@ -139,7 +139,6 @@ function VehicleAnimator({ path, handleCallBack, currentPhase, agvUuid, agvDetai
|
||||||
// }
|
// }
|
||||||
// });
|
// });
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
console.log('isReset: ', isReset);
|
|
||||||
if (isReset) {
|
if (isReset) {
|
||||||
reset();
|
reset();
|
||||||
setCurrentPath([]);
|
setCurrentPath([]);
|
||||||
|
@ -149,7 +148,6 @@ function VehicleAnimator({ path, handleCallBack, currentPhase, agvUuid, agvDetai
|
||||||
movingForward.current = true;
|
movingForward.current = true;
|
||||||
setRestingRotation(false);
|
setRestingRotation(false);
|
||||||
decrementVehicleLoad(agvDetail.modelUuid, 0);
|
decrementVehicleLoad(agvDetail.modelUuid, 0);
|
||||||
console.log('agvDetail: ', vehicles);
|
|
||||||
}
|
}
|
||||||
}, [isReset]);
|
}, [isReset]);
|
||||||
|
|
||||||
|
|
|
@ -33,7 +33,6 @@ function VehicleInstance({ agvDetail }: any) {
|
||||||
// console.log(`AGV ${modelid}: ${status}`);
|
// console.log(`AGV ${modelid}: ${status}`);
|
||||||
}
|
}
|
||||||
function reset() {
|
function reset() {
|
||||||
console.log("runs");
|
|
||||||
setVehicleActive(agvDetail.modelUuid, false);
|
setVehicleActive(agvDetail.modelUuid, false);
|
||||||
setVehicleState(agvDetail.modelUuid, 'idle');
|
setVehicleState(agvDetail.modelUuid, 'idle');
|
||||||
setPath([]);
|
setPath([]);
|
||||||
|
@ -53,11 +52,7 @@ function VehicleInstance({ agvDetail }: any) {
|
||||||
setCurrentPhase('stationed-pickup');
|
setCurrentPhase('stationed-pickup');
|
||||||
vehicleStatus(agvDetail.modelUuid, 'Started from station, heading to pickup');
|
vehicleStatus(agvDetail.modelUuid, 'Started from station, heading to pickup');
|
||||||
return;
|
return;
|
||||||
} else if (
|
} else if (!agvDetail.isActive && agvDetail.state === 'idle' && currentPhase === 'picking') {
|
||||||
!agvDetail.isActive &&
|
|
||||||
agvDetail.state === 'idle' &&
|
|
||||||
currentPhase === 'picking'
|
|
||||||
) {
|
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
incrementVehicleLoad(agvDetail.modelUuid, 2);
|
incrementVehicleLoad(agvDetail.modelUuid, 2);
|
||||||
|
@ -74,12 +69,7 @@ function VehicleInstance({ agvDetail }: any) {
|
||||||
setCurrentPhase('pickup-drop');
|
setCurrentPhase('pickup-drop');
|
||||||
vehicleStatus(agvDetail.modelUuid, 'Started from pickup point, heading to drop point');
|
vehicleStatus(agvDetail.modelUuid, 'Started from pickup point, heading to drop point');
|
||||||
}
|
}
|
||||||
} else if (
|
} else if (!agvDetail.isActive && agvDetail.state === 'idle' && currentPhase === 'dropping' && agvDetail.currentLoad === 0) {
|
||||||
!agvDetail.isActive &&
|
|
||||||
agvDetail.state === 'idle' &&
|
|
||||||
currentPhase === 'dropping' &&
|
|
||||||
agvDetail.currentLoad === 0
|
|
||||||
) {
|
|
||||||
const dropToPickup = computePath(
|
const dropToPickup = computePath(
|
||||||
agvDetail.point.action.unLoadPoint,
|
agvDetail.point.action.unLoadPoint,
|
||||||
agvDetail.point.action.pickUpPoint
|
agvDetail.point.action.pickUpPoint
|
||||||
|
|
|
@ -28,8 +28,8 @@ function Vehicles() {
|
||||||
actionType: "travel",
|
actionType: "travel",
|
||||||
unLoadDuration: 10,
|
unLoadDuration: 10,
|
||||||
loadCapacity: 2,
|
loadCapacity: 2,
|
||||||
pickUpPoint: { x: 98.71483985219794, y: 0, z: 28.66321267938962 },
|
pickUpPoint: { position: { x: 98.71483985219794, y: 0, z: 28.66321267938962 }, rotation: { x: 0, y: 0, z: 0 } },
|
||||||
unLoadPoint: { x: 105.71483985219794, y: 0, z: 28.66321267938962 },
|
unLoadPoint: { position: { x: 105.71483985219794, y: 0, z: 28.66321267938962 }, rotation: { x: 0, y: 0, z: 0 } },
|
||||||
triggers: [
|
triggers: [
|
||||||
{
|
{
|
||||||
triggerUuid: "trig-001",
|
triggerUuid: "trig-001",
|
||||||
|
@ -71,8 +71,8 @@ function Vehicles() {
|
||||||
actionType: "travel",
|
actionType: "travel",
|
||||||
unLoadDuration: 10,
|
unLoadDuration: 10,
|
||||||
loadCapacity: 2,
|
loadCapacity: 2,
|
||||||
pickUpPoint: { x: 90, y: 0, z: 28 },
|
pickUpPoint: { position: { x: 90, y: 0, z: 28 }, rotation: { x: 0, y: 0, z: 0 } },
|
||||||
unLoadPoint: { x: 20, y: 0, z: 10 },
|
unLoadPoint: { position: { x: 20, y: 0, z: 10 }, rotation: { x: 0, y: 0, z: 0 } },
|
||||||
triggers: [
|
triggers: [
|
||||||
{
|
{
|
||||||
triggerUuid: "trig-001",
|
triggerUuid: "trig-001",
|
||||||
|
@ -95,7 +95,8 @@ function Vehicles() {
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, {
|
},
|
||||||
|
{
|
||||||
modelUuid: "e729a4f1-11d2-4778-8d6a-468f1b4f6b79",
|
modelUuid: "e729a4f1-11d2-4778-8d6a-468f1b4f6b79",
|
||||||
modelName: "forklift",
|
modelName: "forklift",
|
||||||
position: [98.85729337188162, 0, 38.36616546567653],
|
position: [98.85729337188162, 0, 38.36616546567653],
|
||||||
|
@ -113,8 +114,8 @@ function Vehicles() {
|
||||||
actionType: "travel",
|
actionType: "travel",
|
||||||
unLoadDuration: 15,
|
unLoadDuration: 15,
|
||||||
loadCapacity: 5,
|
loadCapacity: 5,
|
||||||
pickUpPoint: { x: 98.71483985219794, y: 0, z: 28.66321267938962 },
|
pickUpPoint: { position: { x: 98.71483985219794, y: 0, z: 28.66321267938962 }, rotation: { x: 0, y: 0, z: 0 } },
|
||||||
unLoadPoint: { x: 20, y: 0, z: 10 },
|
unLoadPoint: { position: { x: 20, y: 0, z: 10 }, rotation: { x: 0, y: 0, z: 0 } },
|
||||||
triggers: [
|
triggers: [
|
||||||
{
|
{
|
||||||
triggerUuid: "trig-001",
|
triggerUuid: "trig-001",
|
||||||
|
|
|
@ -44,8 +44,8 @@ interface VehiclePointSchema {
|
||||||
actionType: "travel";
|
actionType: "travel";
|
||||||
unLoadDuration: number;
|
unLoadDuration: number;
|
||||||
loadCapacity: number;
|
loadCapacity: number;
|
||||||
pickUpPoint: { x: number; y: number, z: number } | null;
|
pickUpPoint: { position: { x: number; y: number, z: number }, rotation: { x: number; y: number, z: number } } | null;
|
||||||
unLoadPoint: { x: number; y: number, z: number } | null;
|
unLoadPoint: { position: { x: number; y: number, z: number }, rotation: { x: number; y: number, z: number } } | null;
|
||||||
triggers: TriggerSchema[];
|
triggers: TriggerSchema[];
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue