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">(
|
||||
"default"
|
||||
);
|
||||
const [selectedPointData, setSelectedPointData] = useState<
|
||||
VehiclePointSchema | undefined
|
||||
>();
|
||||
const [selectedPointData, setSelectedPointData] = useState<VehiclePointSchema | undefined>();
|
||||
const { selectedEventData } = useSelectedEventData();
|
||||
const { getPointByUuid, updateEvent, updateAction } = useProductStore();
|
||||
const { selectedProduct } = useSelectedProduct();
|
||||
|
@ -75,18 +73,10 @@ function VehicleMechanics() {
|
|||
|
||||
const handlePickPointChange = (value: string) => {
|
||||
if (!selectedPointData) return;
|
||||
const [x, y, z] = value.split(",").map(Number);
|
||||
updateAction(selectedPointData.action.actionUuid, {
|
||||
pickUpPoint: { x, y, z },
|
||||
});
|
||||
};
|
||||
|
||||
const handleUnloadPointChange = (value: string) => {
|
||||
if (!selectedPointData) return;
|
||||
const [x, y, z] = value.split(",").map(Number);
|
||||
updateAction(selectedPointData.action.actionUuid, {
|
||||
unLoadPoint: { x, y, z },
|
||||
});
|
||||
};
|
||||
|
||||
// Get current values from store
|
||||
|
@ -107,13 +97,9 @@ function VehicleMechanics() {
|
|||
? selectedPointData.action.unLoadDuration.toString()
|
||||
: "1";
|
||||
|
||||
const currentPickPoint = selectedPointData?.action.pickUpPoint
|
||||
? `${selectedPointData.action.pickUpPoint.x},${selectedPointData.action.pickUpPoint.y},${selectedPointData.action.pickUpPoint.z}`
|
||||
: "";
|
||||
const currentPickPoint = selectedPointData?.action.pickUpPoint;
|
||||
|
||||
const currentUnloadPoint = selectedPointData?.action.unLoadPoint
|
||||
? `${selectedPointData.action.unLoadPoint.x},${selectedPointData.action.unLoadPoint.y},${selectedPointData.action.unLoadPoint.z}`
|
||||
: "";
|
||||
const currentUnloadPoint = selectedPointData?.action.unLoadPoint;
|
||||
|
||||
const availableActions = {
|
||||
defaultOption: "travel",
|
||||
|
@ -135,7 +121,7 @@ function VehicleMechanics() {
|
|||
defaultValue={"0.5"}
|
||||
max={10}
|
||||
activeOption="m/s"
|
||||
onClick={() => {}}
|
||||
onClick={() => { }}
|
||||
onChange={handleSpeedChange}
|
||||
/>
|
||||
</div>
|
||||
|
|
|
@ -139,7 +139,6 @@ function VehicleAnimator({ path, handleCallBack, currentPhase, agvUuid, agvDetai
|
|||
// }
|
||||
// });
|
||||
useEffect(() => {
|
||||
console.log('isReset: ', isReset);
|
||||
if (isReset) {
|
||||
reset();
|
||||
setCurrentPath([]);
|
||||
|
@ -149,7 +148,6 @@ function VehicleAnimator({ path, handleCallBack, currentPhase, agvUuid, agvDetai
|
|||
movingForward.current = true;
|
||||
setRestingRotation(false);
|
||||
decrementVehicleLoad(agvDetail.modelUuid, 0);
|
||||
console.log('agvDetail: ', vehicles);
|
||||
}
|
||||
}, [isReset]);
|
||||
|
||||
|
|
|
@ -33,7 +33,6 @@ function VehicleInstance({ agvDetail }: any) {
|
|||
// console.log(`AGV ${modelid}: ${status}`);
|
||||
}
|
||||
function reset() {
|
||||
console.log("runs");
|
||||
setVehicleActive(agvDetail.modelUuid, false);
|
||||
setVehicleState(agvDetail.modelUuid, 'idle');
|
||||
setPath([]);
|
||||
|
@ -53,11 +52,7 @@ function VehicleInstance({ agvDetail }: any) {
|
|||
setCurrentPhase('stationed-pickup');
|
||||
vehicleStatus(agvDetail.modelUuid, 'Started from station, heading to pickup');
|
||||
return;
|
||||
} else if (
|
||||
!agvDetail.isActive &&
|
||||
agvDetail.state === 'idle' &&
|
||||
currentPhase === 'picking'
|
||||
) {
|
||||
} else if (!agvDetail.isActive && agvDetail.state === 'idle' && currentPhase === 'picking') {
|
||||
|
||||
setTimeout(() => {
|
||||
incrementVehicleLoad(agvDetail.modelUuid, 2);
|
||||
|
@ -74,12 +69,7 @@ function VehicleInstance({ agvDetail }: any) {
|
|||
setCurrentPhase('pickup-drop');
|
||||
vehicleStatus(agvDetail.modelUuid, 'Started from pickup point, heading to drop point');
|
||||
}
|
||||
} else if (
|
||||
!agvDetail.isActive &&
|
||||
agvDetail.state === 'idle' &&
|
||||
currentPhase === 'dropping' &&
|
||||
agvDetail.currentLoad === 0
|
||||
) {
|
||||
} else if (!agvDetail.isActive && agvDetail.state === 'idle' && currentPhase === 'dropping' && agvDetail.currentLoad === 0) {
|
||||
const dropToPickup = computePath(
|
||||
agvDetail.point.action.unLoadPoint,
|
||||
agvDetail.point.action.pickUpPoint
|
||||
|
|
|
@ -28,8 +28,8 @@ function Vehicles() {
|
|||
actionType: "travel",
|
||||
unLoadDuration: 10,
|
||||
loadCapacity: 2,
|
||||
pickUpPoint: { x: 98.71483985219794, y: 0, z: 28.66321267938962 },
|
||||
unLoadPoint: { x: 105.71483985219794, y: 0, z: 28.66321267938962 },
|
||||
pickUpPoint: { position: { x: 98.71483985219794, y: 0, z: 28.66321267938962 }, rotation: { x: 0, y: 0, z: 0 } },
|
||||
unLoadPoint: { position: { x: 105.71483985219794, y: 0, z: 28.66321267938962 }, rotation: { x: 0, y: 0, z: 0 } },
|
||||
triggers: [
|
||||
{
|
||||
triggerUuid: "trig-001",
|
||||
|
@ -71,8 +71,8 @@ function Vehicles() {
|
|||
actionType: "travel",
|
||||
unLoadDuration: 10,
|
||||
loadCapacity: 2,
|
||||
pickUpPoint: { x: 90, y: 0, z: 28 },
|
||||
unLoadPoint: { x: 20, y: 0, z: 10 },
|
||||
pickUpPoint: { position: { x: 90, y: 0, z: 28 }, rotation: { x: 0, y: 0, z: 0 } },
|
||||
unLoadPoint: { position: { x: 20, y: 0, z: 10 }, rotation: { x: 0, y: 0, z: 0 } },
|
||||
triggers: [
|
||||
{
|
||||
triggerUuid: "trig-001",
|
||||
|
@ -95,7 +95,8 @@ function Vehicles() {
|
|||
]
|
||||
}
|
||||
}
|
||||
}, {
|
||||
},
|
||||
{
|
||||
modelUuid: "e729a4f1-11d2-4778-8d6a-468f1b4f6b79",
|
||||
modelName: "forklift",
|
||||
position: [98.85729337188162, 0, 38.36616546567653],
|
||||
|
@ -113,8 +114,8 @@ function Vehicles() {
|
|||
actionType: "travel",
|
||||
unLoadDuration: 15,
|
||||
loadCapacity: 5,
|
||||
pickUpPoint: { x: 98.71483985219794, y: 0, z: 28.66321267938962 },
|
||||
unLoadPoint: { x: 20, y: 0, z: 10 },
|
||||
pickUpPoint: { position: { x: 98.71483985219794, y: 0, z: 28.66321267938962 }, rotation: { x: 0, y: 0, z: 0 } },
|
||||
unLoadPoint: { position: { x: 20, y: 0, z: 10 }, rotation: { x: 0, y: 0, z: 0 } },
|
||||
triggers: [
|
||||
{
|
||||
triggerUuid: "trig-001",
|
||||
|
|
|
@ -44,8 +44,8 @@ interface VehiclePointSchema {
|
|||
actionType: "travel";
|
||||
unLoadDuration: number;
|
||||
loadCapacity: number;
|
||||
pickUpPoint: { x: number; y: number, z: number } | null;
|
||||
unLoadPoint: { x: number; y: number, z: number } | null;
|
||||
pickUpPoint: { position: { x: number; y: number, z: number }, rotation: { 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[];
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue