From bd99f5bacb1f7be544badc67012e25ed4bf74d31 Mon Sep 17 00:00:00 2001 From: Hyunseok Yang Date: Thu, 13 Aug 2020 11:54:04 +0900 Subject: [PATCH 01/15] Bug fix measurement unit in Micom Sensor and Input - rad/s in all interface - deg/s in all codes related to unity fix coordinates axis direciton AccGyro interface in Micom Sensor - x, y, z -> x, z, y --- Assets/Scripts/Devices/MicomInput.cs | 14 +++++++------- Assets/Scripts/Devices/MicomSensor.cs | 10 +++++----- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/Assets/Scripts/Devices/MicomInput.cs b/Assets/Scripts/Devices/MicomInput.cs index 36942f42..07b8b87c 100644 --- a/Assets/Scripts/Devices/MicomInput.cs +++ b/Assets/Scripts/Devices/MicomInput.cs @@ -18,11 +18,11 @@ public enum VelocityType {Unknown, LinearAndAngular, LeftAndRight}; public VelocityType ControlType => controlType; - private float wheelVelocityLeft = 0; // rad/s - private float wheelVelocityRight = 0; // rad/s + private float wheelVelocityLeft = 0; // deg/s + private float wheelVelocityRight = 0; // deg/s private float linearVelocity = 0; // m/s - private float angularVelocity = 0; // rad/s + private float angularVelocity = 0; // deg/s protected override void OnAwake() { @@ -80,17 +80,17 @@ protected override void GenerateMessage() = (!child0.Name.Equals("LinearVelocity")) ? 0 : (float)child0.Value.DoubleValue; angularVelocity - = (!child1.Name.Equals("AngularVelocity")) ? 0 : (float)child1.Value.DoubleValue; + = (!child1.Name.Equals("AngularVelocity")) ? 0 : (float)child1.Value.DoubleValue * Mathf.Rad2Deg; } else if (micomWritingData.Value.IntValue == 1) { controlType = VelocityType.LeftAndRight; wheelVelocityLeft - = (!child0.Name.Equals("LeftWheelVelocity")) ? 0 : (float)child0.Value.DoubleValue; + = (!child0.Name.Equals("LeftWheelVelocity")) ? 0 : ((float)child0.Value.DoubleValue * Mathf.Rad2Deg); wheelVelocityRight - = (!child1.Name.Equals("RightWheelVelocity")) ? 0 : (float)child1.Value.DoubleValue; + = (!child1.Name.Equals("RightWheelVelocity")) ? 0 : ((float)child1.Value.DoubleValue* Mathf.Rad2Deg); } else { @@ -119,7 +119,7 @@ public float GetLinearVelocity() public float GetAngularVelocity() { - return (float)angularVelocity * Mathf.Rad2Deg; + return (float)angularVelocity; } public float GetVelocity(in int index) diff --git a/Assets/Scripts/Devices/MicomSensor.cs b/Assets/Scripts/Devices/MicomSensor.cs index 87f43644..200d125b 100644 --- a/Assets/Scripts/Devices/MicomSensor.cs +++ b/Assets/Scripts/Devices/MicomSensor.cs @@ -332,8 +332,8 @@ private void UpdateAccGyro() var angle = localRotation.eulerAngles * Mathf.Deg2Rad; accGyro.AngleX = angle.x; - accGyro.AngleY = angle.y; - accGyro.AngleZ = angle.z; + accGyro.AngleY = angle.z; + accGyro.AngleZ = angle.y; accGyro.AccX = 0; accGyro.AccY = 0; @@ -365,15 +365,15 @@ private bool SetOdomData(in float linearVelocityLeft, in float linearVelocityRig public void SetDifferentialDrive(in float linearVelocityLeft, in float linearVelocityRight) { - var angularVelocityLeft = linearVelocityLeft * divideWheelRadius * Mathf.Rad2Deg; - var angularVelocityRight = linearVelocityRight * divideWheelRadius * Mathf.Rad2Deg; + var angularVelocityLeft = linearVelocityLeft * divideWheelRadius; + var angularVelocityRight = linearVelocityRight * divideWheelRadius; SetMotorVelocity(angularVelocityLeft, angularVelocityRight); } public void SetTwistDrive(in float linearVelocity, in float angularVelocity) { - // m/s, rad/s + // m/s, deg/s // var angularVelocityLeft = ((2 * linearVelocity) + (angularVelocity * wheelBase)) / (2 * wheelRadius); // var angularVelocityRight = ((2 * linearVelocity) + (angularVelocity * wheelBase)) / (2 * wheelRadius); var angularCalculation = (angularVelocity * wheelBase * 0.5f); From 2e4ea8541b0f9cbe84dd319da839a5a77895b890 Mon Sep 17 00:00:00 2001 From: Hyunseok Yang Date: Thu, 13 Aug 2020 13:46:21 +0900 Subject: [PATCH 02/15] Change target frame rate : 60 -> 61 --- Assets/Scripts/ModelLoader.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Assets/Scripts/ModelLoader.cs b/Assets/Scripts/ModelLoader.cs index 45ee2b2a..44d185ff 100644 --- a/Assets/Scripts/ModelLoader.cs +++ b/Assets/Scripts/ModelLoader.cs @@ -81,7 +81,7 @@ void Awake() var worldPaths = worldPathEnv.Split(separator, StringSplitOptions.RemoveEmptyEntries); worldRootDirectories.AddRange(worldPaths); #endif - Application.targetFrameRate = 60; + Application.targetFrameRate = 61; modelsRoot = GameObject.Find(modelsRootName); @@ -203,7 +203,6 @@ private IEnumerator ResetSimulation() } yield return new WaitForSeconds(1); - Debug.LogWarning("[Done] Reset positions in simulation!!!"); isResetting = false; } From 93d59372367ea12e4b3854c790aad11fd0983476 Mon Sep 17 00:00:00 2001 From: Hyunseok Yang Date: Thu, 13 Aug 2020 16:50:55 +0900 Subject: [PATCH 03/15] Reset Clock when simulation is reset. Get all time info in simulation from Clock device Change clock update rate : 250 -> 100 Re-arrange Scription Exeucution order : UnityRosInit(Clock) -> ModelLoader -> SimulationDisplay --- .../DevicePlugins/UnityRosInit.cs.meta | 2 +- Assets/Scripts/Devices/Clock.cs | 21 +++++++++++++- Assets/Scripts/Devices/DeviceHelper.cs | 17 +++++++++-- Assets/Scripts/ModelLoader.cs | 18 ++++++++++-- Assets/Scripts/UI/SimulationDisplay.cs | 29 +++++++------------ Assets/Scripts/UI/SimulationDisplay.cs.meta | 2 +- 6 files changed, 63 insertions(+), 26 deletions(-) diff --git a/Assets/Scripts/DevicePlugins/UnityRosInit.cs.meta b/Assets/Scripts/DevicePlugins/UnityRosInit.cs.meta index 973755e9..f3543f90 100644 --- a/Assets/Scripts/DevicePlugins/UnityRosInit.cs.meta +++ b/Assets/Scripts/DevicePlugins/UnityRosInit.cs.meta @@ -4,7 +4,7 @@ MonoImporter: externalObjects: {} serializedVersion: 2 defaultReferences: [] - executionOrder: 1000 + executionOrder: 100 icon: {instanceID: 0} userData: assetBundleName: diff --git a/Assets/Scripts/Devices/Clock.cs b/Assets/Scripts/Devices/Clock.cs index 9f44eec1..91a1037d 100644 --- a/Assets/Scripts/Devices/Clock.cs +++ b/Assets/Scripts/Devices/Clock.cs @@ -10,12 +10,15 @@ public class Clock : Device { - private const float updateRate = 250f; + private const float updateRate = 100f; private messages.Param timeInfo = null; private messages.Time simTime = null; private messages.Time realTime = null; + private float restartedSimTime = 0; + private float restartedRealTime = 0; + protected override void OnAwake() { } @@ -75,4 +78,20 @@ protected override void GenerateMessage() PushData(timeInfo); } } + + public void ResetTime() + { + restartedSimTime = Time.time; + restartedRealTime = Time.realtimeSinceStartup; + } + + public float GetSimTime() + { + return Time.time - restartedSimTime; + } + + public float GetRealTime() + { + return Time.realtimeSinceStartup - restartedRealTime; + } } \ No newline at end of file diff --git a/Assets/Scripts/Devices/DeviceHelper.cs b/Assets/Scripts/Devices/DeviceHelper.cs index 70bb0981..c53aa0eb 100644 --- a/Assets/Scripts/Devices/DeviceHelper.cs +++ b/Assets/Scripts/Devices/DeviceHelper.cs @@ -10,6 +10,8 @@ public class DeviceHelper { + static Clock clock = null; + public static string GetModelName(in GameObject targetObject, in bool searchOnlyOneDepth = false) { try @@ -52,7 +54,19 @@ public static void SetCurrentTime(in messages.Time gazeboMsgsTime, in bool useRe { if (gazeboMsgsTime != null) { - var timeNow = (useRealTime) ? Time.realtimeSinceStartup : Time.time; + if (clock == null) + { + var coreObject = GameObject.Find("Core"); + if (coreObject != null) + { + clock = coreObject.GetComponent(); + } + } + + var simTime = (clock == null) ? Time.time : clock.GetSimTime(); + var realTime = (clock == null) ? Time.realtimeSinceStartup : clock.GetRealTime(); + + var timeNow = (useRealTime) ? realTime : simTime; gazeboMsgsTime.Sec = (int)timeNow; gazeboMsgsTime.Nsec = (int)((timeNow - (float)gazeboMsgsTime.Sec) * (float)1e+9); } @@ -106,7 +120,6 @@ public static Matrix4x4 MakeCustomProjectionMatrix(in float hFov, in float vFov, return projMatrix; } - public static float HorizontalToVerticalFOV(in float horizontalFOV, in float aspect = 1.0f) { return Mathf.Rad2Deg * 2 * Mathf.Atan(Mathf.Tan((horizontalFOV * Mathf.Deg2Rad) / 2f) / aspect); diff --git a/Assets/Scripts/ModelLoader.cs b/Assets/Scripts/ModelLoader.cs index 44d185ff..1b4530ba 100644 --- a/Assets/Scripts/ModelLoader.cs +++ b/Assets/Scripts/ModelLoader.cs @@ -35,6 +35,7 @@ public class ModelLoader : MonoBehaviour public List worldRootDirectories = new List(); private GameObject modelsRoot = null; + private Clock clock = null; private bool isResetting = false; private bool resetTriggered = false; @@ -85,6 +86,8 @@ void Awake() modelsRoot = GameObject.Find(modelsRootName); + clock = GetComponent(); + ResetTransform(); } @@ -148,7 +151,7 @@ private IEnumerator LoadSdfModels() void LateUpdate() { - if (Input.GetKey(KeyCode.LeftControl) && Input.GetKey(KeyCode.R)) + if (Input.GetKey(KeyCode.LeftControl) && Input.GetKeyUp(KeyCode.R)) { resetTriggered = true; } @@ -165,7 +168,7 @@ void LateUpdate() else { resetTriggered = false; - isResetting = true; + StartCoroutine(ResetSimulation()); } } @@ -185,6 +188,8 @@ public bool TriggerResetService(in string command) private IEnumerator ResetSimulation() { + isResetting = true; + Debug.LogWarning("Reset positions in simulation!!!"); foreach (var plugin in modelsRoot.GetComponentsInChildren()) @@ -202,7 +207,14 @@ private IEnumerator ResetSimulation() plugin.Reset(); } - yield return new WaitForSeconds(1); + yield return null; + + if (clock != null) + { + clock.ResetTime(); + } + + yield return new WaitForSeconds(0.5f); Debug.LogWarning("[Done] Reset positions in simulation!!!"); isResetting = false; } diff --git a/Assets/Scripts/UI/SimulationDisplay.cs b/Assets/Scripts/UI/SimulationDisplay.cs index ab5826dc..725ad0ac 100644 --- a/Assets/Scripts/UI/SimulationDisplay.cs +++ b/Assets/Scripts/UI/SimulationDisplay.cs @@ -11,8 +11,9 @@ public class SimulationDisplay : MonoBehaviour { + private StringBuilder sbToPrint = new StringBuilder(); private TextMeshProUGUI uiText = null; - private StringBuilder sbToPrint; + private Clock clock = null; private int frameCount = 0; private float dt = 0.0F; @@ -23,8 +24,10 @@ public class SimulationDisplay : MonoBehaviour // Start is called before the first frame update void Awake() { - sbToPrint = new StringBuilder(); uiText = GetComponent(); + + var coreObject = GameObject.Find("Core"); + clock = coreObject.GetComponent(); } void Update() @@ -41,18 +44,16 @@ void Update() void LateUpdate() { - var simTs = TimeSpan.FromSeconds(Time.time); - // var simFixedTs = TimeSpan.FromSeconds(Time.fixedTime); - var realTs = TimeSpan.FromSeconds(Time.realtimeSinceStartup); + var simTime = (clock == null) ? Time.time : clock.GetSimTime(); + var realTime = (clock == null) ? Time.realtimeSinceStartup : clock.GetRealTime(); + + var simTs = TimeSpan.FromSeconds(simTime); + var realTs = TimeSpan.FromSeconds(realTime); var diffTs1 = realTs - simTs; - // var diffTs2 = realTs - simFixedTs; - // var timeScale = Time.timeScale; var currentSimTime = simTs.ToString(@"d\:hh\:mm\:ss\.fff"); - // var currentFixedTime = simFixedTs.ToString(@"d\:hh\:mm\:ss\.fff"); var currentRealTime = realTs.ToString(@"d\:hh\:mm\:ss\.fff"); var diffRealSimTime = diffTs1.ToString(@"d\:hh\:mm\:ss\.fff"); - // var diffRealFixedTime = diffTs2.ToString(@"d\:hh\:mm\:ss\.fff"); if (sbToPrint != null) { @@ -60,12 +61,6 @@ void LateUpdate() sbToPrint.Append("Version : "); sbToPrint.Append(Application.version); - // sbToPrint.Append(", Real-Fixed: "); - // sbToPrint.Append(diffRealFixedTime); - - // sbToPrint.Append(", (Time)Scale : "); - // sbToPrint.Append(timeScale.ToString("F1")); - sbToPrint.Append(", FPS : "); sbToPrint.Append(Mathf.Round(fps)); @@ -74,15 +69,13 @@ void LateUpdate() sbToPrint.Append("(Time) Simulation: "); sbToPrint.Append(currentSimTime); - // sbToPrint.Append(", Fixed: "); - // sbToPrint.Append(currentFixedTime); - sbToPrint.Append(", Real: "); sbToPrint.Append(currentRealTime); sbToPrint.Append(", (DiffTime) Real-Sim: "); sbToPrint.Append(diffRealSimTime); + uiText.text = sbToPrint.ToString(); } } diff --git a/Assets/Scripts/UI/SimulationDisplay.cs.meta b/Assets/Scripts/UI/SimulationDisplay.cs.meta index 9da0e0d8..f82afcb2 100644 --- a/Assets/Scripts/UI/SimulationDisplay.cs.meta +++ b/Assets/Scripts/UI/SimulationDisplay.cs.meta @@ -4,7 +4,7 @@ MonoImporter: externalObjects: {} serializedVersion: 2 defaultReferences: [] - executionOrder: 0 + executionOrder: 1000 icon: {instanceID: 0} userData: assetBundleName: From db4d7365f0928bf3dcf4e65eeb734ff5a8a5cee2 Mon Sep 17 00:00:00 2001 From: Hyunseok Yang Date: Thu, 13 Aug 2020 18:16:05 +0900 Subject: [PATCH 04/15] Code refactoring for Elevatorsystem --- .../Scripts/DevicePlugins/ElevatorSystem.cs | 153 +++++++++--------- 1 file changed, 78 insertions(+), 75 deletions(-) diff --git a/Assets/Scripts/DevicePlugins/ElevatorSystem.cs b/Assets/Scripts/DevicePlugins/ElevatorSystem.cs index 29ec728a..10e202d7 100644 --- a/Assets/Scripts/DevicePlugins/ElevatorSystem.cs +++ b/Assets/Scripts/DevicePlugins/ElevatorSystem.cs @@ -220,34 +220,34 @@ public string GetFloorName(in float targetFloorHeight) private void GenerateResponseMessage() { var serviceNameParam = new Param - { - Name = "service_name", - Value = new Any { Type = Any.ValueType.String, StringValue = string.Empty } - }; + { + Name = "service_name", + Value = new Any { Type = Any.ValueType.String, StringValue = string.Empty } + }; var resultParam = new Param - { - Name = "result", - Value = new Any { Type = Any.ValueType.Boolean, BoolValue = false } - }; + { + Name = "result", + Value = new Any { Type = Any.ValueType.Boolean, BoolValue = false } + }; var elevatorIndexParam = new Param - { - Name = "elevator_index", - Value = new Any { Type = Any.ValueType.Int32, IntValue = NON_ELEVATOR_INDEX } - }; + { + Name = "elevator_index", + Value = new Any { Type = Any.ValueType.Int32, IntValue = NON_ELEVATOR_INDEX } + }; var floorParam = new Param - { - Name = "current_floor", - Value = new Any { Type = Any.ValueType.String, StringValue = string.Empty } - }; + { + Name = "current_floor", + Value = new Any { Type = Any.ValueType.String, StringValue = string.Empty } + }; var heightParam = new Param - { - Name = "height", - Value = new Any { Type = Any.ValueType.Double, DoubleValue = 0 } - }; + { + Name = "height", + Value = new Any { Type = Any.ValueType.Double, DoubleValue = 0 } + }; responseMessage.Name = string.Empty; responseMessage.Childrens.Add(serviceNameParam); @@ -350,47 +350,49 @@ private MemoryStream HandleServiceRequest(in Param receivedMessage) private void HandleService(in string serviceName, string currentFloor, in string targetFloor, int elevatorIndex) { - var result = true; + var result = false; var height = 0f; - if (serviceName.Equals("call_elevator")) - { - elevatorIndex = NON_ELEVATOR_INDEX; - result = GetCalledElevator(currentFloor, targetFloor, out elevatorIndex); - if (!result) - { - result = CallElevator(currentFloor, targetFloor); - } - } - else if (serviceName.Equals("get_called_elevator")) - { - result = GetCalledElevator(currentFloor, targetFloor, out elevatorIndex); - } - else if (serviceName.Equals("select_elevator_floor")) - { - result = SelectElevatorFloor(elevatorIndex, targetFloor, currentFloor); - } - else if (serviceName.Equals("request_door_open")) - { - result = RequestDoorOpen(elevatorIndex); - } - else if (serviceName.Equals("request_door_close")) - { - result = RequestDoorClose(elevatorIndex); - } - else if (serviceName.Equals("is_door_opened")) + switch (serviceName) { - result = IsElevatorDoorOpened(elevatorIndex); - } - else if (serviceName.Equals("get_elevator_information")) - { - height = GetElevatorCurrentHeight(elevatorIndex); - currentFloor = GetFloorName(height); - } - else - { - Debug.LogError("Unkown service name: " + serviceName); - result = false; + case "call_elevator": + elevatorIndex = NON_ELEVATOR_INDEX; + result = GetCalledElevator(currentFloor, targetFloor, out elevatorIndex); + if (!result) + { + result = CallElevator(currentFloor, targetFloor); + } + break; + + case "get_called_elevator": + result = GetCalledElevator(currentFloor, targetFloor, out elevatorIndex); + break; + + case "select_elevator_floor": + result = SelectElevatorFloor(elevatorIndex, targetFloor, currentFloor); + break; + + case "request_door_open": + result = RequestDoorOpen(elevatorIndex); + break; + + case "request_door_close": + result = RequestDoorClose(elevatorIndex); + break; + + case "is_door_opened": + result = IsElevatorDoorOpened(elevatorIndex); + break; + + case "get_elevator_information": + result = true; + height = GetElevatorCurrentHeight(elevatorIndex); + currentFloor = GetFloorName(height); + break; + + default: + Debug.LogError("Unkown service name: " + serviceName); + break; } SetResponseMessage(result, elevatorIndex, currentFloor, height); @@ -407,24 +409,25 @@ private IEnumerator ServiceLoop() if (elevatorTaskQueue.TryDequeue(out var task)) { - // Trigger service - if (task.state.Equals(ElevatorTaskState.DOOR_OPEN)) - { - DoServiceOpenDoor(ref task); - } - else if (task.state.Equals(ElevatorTaskState.DOOR_CLOSE)) - { - DoServiceCloseDoor(ref task); - } - else if (task.state.Equals(ElevatorTaskState.STANDBY)) - { - DoServiceInStandby(ref task); - } - - // handling service - if (task.state.Equals(ElevatorTaskState.PROCESSING)) + switch (task.state) { - DoServiceInProcess(ref task); + // Trigger service + case ElevatorTaskState.DOOR_OPEN: + DoServiceOpenDoor(ref task); + break; + + case ElevatorTaskState.DOOR_CLOSE: + DoServiceCloseDoor(ref task); + break; + + case ElevatorTaskState.STANDBY: + DoServiceInStandby(ref task); + break; + + // handling service + case ElevatorTaskState.PROCESSING: + DoServiceInProcess(ref task); + break; } // finishing service From f5e41f5eefd66c76de380d909900df86b56920e3 Mon Sep 17 00:00:00 2001 From: Hyunseok Yang Date: Fri, 14 Aug 2020 11:31:19 +0900 Subject: [PATCH 05/15] Code refactoring in SDF parser - Change if statement -> switch statement --- Assets/Scripts/Tools/SDF/Geometry.cs | 40 +++++----- Assets/Scripts/Tools/SDF/Joint.cs | 101 +++++++++++++------------ Assets/Scripts/Tools/SDF/Sensor.cs | 106 ++++++++++++++++----------- 3 files changed, 136 insertions(+), 111 deletions(-) diff --git a/Assets/Scripts/Tools/SDF/Geometry.cs b/Assets/Scripts/Tools/SDF/Geometry.cs index 4115bb2a..459a97c5 100644 --- a/Assets/Scripts/Tools/SDF/Geometry.cs +++ b/Assets/Scripts/Tools/SDF/Geometry.cs @@ -101,29 +101,25 @@ public ShapeType GetShape() public Type GetShapeType() { - if (Type.Equals("box")) + switch (Type) { - return typeof(Box); - } - else if (Type.Equals("mesh")) - { - return typeof(Mesh); - } - else if (Type.Equals("sphere")) - { - return typeof(Sphere); - } - else if (Type.Equals("cylinder")) - { - return typeof(Cylinder); - } - else if (Type.Equals("plane")) - { - return typeof(Plane); - } - else - { - return null; + case "box": + return typeof(Box); + + case "mesh": + return typeof(Mesh); + + case "sphere": + return typeof(Sphere); + + case "cylinder": + return typeof(Cylinder); + + case "plane": + return typeof(Plane); + + default: + return null; } } } diff --git a/Assets/Scripts/Tools/SDF/Joint.cs b/Assets/Scripts/Tools/SDF/Joint.cs index 2a0b0001..eca46b42 100644 --- a/Assets/Scripts/Tools/SDF/Joint.cs +++ b/Assets/Scripts/Tools/SDF/Joint.cs @@ -4,6 +4,7 @@ * SPDX-License-Identifier: MIT */ +using System; using System.Xml; namespace SDF @@ -93,53 +94,61 @@ protected override void ParseElements() // Console.WriteLine("[{0}] P:{1} C:{2}", GetType().Name, parent, child); - if (Type.Equals("gearbox")) + switch (Type) { - gearbox_ratio = GetValue("gearbox_ratio"); - gearbox_reference_body = GetValue("gearbox_reference_body"); - } - else if (Type.Equals("screw")) - { - thread_pitch = GetValue("thread_pitch"); - } - else if (Type.Equals("revolute") || Type.Equals("revolute2") || Type.Equals("prismatic")) - { - axis = new Axis(); - var xyzStr = GetValue("axis/xyz"); - axis.xyz.SetByString(xyzStr); - - if (IsValidNode("axis/limit")) - { - axis.limit_lower = GetValue("axis/limit/lower"); - axis.limit_upper = GetValue("axis/limit/upper"); - } - - if (IsValidNode("axis/dynamics")) - { - axis.dynamics_damping = GetValue("axis/dynamics/damping"); - axis.dynamics_spring_stiffness = GetValue("axis/dynamics/spring_stiffness"); - } - } - - if (Type.Equals("revolute2")) - { - axis2 = new Axis(); - var xyzStr = GetValue("axis2/xyz"); - axis2.xyz.SetByString(xyzStr); - - if (IsValidNode("axis2/limit")) - { - axis2.limit_lower = GetValue("axis2/limit/lower"); - axis2.limit_upper = GetValue("axis2/limit/upper"); - } - } - - if (IsValidNode("physics/ode")) - { - if (IsValidNode("physics/ode/max_force")) - { - odePhysics.max_force = GetValue("physics/ode/max_force"); - } + case "gearbox": + gearbox_ratio = GetValue("gearbox_ratio"); + gearbox_reference_body = GetValue("gearbox_reference_body"); + break; + + case "screw": + thread_pitch = GetValue("thread_pitch"); + break; + + case "revolute": + case "revolute2": + case "prismatic": + axis = new Axis(); + var xyzStr = GetValue("axis/xyz"); + axis.xyz.SetByString(xyzStr); + + if (IsValidNode("axis/limit")) + { + axis.limit_lower = GetValue("axis/limit/lower"); + axis.limit_upper = GetValue("axis/limit/upper"); + } + + if (IsValidNode("axis/dynamics")) + { + axis.dynamics_damping = GetValue("axis/dynamics/damping"); + axis.dynamics_spring_stiffness = GetValue("axis/dynamics/spring_stiffness"); + } + + if (Type.Equals("revolute2")) + { + axis2 = new Axis(); + xyzStr = GetValue("axis2/xyz"); + axis2.xyz.SetByString(xyzStr); + + if (IsValidNode("axis2/limit")) + { + axis2.limit_lower = GetValue("axis2/limit/lower"); + axis2.limit_upper = GetValue("axis2/limit/upper"); + } + } + + if (IsValidNode("physics/ode")) + { + if (IsValidNode("physics/ode/max_force")) + { + odePhysics.max_force = GetValue("physics/ode/max_force"); + } + } + break; + + default: + Console.WriteLine("Invalid Type [{0}] P:{1} C:{2}", Type, parent, child); + break; } } } diff --git a/Assets/Scripts/Tools/SDF/Sensor.cs b/Assets/Scripts/Tools/SDF/Sensor.cs index 432e4f0f..386a847c 100644 --- a/Assets/Scripts/Tools/SDF/Sensor.cs +++ b/Assets/Scripts/Tools/SDF/Sensor.cs @@ -65,55 +65,75 @@ protected override void ParseElements() // Console.WriteLine("[{0}] P:{1} C:{2}", GetType().Name, parent, child); - if (IsValidNode("ray") && (Type.Equals("gpu_ray") || Type.Equals("ray") || Type.Equals("lidar"))) + switch (Type) { - sensor = ParseRay(); - } - else if (IsValidNode("camera")) - { - if (Type.Equals("multicamera")) - { - var cameras = new Cameras(); - cameras.name = "multiple_camera"; + case "gpu_ray": + case "ray": + case "lidar": + if (IsValidNode("ray")) + { + sensor = ParseRay(); + } + break; + + case "multicamera": + if (IsValidNode("camera")) + { + var cameras = new Cameras(); + cameras.name = "multiple_camera"; + + var nodes = GetNodes("camera"); + // Console.WriteLine("totalCamera: " + nodes.Count); + + for (var index = 1; index <= nodes.Count; index++) + { + cameras.list.Add(ParseCamera(index)); + } - var nodes = GetNodes("camera"); - // Console.WriteLine("totalCamera: " + nodes.Count); + sensor = cameras; + } + break; - for (int index = 1; index <= nodes.Count; index++) + case "camera": + case "depth": + case "wideanglecamera": + if (IsValidNode("camera")) { - cameras.list.Add(ParseCamera(index)); + sensor = ParseCamera(); } + break; - sensor = cameras; - } - else if (Type.Equals("camera") || Type.Equals("depth") || Type.Equals("wideanglecamera")) - { - sensor = ParseCamera(); - } - else - { - Console.WriteLine("Not supported camera type !? => " + Type); - } - } - else if (IsValidNode("sonar") && Type.Equals("sonar")) - { - sensor = ParseSonar(); - } - else if (IsValidNode("imu") && Type.Equals("imu")) - { - sensor = ParseIMU(); - } - else if (IsValidNode("gps") && Type.Equals("gps")) - { - sensor = ParseGPS(); - } - else if (IsValidNode("contact") && Type.Equals("contact")) - { - sensor = ParseContact(); - } - else - { - Console.WriteLine("Not supported sensor type!!!!! => " + Type); + case "sonar": + if (IsValidNode("sonar")) + { + sensor = ParseSonar(); + } + break; + + case "imu": + if (IsValidNode("imu")) + { + sensor = ParseIMU(); + } + break; + + case "gps": + if (IsValidNode("gps")) + { + sensor = ParseGPS(); + } + break; + + case "contact": + if (IsValidNode("contact")) + { + sensor = ParseContact(); + } + break; + + default: + Console.WriteLine("Not supported sensor type!!!!! => " + Type); + break; } // Set common From 20b4ecba4fff712cab4365983b634d07d277a5c8 Mon Sep 17 00:00:00 2001 From: Hyunseok Yang Date: Fri, 14 Aug 2020 11:35:52 +0900 Subject: [PATCH 06/15] Code refactoring in SDF importer - Change if statement -> switch statement --- .../SDFImporter/SDFImplement.Geometry.cs | 26 +++-- .../Tools/SDFImporter/SDFImporter.Joint.cs | 78 ++++++------- .../Tools/SDFImporter/SDFImporter.Sensor.cs | 107 ++++++++++-------- 3 files changed, 111 insertions(+), 100 deletions(-) diff --git a/Assets/Scripts/Tools/SDFImporter/SDFImplement.Geometry.cs b/Assets/Scripts/Tools/SDFImporter/SDFImplement.Geometry.cs index 7925075f..d5ab3f2f 100644 --- a/Assets/Scripts/Tools/SDFImporter/SDFImplement.Geometry.cs +++ b/Assets/Scripts/Tools/SDFImporter/SDFImplement.Geometry.cs @@ -30,18 +30,20 @@ public static void SetMesh(in SDF.Mesh obj, in GameObject targetObject) // var meshName = Path.GetFileNameWithoutExtension(obj.uri); var fileExtension = Path.GetExtension(obj.uri).ToLower(); - if (fileExtension.Equals(".obj")) + switch (fileExtension) { - var mtlPath = obj.uri.Replace(fileExtension, ".mtl"); - SDF2Unity.LoadObjMesh(targetObject, obj.uri, mtlPath); - } - else if (fileExtension.Equals(".stl")) - { - SDF2Unity.LoadStlMesh(targetObject, obj.uri); - } - else - { - Debug.LogWarning("Unknown file extension: " + fileExtension); + case ".obj": + var mtlPath = obj.uri.Replace(fileExtension, ".mtl"); + SDF2Unity.LoadObjMesh(targetObject, obj.uri, mtlPath); + break; + + case ".stl": + SDF2Unity.LoadStlMesh(targetObject, obj.uri); + break; + + default: + Debug.LogWarning("Unknown file extension: " + fileExtension); + break; } foreach (var meshFilter in targetObject.GetComponentsInChildren()) @@ -49,7 +51,7 @@ public static void SetMesh(in SDF.Mesh obj, in GameObject targetObject) var mesh = meshFilter.sharedMesh; // Scaling - Vector3[] vertices = mesh.vertices; + var vertices = mesh.vertices; var scaleFactor = obj.scale; for (var v = 0; v < mesh.vertexCount; v++) { diff --git a/Assets/Scripts/Tools/SDFImporter/SDFImporter.Joint.cs b/Assets/Scripts/Tools/SDFImporter/SDFImporter.Joint.cs index 57d932bf..16382af3 100644 --- a/Assets/Scripts/Tools/SDFImporter/SDFImporter.Joint.cs +++ b/Assets/Scripts/Tools/SDFImporter/SDFImporter.Joint.cs @@ -69,45 +69,47 @@ protected override void ImportJoint(in SDF.Joint joint, in System.Object parentO Joint jointComponent = null; - if (joint.Type.Equals("ball")) + switch (joint.Type) { - var ballJoint = SDFImplement.Joint.AddBall(linkObjectChild, rigidBodyParent); - jointComponent = ballJoint as Joint; - } - else if (joint.Type.Equals("prismatic")) - { - var prismaticJoint = SDFImplement.Joint.AddPrismatic(joint.Axis, joint.OdePhysics, joint.Pose, linkObjectChild, rigidBodyParent); - jointComponent = prismaticJoint as Joint; - } - else if (joint.Type.Equals("revolute")) - { - var revoluteJointComponent = SDFImplement.Joint.AddRevolute(joint.Axis, linkObjectChild, rigidBodyParent); - jointComponent = revoluteJointComponent as Joint; - } - else if (joint.Type.Equals("revolute2")) - { - var revolute2JointComponent = SDFImplement.Joint.AddRevolute2(joint.Axis, joint.Axis2, linkObjectChild, rigidBodyParent); - jointComponent = revolute2JointComponent as Joint; - } - else if (joint.Type.Equals("fixed")) - { - var fixedJointComponent = SDFImplement.Joint.AddFixed(linkObjectChild, rigidBodyParent); - jointComponent = fixedJointComponent as Joint; - } - else if (joint.Type.Equals("gearbox")) - { - // gearbox_ratio = GetValue("gearbox_ratio"); - // gearbox_reference_body = GetValue("gearbox_reference_body"); - Debug.LogWarning("This type[gearbox] is not supported now."); - } - else if (joint.Type.Equals("screw")) - { - // thread_pitch = GetValue("thread_pitch"); - Debug.LogWarning("This type[screw] is not supported now."); - } - else - { - Debug.LogWarningFormat("Check Joint type[{0}]", joint.Type); + case "ball": + var ballJoint = SDFImplement.Joint.AddBall(linkObjectChild, rigidBodyParent); + jointComponent = ballJoint as Joint; + break; + + case "prismatic": + var prismaticJoint = SDFImplement.Joint.AddPrismatic(joint.Axis, joint.OdePhysics, joint.Pose, linkObjectChild, rigidBodyParent); + jointComponent = prismaticJoint as Joint; + break; + + case "revolute": + var revoluteJointComponent = SDFImplement.Joint.AddRevolute(joint.Axis, linkObjectChild, rigidBodyParent); + jointComponent = revoluteJointComponent as Joint; + break; + + case "revolute2": + var revolute2JointComponent = SDFImplement.Joint.AddRevolute2(joint.Axis, joint.Axis2, linkObjectChild, rigidBodyParent); + jointComponent = revolute2JointComponent as Joint; + break; + + case "fixed": + var fixedJointComponent = SDFImplement.Joint.AddFixed(linkObjectChild, rigidBodyParent); + jointComponent = fixedJointComponent as Joint; + break; + + case "gearbox": + // gearbox_ratio = GetValue("gearbox_ratio"); + // gearbox_reference_body = GetValue("gearbox_reference_body"); + Debug.LogWarning("This type[gearbox] is not supported now."); + break; + + case "screw": + // thread_pitch = GetValue("thread_pitch"); + Debug.LogWarning("This type[screw] is not supported now."); + break; + + default: + Debug.LogWarningFormat("Check Joint type[{0}]", joint.Type); + break; } if (jointComponent != null) diff --git a/Assets/Scripts/Tools/SDFImporter/SDFImporter.Sensor.cs b/Assets/Scripts/Tools/SDFImporter/SDFImporter.Sensor.cs index c7e6dc05..a4320bd5 100644 --- a/Assets/Scripts/Tools/SDFImporter/SDFImporter.Sensor.cs +++ b/Assets/Scripts/Tools/SDFImporter/SDFImporter.Sensor.cs @@ -21,57 +21,64 @@ protected override System.Object ImportSensor(in SDF.Sensor item, in System.Obje var sensorType = item.Type; - if (sensorType.Equals("lidar") || sensorType.Equals("ray") || sensorType.Equals("gpu_ray")) + switch (sensorType) { - var ray = item.GetSensor() as SDF.Ray; - sensor = SDFImplement.Sensor.AddLidar(ray, targetObject); - } - else if (sensorType.Equals("depth")) - { - var depthCamera = item.GetSensor() as SDF.Camera; - sensor = SDFImplement.Sensor.AddDepthCamera(depthCamera, targetObject); - } - else if (sensorType.Equals("camera")) - { - var camera = item.GetSensor() as SDF.Camera; - sensor = SDFImplement.Sensor.AddCamera(camera, targetObject); - } - else if (sensorType.Equals("multicamera")) - { - var cameras = item.GetSensor() as SDF.Cameras; - sensor = SDFImplement.Sensor.AddMultiCamera(cameras, targetObject); - } - else if (sensorType.Equals("imu")) - { - var imu = item.GetSensor() as SDF.IMU; - sensor = SDFImplement.Sensor.AddImu(imu, targetObject); - } - else if (sensorType.Equals("sonar")) - { - var sonar = item.GetSensor() as SDF.Sonar; - sensor = SDFImplement.Sensor.AddSonar(sonar, targetObject); - } - else if (sensorType.Equals("gps")) - { - var gps = item.GetSensor() as SDF.GPS; - sensor = SDFImplement.Sensor.AddGps(gps, targetObject); - } - else if (sensorType.Equals("contact")) - { - var contact = item.GetSensor() as SDF.Contact; - sensor = SDFImplement.Sensor.AddContact(contact, targetObject); - } - else if (sensorType.Equals("air_pressure") || sensorType.Equals("altimeter") || - sensorType.Equals("force_torque") || - sensorType.Equals("logical_camera") || sensorType.Equals("magnetometer") || - sensorType.Equals("rfidtag") || - sensorType.Equals("rfid") || sensorType.Equals("transceiver")) - { - Console.WriteLine("[Sensor] Not supported sensor name({0}) type({1})!!!!!", item.Name, sensorType); - } - else - { - Debug.LogWarningFormat("[Sensor] type({0}) is not supprted.", sensorType); + case "lidar": + case "ray": + case "gpu_ray": + var ray = item.GetSensor() as SDF.Ray; + sensor = SDFImplement.Sensor.AddLidar(ray, targetObject); + break; + + case "depth": + var depthCamera = item.GetSensor() as SDF.Camera; + sensor = SDFImplement.Sensor.AddDepthCamera(depthCamera, targetObject); + break; + + case "camera": + var camera = item.GetSensor() as SDF.Camera; + sensor = SDFImplement.Sensor.AddCamera(camera, targetObject); + break; + + case "multicamera": + var cameras = item.GetSensor() as SDF.Cameras; + sensor = SDFImplement.Sensor.AddMultiCamera(cameras, targetObject); + break; + + case "imu": + var imu = item.GetSensor() as SDF.IMU; + sensor = SDFImplement.Sensor.AddImu(imu, targetObject); + break; + + case "sonar": + var sonar = item.GetSensor() as SDF.Sonar; + sensor = SDFImplement.Sensor.AddSonar(sonar, targetObject); + break; + + case "gps": + var gps = item.GetSensor() as SDF.GPS; + sensor = SDFImplement.Sensor.AddGps(gps, targetObject); + break; + + case "contact": + var contact = item.GetSensor() as SDF.Contact; + sensor = SDFImplement.Sensor.AddContact(contact, targetObject); + break; + + case "air_pressure": + case "altimeter": + case "force_torque": + case "logical_camera": + case "magnetometer": + case "rfidtag": + case "rfid": + case "transceiver": + Console.WriteLine("[Sensor] Not supported sensor name({0}) type({1})!!!!!", item.Name, sensorType); + break; + + default: + Debug.LogWarningFormat("[Sensor] type({0}) is not supprted.", sensorType); + break; } GameObject newSensorObject = null; From cbd711f23c043e6a999568401acd75bd8009d695 Mon Sep 17 00:00:00 2001 From: Hyunseok Yang Date: Fri, 14 Aug 2020 11:37:32 +0900 Subject: [PATCH 07/15] Disable and disconnect Unity Services --- ProjectSettings/ProjectSettings.asset | 2 +- ProjectSettings/UnityConnectSettings.asset | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ProjectSettings/ProjectSettings.asset b/ProjectSettings/ProjectSettings.asset index d5f1bb20..24b88750 100644 --- a/ProjectSettings/ProjectSettings.asset +++ b/ProjectSettings/ProjectSettings.asset @@ -712,7 +712,7 @@ PlayerSettings: Collab: 0 ErrorHub: 0 Hub: 0 - UNet: 1 + UNet: 0 luminIcon: m_Name: m_ModelFolderPath: diff --git a/ProjectSettings/UnityConnectSettings.asset b/ProjectSettings/UnityConnectSettings.asset index 584eee75..c3ae9a02 100644 --- a/ProjectSettings/UnityConnectSettings.asset +++ b/ProjectSettings/UnityConnectSettings.asset @@ -12,7 +12,7 @@ UnityConnectSettings: m_TestInitMode: 0 CrashReportingSettings: m_EventUrl: https://perf-events.cloud.unity3d.com - m_Enabled: 1 + m_Enabled: 0 m_LogBufferSize: 10 m_CaptureEditorExceptions: 1 UnityPurchasingSettings: From 3fca460e0ca7bad16d7428eb58d60b0605fa9d5f Mon Sep 17 00:00:00 2001 From: Hyunseok Yang Date: Fri, 14 Aug 2020 11:38:27 +0900 Subject: [PATCH 08/15] Code refactoring in Simulation Control Service - Change if statement -> switch statement --- .../Services/SimulationControlService.cs | 42 +++++++++++-------- 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/Assets/Scripts/Services/SimulationControlService.cs b/Assets/Scripts/Services/SimulationControlService.cs index 98a163e1..ee83af58 100644 --- a/Assets/Scripts/Services/SimulationControlService.cs +++ b/Assets/Scripts/Services/SimulationControlService.cs @@ -94,25 +94,31 @@ protected override void OnMessage(MessageEventArgs e) SimulationControlResponseBase output = null; - if (request.command.Equals("reset")) + switch (request.command) { - var wasSuccessful = modelLoaderService.TriggerResetService(request.command); - var result = (wasSuccessful)? SimulationService.SUCCESS:SimulationService.FAIL; - - output = new SimulationControlResponseNormal(); - (output as SimulationControlResponseNormal).result = result; - } - else if (request.command.Equals("device_list")) - { - var result = portDeviceService.GetSensorPortList(); - - output = new SimulationControlResponseSensorPortList(); - (output as SimulationControlResponseSensorPortList).result = result; - } - else - { - output = new SimulationControlResponseBase(); - request.command = "Invalid Command"; + case "reset": + { + var wasSuccessful = modelLoaderService.TriggerResetService(request.command); + var result = (wasSuccessful) ? SimulationService.SUCCESS : SimulationService.FAIL; + + output = new SimulationControlResponseNormal(); + (output as SimulationControlResponseNormal).result = result; + } + break; + + case "device_list": + { + var result = portDeviceService.GetSensorPortList(); + + output = new SimulationControlResponseSensorPortList(); + (output as SimulationControlResponseSensorPortList).result = result; + } + break; + + default: + output = new SimulationControlResponseBase(); + request.command = "Invalid Command"; + break; } output.command = request.command; From 6715e3d2c80785317eb6e548344a93545082058a Mon Sep 17 00:00:00 2001 From: Hyunseok Yang Date: Fri, 14 Aug 2020 11:39:50 +0900 Subject: [PATCH 09/15] Code refactoring in Camera Device - Change if statement -> switch statement --- Assets/Scripts/Devices/Camera.CameraData.cs | 128 +++++++++++--------- Assets/Scripts/Devices/DepthCamera.cs | 20 +-- 2 files changed, 82 insertions(+), 66 deletions(-) diff --git a/Assets/Scripts/Devices/Camera.CameraData.cs b/Assets/Scripts/Devices/Camera.CameraData.cs index 94681a29..9ff63fd6 100644 --- a/Assets/Scripts/Devices/Camera.CameraData.cs +++ b/Assets/Scripts/Devices/Camera.CameraData.cs @@ -32,29 +32,37 @@ static public PixelFormat GetPixelFormat(in string imageFormat) } // Handle old format strings - if (imageFormat.Equals("L8") || imageFormat.Equals("L_INT8")) - { - parsedEnum = PixelFormat.L_INT8; - } - else if (imageFormat.Equals("L16") || imageFormat.Equals("L_INT16") || imageFormat.Equals("L_UINT16")) - { - // Note: we are treating unsigned and signed 16bit the same but it is - // better to add a L_UINT16 format to distinguish between the two - parsedEnum = PixelFormat.L_INT16; - } - else if (imageFormat.Equals("R8G8B8") || imageFormat.Equals("RGB_INT8")) - { - parsedEnum = PixelFormat.RGB_INT8; - } - else if (imageFormat.Equals("R16G16B16") || imageFormat.Equals("RGB_INT16")|| imageFormat.Equals("RGB_UINT16")) - { - // Note: we are treating unsigned and signed 16bit the same but it is - // better to add a RGB_UINT16 format to distinguish between the two - parsedEnum = PixelFormat.RGB_INT16; - } - else - { - parsedEnum = (PixelFormat)Enum.Parse(typeof(PixelFormat), imageFormat); + switch (imageFormat) + { + case "L8": + case "L_INT8": + parsedEnum = PixelFormat.L_INT8; + break; + + case "L16": + case "L_INT16": + case "L_UINT16": + // Note: we are treating unsigned and signed 16bit the same but it is + // better to add a L_UINT16 format to distinguish between the two + parsedEnum = PixelFormat.L_INT16; + break; + + case "R8G8B8": + case "RGB_INT8": + parsedEnum = PixelFormat.RGB_INT8; + break; + + case "R16G16B16": + case "RGB_INT16": + case "RGB_UINT16": + // Note: we are treating unsigned and signed 16bit the same but it is + // better to add a RGB_UINT16 format to distinguish between the two + parsedEnum = PixelFormat.RGB_INT16; + break; + + default: + parsedEnum = (PixelFormat)Enum.Parse(typeof(PixelFormat), imageFormat); + break; } return parsedEnum; @@ -62,45 +70,53 @@ static public PixelFormat GetPixelFormat(in string imageFormat) static public int GetImageDepth(in string imageFormat) { - int depth = 0; + var depth = 0; if (imageFormat == null || imageFormat.Equals(string.Empty)) { return depth; } - if (imageFormat.Equals("L8") || imageFormat.Equals("L_INT8")) - { - depth = 1; - } - else if (imageFormat.Equals("L16") || imageFormat.Equals("L_INT16")|| imageFormat.Equals("L_UINT16")) - { - depth = 2; - } - else if (imageFormat.Equals("R8G8B8")|| imageFormat.Equals("RGB_INT8")) - { - depth = 3; - } - else if (imageFormat.Equals("B8G8R8")|| imageFormat.Equals("BGR_INT8")) - { - depth = 3; - } - else if (imageFormat.Equals("R_FLOAT32")) - { - depth = 4; - } - else if (imageFormat.Equals("R16G16B16")|| imageFormat.Equals("RGB_INT16")|| imageFormat.Equals("RGB_UINT16")) - { - depth = 6; - } - else if (imageFormat.Equals("BAYER_RGGB8") || imageFormat.Equals("BAYER_BGGR8") || - imageFormat.Equals("BAYER_GBRG8") || imageFormat.Equals("BAYER_GRBG8")) - { - depth = 1; - } - else - { - Debug.LogErrorFormat("Error parsing image format ({0}), using default PF_R8G8B8", imageFormat); + switch (imageFormat) + { + case "L8": + case "L_INT8": + depth = 1; + break; + + case "L16": + case "L_INT16": + case "L_UINT16": + depth = 2; + break; + + case "R8G8B8": + case "RGB_INT8": + case "B8G8R8": + case "BGR_INT8": + depth = 3; + break; + + case "R16G16B16": + case "RGB_INT16": + case "RGB_UINT16": + depth = 6; + break; + + case "R_FLOAT32": + depth = 4; + break; + + case "BAYER_RGGB8": + case "BAYER_BGGR8": + case "BAYER_GBRG8": + case "BAYER_GRBG8": + depth = 1; + break; + + default: + Debug.LogErrorFormat("Error parsing image format ({0}), using default PF_R8G8B8", imageFormat); + break; } return depth; diff --git a/Assets/Scripts/Devices/DepthCamera.cs b/Assets/Scripts/Devices/DepthCamera.cs index 2156fbd5..1690fbde 100644 --- a/Assets/Scripts/Devices/DepthCamera.cs +++ b/Assets/Scripts/Devices/DepthCamera.cs @@ -16,8 +16,6 @@ public partial class DepthCamera : Camera private Material depthMaterial = null; - public bool isPointCloud = false; - void OnRenderImage(RenderTexture source, RenderTexture destination) { if (depthMaterial) @@ -29,21 +27,23 @@ void OnRenderImage(RenderTexture source, RenderTexture destination) Graphics.Blit(source, destination); } } + protected override void SetupTexture() { var shader = Shader.Find("Sensor/Depth"); depthMaterial = new Material(shader); depthMaterial.SetFloat("_ReverseData", 1.0f); - if (parameters.depth_camera_output.Equals("points")) - { - isPointCloud = true; - Debug.Log("Enable Point Cloud data mode"); - parameters.image_format = "RGB_FLOAT32"; - } - else + switch (parameters.depth_camera_output) { - parameters.image_format = "R_FLOAT32"; + case "points": + Debug.Log("Enable Point Cloud data mode"); + parameters.image_format = "RGB_FLOAT32"; + break; + + default: + parameters.image_format = "R_FLOAT32"; + break; } cam.backgroundColor = Color.white; From f698f2873b600933dcd80379fc9e8401f05d0c47 Mon Sep 17 00:00:00 2001 From: Hyunseok Yang Date: Fri, 14 Aug 2020 14:02:23 +0900 Subject: [PATCH 10/15] Code refactoring in MarkerVisualizer Return false if adding markers already exist in simulation. --- .../MarkerVisualizer/MarkerVisualizer.add.cs | 8 ++- .../UI/MarkerVisualizer/MarkerVisualizer.cs | 68 ++++++++----------- .../MarkerVisualizer/MarkerVisualizer.list.cs | 16 ++--- 3 files changed, 38 insertions(+), 54 deletions(-) diff --git a/Assets/Scripts/UI/MarkerVisualizer/MarkerVisualizer.add.cs b/Assets/Scripts/UI/MarkerVisualizer/MarkerVisualizer.add.cs index 74d6710a..9b87aa68 100644 --- a/Assets/Scripts/UI/MarkerVisualizer/MarkerVisualizer.add.cs +++ b/Assets/Scripts/UI/MarkerVisualizer/MarkerVisualizer.add.cs @@ -22,12 +22,16 @@ bool AddMarkers() foreach (var item in request.markers) { var markerName = item.MarkerName(); - if (registeredMarkers[markerName] != null) { Debug.LogWarning(markerName + " is Already Exist in visual marker list!!!"); - continue; + return false; } + } + + foreach (var item in request.markers) + { + var markerName = item.MarkerName(); marker = null; switch (item.type) diff --git a/Assets/Scripts/UI/MarkerVisualizer/MarkerVisualizer.cs b/Assets/Scripts/UI/MarkerVisualizer/MarkerVisualizer.cs index a367b4e1..754b9d63 100644 --- a/Assets/Scripts/UI/MarkerVisualizer/MarkerVisualizer.cs +++ b/Assets/Scripts/UI/MarkerVisualizer/MarkerVisualizer.cs @@ -11,7 +11,7 @@ public partial class MarkerVisualizer : MonoBehaviour { - private UnityEvent responseEvent; + private UnityEvent responseEvent = new UnityEvent(); private const string targetRootName = "Markers"; private const string mainCameraName = "Main Camera"; private const string commonShaderName = "UI/Unlit/Text"; @@ -19,39 +19,20 @@ public partial class MarkerVisualizer : MonoBehaviour private Camera mainCamera = null; private GameObject rootMarkers = null; - private Hashtable registeredMarkers = null; - private Hashtable registeredObjectsForFollowingText = null; - - private Hashtable followingTextMarkers = null; + private Hashtable registeredMarkers = new Hashtable(); + private Hashtable registeredObjectsForFollowingText = new Hashtable(); + private Hashtable followingTextMarkers = new Hashtable(); #region Request private VisualMarkerRequest request = null; #endregion #region Response - private VisualMarkerResponse response = null; + private VisualMarkerResponse response = new VisualMarkerResponse(); #endregion - MarkerVisualizer() - { - registeredMarkers = new Hashtable(); - - registeredObjectsForFollowingText = new Hashtable(); - followingTextMarkers = new Hashtable(); - - response = new VisualMarkerResponse(); - - InitializeList(); - } - void Awake() { - if (responseEvent == null) - { - // Debug.Log("UnityEvent"); - responseEvent = new UnityEvent(); - } - rootMarkers = GameObject.Find(targetRootName); commonShader = Shader.Find(commonShaderName); mainCamera = GameObject.Find(mainCameraName).GetComponent(); @@ -67,18 +48,22 @@ void Update() void LateUpdate() { - HandleFollowingText(); + StartCoroutine(HandleFollowingText()); } - private void HandleFollowingText() + private IEnumerator HandleFollowingText() { + var newPos = Vector3.zero; + foreach (DictionaryEntry textMarker in followingTextMarkers) { + yield return null; + // Look at camera var textObject = (textMarker.Value as TextMeshPro).gameObject; textObject.transform.LookAt(mainCamera.transform); - // Following Objects + // Text marker follows Objects var markerName = textObject.name; var followingTargetObject = registeredObjectsForFollowingText[markerName] as GameObject; if (followingTargetObject != null) @@ -86,10 +71,13 @@ private void HandleFollowingText() var rectTransform = textObject.GetComponent(); var followingObjectPosition = followingTargetObject.transform.position; var textPosition = rectTransform.localPosition; - var newPos = new Vector3(followingObjectPosition.x, textPosition.y, followingObjectPosition.z); + + newPos.Set(followingObjectPosition.x, textPosition.y, followingObjectPosition.z); rectTransform.position = newPos; } } + + yield return null; } public void RegisterResponseAction(in UnityAction call) @@ -104,17 +92,13 @@ public void RegisterResponseAction(in UnityAction call) } } - private void DoneMarkerRequested(in string command, in bool result) + private void DoneMarkerRequested(in VisualMarkerRequest.MarkerCommands command, in bool result) { - request = null; - - response.command = command; + response.command = command.ToString().ToLower(); response.result = (result)? SimulationService.SUCCESS : SimulationService.FAIL; + responseEvent.Invoke(); - if (result) - { - responseEvent.Invoke(); - } + request = null; // remove requested message } private void SetDefaultMeshRenderer(in Renderer renderer) @@ -132,6 +116,11 @@ private void SetDefaultMeshRenderer(in Renderer renderer) private IEnumerator HandleRequsetMarkers() { + if (request == null) + { + yield return null; + } + var result = false; switch (request.command) @@ -160,19 +149,18 @@ private IEnumerator HandleRequsetMarkers() break; } - var command = request.command.ToString().ToLower(); - DoneMarkerRequested(command, result); + + DoneMarkerRequested(request.command, result); yield return null; } - public bool PushRequsetMarkers(in VisualMarkerRequest markerRequest) { if (markerRequest.command.Equals(VisualMarkerRequest.MarkerCommands.List) && markerRequest.markers.Count > 0) { request = null; - response.command = "";//request.command; + response.command = ""; response.result = SimulationService.FAIL; response.lines = null; response.texts = null; diff --git a/Assets/Scripts/UI/MarkerVisualizer/MarkerVisualizer.list.cs b/Assets/Scripts/UI/MarkerVisualizer/MarkerVisualizer.list.cs index 8a28c5b1..5f291636 100644 --- a/Assets/Scripts/UI/MarkerVisualizer/MarkerVisualizer.list.cs +++ b/Assets/Scripts/UI/MarkerVisualizer/MarkerVisualizer.list.cs @@ -11,18 +11,10 @@ public partial class MarkerVisualizer : MonoBehaviour { - private List requestedMarkerLineList; - private List requestedMarkerTextList; - private List requestedMarkerBoxList; - private List requestedMarkerSphereList; - - public void InitializeList() - { - requestedMarkerLineList = new List(); - requestedMarkerTextList = new List(); - requestedMarkerBoxList = new List(); - requestedMarkerSphereList = new List(); - } + private List requestedMarkerLineList = new List(); + private List requestedMarkerTextList = new List(); + private List requestedMarkerBoxList = new List(); + private List requestedMarkerSphereList = new List(); public bool ListMarkers() { From 68c3e6fd030a3467d00b02643ed3856da6087610 Mon Sep 17 00:00:00 2001 From: Hyunseok Yang Date: Fri, 14 Aug 2020 14:17:42 +0900 Subject: [PATCH 11/15] Code refactoring in DevicePlugins - Camera, multi-camera --- Assets/Scripts/DevicePlugins/CameraPlugin.cs | 18 ++++++++++--- .../DevicePlugins/MultiCameraPlugin.cs | 25 +++++++++++++------ 2 files changed, 31 insertions(+), 12 deletions(-) diff --git a/Assets/Scripts/DevicePlugins/CameraPlugin.cs b/Assets/Scripts/DevicePlugins/CameraPlugin.cs index e23cca50..54530d43 100644 --- a/Assets/Scripts/DevicePlugins/CameraPlugin.cs +++ b/Assets/Scripts/DevicePlugins/CameraPlugin.cs @@ -74,13 +74,23 @@ private void Response() var requestMessage = ParsingCameraInfoRequest(ref memoryStreamForCameraInfo, receivedBuffer); // Debug.Log(subPartName + receivedString); - if (requestMessage != null && requestMessage.Name.Equals("request_camera_info")) + if (requestMessage != null) { - var cameraInfoMessage = cam.GetCameraInfo(); + switch (requestMessage.Name) + { + case "request_camera_info": - SetCameraInfoResponse(ref memoryStreamForCameraInfo, cameraInfoMessage); + var cameraInfoMessage = cam.GetCameraInfo(); - SendResponse(memoryStreamForCameraInfo); + SetCameraInfoResponse(ref memoryStreamForCameraInfo, cameraInfoMessage); + + SendResponse(memoryStreamForCameraInfo); + + break; + + default: + break; + } } } } diff --git a/Assets/Scripts/DevicePlugins/MultiCameraPlugin.cs b/Assets/Scripts/DevicePlugins/MultiCameraPlugin.cs index 102b487b..f8871f26 100644 --- a/Assets/Scripts/DevicePlugins/MultiCameraPlugin.cs +++ b/Assets/Scripts/DevicePlugins/MultiCameraPlugin.cs @@ -69,18 +69,27 @@ private void Response() var requestMessage = CameraPlugin.ParsingCameraInfoRequest(ref memoryStreamForCameraInfo, receivedBuffer); - if (requestMessage != null && requestMessage.Name.Equals("request_camera_info")) + if (requestMessage != null) { - var cameraName = requestMessage.Value.StringValue; - - if (cameraName != null) + switch (requestMessage.Name) { - var cameraInfoMessage = cam.GetCameraInfo(cameraName); + case "request_camera_info": - CameraPlugin.SetCameraInfoResponse(ref memoryStreamForCameraInfo, cameraInfoMessage); - } + var cameraName = requestMessage.Value.StringValue; + if (cameraName != null) + { + var cameraInfoMessage = cam.GetCameraInfo(cameraName); + + CameraPlugin.SetCameraInfoResponse(ref memoryStreamForCameraInfo, cameraInfoMessage); + } - SendResponse(memoryStreamForCameraInfo); + SendResponse(memoryStreamForCameraInfo); + + break; + + default: + break; + } } } } From b27b6814617f3c90b56b526f3eec8ad7a3c3332a Mon Sep 17 00:00:00 2001 From: Hyunseok Yang Date: Fri, 14 Aug 2020 14:24:09 +0900 Subject: [PATCH 12/15] Update app version info in Project settings : 1.5.2 -> 1.5.3 --- ProjectSettings/ProjectSettings.asset | 218 +++++++++++++------------- 1 file changed, 109 insertions(+), 109 deletions(-) diff --git a/ProjectSettings/ProjectSettings.asset b/ProjectSettings/ProjectSettings.asset index 24b88750..a231eb0c 100644 --- a/ProjectSettings/ProjectSettings.asset +++ b/ProjectSettings/ProjectSettings.asset @@ -124,7 +124,7 @@ PlayerSettings: 16:10: 1 16:9: 1 Others: 1 - bundleVersion: 1.5.2 + bundleVersion: 1.5.3 preloadedAssets: [] metroInputSource: 0 wsaTransparentSwapchain: 0 @@ -173,7 +173,7 @@ PlayerSettings: AndroidMinSdkVersion: 19 AndroidTargetSdkVersion: 0 AndroidPreferredInstallLocation: 1 - aotOptions: + aotOptions: stripEngineCode: 1 iPhoneStrippingLevel: 0 iPhoneScriptCallOptimization: 0 @@ -213,7 +213,7 @@ PlayerSettings: rgba: 0 iOSLaunchScreenFillPct: 100 iOSLaunchScreenSize: 100 - iOSLaunchScreenCustomXibPath: + iOSLaunchScreenCustomXibPath: iOSLaunchScreeniPadType: 0 iOSLaunchScreeniPadImage: {fileID: 0} iOSLaunchScreeniPadBackgroundColor: @@ -221,9 +221,9 @@ PlayerSettings: rgba: 0 iOSLaunchScreeniPadFillPct: 100 iOSLaunchScreeniPadSize: 100 - iOSLaunchScreeniPadCustomXibPath: + iOSLaunchScreeniPadCustomXibPath: iOSUseLaunchScreenStoryboard: 0 - iOSLaunchScreenCustomStoryboardPath: + iOSLaunchScreenCustomStoryboardPath: iOSDeviceRequirements: [] iOSURLSchemes: [] iOSBackgroundModes: 0 @@ -231,9 +231,9 @@ PlayerSettings: metalEditorSupport: 1 metalAPIValidation: 1 iOSRenderExtraFrameOnPause: 0 - appleDeveloperTeamID: - iOSManualSigningProvisioningProfileID: - tvOSManualSigningProvisioningProfileID: + appleDeveloperTeamID: + iOSManualSigningProvisioningProfileID: + tvOSManualSigningProvisioningProfileID: iOSManualSigningProvisioningProfileType: 0 tvOSManualSigningProvisioningProfileType: 0 appleEnableAutomaticSigning: 0 @@ -241,13 +241,13 @@ PlayerSettings: iOSAutomaticallyDetectAndAddCapabilities: 1 appleEnableProMotion: 0 clonedFromGUID: c0afd0d1d80e3634a9dac47e8a0426ea - templatePackageId: + templatePackageId: templateDefaultScene: Assets/Scenes/MainScene.unity AndroidTargetArchitectures: 1 AndroidSplashScreenScale: 0 androidSplashScreen: {fileID: 0} AndroidKeystoreName: '{inproject}: ' - AndroidKeyaliasName: + AndroidKeyaliasName: AndroidBuildApkPerCpuArchitecture: 0 AndroidTVCompatibility: 0 AndroidIsGame: 1 @@ -305,7 +305,7 @@ PlayerSettings: m_Width: 16 m_Height: 16 m_Kind: 0 - - m_BuildTarget: + - m_BuildTarget: m_Icons: - serializedVersion: 2 m_Icon: {fileID: 2800000, guid: 42491c491c989c4f2a78e1338a397f7e, type: 3} @@ -410,47 +410,47 @@ PlayerSettings: enableInternalProfiler: 0 logObjCUncaughtExceptions: 1 enableCrashReportAPI: 0 - cameraUsageDescription: - locationUsageDescription: - microphoneUsageDescription: - switchNetLibKey: + cameraUsageDescription: + locationUsageDescription: + microphoneUsageDescription: + switchNetLibKey: switchSocketMemoryPoolSize: 6144 switchSocketAllocatorPoolSize: 128 switchSocketConcurrencyLimit: 14 switchScreenResolutionBehavior: 2 switchUseCPUProfiler: 0 switchApplicationID: 0x01004b9000490000 - switchNSODependencies: - switchTitleNames_0: - switchTitleNames_1: - switchTitleNames_2: - switchTitleNames_3: - switchTitleNames_4: - switchTitleNames_5: - switchTitleNames_6: - switchTitleNames_7: - switchTitleNames_8: - switchTitleNames_9: - switchTitleNames_10: - switchTitleNames_11: - switchTitleNames_12: - switchTitleNames_13: - switchTitleNames_14: - switchPublisherNames_0: - switchPublisherNames_1: - switchPublisherNames_2: - switchPublisherNames_3: - switchPublisherNames_4: - switchPublisherNames_5: - switchPublisherNames_6: - switchPublisherNames_7: - switchPublisherNames_8: - switchPublisherNames_9: - switchPublisherNames_10: - switchPublisherNames_11: - switchPublisherNames_12: - switchPublisherNames_13: - switchPublisherNames_14: + switchNSODependencies: + switchTitleNames_0: + switchTitleNames_1: + switchTitleNames_2: + switchTitleNames_3: + switchTitleNames_4: + switchTitleNames_5: + switchTitleNames_6: + switchTitleNames_7: + switchTitleNames_8: + switchTitleNames_9: + switchTitleNames_10: + switchTitleNames_11: + switchTitleNames_12: + switchTitleNames_13: + switchTitleNames_14: + switchPublisherNames_0: + switchPublisherNames_1: + switchPublisherNames_2: + switchPublisherNames_3: + switchPublisherNames_4: + switchPublisherNames_5: + switchPublisherNames_6: + switchPublisherNames_7: + switchPublisherNames_8: + switchPublisherNames_9: + switchPublisherNames_10: + switchPublisherNames_11: + switchPublisherNames_12: + switchPublisherNames_13: + switchPublisherNames_14: switchIcons_0: {fileID: 0} switchIcons_1: {fileID: 0} switchIcons_2: {fileID: 0} @@ -481,11 +481,11 @@ PlayerSettings: switchSmallIcons_12: {fileID: 0} switchSmallIcons_13: {fileID: 0} switchSmallIcons_14: {fileID: 0} - switchManualHTML: - switchAccessibleURLs: - switchLegalInformation: + switchManualHTML: + switchAccessibleURLs: + switchLegalInformation: switchMainThreadStackSize: 1048576 - switchPresenceGroupId: + switchPresenceGroupId: switchLogoHandling: 0 switchReleaseVersion: 0 switchDisplayVersion: 1.0.0 @@ -493,7 +493,7 @@ PlayerSettings: switchTouchScreenUsage: 0 switchSupportedLanguagesMask: 0 switchLogoType: 0 - switchApplicationErrorCodeCategory: + switchApplicationErrorCodeCategory: switchUserAccountSaveDataSize: 0 switchUserAccountSaveDataJournalSize: 0 switchApplicationAttribute: 0 @@ -513,14 +513,14 @@ PlayerSettings: switchRatingsInt_10: 0 switchRatingsInt_11: 0 switchRatingsInt_12: 0 - switchLocalCommunicationIds_0: - switchLocalCommunicationIds_1: - switchLocalCommunicationIds_2: - switchLocalCommunicationIds_3: - switchLocalCommunicationIds_4: - switchLocalCommunicationIds_5: - switchLocalCommunicationIds_6: - switchLocalCommunicationIds_7: + switchLocalCommunicationIds_0: + switchLocalCommunicationIds_1: + switchLocalCommunicationIds_2: + switchLocalCommunicationIds_3: + switchLocalCommunicationIds_4: + switchLocalCommunicationIds_5: + switchLocalCommunicationIds_6: + switchLocalCommunicationIds_7: switchParentalControl: 0 switchAllowsScreenshot: 1 switchAllowsVideoCapturing: 1 @@ -544,34 +544,34 @@ PlayerSettings: switchNetworkInterfaceManagerInitializeEnabled: 1 switchPlayerConnectionEnabled: 1 ps4NPAgeRating: 12 - ps4NPTitleSecret: - ps4NPTrophyPackPath: + ps4NPTitleSecret: + ps4NPTrophyPackPath: ps4ParentalLevel: 11 ps4ContentID: ED1633-NPXX51362_00-0000000000000000 ps4Category: 0 ps4MasterVersion: 01.00 ps4AppVersion: 01.00 ps4AppType: 0 - ps4ParamSfxPath: + ps4ParamSfxPath: ps4VideoOutPixelFormat: 0 ps4VideoOutInitialWidth: 1920 ps4VideoOutBaseModeInitialWidth: 1920 ps4VideoOutReprojectionRate: 60 - ps4PronunciationXMLPath: - ps4PronunciationSIGPath: - ps4BackgroundImagePath: - ps4StartupImagePath: - ps4StartupImagesFolder: - ps4IconImagesFolder: - ps4SaveDataImagePath: - ps4SdkOverride: - ps4BGMPath: - ps4ShareFilePath: - ps4ShareOverlayImagePath: - ps4PrivacyGuardImagePath: - ps4NPtitleDatPath: + ps4PronunciationXMLPath: + ps4PronunciationSIGPath: + ps4BackgroundImagePath: + ps4StartupImagePath: + ps4StartupImagesFolder: + ps4IconImagesFolder: + ps4SaveDataImagePath: + ps4SdkOverride: + ps4BGMPath: + ps4ShareFilePath: + ps4ShareOverlayImagePath: + ps4PrivacyGuardImagePath: + ps4NPtitleDatPath: ps4RemotePlayKeyAssignment: -1 - ps4RemotePlayKeyMappingDir: + ps4RemotePlayKeyMappingDir: ps4PlayTogetherPlayerCount: 0 ps4EnterButtonAssignment: 1 ps4ApplicationParam1: 0 @@ -599,9 +599,9 @@ PlayerSettings: ps4ScriptOptimizationLevel: 0 ps4Audio3dVirtualSpeakerCount: 14 ps4attribCpuUsage: 0 - ps4PatchPkgPath: - ps4PatchLatestPkgPath: - ps4PatchChangeinfoPath: + ps4PatchPkgPath: + ps4PatchLatestPkgPath: + ps4PatchChangeinfoPath: ps4PatchDayOne: 0 ps4attribUserManagement: 0 ps4attribMoveSupport: 0 @@ -614,18 +614,18 @@ PlayerSettings: ps4attribEyeToEyeDistanceSettingVR: 0 ps4IncludedModules: [] ps4attribVROutputEnabled: 0 - monoEnv: + monoEnv: splashScreenBackgroundSourceLandscape: {fileID: 0} splashScreenBackgroundSourcePortrait: {fileID: 0} blurSplashScreenBackground: 1 - spritePackerPolicy: + spritePackerPolicy: webGLMemorySize: 16 webGLExceptionSupport: 1 webGLNameFilesAsHashes: 0 webGLDataCaching: 1 webGLDebugSymbols: 0 - webGLEmscriptenArgs: - webGLModulesDirectory: + webGLEmscriptenArgs: + webGLModulesDirectory: webGLTemplate: APPLICATION:Default webGLAnalyzeBuildSize: 0 webGLUseEmbeddedResources: 0 @@ -642,7 +642,7 @@ PlayerSettings: Standalone: 1 incrementalIl2cppBuild: {} allowUnsafeCode: 0 - additionalIl2CppArgs: + additionalIl2CppArgs: scriptingRuntimeVersion: 1 gcIncremental: 1 gcWBarrierValidation: 0 @@ -651,15 +651,15 @@ PlayerSettings: m_RenderingPath: 1 m_MobileRenderingPath: 1 metroPackageName: CLOiSim - metroPackageVersion: - metroCertificatePath: - metroCertificatePassword: - metroCertificateSubject: - metroCertificateIssuer: + metroPackageVersion: + metroCertificatePath: + metroCertificatePassword: + metroCertificateSubject: + metroCertificateIssuer: metroCertificateNotAfter: 0000000000000000 metroApplicationDescription: CLOiSim wsaImages: {} - metroTileShortName: + metroTileShortName: metroTileShowName: 0 metroMediumTileShowName: 0 metroLargeTileShowName: 0 @@ -674,22 +674,22 @@ PlayerSettings: metroSplashScreenUseBackgroundColor: 0 platformCapabilities: {} metroTargetDeviceFamilies: {} - metroFTAName: + metroFTAName: metroFTAFileTypes: [] - metroProtocolName: - XboxOneProductId: - XboxOneUpdateKey: - XboxOneSandboxId: - XboxOneContentId: - XboxOneTitleId: - XboxOneSCId: - XboxOneGameOsOverridePath: - XboxOnePackagingOverridePath: - XboxOneAppManifestOverridePath: + metroProtocolName: + XboxOneProductId: + XboxOneUpdateKey: + XboxOneSandboxId: + XboxOneContentId: + XboxOneTitleId: + XboxOneSCId: + XboxOneGameOsOverridePath: + XboxOnePackagingOverridePath: + XboxOneAppManifestOverridePath: XboxOneVersion: 1.0.0.0 XboxOnePackageEncryption: 0 XboxOnePackageUpdateGranularity: 2 - XboxOneDescription: + XboxOneDescription: XboxOneLanguage: - enus XboxOneCapability: [] @@ -701,8 +701,8 @@ PlayerSettings: XboxOneAllowedProductIds: [] XboxOnePersistentLocalStorageSize: 0 XboxOneXTitleMemory: 8 - XboxOneOverrideIdentityName: - XboxOneOverrideIdentityPublisher: + XboxOneOverrideIdentityName: + XboxOneOverrideIdentityPublisher: vrEditorSettings: daydream: daydreamIconForeground: {fileID: 0} @@ -714,16 +714,16 @@ PlayerSettings: Hub: 0 UNet: 0 luminIcon: - m_Name: - m_ModelFolderPath: - m_PortalFolderPath: + m_Name: + m_ModelFolderPath: + m_PortalFolderPath: luminCert: - m_CertPath: + m_CertPath: m_SignPackage: 1 luminIsChannelApp: 0 luminVersion: m_VersionCode: 1 - m_VersionName: + m_VersionName: apiCompatibilityLevel: 6 cloudProjectId: 73a56b8e-7805-4cf3-ae10-497db8ccebcf framebufferDepthMemorylessMode: 0 From b403658b7e2c4c1df7c82db43d8d581a99d0fd49 Mon Sep 17 00:00:00 2001 From: Hyunseok Yang Date: Fri, 14 Aug 2020 15:37:41 +0900 Subject: [PATCH 13/15] Tuned Main Camera for performance - Set depth texture mode NONE --- Assets/Scripts/ModelLoader.cs | 9 ++++++++- Assets/Scripts/Tools/SDF/Importer.cs | 4 ---- Assets/Scripts/Tools/SDFImporter/SDFImporter.cs | 12 ++++-------- 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/Assets/Scripts/ModelLoader.cs b/Assets/Scripts/ModelLoader.cs index 1b4530ba..66083dac 100644 --- a/Assets/Scripts/ModelLoader.cs +++ b/Assets/Scripts/ModelLoader.cs @@ -36,6 +36,7 @@ public class ModelLoader : MonoBehaviour private GameObject modelsRoot = null; private Clock clock = null; + private Camera mainCamera = null; private bool isResetting = false; private bool resetTriggered = false; @@ -82,6 +83,12 @@ void Awake() var worldPaths = worldPathEnv.Split(separator, StringSplitOptions.RemoveEmptyEntries); worldRootDirectories.AddRange(worldPaths); #endif + + mainCamera = Camera.main; + mainCamera.depthTextureMode = DepthTextureMode.None; + mainCamera.allowHDR = true; + mainCamera.allowMSAA = true; + Application.targetFrameRate = 61; modelsRoot = GameObject.Find(modelsRootName); @@ -127,7 +134,7 @@ private IEnumerator LoadSdfModels() var importer = new SDFImporter(); importer.SetRootObject(modelsRoot); - importer.SetMainCamera(defaultCameraName); + importer.SetMainCamera(mainCamera); importer.Start(sdf.World()); } else diff --git a/Assets/Scripts/Tools/SDF/Importer.cs b/Assets/Scripts/Tools/SDF/Importer.cs index ab241fa0..20269422 100644 --- a/Assets/Scripts/Tools/SDF/Importer.cs +++ b/Assets/Scripts/Tools/SDF/Importer.cs @@ -12,10 +12,6 @@ namespace SDF { public class Importer { - public Importer() - { - } - protected virtual void ImportWorld(in World world) { PrintNotImported(MethodBase.GetCurrentMethod().Name, world.Name); diff --git a/Assets/Scripts/Tools/SDFImporter/SDFImporter.cs b/Assets/Scripts/Tools/SDFImporter/SDFImporter.cs index 7059e660..ad61f803 100644 --- a/Assets/Scripts/Tools/SDFImporter/SDFImporter.cs +++ b/Assets/Scripts/Tools/SDFImporter/SDFImporter.cs @@ -9,17 +9,15 @@ public partial class SDFImporter : SDF.Importer { - private GameObject rootObject; - private UnityEngine.Camera mainCamera; + private GameObject rootObject = null; + private UnityEngine.Camera mainCamera = null; public SDFImporter() { // Debug.Log(MethodBase.GetCurrentMethod().Name); - mainCamera = Camera.main; } public SDFImporter(GameObject target) - : this() { SetRootObject(target); } @@ -29,13 +27,11 @@ public void SetRootObject(GameObject target) rootObject = target; } - public void SetMainCamera(in string cameraName) + public void SetMainCamera(in UnityEngine.Camera camera) { - var newMainCamera = GameObject.Find(cameraName).GetComponent(); - if (mainCamera == null) { - mainCamera = newMainCamera; + mainCamera = camera; } } From 9f9f6fac322fe87a115769bc00e9d28ecb3ec735 Mon Sep 17 00:00:00 2001 From: Hyunseok Yang Date: Fri, 14 Aug 2020 15:53:03 +0900 Subject: [PATCH 14/15] Code refactroing in ElevatorSystem plugin --- .../Scripts/DevicePlugins/ElevatorSystem.cs | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/Assets/Scripts/DevicePlugins/ElevatorSystem.cs b/Assets/Scripts/DevicePlugins/ElevatorSystem.cs index 10e202d7..510164af 100644 --- a/Assets/Scripts/DevicePlugins/ElevatorSystem.cs +++ b/Assets/Scripts/DevicePlugins/ElevatorSystem.cs @@ -40,20 +40,11 @@ public ElevatorTask(in int index) private const int NON_ELEVATOR_INDEX = -1; private bool isRunningThread = true; - private MemoryStream memoryStreamForService = null; - private Param responseMessage = null; - private Dictionary floorList; - private Dictionary elevatorList; - private ConcurrentQueue elevatorTaskQueue; - - ElevatorSystem() - { - memoryStreamForService = new MemoryStream(); - responseMessage = new Param(); - floorList = new Dictionary(); - elevatorList = new Dictionary(); - elevatorTaskQueue = new ConcurrentQueue(); - } + private MemoryStream memoryStreamForService = new MemoryStream(); + private Param responseMessage = new Param(); + private Dictionary floorList = new Dictionary(); + private Dictionary elevatorList = new Dictionary(); + private ConcurrentQueue elevatorTaskQueue = new ConcurrentQueue(); protected override void OnAwake() { From bbf3e02cdcd596bd8b512a8d9c78451da66657e4 Mon Sep 17 00:00:00 2001 From: Hyunseok Yang Date: Fri, 14 Aug 2020 15:54:42 +0900 Subject: [PATCH 15/15] Code cleanup in Devices - IMU - Lidar --- Assets/Scripts/Devices/IMU.cs | 8 ++------ Assets/Scripts/Devices/Lidar.cs | 1 - 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/Assets/Scripts/Devices/IMU.cs b/Assets/Scripts/Devices/IMU.cs index 824f2999..3d5fc49d 100644 --- a/Assets/Scripts/Devices/IMU.cs +++ b/Assets/Scripts/Devices/IMU.cs @@ -6,7 +6,6 @@ using System.Collections; using UnityEngine; -using Stopwatch = System.Diagnostics.Stopwatch; using messages = gazebo.msgs; namespace SensorDevices @@ -86,14 +85,11 @@ void FixedUpdate() protected override IEnumerator MainDeviceWorker() { - var sw = new Stopwatch(); + var waitForSeconds = new WaitForSeconds(UpdatePeriod); while (true) { - sw.Restart(); GenerateMessage(); - sw.Stop(); - - yield return new WaitForSeconds(WaitPeriod((float)sw.Elapsed.TotalSeconds)); + yield return waitForSeconds; } } diff --git a/Assets/Scripts/Devices/Lidar.cs b/Assets/Scripts/Devices/Lidar.cs index 2248b069..7a8dcfd2 100644 --- a/Assets/Scripts/Devices/Lidar.cs +++ b/Assets/Scripts/Devices/Lidar.cs @@ -262,7 +262,6 @@ private IEnumerator LaserCameraWorker() protected override IEnumerator MainDeviceWorker() { - // var waitForSeconds = new WaitForSeconds(UpdatePeriod * adjustCapturingRate); var sw = new Stopwatch(); while (true) {