diff --git a/.json b/.json index 0637a088..b74ed2d2 100644 --- a/.json +++ b/.json @@ -1 +1,92 @@ -[] \ No newline at end of file +[ + { + "prefabName": "ForkLift", + "modelName": "ForkLift_0", + "modelType": "Move", + "modelID": "", + "nodeID": "conveyor_0_59857fd6-573b-4ac1-8ea3-caaafe362d8f", + "position": "(14.64, 0.00, -12.49)", + "rotation": "(0.00000, 0.00000, 0.00000, 1.00000)", + "scale": "(1.00, 1.00, 1.00)" + }, + { + "prefabName": "BigShelves01", + "modelName": "BigShelves01_0", + "modelType": "Queue", + "modelID": "", + "nodeID": "queue_0_e38d4154-304b-49bf-b3b3-8efb9eec5bcc", + "position": "(2.33, 0.00, -11.97)", + "rotation": "(0.00000, 0.00000, 0.00000, 1.00000)", + "scale": "(1.00, 1.00, 1.00)" + }, + { + "prefabName": "Pallet", + "modelName": "Pallet_0", + "modelType": "Source", + "modelID": "", + "nodeID": "product_generator_0_9752fa8d-edce-4688-ae61-5c230fd9e215", + "position": "(-8.78, 0.00, -11.54)", + "rotation": "(0.00000, 0.00000, 0.00000, 1.00000)", + "scale": "(1.00, 1.00, 1.00)" + }, + { + "prefabName": "Pallet", + "modelName": "Pallet_1", + "modelType": "Source", + "modelID": "", + "nodeID": "queue_0_814c82ee-39dd-400c-9431-7a08e53c7cdc", + "position": "(19.00, 0.00, -10.32)", + "rotation": "(0.00000, 0.00000, 0.00000, 1.00000)", + "scale": "(1.00, 1.00, 1.00)" + }, + { + "prefabName": "Pallet", + "modelName": "Pallet_2", + "modelType": "Source", + "modelID": "", + "nodeID": "queue_0_5fe5935a-12da-4df8-826a-2866f1ebb39c", + "position": "(44.92, 0.00, -10.08)", + "rotation": "(0.00000, 0.00000, 0.00000, 1.00000)", + "scale": "(1.00, 1.00, 1.00)" + }, + { + "prefabName": "Pallet", + "modelName": "Pallet_3", + "modelType": "Source", + "modelID": "", + "nodeID": "queue_0_7d839a7a-8669-4a52-8ee3-9397d9eea97d", + "position": "(54.26, 0.00, -9.26)", + "rotation": "(0.00000, 0.00000, 0.00000, 1.00000)", + "scale": "(1.00, 1.00, 1.00)" + }, + { + "prefabName": "Pallet", + "modelName": "Pallet_4", + "modelType": "Source", + "modelID": "", + "nodeID": "shipment_0_6b2177cc-e89c-48c0-8948-918ed6adf8ee", + "position": "(63.43, 0.00, -9.95)", + "rotation": "(0.00000, 0.00000, 0.00000, 1.00000)", + "scale": "(1.00, 1.00, 1.00)" + }, + { + "prefabName": "ForkLift", + "modelName": "ForkLift_1", + "modelType": "Move", + "modelID": "", + "nodeID": "conveyor_0_32e374b3-7f80-44ae-ae24-c686fd77d4c1", + "position": "(48.46, 0.00, -9.92)", + "rotation": "(0.00000, 0.00000, 0.00000, 1.00000)", + "scale": "(1.00, 1.00, 1.00)" + }, + { + "prefabName": "BigShelves01", + "modelName": "BigShelves01_1", + "modelType": "Queue", + "modelID": "", + "nodeID": "store_0_28fefae0-5091-4e0f-a1ac-a44ae5d272db", + "position": "(31.60, 0.00, -11.43)", + "rotation": "(0.00000, 0.00000, 0.00000, 1.00000)", + "scale": "(1.00, 1.00, 1.00)" + } +] \ No newline at end of file diff --git a/Assets/Model/Prefab/AssemblyLine.prefab b/Assets/Model/Prefab/AssemblyLine.prefab index 8e6203af..26632a19 100644 --- a/Assets/Model/Prefab/AssemblyLine.prefab +++ b/Assets/Model/Prefab/AssemblyLine.prefab @@ -9,7 +9,7 @@ GameObject: serializedVersion: 6 m_Component: - component: {fileID: 6630605483932097968} - - component: {fileID: 3972856234212190539} + - component: {fileID: -8728010719361298920} m_Layer: 0 m_Name: AssemblyLine m_TagString: Untagged @@ -31,9 +31,12 @@ Transform: m_ConstrainProportionsScale: 0 m_Children: - {fileID: 2351775973713354599} + - {fileID: 150297742223292913} + - {fileID: 5944348266847543735} + - {fileID: 2251514371132152866} m_Father: {fileID: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} ---- !u!114 &3972856234212190539 +--- !u!114 &-8728010719361298920 MonoBehaviour: m_ObjectHideFlags: 0 m_CorrespondingSourceObject: {fileID: 0} @@ -42,11 +45,75 @@ MonoBehaviour: m_GameObject: {fileID: 830732352977089045} m_Enabled: 1 m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: c1d14145e7d8b3546a7232d42ee091dc, type: 3} + m_Script: {fileID: 11500000, guid: 3c1c4b267f3ba2a4db0bf182de028232, type: 3} m_Name: m_EditorClassIdentifier: modelName: AssemblyLine - modelType: Move + modelType: Conveyor + modelID: + nodeID: +--- !u!1 &2840629559553155426 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 5944348266847543735} + m_Layer: 0 + m_Name: startPosition + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &5944348266847543735 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 2840629559553155426} + serializedVersion: 2 + m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} + m_LocalPosition: {x: -1.781, y: 1.24, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_ConstrainProportionsScale: 0 + m_Children: [] + m_Father: {fileID: 6630605483932097968} + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!1 &7132286700177672932 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 2251514371132152866} + m_Layer: 0 + m_Name: endPosition + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &2251514371132152866 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 7132286700177672932} + serializedVersion: 2 + m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} + m_LocalPosition: {x: 1.762, y: 1.24, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_ConstrainProportionsScale: 0 + m_Children: [] + m_Father: {fileID: 6630605483932097968} + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1001 &1510943800273267816 PrefabInstance: m_ObjectHideFlags: 0 @@ -61,7 +128,7 @@ PrefabInstance: objectReference: {fileID: 0} - target: {fileID: 3770881403112551183, guid: 69e0d0d3b9856f540a0447f967fce8d9, type: 3} propertyPath: m_LocalPosition.x - value: 0 + value: -1.275 objectReference: {fileID: 0} - target: {fileID: 3770881403112551183, guid: 69e0d0d3b9856f540a0447f967fce8d9, type: 3} propertyPath: m_LocalPosition.y @@ -109,3 +176,65 @@ Transform: m_CorrespondingSourceObject: {fileID: 3770881403112551183, guid: 69e0d0d3b9856f540a0447f967fce8d9, type: 3} m_PrefabInstance: {fileID: 1510943800273267816} m_PrefabAsset: {fileID: 0} +--- !u!1001 &3909453952984632062 +PrefabInstance: + m_ObjectHideFlags: 0 + serializedVersion: 2 + m_Modification: + serializedVersion: 3 + m_TransformParent: {fileID: 6630605483932097968} + m_Modifications: + - target: {fileID: 3656036082104082164, guid: 69e0d0d3b9856f540a0447f967fce8d9, type: 3} + propertyPath: m_Name + value: SM_AssemblyLine01 (1) + objectReference: {fileID: 0} + - target: {fileID: 3770881403112551183, guid: 69e0d0d3b9856f540a0447f967fce8d9, type: 3} + propertyPath: m_LocalPosition.x + value: 1.16 + objectReference: {fileID: 0} + - target: {fileID: 3770881403112551183, guid: 69e0d0d3b9856f540a0447f967fce8d9, type: 3} + propertyPath: m_LocalPosition.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 3770881403112551183, guid: 69e0d0d3b9856f540a0447f967fce8d9, type: 3} + propertyPath: m_LocalPosition.z + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 3770881403112551183, guid: 69e0d0d3b9856f540a0447f967fce8d9, type: 3} + propertyPath: m_LocalRotation.w + value: 0.7071068 + objectReference: {fileID: 0} + - target: {fileID: 3770881403112551183, guid: 69e0d0d3b9856f540a0447f967fce8d9, type: 3} + propertyPath: m_LocalRotation.x + value: -0.7071068 + objectReference: {fileID: 0} + - target: {fileID: 3770881403112551183, guid: 69e0d0d3b9856f540a0447f967fce8d9, type: 3} + propertyPath: m_LocalRotation.y + value: -0 + objectReference: {fileID: 0} + - target: {fileID: 3770881403112551183, guid: 69e0d0d3b9856f540a0447f967fce8d9, type: 3} + propertyPath: m_LocalRotation.z + value: -0 + objectReference: {fileID: 0} + - target: {fileID: 3770881403112551183, guid: 69e0d0d3b9856f540a0447f967fce8d9, type: 3} + propertyPath: m_LocalEulerAnglesHint.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 3770881403112551183, guid: 69e0d0d3b9856f540a0447f967fce8d9, type: 3} + propertyPath: m_LocalEulerAnglesHint.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 3770881403112551183, guid: 69e0d0d3b9856f540a0447f967fce8d9, type: 3} + propertyPath: m_LocalEulerAnglesHint.z + value: 0 + objectReference: {fileID: 0} + m_RemovedComponents: [] + m_RemovedGameObjects: [] + m_AddedGameObjects: [] + m_AddedComponents: [] + m_SourcePrefab: {fileID: 100100000, guid: 69e0d0d3b9856f540a0447f967fce8d9, type: 3} +--- !u!4 &150297742223292913 stripped +Transform: + m_CorrespondingSourceObject: {fileID: 3770881403112551183, guid: 69e0d0d3b9856f540a0447f967fce8d9, type: 3} + m_PrefabInstance: {fileID: 3909453952984632062} + m_PrefabAsset: {fileID: 0} diff --git a/Assets/Resources/Models/AssemblyLine.prefab b/Assets/Resources/Models/AssemblyLine.prefab index 8e6203af..a3cd414b 100644 --- a/Assets/Resources/Models/AssemblyLine.prefab +++ b/Assets/Resources/Models/AssemblyLine.prefab @@ -9,7 +9,7 @@ GameObject: serializedVersion: 6 m_Component: - component: {fileID: 6630605483932097968} - - component: {fileID: 3972856234212190539} + - component: {fileID: 5171047144740992173} m_Layer: 0 m_Name: AssemblyLine m_TagString: Untagged @@ -33,7 +33,7 @@ Transform: - {fileID: 2351775973713354599} m_Father: {fileID: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} ---- !u!114 &3972856234212190539 +--- !u!114 &5171047144740992173 MonoBehaviour: m_ObjectHideFlags: 0 m_CorrespondingSourceObject: {fileID: 0} @@ -42,11 +42,13 @@ MonoBehaviour: m_GameObject: {fileID: 830732352977089045} m_Enabled: 1 m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: c1d14145e7d8b3546a7232d42ee091dc, type: 3} + m_Script: {fileID: 11500000, guid: 3c1c4b267f3ba2a4db0bf182de028232, type: 3} m_Name: m_EditorClassIdentifier: modelName: AssemblyLine modelType: Move + modelID: + nodeID: --- !u!1001 &1510943800273267816 PrefabInstance: m_ObjectHideFlags: 0 diff --git a/Assets/Scripts/SimulationModels/SimulationModel.cs b/Assets/Scripts/SimulationModels/SimulationModel.cs index c077f4a2..0ea5e471 100644 --- a/Assets/Scripts/SimulationModels/SimulationModel.cs +++ b/Assets/Scripts/SimulationModels/SimulationModel.cs @@ -15,6 +15,7 @@ public class SimulationModel : MonoBehaviour, IClickable } private void OnEnable() { + Debug.Log(this.name); DataManager.I.AddModel(this); StartCoroutine(RunSimulationCoroutine()); } diff --git a/Assets/Scripts/SimulationModels/SimulationModelConveyor.cs b/Assets/Scripts/SimulationModels/SimulationModelConveyor.cs new file mode 100644 index 00000000..ed127afd --- /dev/null +++ b/Assets/Scripts/SimulationModels/SimulationModelConveyor.cs @@ -0,0 +1,617 @@ +using System; +using Newtonsoft.Json; +using System.Collections.Generic; +using UnityEngine; +using System.Collections; +using Newtonsoft.Json.Linq; +using System.Collections.Concurrent; +using RTG; +using Unity.VisualScripting; +using Best.HTTP.JSON; + +public class SimulationModelConveyor : SimulationModel +{ + Vector3 startPosition; + Vector3 endPosition; + ConcurrentQueue dataQueue; + GameObject targetCargo; + int transportTime; + float elapseTime; + string inputQueueID; + // Start is called once before the first execution of Update after the MonoBehaviour is created + void Start() + { + startPosition = this.transform.Find(nameof(startPosition)).transform.position; + endPosition = this.transform.Find(nameof(endPosition)).transform.position; + } + + // Update is called once per frame + void Update() + { + if ( targetCargo != null) + { + startPosition = this.transform.Find(nameof(startPosition)).transform.position; + endPosition = this.transform.Find(nameof(endPosition)).transform.position; + + elapseTime += Time.deltaTime; + + if (elapseTime < transportTime) + { + targetCargo.transform.position = Vector3.Lerp(startPosition, endPosition, elapseTime / transportTime); + } + else if ( elapseTime > transportTime ) + { + //targetCargo = null; + elapseTime = 0; + } + + } + } + + + protected override IEnumerator RunSimulationCoroutine() + { + Debug.Log("Start"); + + yield return new WaitUntil(() => !string.IsNullOrEmpty(nodeID)); + while (dataQueue == null) + { + dataQueue = MQTTDataBase.Instance.GetDataQueue(nodeID); + if (dataQueue == null) + yield return null; + else + break; + } + + while(true) + { + if (dataQueue.TryDequeue(out JObject currentData)) + { + 0string rawData = currentData.ToString(); + + + Debug.Log(rawData); + if ( rawData.Contains("conveyor_loading")) + { + //targetCargo = Instantiate(this.gameObject); + //var resourcePath = "Models"; + //var tmpModel = Resources.Load(string.Format("{0}/{1}", resourcePath, "Box_Pallet")); + //targetCargo = Instantiate(tmpModel); + + SimulationModel model = DataManager.I.GetModel(inputQueueID); + SimulationModelStore storeModel = (SimulationModelStore)model; + + if ( targetCargo == null) + { + yield return new WaitUntil(() => + { + targetCargo = storeModel.GetProduct(); + return targetCargo != null; + }); + + targetCargo.transform.position = startPosition; + targetCargo.transform.rotation = Quaternion.identity; + + } + + ConveyorLoadingEventMessage message + = JsonConvert.DeserializeObject(rawData); + Debug.Log(message); + + } + + if ( rawData.Contains("conveyor_started")) + { + string[] transportTimeparseKey = { "data", "move_time" }; + + + + ConveyorStartedEventMessage startDataMessage + = JsonConvert.DeserializeObject(rawData); + + transportTime = (int)startDataMessage.Data.MoveTime; + inputQueueID = startDataMessage.Data.InputQueues[0].Queue; + + } + + if ( rawData.Contains("conveyor_unloading")) + { + if ( rawData.Contains("_to_queue")) + { + ConveyorUnloadingToQueueEventMessage message + = JsonConvert.DeserializeObject(rawData); + + string destinationID = message.Data.QueueName; + + SimulationModel model = DataManager.I.GetModel(destinationID); + SimulationModelStore storemodel = (SimulationModelStore)model; + + storemodel.StoreProduct(targetCargo); + targetCargo = null; + } + + else if ( rawData.Contains("_to_store")) + { + ConveyorUnloadingToStoreEventMessage message + = JsonConvert.DeserializeObject(rawData); + + + string destinationID = message.Data.StoreName; + + SimulationModel model = DataManager.I.GetModel(destinationID); + SimulationModelStore storemodel = (SimulationModelStore)model; + + storemodel.StoreProduct(targetCargo); + targetCargo = null; + } + + + } + + } + + yield return null; + } + + } +} + +[Serializable] +public class ConveyorUnloadingToStoreEventMessage +{ + [JsonProperty("type")] + public string? Type { get; set; } + + [JsonProperty("_event")] + public string? Event { get; set; } + + [JsonProperty("component_type")] + public string? ComponentType { get; set; } + + [JsonProperty("component_id")] + public string? ComponentId { get; set; } + + [JsonProperty("simulation_time")] + public double? SimulationTime { get; set; } + + [JsonProperty("data")] + public ConveyorUnloadingToStoreData? Data { get; set; } + + [JsonProperty("timestamp")] + public string? Timestamp { get; set; } +} + +[Serializable] +public class ConveyorUnloadingToStoreData +{ + [JsonProperty("product_id")] + public string? ProductId { get; set; } + + [JsonProperty("store_name")] + public string? StoreName { get; set; } + + [JsonProperty("store_length")] + public int? StoreLength { get; set; } + + [JsonProperty("destination_type")] + public string? DestinationType { get; set; } + + [JsonProperty("is_defective")] + public bool? IsDefective { get; set; } + + [JsonProperty("items_count")] + public int? ItemsCount { get; set; } + + [JsonProperty("remaining_capacity")] + public int? RemainingCapacity { get; set; } + + [JsonProperty("transported_count")] + public int? TransportedCount { get; set; } + + [JsonProperty("conveyor_id")] + public string? ConveyorId { get; set; } + + [JsonProperty("conveyor_label")] + public string? ConveyorLabel { get; set; } + + [JsonProperty("belt_speed")] + public double? BeltSpeed { get; set; } + + [JsonProperty("belt_length")] + public double? BeltLength { get; set; } + + [JsonProperty("capacity")] + public int? Capacity { get; set; } + + [JsonProperty("items_on_belt")] + public int? ItemsOnBelt { get; set; } +} + + +[Serializable] +public class ConveyorUnloadingToQueueEventMessage +{ + [JsonProperty("type")] + public string? Type { get; set; } + + [JsonProperty("_event")] + public string? Event { get; set; } + + [JsonProperty("component_type")] + public string? ComponentType { get; set; } + + [JsonProperty("component_id")] + public string? ComponentId { get; set; } + + [JsonProperty("simulation_time")] + public double? SimulationTime { get; set; } + + [JsonProperty("data")] + public ConveyorUnloadingToQueueData? Data { get; set; } + + [JsonProperty("timestamp")] + public string? Timestamp { get; set; } +} + +[Serializable] +public class ConveyorUnloadingToQueueData +{ + [JsonProperty("product_id")] + public string? ProductId { get; set; } + + [JsonProperty("queue_name")] + public string? QueueName { get; set; } + + [JsonProperty("queue_length")] + public int? QueueLength { get; set; } + + [JsonProperty("destination_type")] + public string? DestinationType { get; set; } + + [JsonProperty("is_defective")] + public bool? IsDefective { get; set; } + + [JsonProperty("items_count")] + public int? ItemsCount { get; set; } + + [JsonProperty("remaining_capacity")] + public int? RemainingCapacity { get; set; } + + [JsonProperty("transported_count")] + public int? TransportedCount { get; set; } + + [JsonProperty("conveyor_id")] + public string? ConveyorId { get; set; } + + [JsonProperty("conveyor_label")] + public string? ConveyorLabel { get; set; } + + [JsonProperty("belt_speed")] + public double? BeltSpeed { get; set; } + + [JsonProperty("belt_length")] + public double? BeltLength { get; set; } + + [JsonProperty("capacity")] + public int? Capacity { get; set; } + + [JsonProperty("items_on_belt")] + public int? ItemsOnBelt { get; set; } +} + + +[Serializable] +public class ConveyorUnloadingEventMessage +{ + [JsonProperty("type")] + public string? Type { get; set; } + + [JsonProperty("_event")] + public string? Event { get; set; } + + [JsonProperty("component_type")] + public string? ComponentType { get; set; } + + [JsonProperty("component_id")] + public string? ComponentId { get; set; } + + [JsonProperty("component_label")] + public string? ComponentLabel { get; set; } + + [JsonProperty("simulation_time")] + public float? SimulationTime { get; set; } + + [JsonProperty("data")] + public ConveyorUnloadingData? Data { get; set; } +} + +[Serializable] +public class ConveyorUnloadingData +{ + [JsonProperty("product_id")] + public string? ProductId { get; set; } + + [JsonProperty("product_position")] + public float? ProductPosition { get; set; } + + [JsonProperty("travel_time")] + public float? TravelTime { get; set; } + + [JsonProperty("is_defective")] + public bool? IsDefective { get; set; } + + [JsonProperty("destination_queue")] + public string? DestinationQueue { get; set; } + + [JsonProperty("conveyor_id")] + public string? ConveyorId { get; set; } + + [JsonProperty("conveyor_label")] + public string? ConveyorLabel { get; set; } + + [JsonProperty("belt_speed")] + public float? BeltSpeed { get; set; } + + [JsonProperty("belt_length")] + public float? BeltLength { get; set; } + + [JsonProperty("capacity")] + public int? Capacity { get; set; } + + [JsonProperty("items_on_belt")] + public int? ItemsOnBelt { get; set; } +} + + +[Serializable] +public class ConveyorStartedEventMessage +{ + [JsonProperty("type")] + public string? Type { get; set; } + + [JsonProperty("_event")] + public string? Event { get; set; } + + [JsonProperty("component_type")] + public string? ComponentType { get; set; } + + [JsonProperty("component_id")] + public string? ComponentId { get; set; } + + [JsonProperty("component_label")] + public string? ComponentLabel { get; set; } + + [JsonProperty("simulation_time")] + public float? SimulationTime { get; set; } + + [JsonProperty("data")] + public ConveyorStartedData? Data { get; set; } +} + +[Serializable] +public class ConveyorStartedData +{ + [JsonProperty("conveyor_id")] + public string? ConveyorId { get; set; } + + [JsonProperty("conveyor_label")] + public string? ConveyorLabel { get; set; } + + [JsonProperty("move_time")] + public int? MoveTime { get; set; } + + [JsonProperty("belt_speed")] + public float? BeltSpeed { get; set; } + + [JsonProperty("belt_length")] + public float? BeltLength { get; set; } + + [JsonProperty("capacity")] + public int? Capacity { get; set; } + + [JsonProperty("min_gap")] + public float? MinGap { get; set; } + + [JsonProperty("input_queues")] + public List? InputQueues { get; set; } + + [JsonProperty("output_queue")] + public string? OutputQueue { get; set; } + + [JsonProperty("defect_queue")] + public string? DefectQueue { get; set; } + + [JsonProperty("required_resource")] + public string? RequiredResource { get; set; } + + [JsonProperty("items_on_belt")] + public int? ItemsOnBelt { get; set; } +} + +[Serializable] +public class InputQueue +{ + [JsonProperty("queue")] + public string? Queue { get; set; } + + [JsonProperty("required_items")] + public int? RequiredItems { get; set; } +} + + +[Serializable] +public class ConveyorLoadingEventMessage +{ + [JsonProperty("type")] + public string? Type { get; set; } + + [JsonProperty("_event")] + public string? Event { get; set; } + + [JsonProperty("component_type")] + public string? ComponentType { get; set; } + + [JsonProperty("component_id")] + public string? ComponentId { get; set; } + + [JsonProperty("component_label")] + public string? ComponentLabel { get; set; } + + [JsonProperty("simulation_time")] + public float? SimulationTime { get; set; } + + [JsonProperty("data")] + public ConveyorLoadingData? Data { get; set; } +} + +[Serializable] +public class ConveyorLoadingData +{ + [JsonProperty("product_id")] + public string? ProductId { get; set; } + + [JsonProperty("belt_load_percentage")] + public float? BeltLoadPercentage { get; set; } + + [JsonProperty("first_item_position")] + public float? FirstItemPosition { get; set; } + + [JsonProperty("conveyor_id")] + public string? ConveyorId { get; set; } + + [JsonProperty("conveyor_label")] + public string? ConveyorLabel { get; set; } + + [JsonProperty("belt_speed")] + public float? BeltSpeed { get; set; } + + [JsonProperty("belt_length")] + public float? BeltLength { get; set; } + + [JsonProperty("capacity")] + public int? Capacity { get; set; } + + [JsonProperty("items_on_belt")] + public int? ItemsOnBelt { get; set; } +} + +[Serializable] + public class ConveyorEventMessage + { + [JsonProperty("type")] + public string? Type { get; set; } + + [JsonProperty("_event")] + public string? Event { get; set; } + + [JsonProperty("component_type")] + public string? ComponentType { get; set; } + + [JsonProperty("component_id")] + public string? ComponentId { get; set; } + + [JsonProperty("component_label")] + public string? ComponentLabel { get; set; } + + [JsonProperty("simulation_time")] + public float? SimulationTime { get; set; } + + [JsonProperty("data")] + public ConveyorEventData? Data { get; set; } + } + + [Serializable] + public class ConveyorEventData + { + [JsonProperty("conveyor_id")] + public string? ConveyorId { get; set; } + + [JsonProperty("conveyor_label")] + public string? ConveyorLabel { get; set; } + + [JsonProperty("move_time")] + public int? MoveTime { get; set; } + + [JsonProperty("belt_speed")] + public float? BeltSpeed { get; set; } + + [JsonProperty("belt_length")] + public float? BeltLength { get; set; } + + [JsonProperty("capacity")] + public int? Capacity { get; set; } + + [JsonProperty("min_gap")] + public float? MinGap { get; set; } + + [JsonProperty("input_queues")] + public List? InputQueues { get; set; } + + [JsonProperty("output_queue")] + public string? OutputQueue { get; set; } + + [JsonProperty("defect_queue")] + public string? DefectQueue { get; set; } + + [JsonProperty("required_resource")] + public string? RequiredResource { get; set; } + + [JsonProperty("items_on_belt")] + public int? ItemsOnBelt { get; set; } + } + + [Serializable] + public class ConveyorMovingEventMessage + { + [JsonProperty("type")] + public string? Type { get; set; } + + [JsonProperty("_event")] + public string? Event { get; set; } + + [JsonProperty("component_type")] + public string? ComponentType { get; set; } + + [JsonProperty("component_id")] + public string? ComponentId { get; set; } + + [JsonProperty("component_label")] + public string? ComponentLabel { get; set; } + + [JsonProperty("simulation_time")] + public float? SimulationTime { get; set; } + + [JsonProperty("data")] + public ConveyorMovingData? Data { get; set; } + } + + [Serializable] + public class ConveyorMovingData + { + [JsonProperty("item_positions")] + public List? ItemPositions { get; set; } + + [JsonProperty("average_position")] + public float? AveragePosition { get; set; } + + [JsonProperty("current_speed")] + public float? CurrentSpeed { get; set; } + + [JsonProperty("conveyor_id")] + public string? ConveyorId { get; set; } + + [JsonProperty("conveyor_label")] + public string? ConveyorLabel { get; set; } + + [JsonProperty("belt_speed")] + public float? BeltSpeed { get; set; } + + [JsonProperty("belt_length")] + public float? BeltLength { get; set; } + + [JsonProperty("capacity")] + public int? Capacity { get; set; } + + [JsonProperty("items_on_belt")] + public int? ItemsOnBelt { get; set; } + } diff --git a/Assets/Scripts/SimulationModels/SimulationModelConveyor.cs.meta b/Assets/Scripts/SimulationModels/SimulationModelConveyor.cs.meta new file mode 100644 index 00000000..06e4d0a0 --- /dev/null +++ b/Assets/Scripts/SimulationModels/SimulationModelConveyor.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: 3c1c4b267f3ba2a4db0bf182de028232 \ No newline at end of file diff --git a/Assets/Scripts/SimulationModels/SimulationModelMove.cs b/Assets/Scripts/SimulationModels/SimulationModelMove.cs index e83ec461..d62dd3d1 100644 --- a/Assets/Scripts/SimulationModels/SimulationModelMove.cs +++ b/Assets/Scripts/SimulationModels/SimulationModelMove.cs @@ -25,6 +25,9 @@ public class SimulationModelMove : SimulationModel float elapsedTime = 0; Vector3 originalPos; Vector3 prevPos; + + bool isRewind = false; + void Update() { int interval = 0; @@ -41,6 +44,7 @@ public class SimulationModelMove : SimulationModel if (destination != null) { elapsedTime += Time.deltaTime; + if (elapsedTime / arrivalTime > 1.0f) { transform.position = destination.position; @@ -55,7 +59,8 @@ public class SimulationModelMove : SimulationModel dir.Normalize(); transform.forward = dir; prevPos = transform.position; - } + } + } } protected override IEnumerator RunSimulationCoroutine() @@ -85,6 +90,7 @@ public class SimulationModelMove : SimulationModel string[] adjustedTimeKey = { "data", "adjusted" }; string[] inputQueueKey = { "data", "input", "queues" }; string[] outputQueueKey = { "data", "output", "queue" }; + string[] outputStoreKey = { "data", "output", "store" }; string[] sourceQueueKey = { "data", "source_queues" }; string[] sourceStoreKey = { "data", "source_stores" }; string[] loadCountKey = { "data", "loaded_count" }; @@ -93,11 +99,46 @@ public class SimulationModelMove : SimulationModel if (currentData.ContainsKey(eventKey)) { string value = currentData[eventKey].ToString(); + + + //if (value.Contains(eventMove)) + //{ + // Debug.Log("MoveeventIncomming"); + + // elapsedTime = 0; + // arrivalTime = GetJsonFloatValue(currentData, arrivalTimeKey); + // originalPos = transform.position; + // prevPos = transform.position; + // JArray originQueues = GetJsonArray(currentData, inputQueueKey); + // string arrivalQueue = GetJsonValue(currentData, outputQueueKey)?.ToString(); + + // if ( string.IsNullOrEmpty(arrivalQueue)) + // { + // arrivalQueue = GetJsonValue(currentData, outputStoreKey)?.ToString(); + // } + + // if (originQueues != null && originQueues.HasValues) + // { + // string queueID = originQueues[0].ToString(); + // SimulationModel model = DataManager.I.GetModel(queueID); + // SimulationModelStore storeModel = (SimulationModelStore)model; + // origin = storeModel.GetTransporterPosition(); + // } + // if (arrivalQueue != null) + // { + // SimulationModel model = DataManager.I.GetModel(arrivalQueue); + // SimulationModelStore storeModel = (SimulationModelStore)model; + // destination = storeModel.GetTransporterPosition(); + // } + //} + if (value.Contains(eventLoading)) { - JArray sourceQueues = GetJsonArray(currentData, sourceQueueKey); - JArray sourceStores = GetJsonArray(currentData, sourceStoreKey); - int loadCount = GetJsonIntValue(currentData, loadCountKey); + yield return null; + + JArray sourceQueues = GetJsonArray(currentData, sourceQueueKey); + JArray sourceStores = GetJsonArray(currentData, sourceStoreKey); + int loadCount = GetJsonIntValue(currentData, loadCountKey); if (sourceQueues != null && sourceQueues.HasValues) { string queueID = sourceQueues[0].ToString(); @@ -106,9 +147,11 @@ public class SimulationModelMove : SimulationModel for (int i = 0; i < loadCount; i++) { GameObject product = null; - yield return new WaitUntil(() => { + yield return new WaitUntil(() => + { product = storeModel.GetProduct(); - return product != null; }); + return product != null; + }); product.transform.parent = productPos; product.transform.localPosition = Vector3.zero; product.transform.localRotation = Quaternion.identity; @@ -123,7 +166,8 @@ public class SimulationModelMove : SimulationModel for (int i = 0; i < loadCount; i++) { GameObject product = null; - yield return new WaitUntil(() => { + yield return new WaitUntil(() => + { product = storeModel.GetProduct(); return product != null; }); @@ -135,8 +179,10 @@ public class SimulationModelMove : SimulationModel } else if (value.Contains(eventMove)) { + Debug.Log("MoveeventIncomming"); + elapsedTime = 0; - arrivalTime = GetJsonFloatValue(currentData, arrivalTimeKey); + arrivalTime = GetJsonFloatValue(currentData, arrivalTimeKey); originalPos = transform.position; prevPos = transform.position; JArray originQueues = GetJsonArray(currentData, inputQueueKey); @@ -146,17 +192,19 @@ public class SimulationModelMove : SimulationModel string queueID = originQueues[0].ToString(); SimulationModel model = DataManager.I.GetModel(queueID); SimulationModelStore storeModel = (SimulationModelStore)model; - origin = storeModel.GetTransporterPosition(); + origin = storeModel.GetTransporterPosition(); } if (arrivalQueue != null) - { + { SimulationModel model = DataManager.I.GetModel(arrivalQueue); SimulationModelStore storeModel = (SimulationModelStore)model; - destination = storeModel.GetTransporterPosition(); + destination = storeModel.GetTransporterPosition(); } } else if (value.Contains(eventUnloading)) - { + { + yield return null; + string queueID = GetJsonValue(currentData, unloadQueueKey)?.ToString(); SimulationModel model = DataManager.I.GetModel(queueID); SimulationModelStore storeModel = (SimulationModelStore)model; @@ -176,7 +224,7 @@ public class SimulationModelMove : SimulationModel float originalTime = GetJsonFloatValue(currentData, originalTimeKey); float adjustedTime = GetJsonFloatValue(currentData, adjustedTimeKey); arrivalTime += adjustedTime - originalTime; - elapsedTime = 0; + elapsedTime = 0; originalPos = transform.position; prevPos = transform.position; } diff --git a/Assets/WorkSpace/LH/LogicData/LogicDataManager.cs b/Assets/WorkSpace/LH/LogicData/LogicDataManager.cs index 99b32736..705de81d 100644 --- a/Assets/WorkSpace/LH/LogicData/LogicDataManager.cs +++ b/Assets/WorkSpace/LH/LogicData/LogicDataManager.cs @@ -92,6 +92,8 @@ namespace Octopus.Simulator void GetDataFromInfo(LogicData Data) { + Debug.Log("what"); + currentData = Data; config = Data.webConfig; QueueVisulization(Data.data.queues); @@ -103,6 +105,9 @@ namespace Octopus.Simulator void QueueVisulization(List queues) { + dataMap.Clear(); + idMap.Clear(); + foreach (var queue in queues) { var logicButton = Instantiate(logicPrefab, LogicContent); diff --git a/Assets/WorkSpace/LH/LogicInfo.cs b/Assets/WorkSpace/LH/LogicInfo.cs index 1a8006eb..001e81a0 100644 --- a/Assets/WorkSpace/LH/LogicInfo.cs +++ b/Assets/WorkSpace/LH/LogicInfo.cs @@ -259,15 +259,16 @@ namespace Octopus.Simulator [Serializable] public class Shipment : ILogicComponent { - public string name; - public string description; - public string label; + public string? name; + public string? description; + public string? label; public int? shipping_interval = 0; public int? shipping_amount = 0; - public List input_queues; - public override string Name => name; - public override string Description => description; - public override string Label => label; + public List? input_queues; + + public override string? Name => name; + public override string? Description => description; + public override string? Label => label; public override ComponentType Type => ComponentType.Shipment; } @@ -474,9 +475,12 @@ namespace Octopus.Simulator "transporter" => new Transporter(), "shipment" => new Shipment(), "conveyor" => new Conveyor(), + "store" => new Conveyor(), _ => throw new NotSupportedException($"Áö¿øÇÏÁö ¾Ê´Â component type: {type}") }; + Debug.Log(type); + // JSON ¡æ ÀνºÅϽº ä¿ì±â serializer.Populate(jo.CreateReader(), comp); list.Add(comp); diff --git a/Assets/WorkSpace/LH/MQTTDataBase.cs b/Assets/WorkSpace/LH/MQTTDataBase.cs index c40f7d78..3b7624cf 100644 --- a/Assets/WorkSpace/LH/MQTTDataBase.cs +++ b/Assets/WorkSpace/LH/MQTTDataBase.cs @@ -18,7 +18,7 @@ public class MQTTDataBase : MonoBehaviour public void AddDict(string key, string value) { - Debug.Log("#### : " + key + " : " + value); + //Debug.Log("#### : " + key + " : " + value); JObject json = JObject.Parse(value); var queue = mqttData.GetOrAdd(key, _ => new ConcurrentQueue()); queue.Enqueue(json); diff --git a/Assets/WorkSpace/LH/MQTTManager.cs b/Assets/WorkSpace/LH/MQTTManager.cs index 5baea5fc..829489f0 100644 --- a/Assets/WorkSpace/LH/MQTTManager.cs +++ b/Assets/WorkSpace/LH/MQTTManager.cs @@ -124,7 +124,7 @@ namespace Octopus.Simulator.Networks private void OnMessage(MQTTClient client, SubscriptionTopic topic, string topicName, ApplicationMessage message) { var payload = Encoding.UTF8.GetString(message.Payload.Data, message.Payload.Offset, message.Payload.Count); - Debug.Log(payload); + //Debug.Log(payload); if (payload.Contains("component_id")) { basemessage = JsonConvert.DeserializeObject(payload); diff --git a/Assets/WorkSpace/LH/ProjectDataManager.cs b/Assets/WorkSpace/LH/ProjectDataManager.cs index 9bd0a678..77da4823 100644 --- a/Assets/WorkSpace/LH/ProjectDataManager.cs +++ b/Assets/WorkSpace/LH/ProjectDataManager.cs @@ -16,7 +16,7 @@ public class ProjectDataManager : MonoBehaviour // Start is called once before the first execution of Update after the MonoBehaviour is created void Start() { - FindAnyObjectByType().onParameterRecived += RequestInfo; + //FindAnyObjectByType().onParameterRecived += RequestInfo; projectMenuButton.onClick.AddListener(SetActive); } public void RequestInfo() diff --git a/Assets/WorkSpace/LWJ/SaveLoadmanager.cs b/Assets/WorkSpace/LWJ/SaveLoadmanager.cs index 036cc033..f5ca1097 100644 --- a/Assets/WorkSpace/LWJ/SaveLoadmanager.cs +++ b/Assets/WorkSpace/LWJ/SaveLoadmanager.cs @@ -24,7 +24,7 @@ public class SaveLoadmanager : MonoBehaviour public void Onclick_Save() { - //var path = StandaloneFileBrowser.SaveFilePanel("Save Layout", "", "", ""); + var path = StandaloneFileBrowser.SaveFilePanel("Save Layout", "", "", ""); var simulationModels = FindObjectsByType(FindObjectsSortMode.None); List saveInfos = new List(); @@ -51,43 +51,43 @@ public class SaveLoadmanager : MonoBehaviour string jsonObject = JsonConvert.SerializeObject(saveInfos, Formatting.Indented); - var modelClass = new WebModelClass(); - modelClass.logicId = int.Parse(WebParameters.config.logicId); - modelClass.name = "new model"; - modelClass.description = "new model"; - modelClass.data.info = jsonObject; + //var modelClass = new WebModelClass(); + //modelClass.logicId = int.Parse(WebParameters.config.logicId); + //modelClass.name = "new model"; + //modelClass.description = "new model"; + //modelClass.data.info = jsonObject; - string requestAPI = $"{WebManager.webManager.apiConfig.model}"; - Debug.Log(requestAPI); - if (string.IsNullOrEmpty(WebParameters.config.modelId)) - { - WebManager.webManager.Request_Post(modelClass, requestAPI, (flag, value) => - { - if (flag) - { - var webreturnClass = JsonConvert.DeserializeObject(value); - WebParameters.config.modelId = webreturnClass.data.insertedId.ToString(); - } - }); - } - else - { - WebManager.webManager.Request_Put(requestAPI, (flag, value) => - { - if (flag) - { - var webreturnClass = JsonConvert.DeserializeObject(value); - WebParameters.config.modelId = webreturnClass.data.insertedId.ToString(); - } - }); - } - /* + //string requestAPI = $"{WebManager.webManager.apiConfig.model}"; + //Debug.Log(requestAPI); + //if (string.IsNullOrEmpty(WebParameters.config.modelId)) + //{ + // WebManager.webManager.Request_Post(modelClass, requestAPI, (flag, value) => + // { + // if (flag) + // { + // var webreturnClass = JsonConvert.DeserializeObject(value); + // WebParameters.config.modelId = webreturnClass.data.insertedId.ToString(); + // } + // }); + //} + //else + //{ + // WebManager.webManager.Request_Put(requestAPI, (flag, value) => + // { + // if (flag) + // { + // var webreturnClass = JsonConvert.DeserializeObject(value); + // WebParameters.config.modelId = webreturnClass.data.insertedId.ToString(); + // } + // }); + //} + FileStream fileStream = new FileStream(string.Format("{0}.json", path), FileMode.Create); byte[] buffer = Encoding.UTF8.GetBytes(jsonObject); fileStream.Write(buffer, 0, buffer.Length); fileStream.Close(); - */ + }