From 4d77aa6a994d8bd94c14162f7eb8455050a1bc3a Mon Sep 17 00:00:00 2001 From: Poovizhi99 Date: Tue, 10 Jun 2025 18:46:48 +0530 Subject: [PATCH] refactor: Improve path computation logic and enhance error handling in VehicleInstance; add debug logs in UserAuth for API response --- .../instances/instance/vehicleInstance.tsx | 22 +++++++++++++++---- app/src/pages/UserAuth.tsx | 14 ++++++------ 2 files changed, 25 insertions(+), 11 deletions(-) diff --git a/app/src/modules/simulation/vehicle/instances/instance/vehicleInstance.tsx b/app/src/modules/simulation/vehicle/instances/instance/vehicleInstance.tsx index 2031f99..9952888 100644 --- a/app/src/modules/simulation/vehicle/instances/instance/vehicleInstance.tsx +++ b/app/src/modules/simulation/vehicle/instances/instance/vehicleInstance.tsx @@ -48,14 +48,24 @@ function VehicleInstance({ agvDetail }: Readonly<{ agvDetail: VehicleStatus }>) const computePath = useCallback( (start: any, end: any) => { + console.log('end: ', end); try { const navMeshQuery = new NavMeshQuery(navMesh); const { path: segmentPath } = navMeshQuery.computePath(start, end); - return ( - segmentPath?.map(({ x, y, z }) => [x, 0, z] as [number, number, number]) || [] - ); + if ( + segmentPath.length > 0 && + Math.round(segmentPath[segmentPath.length - 1].x) == Math.round(end.x) && + Math.round(segmentPath[segmentPath.length - 1].z) == Math.round(end.z) + ) { + console.log('if ', segmentPath); + return segmentPath?.map(({ x, y, z }) => [x, 0, z] as [number, number, number]) || []; + } else { + console.log("There is no path here...Choose valid path") + const { path: segmentPaths } = navMeshQuery.computePath(start, start); + return segmentPaths.map(({ x, y, z }) => [x, 0, z] as [number, number, number]) || []; + } } catch { - echo.error("Failed to compute path"); + console.error("Failed to compute path"); return []; } }, @@ -96,6 +106,10 @@ function VehicleInstance({ agvDetail }: Readonly<{ agvDetail: VehicleStatus }>) new THREE.Vector3(agvDetail?.position[0], agvDetail?.position[1], agvDetail?.position[2]), agvDetail?.point?.action?.pickUpPoint?.position ); + // const toPickupPath = computePath( + // new THREE.Vector3(agvDetail?.position[0], agvDetail?.position[1], agvDetail?.position[2]), + // new THREE.Vector3(agvDetail?.position[0], agvDetail?.position[1], agvDetail?.position[2]) + // ); setPath(toPickupPath); setCurrentPhase('stationed-pickup'); setVehicleState(agvDetail.modelUuid, 'running'); diff --git a/app/src/pages/UserAuth.tsx b/app/src/pages/UserAuth.tsx index fb8de9e..700265a 100644 --- a/app/src/pages/UserAuth.tsx +++ b/app/src/pages/UserAuth.tsx @@ -45,6 +45,7 @@ const UserAuth: React.FC = () => { const organization = email.split("@")[1].split(".")[0]; try { const res = await signInApi(email, password, organization, fingerprint); + console.log('res: ', res); if (res.message.message === "login successfull") { setError(""); setOrganization(organization); @@ -59,14 +60,13 @@ const UserAuth: React.FC = () => { try { const projects = await recentlyViewed(organization, res.message.userId); - if (Object.values(projects.RecentlyViewed).length > 0) { - const firstId = (Object.values(projects?.RecentlyViewed || {})[0] as any)?._id; - setLoadingProgress(1) - navigate(`/${firstId}`) - } else { - if (res.message.isShare) { + if (res.message.isShare) { + if (Object.values(projects.RecentlyViewed).length > 0) { + const firstId = (Object.values(projects?.RecentlyViewed || {})[0] as any)?._id; + setLoadingProgress(1) + navigate(`/${firstId}`) + } else { setLoadingProgress(1); - // navigate("/Project"); navigate("/Dashboard"); } }