feat: Refactor vehicle management and update storage unit load handling; remove unused vehicle component and enhance vehicle status types
This commit is contained in:
@@ -25,19 +25,8 @@ const avatarColors: string[] = [
|
|||||||
export function getAvatarColor(index: number, name?: string): string {
|
export function getAvatarColor(index: number, name?: string): string {
|
||||||
// Check if the color is already stored in localStorage
|
// Check if the color is already stored in localStorage
|
||||||
const localStorageKey = "userAvatarColors";
|
const localStorageKey = "userAvatarColors";
|
||||||
// Helper function to check if local storage is available
|
|
||||||
function isLocalStorageAvailable(): boolean {
|
|
||||||
try {
|
|
||||||
const testKey = "__test__";
|
|
||||||
localStorage.setItem(testKey, "test");
|
|
||||||
localStorage.removeItem(testKey);
|
|
||||||
return true;
|
|
||||||
} catch (e) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Check if local storage is available
|
// Check if local storage is available
|
||||||
if (isLocalStorageAvailable() && name) {
|
if (name) {
|
||||||
let userColors = JSON.parse(localStorage.getItem(localStorageKey) || "{}");
|
let userColors = JSON.parse(localStorage.getItem(localStorageKey) || "{}");
|
||||||
|
|
||||||
// Check if the user already has an assigned color
|
// Check if the user already has an assigned color
|
||||||
|
|||||||
@@ -26,12 +26,9 @@ const MeasurementTool = () => {
|
|||||||
);
|
);
|
||||||
const [coneSize, setConeSize] = useState({ radius: 0.2, height: 0.5 });
|
const [coneSize, setConeSize] = useState({ radius: 0.2, height: 0.5 });
|
||||||
|
|
||||||
const MIN_RADIUS = 0.001,
|
const MIN_RADIUS = 0.001, MAX_RADIUS = 0.1;
|
||||||
MAX_RADIUS = 0.1;
|
const MIN_CONE_RADIUS = 0.01, MAX_CONE_RADIUS = 0.4;
|
||||||
const MIN_CONE_RADIUS = 0.01,
|
const MIN_CONE_HEIGHT = 0.035, MAX_CONE_HEIGHT = 2.0;
|
||||||
MAX_CONE_RADIUS = 0.4;
|
|
||||||
const MIN_CONE_HEIGHT = 0.035,
|
|
||||||
MAX_CONE_HEIGHT = 2.0;
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const canvasElement = gl.domElement;
|
const canvasElement = gl.domElement;
|
||||||
@@ -125,21 +122,9 @@ const MeasurementTool = () => {
|
|||||||
const updateMeasurement = (start: THREE.Vector3, end: THREE.Vector3) => {
|
const updateMeasurement = (start: THREE.Vector3, end: THREE.Vector3) => {
|
||||||
const distance = start.distanceTo(end);
|
const distance = start.distanceTo(end);
|
||||||
|
|
||||||
const radius = THREE.MathUtils.clamp(
|
const radius = THREE.MathUtils.clamp(distance * 0.02, MIN_RADIUS, MAX_RADIUS);
|
||||||
distance * 0.02,
|
const coneRadius = THREE.MathUtils.clamp(distance * 0.05, MIN_CONE_RADIUS, MAX_CONE_RADIUS);
|
||||||
MIN_RADIUS,
|
const coneHeight = THREE.MathUtils.clamp(distance * 0.2, MIN_CONE_HEIGHT, MAX_CONE_HEIGHT);
|
||||||
MAX_RADIUS
|
|
||||||
);
|
|
||||||
const coneRadius = THREE.MathUtils.clamp(
|
|
||||||
distance * 0.05,
|
|
||||||
MIN_CONE_RADIUS,
|
|
||||||
MAX_CONE_RADIUS
|
|
||||||
);
|
|
||||||
const coneHeight = THREE.MathUtils.clamp(
|
|
||||||
distance * 0.2,
|
|
||||||
MIN_CONE_HEIGHT,
|
|
||||||
MAX_CONE_HEIGHT
|
|
||||||
);
|
|
||||||
|
|
||||||
setConeSize({ radius: coneRadius, height: coneHeight });
|
setConeSize({ radius: coneRadius, height: coneHeight });
|
||||||
|
|
||||||
@@ -180,7 +165,7 @@ const MeasurementTool = () => {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (points.length === 2) {
|
if (points.length === 2) {
|
||||||
console.log(points[0].distanceTo(points[1]));
|
// console.log(points[0].distanceTo(points[1]));
|
||||||
}
|
}
|
||||||
}, [points]);
|
}, [points]);
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import React, { useEffect } from 'react';
|
import React, { useEffect } from 'react';
|
||||||
import { useEventsStore } from '../../store/simulation/useEventsStore';
|
import { useEventsStore } from '../../store/simulation/useEventsStore';
|
||||||
import { useProductStore } from '../../store/simulation/useProductStore';
|
import { useProductStore } from '../../store/simulation/useProductStore';
|
||||||
|
import Vehicles from './vehicle/vehicles';
|
||||||
|
|
||||||
function Simulation() {
|
function Simulation() {
|
||||||
const { events } = useEventsStore();
|
const { events } = useEventsStore();
|
||||||
@@ -16,6 +17,7 @@ function Simulation() {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
|
<Vehicles />
|
||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,8 @@ import React from 'react'
|
|||||||
|
|
||||||
function VehicleAnimator() {
|
function VehicleAnimator() {
|
||||||
return (
|
return (
|
||||||
<div>VehicleAnimator</div>
|
<>
|
||||||
|
</>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,14 +0,0 @@
|
|||||||
import React from 'react'
|
|
||||||
import VehicleInstances from './instances/vehicleInstances';
|
|
||||||
|
|
||||||
function Vehicle() {
|
|
||||||
return (
|
|
||||||
<>
|
|
||||||
|
|
||||||
<VehicleInstances />
|
|
||||||
|
|
||||||
</>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
export default Vehicle
|
|
||||||
133
app/src/modules/simulation/vehicle/vehicles.tsx
Normal file
133
app/src/modules/simulation/vehicle/vehicles.tsx
Normal file
@@ -0,0 +1,133 @@
|
|||||||
|
import React, { useEffect } from 'react'
|
||||||
|
import VehicleInstances from './instances/vehicleInstances';
|
||||||
|
|
||||||
|
import { useVehicleStore } from '../../../store/simulation/useVehicleStore';
|
||||||
|
|
||||||
|
function Vehicles() {
|
||||||
|
|
||||||
|
const { vehicles, addVehicle } = useVehicleStore();
|
||||||
|
|
||||||
|
const vehicleStatusSample: VehicleStatus[] = [
|
||||||
|
{
|
||||||
|
modelUuid: "veh-123",
|
||||||
|
modelName: "Autonomous Truck A1",
|
||||||
|
position: [10, 0, 5],
|
||||||
|
rotation: [0, 0, 0],
|
||||||
|
state: "idle",
|
||||||
|
type: "vehicle",
|
||||||
|
speed: 2.5,
|
||||||
|
point: {
|
||||||
|
uuid: "point-789",
|
||||||
|
position: [0, 1, 0],
|
||||||
|
rotation: [0, 0, 0],
|
||||||
|
action: {
|
||||||
|
actionUuid: "action-456",
|
||||||
|
actionName: "Deliver to Zone A",
|
||||||
|
actionType: "travel",
|
||||||
|
material: "crate",
|
||||||
|
unLoadDuration: 15,
|
||||||
|
loadCapacity: 5,
|
||||||
|
pickUpPoint: { x: 5, y: 0, z: 3 },
|
||||||
|
unLoadPoint: { x: 20, y: 0, z: 10 },
|
||||||
|
triggers: [
|
||||||
|
{
|
||||||
|
triggerUuid: "trig-001",
|
||||||
|
triggerName: "Start Travel",
|
||||||
|
triggerType: "onComplete",
|
||||||
|
delay: 0,
|
||||||
|
triggeredAsset: {
|
||||||
|
triggeredModel: { modelName: "ArmBot-X", modelUuid: "arm-001" },
|
||||||
|
triggeredPoint: { pointName: "Pickup Arm Point", pointUuid: "arm-point-01" },
|
||||||
|
triggeredAction: { actionName: "Grab Widget", actionUuid: "grab-001" }
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
triggerUuid: "trig-002",
|
||||||
|
triggerName: "Complete Travel",
|
||||||
|
triggerType: "onComplete",
|
||||||
|
delay: 2,
|
||||||
|
triggeredAsset: null
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
productId: "prod-890",
|
||||||
|
isActive: false,
|
||||||
|
idleTime: 0,
|
||||||
|
activeTime: 0,
|
||||||
|
currentLoad: 0,
|
||||||
|
distanceTraveled: 0
|
||||||
|
},
|
||||||
|
{
|
||||||
|
modelUuid: "veh-123",
|
||||||
|
modelName: "Autonomous Truck A1",
|
||||||
|
position: [10, 0, 5],
|
||||||
|
rotation: [0, 0, 0],
|
||||||
|
state: "idle",
|
||||||
|
type: "vehicle",
|
||||||
|
speed: 2.5,
|
||||||
|
point: {
|
||||||
|
uuid: "point-789",
|
||||||
|
position: [0, 1, 0],
|
||||||
|
rotation: [0, 0, 0],
|
||||||
|
action: {
|
||||||
|
actionUuid: "action-456",
|
||||||
|
actionName: "Deliver to Zone A",
|
||||||
|
actionType: "travel",
|
||||||
|
material: "crate",
|
||||||
|
unLoadDuration: 15,
|
||||||
|
loadCapacity: 5,
|
||||||
|
pickUpPoint: { x: 5, y: 0, z: 3 },
|
||||||
|
unLoadPoint: { x: 20, y: 0, z: 10 },
|
||||||
|
triggers: [
|
||||||
|
{
|
||||||
|
triggerUuid: "trig-001",
|
||||||
|
triggerName: "Start Travel",
|
||||||
|
triggerType: "onStart",
|
||||||
|
delay: 0,
|
||||||
|
triggeredAsset: {
|
||||||
|
triggeredModel: { modelName: "ArmBot-X", modelUuid: "arm-001" },
|
||||||
|
triggeredPoint: { pointName: "Pickup Arm Point", pointUuid: "arm-point-01" },
|
||||||
|
triggeredAction: { actionName: "Grab Widget", actionUuid: "grab-001" }
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
triggerUuid: "trig-002",
|
||||||
|
triggerName: "Complete Travel",
|
||||||
|
triggerType: "onComplete",
|
||||||
|
delay: 2,
|
||||||
|
triggeredAsset: null
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
productId: "prod-890",
|
||||||
|
isActive: false,
|
||||||
|
idleTime: 0,
|
||||||
|
activeTime: 0,
|
||||||
|
currentLoad: 0,
|
||||||
|
distanceTraveled: 0
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
addVehicle('123', vehicleStatusSample[0]);
|
||||||
|
addVehicle('123', vehicleStatusSample[1]);
|
||||||
|
}, [])
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
console.log('vehicles: ', vehicles);
|
||||||
|
}, [vehicles])
|
||||||
|
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
|
||||||
|
<VehicleInstances />
|
||||||
|
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default Vehicles;
|
||||||
@@ -117,7 +117,6 @@ export default function Dropped3dWidgets() {
|
|||||||
!intersect.object.name.includes("Roof") &&
|
!intersect.object.name.includes("Roof") &&
|
||||||
!intersect.object.name.includes("agv-collider") &&
|
!intersect.object.name.includes("agv-collider") &&
|
||||||
!intersect.object.name.includes("MeasurementReference") &&
|
!intersect.object.name.includes("MeasurementReference") &&
|
||||||
!intersect.object.userData.isPathObject &&
|
|
||||||
!(intersect.object.type === "GridHelper")
|
!(intersect.object.type === "GridHelper")
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -154,7 +153,6 @@ export default function Dropped3dWidgets() {
|
|||||||
!intersect.object.name.includes("Roof") &&
|
!intersect.object.name.includes("Roof") &&
|
||||||
!intersect.object.name.includes("agv-collider") &&
|
!intersect.object.name.includes("agv-collider") &&
|
||||||
!intersect.object.name.includes("MeasurementReference") &&
|
!intersect.object.name.includes("MeasurementReference") &&
|
||||||
!intersect.object.userData.isPathObject &&
|
|
||||||
!(intersect.object.type === "GridHelper")
|
!(intersect.object.type === "GridHelper")
|
||||||
);
|
);
|
||||||
// Update widget's position in memory
|
// Update widget's position in memory
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ interface StorageUnitStore {
|
|||||||
setStorageUnitState: (modelUuid: string, newState: StorageUnitStatus['state']) => void;
|
setStorageUnitState: (modelUuid: string, newState: StorageUnitStatus['state']) => void;
|
||||||
|
|
||||||
// Load updates
|
// Load updates
|
||||||
updateStorageUnitLoad: (modelUuid: string, load: number) => void;
|
updateStorageUnitLoad: (modelUuid: string, incrementBy: number) => void;
|
||||||
|
|
||||||
// Time tracking
|
// Time tracking
|
||||||
incrementActiveTime: (modelUuid: string, incrementBy: number) => void;
|
incrementActiveTime: (modelUuid: string, incrementBy: number) => void;
|
||||||
@@ -95,11 +95,11 @@ export const useStorageUnitStore = create<StorageUnitStore>()(
|
|||||||
},
|
},
|
||||||
|
|
||||||
// Load updates
|
// Load updates
|
||||||
updateStorageUnitLoad: (modelUuid, load) => {
|
updateStorageUnitLoad: (modelUuid, incrementBy) => {
|
||||||
set((state) => {
|
set((state) => {
|
||||||
const unit = state.storageUnits.find(s => s.modelUuid === modelUuid);
|
const unit = state.storageUnits.find(s => s.modelUuid === modelUuid);
|
||||||
if (unit) {
|
if (unit) {
|
||||||
unit.currentLoad = load;
|
unit.currentLoad += incrementBy;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -30,7 +30,6 @@ interface VehiclesStore {
|
|||||||
getVehiclesByProduct: (productId: string) => VehicleStatus[];
|
getVehiclesByProduct: (productId: string) => VehicleStatus[];
|
||||||
getVehiclesByState: (state: string) => VehicleStatus[];
|
getVehiclesByState: (state: string) => VehicleStatus[];
|
||||||
getActiveVehicles: () => VehicleStatus[];
|
getActiveVehicles: () => VehicleStatus[];
|
||||||
getIdleVehicles: () => VehicleStatus[];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export const useVehicleStore = create<VehiclesStore>()(
|
export const useVehicleStore = create<VehiclesStore>()(
|
||||||
@@ -125,10 +124,6 @@ export const useVehicleStore = create<VehiclesStore>()(
|
|||||||
|
|
||||||
getActiveVehicles: () => {
|
getActiveVehicles: () => {
|
||||||
return get().vehicles.filter(v => v.isActive);
|
return get().vehicles.filter(v => v.isActive);
|
||||||
},
|
|
||||||
|
|
||||||
getIdleVehicles: () => {
|
|
||||||
return get().vehicles.filter(v => !v.isActive && v.currentLoad > 0);
|
|
||||||
}
|
}
|
||||||
}))
|
}))
|
||||||
);
|
);
|
||||||
|
|||||||
11
app/src/types/simulationTypes.d.ts
vendored
11
app/src/types/simulationTypes.d.ts
vendored
@@ -42,7 +42,7 @@ interface VehiclePointSchema {
|
|||||||
actionUuid: string;
|
actionUuid: string;
|
||||||
actionName: string;
|
actionName: string;
|
||||||
actionType: "travel";
|
actionType: "travel";
|
||||||
material: string;
|
material: string | null;
|
||||||
unLoadDuration: number;
|
unLoadDuration: number;
|
||||||
loadCapacity: number;
|
loadCapacity: number;
|
||||||
pickUpPoint: { x: number; y: number, z: number } | null;
|
pickUpPoint: { x: number; y: number, z: number } | null;
|
||||||
@@ -126,3 +126,12 @@ type productsSchema = {
|
|||||||
productId: string;
|
productId: string;
|
||||||
eventsData: EventsSchema[];
|
eventsData: EventsSchema[];
|
||||||
}[]
|
}[]
|
||||||
|
|
||||||
|
interface VehicleStatus extends VehicleEventSchema {
|
||||||
|
productId: string;
|
||||||
|
isActive: boolean;
|
||||||
|
idleTime: number;
|
||||||
|
activeTime: number;
|
||||||
|
currentLoad: number;
|
||||||
|
distanceTraveled: number;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user