From 4a5886f8297af9b4289a3124a289c4e80b87af5b Mon Sep 17 00:00:00 2001 From: Szymon Lis Date: Thu, 8 Feb 2024 15:21:10 +0100 Subject: [PATCH 01/13] Added TimeSource for Simulation Time --- .../Scripts/DotNetSimulationTimeSource.cs | 44 +++++++++++++++++++ .../DotNetSimulationTimeSource.cs.meta | 11 +++++ .../Clock/Scripts/TimeSourceProvider.cs | 16 ++++++- 3 files changed, 70 insertions(+), 1 deletion(-) create mode 100644 Assets/AWSIM/Scripts/Clock/Scripts/DotNetSimulationTimeSource.cs create mode 100644 Assets/AWSIM/Scripts/Clock/Scripts/DotNetSimulationTimeSource.cs.meta diff --git a/Assets/AWSIM/Scripts/Clock/Scripts/DotNetSimulationTimeSource.cs b/Assets/AWSIM/Scripts/Clock/Scripts/DotNetSimulationTimeSource.cs new file mode 100644 index 000000000..158a86017 --- /dev/null +++ b/Assets/AWSIM/Scripts/Clock/Scripts/DotNetSimulationTimeSource.cs @@ -0,0 +1,44 @@ +using System; +using System.Threading; +using ROS2; + +namespace AWSIM +{ + + public class DotNetSimulationTimeSource : ITimeSource + { + private DateTime prevDateTime; + private double time; + private bool hasStarted = false; + + private readonly object lockObject = new object(); + + public DotNetSimulationTimeSource() + { + hasStarted = false; + } + + public void GetTime(out int seconds, out uint nanoseconds) + { + lock (lockObject) + { + DateTime currDateTime = DateTime.UtcNow; + + if(!hasStarted) + { + hasStarted = true; + time = 0.0; + + prevDateTime = currDateTime; + } + + TimeSpan timeSpan = currDateTime - prevDateTime; + prevDateTime = currDateTime; + + time += timeSpan.TotalMilliseconds * 0.001f * TimeScaleProvider.TimeScale; + TimeUtils.TimeFromTotalSeconds(time, out seconds, out nanoseconds); + } + } + } + +} diff --git a/Assets/AWSIM/Scripts/Clock/Scripts/DotNetSimulationTimeSource.cs.meta b/Assets/AWSIM/Scripts/Clock/Scripts/DotNetSimulationTimeSource.cs.meta new file mode 100644 index 000000000..42f090809 --- /dev/null +++ b/Assets/AWSIM/Scripts/Clock/Scripts/DotNetSimulationTimeSource.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 0d4d8d5d1c4ad4f8999b97cad5200dd3 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/AWSIM/Scripts/Clock/Scripts/TimeSourceProvider.cs b/Assets/AWSIM/Scripts/Clock/Scripts/TimeSourceProvider.cs index 8b8b22844..9c1d739cd 100644 --- a/Assets/AWSIM/Scripts/Clock/Scripts/TimeSourceProvider.cs +++ b/Assets/AWSIM/Scripts/Clock/Scripts/TimeSourceProvider.cs @@ -1,3 +1,4 @@ +using AWSIM.Samples; using ROS2; using System; @@ -12,7 +13,8 @@ public enum TimeSourceType { UNITY, SS2, - DOTNET + DOTNET, + DOTNET_SIMULATION, } #region [Event] @@ -107,6 +109,18 @@ public static void SetTimeSource(TimeSourceType type) return; } + // dot net simulation time source + if(type == TimeSourceType.DOTNET_SIMULATION) + { + if(currentTimeSource == null || !(currentTimeSource is DotNetSimulationTimeSource)) + { + currentTimeSource = new DotNetSimulationTimeSource(); + onTimeSourceChanged?.Invoke(); + } + + return; + } + // default time source if(currentTimeSource == null || !(currentTimeSource is UnityTimeSource)) { From 2269625b906cb48c03b6fe6b1b1109b6ff477400 Mon Sep 17 00:00:00 2001 From: Szymon Lis Date: Fri, 9 Feb 2024 16:31:54 +0100 Subject: [PATCH 02/13] Improved System ITimeSource --- .../Clock/Scripts/DotNetSystemTimeSource.cs | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/Assets/AWSIM/Scripts/Clock/Scripts/DotNetSystemTimeSource.cs b/Assets/AWSIM/Scripts/Clock/Scripts/DotNetSystemTimeSource.cs index 40c35c3ac..92444a34e 100644 --- a/Assets/AWSIM/Scripts/Clock/Scripts/DotNetSystemTimeSource.cs +++ b/Assets/AWSIM/Scripts/Clock/Scripts/DotNetSystemTimeSource.cs @@ -11,13 +11,13 @@ public class DotNetSystemTimeSource : ITimeSource { private DateTime prevDateTime; private double time; + private bool hasStarted = false; private readonly object lockObject = new object(); public DotNetSystemTimeSource() { - prevDateTime = DateTime.UtcNow; - time = 0.0; + hasStarted = false; } public void GetTime(out int seconds, out uint nanoseconds) @@ -25,10 +25,23 @@ public void GetTime(out int seconds, out uint nanoseconds) lock (lockObject) { DateTime currDateTime = DateTime.UtcNow; + + if(!hasStarted) + { + hasStarted = true; + + // this return the same as ROS2.Clock.Now.Seconds(); + // get the time in millisecond since epoch + long timeOffset = ((DateTimeOffset)currDateTime).ToUnixTimeMilliseconds(); + time = (double)timeOffset * 0.001; + + prevDateTime = currDateTime; + } + TimeSpan timeSpan = currDateTime - prevDateTime; prevDateTime = currDateTime; - time += timeSpan.TotalMilliseconds * 0.001f * TimeScaleProvider.TimeScale; + time += timeSpan.TotalMilliseconds * 0.001 * TimeScaleProvider.TimeScale; TimeUtils.TimeFromTotalSeconds(time, out seconds, out nanoseconds); } } From 0fe4f7b9689efc86ef4c02fc5f3654bc58b84bda Mon Sep 17 00:00:00 2001 From: Szymon Lis Date: Mon, 12 Feb 2024 11:05:07 +0100 Subject: [PATCH 03/13] Added feature of setting time source from config.json --- .../AutowareSimulation/AutowareSimulation.cs | 16 +++++++ .../Main/AutowareSimulation/config.json | 3 +- .../Clock/Scripts/TimeSourceSelector.cs | 46 +++++++++++++++++++ 3 files changed, 64 insertions(+), 1 deletion(-) diff --git a/Assets/AWSIM/Scenes/Main/AutowareSimulation/AutowareSimulation.cs b/Assets/AWSIM/Scenes/Main/AutowareSimulation/AutowareSimulation.cs index c81a736d9..6ed8d1a84 100644 --- a/Assets/AWSIM/Scenes/Main/AutowareSimulation/AutowareSimulation.cs +++ b/Assets/AWSIM/Scenes/Main/AutowareSimulation/AutowareSimulation.cs @@ -12,6 +12,7 @@ public class AutowareSimulation : MonoBehaviour { [SerializeField] TrafficManager trafficManager; [SerializeField] Transform egoTransform; + private TimeSourceSelector timeSourceSelector; [Header("Player Config")] [SerializeField] string commandLineConfigParam = "--json_path"; @@ -33,6 +34,7 @@ public class EgoConfiguration public class Configuration { public float TimeScale; // Reflected in Time.timeScale + public string TimeSource; // Reflected in TimeSourceSelector public int RandomTrafficSeed; // Reflected in TrafficManager.seed public int MaxVehicleCount; // Reflected in TrafficManager.maxVehicleCount public EgoConfiguration Ego = new EgoConfiguration(); @@ -40,6 +42,7 @@ public class Configuration void Awake() { + CollectComponents(); #if !UNITY_EDITOR // initialize @@ -62,6 +65,19 @@ void Awake() var rotation = Quaternion.Euler(config.Ego.EulerAngles); egoTransform.rotation = ROS2Utility.RosToUnityRotation(rotation); + + // set time source + timeSourceSelector?.SetType(config.TimeSource); + } + } + + void CollectComponents() + { + // get time source selector + timeSourceSelector = FindObjectOfType(); + if(timeSourceSelector == null) + { + Debug.LogWarning("TimeSource: There is no TimeSourceSelector object in the active scene. The default time source will be used."); } } } diff --git a/Assets/AWSIM/Scenes/Main/AutowareSimulation/config.json b/Assets/AWSIM/Scenes/Main/AutowareSimulation/config.json index fc2631494..f0bda86a2 100644 --- a/Assets/AWSIM/Scenes/Main/AutowareSimulation/config.json +++ b/Assets/AWSIM/Scenes/Main/AutowareSimulation/config.json @@ -1,5 +1,6 @@ { "TimeScale": 0.2, + "TimeSource": "simulation", "RandomTrafficSeed": 33, "MaxVehicleCount": 2, "Ego": { @@ -14,4 +15,4 @@ "z": 35.0 } } -} \ No newline at end of file +} diff --git a/Assets/AWSIM/Scripts/Clock/Scripts/TimeSourceSelector.cs b/Assets/AWSIM/Scripts/Clock/Scripts/TimeSourceSelector.cs index 2dacd2f02..08e384ac5 100644 --- a/Assets/AWSIM/Scripts/Clock/Scripts/TimeSourceSelector.cs +++ b/Assets/AWSIM/Scripts/Clock/Scripts/TimeSourceSelector.cs @@ -20,6 +20,52 @@ private void Awake() TimeSourceProvider.SetTimeSource(Type); } + #region [Public Methods] + + /// + /// Set the time source of the desired type. + /// + /// Type of requested time source. + public void SetType(string type) + { + if(type == null || type == "") + { + return; + } + + if(string.CompareOrdinal(type.ToLower(), "simulation") == 0) + { + SetType(TimeSourceProvider.TimeSourceType.DOTNET_SIMULATION); + } + else if(string.CompareOrdinal(type.ToLower(), "system") == 0) + { + SetType(TimeSourceProvider.TimeSourceType.DOTNET); + } + else if(string.CompareOrdinal(type.ToLower(), "ss2") == 0) + { + SetType(TimeSourceProvider.TimeSourceType.SS2); + } + else + { + Debug.LogWarning("TimeSourceSelector: " + type + " is not recognized as a valid time source."); + } + } + + #endregion + + #region [Private Methods] + + /// + /// Set the time source of the desired type. + /// + /// Type of requested time source. + private void SetType(TimeSourceProvider.TimeSourceType type) + { + Type = type; + TimeSourceProvider.SetTimeSource(Type); + } + + #endregion } } From 4388b6409ea30c74665ce44825902306d42bf56c Mon Sep 17 00:00:00 2001 From: Szymon Lis Date: Mon, 12 Feb 2024 11:38:19 +0100 Subject: [PATCH 04/13] Improved DotNet TimeSources --- .../Scripts/Clock/Scripts/DotNetSimulationTimeSource.cs | 6 +++++- .../AWSIM/Scripts/Clock/Scripts/DotNetSystemTimeSource.cs | 4 ++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/Assets/AWSIM/Scripts/Clock/Scripts/DotNetSimulationTimeSource.cs b/Assets/AWSIM/Scripts/Clock/Scripts/DotNetSimulationTimeSource.cs index 158a86017..100d1130f 100644 --- a/Assets/AWSIM/Scripts/Clock/Scripts/DotNetSimulationTimeSource.cs +++ b/Assets/AWSIM/Scripts/Clock/Scripts/DotNetSimulationTimeSource.cs @@ -4,7 +4,11 @@ namespace AWSIM { - + /// + /// A thread-safe timesource class that provides simulation time based on the dot net system utc time. + /// This time source takes into account the value of the simulation timescale and + /// starts at zero value when the simulation is started. + /// public class DotNetSimulationTimeSource : ITimeSource { private DateTime prevDateTime; diff --git a/Assets/AWSIM/Scripts/Clock/Scripts/DotNetSystemTimeSource.cs b/Assets/AWSIM/Scripts/Clock/Scripts/DotNetSystemTimeSource.cs index 92444a34e..3a3f42078 100644 --- a/Assets/AWSIM/Scripts/Clock/Scripts/DotNetSystemTimeSource.cs +++ b/Assets/AWSIM/Scripts/Clock/Scripts/DotNetSystemTimeSource.cs @@ -5,7 +5,8 @@ namespace AWSIM { /// - /// A thread-safe timesource class that provides the dot net system utc time. + /// A thread-safe timesource class that provides the dot net system utc time since epoch. + /// This timesource takes into account the value of the simulation timescale. /// public class DotNetSystemTimeSource : ITimeSource { @@ -30,7 +31,6 @@ public void GetTime(out int seconds, out uint nanoseconds) { hasStarted = true; - // this return the same as ROS2.Clock.Now.Seconds(); // get the time in millisecond since epoch long timeOffset = ((DateTimeOffset)currDateTime).ToUnixTimeMilliseconds(); time = (double)timeOffset * 0.001; From c9579a17d0a7319a753d3da4e32733acec806323 Mon Sep 17 00:00:00 2001 From: Szymon Lis Date: Wed, 14 Feb 2024 13:54:11 +0100 Subject: [PATCH 05/13] Added thread-safe TimeAsDouble value --- .../Clock/Scripts/TimeAsDoubleProvider.cs | 41 +++++++++++++++++++ .../Scripts/TimeAsDoubleProvider.cs.meta | 11 +++++ Assets/AWSIM/Scripts/ROS/ClockPublisher.cs | 10 +++++ 3 files changed, 62 insertions(+) create mode 100644 Assets/AWSIM/Scripts/Clock/Scripts/TimeAsDoubleProvider.cs create mode 100644 Assets/AWSIM/Scripts/Clock/Scripts/TimeAsDoubleProvider.cs.meta diff --git a/Assets/AWSIM/Scripts/Clock/Scripts/TimeAsDoubleProvider.cs b/Assets/AWSIM/Scripts/Clock/Scripts/TimeAsDoubleProvider.cs new file mode 100644 index 000000000..6a4a65131 --- /dev/null +++ b/Assets/AWSIM/Scripts/Clock/Scripts/TimeAsDoubleProvider.cs @@ -0,0 +1,41 @@ +using UnityEngine; + +namespace AWSIM +{ + /// + /// A thread-safe static class to provide the value of the Unity time as double. + /// + public static class TimeAsDoubleProvider + { + private static readonly object lockObject = new object(); + + private static double timeAsDouble = 0.0; + public static double TimeAsDouble + { + get + { + lock(lockObject) + { + return timeAsDouble; + } + } + } + + + #region [Public Methods] + + /// + /// Synchronise the value of the timeAsDouble variable with the Time.timeAsDouble from the Unity thread. + /// + public static void DoUpdate() + { + lock(lockObject) + { + timeAsDouble = Time.timeAsDouble; + } + } + + #endregion + } +} + diff --git a/Assets/AWSIM/Scripts/Clock/Scripts/TimeAsDoubleProvider.cs.meta b/Assets/AWSIM/Scripts/Clock/Scripts/TimeAsDoubleProvider.cs.meta new file mode 100644 index 000000000..af90baa82 --- /dev/null +++ b/Assets/AWSIM/Scripts/Clock/Scripts/TimeAsDoubleProvider.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 26a9b446c6fcc6ff08f19aa85f8c3330 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/AWSIM/Scripts/ROS/ClockPublisher.cs b/Assets/AWSIM/Scripts/ROS/ClockPublisher.cs index 33bc224a0..635cc502d 100644 --- a/Assets/AWSIM/Scripts/ROS/ClockPublisher.cs +++ b/Assets/AWSIM/Scripts/ROS/ClockPublisher.cs @@ -32,6 +32,7 @@ void Awake() void Start() { TimeScaleProvider.DoUpdate(); + TimeAsDoubleProvider.DoUpdate(); StartClockThread(); } @@ -43,6 +44,15 @@ void OnDestroy() #endregion + #region [Main Thread] + + void Update() + { + TimeAsDoubleProvider.DoUpdate(); + } + + #endregion + #region [Clock Thread] void StartClockThread() From 7fc0d3b5c2a63651a46185c544d2dfcb16f39ae0 Mon Sep 17 00:00:00 2001 From: Szymon Lis Date: Wed, 14 Feb 2024 13:57:19 +0100 Subject: [PATCH 06/13] Updated UnityTimeSource --- Assets/Ros2ForUnity/Scripts/Time/UnityTimeSource.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Assets/Ros2ForUnity/Scripts/Time/UnityTimeSource.cs b/Assets/Ros2ForUnity/Scripts/Time/UnityTimeSource.cs index 7a0ec7a8c..494b5ab8f 100644 --- a/Assets/Ros2ForUnity/Scripts/Time/UnityTimeSource.cs +++ b/Assets/Ros2ForUnity/Scripts/Time/UnityTimeSource.cs @@ -14,6 +14,7 @@ using System; using System.Threading; +using AWSIM; using UnityEngine; namespace ROS2 @@ -37,7 +38,7 @@ public UnityTimeSource() public void GetTime(out int seconds, out uint nanoseconds) { - lastReadingSecs = mainThread.Equals(Thread.CurrentThread) ? Time.timeAsDouble : lastReadingSecs; + lastReadingSecs = mainThread.Equals(Thread.CurrentThread) ? Time.timeAsDouble : TimeAsDoubleProvider.TimeAsDouble; TimeUtils.TimeFromTotalSeconds(lastReadingSecs, out seconds, out nanoseconds); } } From 669121cbf45b47199c4166aac1e59de7329f09b5 Mon Sep 17 00:00:00 2001 From: Szymon Lis Date: Wed, 14 Feb 2024 14:18:08 +0100 Subject: [PATCH 07/13] Set default TimeSource for simulation --- Assets/AWSIM/Scenes/Main/AutowareSimulation.unity | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Assets/AWSIM/Scenes/Main/AutowareSimulation.unity b/Assets/AWSIM/Scenes/Main/AutowareSimulation.unity index 193f1b6ae..0cf53c818 100644 --- a/Assets/AWSIM/Scenes/Main/AutowareSimulation.unity +++ b/Assets/AWSIM/Scenes/Main/AutowareSimulation.unity @@ -4046,7 +4046,7 @@ PrefabInstance: objectReference: {fileID: 0} - target: {fileID: 3077555317673241940, guid: 27181f17b3e1bb607a4b8fcb8a827e0f, type: 3} propertyPath: Type - value: 2 + value: 3 objectReference: {fileID: 0} m_RemovedComponents: [] m_SourcePrefab: {fileID: 100100000, guid: 27181f17b3e1bb607a4b8fcb8a827e0f, type: 3} From 128bbda95830fb99cb3e23e69b52e0b9a83da96c Mon Sep 17 00:00:00 2001 From: Szymon Lis Date: Wed, 14 Feb 2024 14:31:23 +0100 Subject: [PATCH 08/13] Added ROS2TimeSource into time source provider --- .../Scripts/Clock/Scripts/TimeSourceProvider.cs | 13 +++++++++++++ .../Scripts/Clock/Scripts/TimeSourceSelector.cs | 4 ++++ 2 files changed, 17 insertions(+) diff --git a/Assets/AWSIM/Scripts/Clock/Scripts/TimeSourceProvider.cs b/Assets/AWSIM/Scripts/Clock/Scripts/TimeSourceProvider.cs index 9c1d739cd..78f4f560a 100644 --- a/Assets/AWSIM/Scripts/Clock/Scripts/TimeSourceProvider.cs +++ b/Assets/AWSIM/Scripts/Clock/Scripts/TimeSourceProvider.cs @@ -15,6 +15,7 @@ public enum TimeSourceType SS2, DOTNET, DOTNET_SIMULATION, + ROS2, } #region [Event] @@ -121,6 +122,18 @@ public static void SetTimeSource(TimeSourceType type) return; } + // ros2 time source + if(type == TimeSourceType.ROS2) + { + if(currentTimeSource == null || !(currentTimeSource is ROS2TimeSource)) + { + currentTimeSource = new ROS2TimeSource(); + onTimeSourceChanged?.Invoke(); + } + + return; + } + // default time source if(currentTimeSource == null || !(currentTimeSource is UnityTimeSource)) { diff --git a/Assets/AWSIM/Scripts/Clock/Scripts/TimeSourceSelector.cs b/Assets/AWSIM/Scripts/Clock/Scripts/TimeSourceSelector.cs index 08e384ac5..712c0b234 100644 --- a/Assets/AWSIM/Scripts/Clock/Scripts/TimeSourceSelector.cs +++ b/Assets/AWSIM/Scripts/Clock/Scripts/TimeSourceSelector.cs @@ -45,6 +45,10 @@ public void SetType(string type) { SetType(TimeSourceProvider.TimeSourceType.SS2); } + else if(string.CompareOrdinal(type.ToLower(), "ros2") == 0) + { + SetType(TimeSourceProvider.TimeSourceType.ROS2); + } else { Debug.LogWarning("TimeSourceSelector: " + type + " is not recognized as a valid time source."); From b3e555313dc50dedecb46a17b7bbe4af5f0ccfb4 Mon Sep 17 00:00:00 2001 From: Szymon Lis Date: Wed, 14 Feb 2024 14:39:11 +0100 Subject: [PATCH 09/13] Enable unity time to be selected from json config --- Assets/AWSIM/Scripts/Clock/Scripts/TimeSourceSelector.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Assets/AWSIM/Scripts/Clock/Scripts/TimeSourceSelector.cs b/Assets/AWSIM/Scripts/Clock/Scripts/TimeSourceSelector.cs index 712c0b234..b05994bdb 100644 --- a/Assets/AWSIM/Scripts/Clock/Scripts/TimeSourceSelector.cs +++ b/Assets/AWSIM/Scripts/Clock/Scripts/TimeSourceSelector.cs @@ -33,7 +33,11 @@ public void SetType(string type) return; } - if(string.CompareOrdinal(type.ToLower(), "simulation") == 0) + if(string.CompareOrdinal(type.ToLower(), "unity") == 0) + { + SetType(TimeSourceProvider.TimeSourceType.UNITY); + } + else if(string.CompareOrdinal(type.ToLower(), "simulation") == 0) { SetType(TimeSourceProvider.TimeSourceType.DOTNET_SIMULATION); } From 53d251d53c1ddb3b5dd7bf8569babe827ebcc044 Mon Sep 17 00:00:00 2001 From: Szymon Lis Date: Wed, 14 Feb 2024 14:45:05 +0100 Subject: [PATCH 10/13] Refactor - change name of dotnet system time source --- Assets/AWSIM/Scripts/Clock/Scripts/TimeSourceProvider.cs | 4 ++-- Assets/AWSIM/Scripts/Clock/Scripts/TimeSourceSelector.cs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Assets/AWSIM/Scripts/Clock/Scripts/TimeSourceProvider.cs b/Assets/AWSIM/Scripts/Clock/Scripts/TimeSourceProvider.cs index 78f4f560a..12fbd1344 100644 --- a/Assets/AWSIM/Scripts/Clock/Scripts/TimeSourceProvider.cs +++ b/Assets/AWSIM/Scripts/Clock/Scripts/TimeSourceProvider.cs @@ -13,7 +13,7 @@ public enum TimeSourceType { UNITY, SS2, - DOTNET, + DOTNET_SYSTEM, DOTNET_SIMULATION, ROS2, } @@ -99,7 +99,7 @@ public static void SetTimeSource(TimeSourceType type) } // dot net system time source - if(type == TimeSourceType.DOTNET) + if(type == TimeSourceType.DOTNET_SYSTEM) { if(currentTimeSource == null || !(currentTimeSource is DotNetSystemTimeSource)) { diff --git a/Assets/AWSIM/Scripts/Clock/Scripts/TimeSourceSelector.cs b/Assets/AWSIM/Scripts/Clock/Scripts/TimeSourceSelector.cs index b05994bdb..90181c5c0 100644 --- a/Assets/AWSIM/Scripts/Clock/Scripts/TimeSourceSelector.cs +++ b/Assets/AWSIM/Scripts/Clock/Scripts/TimeSourceSelector.cs @@ -43,7 +43,7 @@ public void SetType(string type) } else if(string.CompareOrdinal(type.ToLower(), "system") == 0) { - SetType(TimeSourceProvider.TimeSourceType.DOTNET); + SetType(TimeSourceProvider.TimeSourceType.DOTNET_SYSTEM); } else if(string.CompareOrdinal(type.ToLower(), "ss2") == 0) { From c40a3d63426dc3cfce73eaa2f1eea980b2db1ebf Mon Sep 17 00:00:00 2001 From: Szymon Lis Date: Wed, 14 Feb 2024 15:15:44 +0100 Subject: [PATCH 11/13] Refactor --- Assets/AWSIM/Scripts/Clock/Scripts/TimeScaleProvider.cs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/Assets/AWSIM/Scripts/Clock/Scripts/TimeScaleProvider.cs b/Assets/AWSIM/Scripts/Clock/Scripts/TimeScaleProvider.cs index 0306d4cda..94bd6cf38 100644 --- a/Assets/AWSIM/Scripts/Clock/Scripts/TimeScaleProvider.cs +++ b/Assets/AWSIM/Scripts/Clock/Scripts/TimeScaleProvider.cs @@ -31,10 +31,7 @@ public static void DoUpdate() { lock(lockObject) { - if (Mathf.Abs(Time.timeScale - timeScale) > 0.01f) - { - timeScale = Time.timeScale; - } + timeScale = Time.timeScale; } } From 9519b0b90b7d3be6144144d6f4ed6b58afa7f628 Mon Sep 17 00:00:00 2001 From: Szymon Lis Date: Thu, 22 Feb 2024 12:28:43 +0100 Subject: [PATCH 12/13] Added obsolete attribute to redundant time sources --- Assets/Ros2ForUnity/Scripts/Time/DotnetTimeSource.cs | 1 + Assets/Ros2ForUnity/Scripts/Time/ROS2ScalableTimeSource.cs | 1 + 2 files changed, 2 insertions(+) diff --git a/Assets/Ros2ForUnity/Scripts/Time/DotnetTimeSource.cs b/Assets/Ros2ForUnity/Scripts/Time/DotnetTimeSource.cs index 5fa9e99e4..cfc0dfe25 100644 --- a/Assets/Ros2ForUnity/Scripts/Time/DotnetTimeSource.cs +++ b/Assets/Ros2ForUnity/Scripts/Time/DotnetTimeSource.cs @@ -22,6 +22,7 @@ namespace ROS2 /// DateTime based clock that has resolution increased using Stopwatch. /// DateTime is used to synchronize since Stopwatch tends to drift. /// +[System.Obsolete("This TimeSource is deprecated and will be removed in the future versions. Please use DotNetSystemTimeSource instead.")] public class DotnetTimeSource : ITimeSource { private readonly double maxUnsyncedSeconds = 10; diff --git a/Assets/Ros2ForUnity/Scripts/Time/ROS2ScalableTimeSource.cs b/Assets/Ros2ForUnity/Scripts/Time/ROS2ScalableTimeSource.cs index 6c7c129ee..065d4141d 100644 --- a/Assets/Ros2ForUnity/Scripts/Time/ROS2ScalableTimeSource.cs +++ b/Assets/Ros2ForUnity/Scripts/Time/ROS2ScalableTimeSource.cs @@ -21,6 +21,7 @@ namespace ROS2 /// /// ros2 time source (system time by default). /// +[System.Obsolete("This TimeSource is deprecated and will be removed in the future versions. Please use DotNetSystemTimeSource instead.")] public class ROS2ScalableTimeSource : ITimeSource { private Thread mainThread; From bfa79b62a902b159113da45710e496fdbd38bcb4 Mon Sep 17 00:00:00 2001 From: Szymon Lis Date: Mon, 26 Feb 2024 15:44:33 +0100 Subject: [PATCH 13/13] Remove FindObjectOfType --- .../Scenes/Main/AutowareSimulation.unity | 108 ++++++++++-------- .../AutowareSimulation/AutowareSimulation.cs | 18 +-- 2 files changed, 66 insertions(+), 60 deletions(-) diff --git a/Assets/AWSIM/Scenes/Main/AutowareSimulation.unity b/Assets/AWSIM/Scenes/Main/AutowareSimulation.unity index 0cf53c818..f5c0cccd0 100644 --- a/Assets/AWSIM/Scenes/Main/AutowareSimulation.unity +++ b/Assets/AWSIM/Scenes/Main/AutowareSimulation.unity @@ -38,7 +38,7 @@ RenderSettings: m_ReflectionIntensity: 1 m_CustomReflection: {fileID: 0} m_Sun: {fileID: 0} - m_IndirectSpecularColor: {r: 1519.6069, g: 1883.9946, b: 2490.9849, a: 1} + m_IndirectSpecularColor: {r: 1520.0924, g: 1884.674, b: 2491.8425, a: 1} m_UseRadianceAmbientProbe: 0 --- !u!157 &3 LightmapSettings: @@ -536,6 +536,7 @@ MonoBehaviour: m_EditorClassIdentifier: trafficManager: {fileID: 723377035} egoTransform: {fileID: 7808269042169720464} + timeSourceSelector: {fileID: 1259688278} commandLineConfigParam: --json_path useJsonConfig: 0 jsonPath: @@ -3239,6 +3240,17 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 830ab73cebda3db4580ebd3ece935931, type: 3} m_Name: m_EditorClassIdentifier: +--- !u!114 &1259688278 stripped +MonoBehaviour: + m_CorrespondingSourceObject: {fileID: 3077555317673241940, guid: 27181f17b3e1bb607a4b8fcb8a827e0f, type: 3} + m_PrefabInstance: {fileID: 1575276244} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 0dde57169074a9c5c9780c80294b4427, type: 3} + m_Name: + m_EditorClassIdentifier: --- !u!1001 &1381324630 PrefabInstance: m_ObjectHideFlags: 0 @@ -4530,6 +4542,53 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 23c1ce4fb46143f46bc5cb5224c934f6, type: 3} m_Name: m_EditorClassIdentifier: + m_Version: 7 + m_ObsoleteRenderingPath: 0 + m_ObsoleteFrameSettings: + overrides: 0 + enableShadow: 0 + enableContactShadows: 0 + enableShadowMask: 0 + enableSSR: 0 + enableSSAO: 0 + enableSubsurfaceScattering: 0 + enableTransmission: 0 + enableAtmosphericScattering: 0 + enableVolumetrics: 0 + enableReprojectionForVolumetrics: 0 + enableLightLayers: 0 + enableExposureControl: 1 + diffuseGlobalDimmer: 0 + specularGlobalDimmer: 0 + shaderLitMode: 0 + enableDepthPrepassWithDeferredRendering: 0 + enableTransparentPrepass: 0 + enableMotionVectors: 0 + enableObjectMotionVectors: 0 + enableDecals: 0 + enableRoughRefraction: 0 + enableTransparentPostpass: 0 + enableDistortion: 0 + enablePostprocess: 0 + enableOpaqueObjects: 0 + enableTransparentObjects: 0 + enableRealtimePlanarReflection: 0 + enableMSAA: 0 + enableAsyncCompute: 0 + runLightListAsync: 0 + runSSRAsync: 0 + runSSAOAsync: 0 + runContactShadowsAsync: 0 + runVolumeVoxelizationAsync: 0 + lightLoopSettings: + overrides: 0 + enableDeferredTileAndCluster: 0 + enableComputeLightEvaluation: 0 + enableComputeLightVariants: 0 + enableComputeMaterialVariants: 0 + enableFptlForForwardOpaque: 0 + enableBigTilePrepass: 0 + isFptlEnabled: 0 clearColorMode: 0 backgroundColorHDR: {r: 0.025, g: 0.07, b: 0.19, a: 0} clearDepth: 1 @@ -4585,53 +4644,6 @@ MonoBehaviour: data1: 0 data2: 0 defaultFrameSettings: 0 - m_Version: 7 - m_ObsoleteRenderingPath: 0 - m_ObsoleteFrameSettings: - overrides: 0 - enableShadow: 0 - enableContactShadows: 0 - enableShadowMask: 0 - enableSSR: 0 - enableSSAO: 0 - enableSubsurfaceScattering: 0 - enableTransmission: 0 - enableAtmosphericScattering: 0 - enableVolumetrics: 0 - enableReprojectionForVolumetrics: 0 - enableLightLayers: 0 - enableExposureControl: 1 - diffuseGlobalDimmer: 0 - specularGlobalDimmer: 0 - shaderLitMode: 0 - enableDepthPrepassWithDeferredRendering: 0 - enableTransparentPrepass: 0 - enableMotionVectors: 0 - enableObjectMotionVectors: 0 - enableDecals: 0 - enableRoughRefraction: 0 - enableTransparentPostpass: 0 - enableDistortion: 0 - enablePostprocess: 0 - enableOpaqueObjects: 0 - enableTransparentObjects: 0 - enableRealtimePlanarReflection: 0 - enableMSAA: 0 - enableAsyncCompute: 0 - runLightListAsync: 0 - runSSRAsync: 0 - runSSAOAsync: 0 - runContactShadowsAsync: 0 - runVolumeVoxelizationAsync: 0 - lightLoopSettings: - overrides: 0 - enableDeferredTileAndCluster: 0 - enableComputeLightEvaluation: 0 - enableComputeLightVariants: 0 - enableComputeMaterialVariants: 0 - enableFptlForForwardOpaque: 0 - enableBigTilePrepass: 0 - isFptlEnabled: 0 --- !u!81 &2122627085 AudioListener: m_ObjectHideFlags: 0 diff --git a/Assets/AWSIM/Scenes/Main/AutowareSimulation/AutowareSimulation.cs b/Assets/AWSIM/Scenes/Main/AutowareSimulation/AutowareSimulation.cs index 6ed8d1a84..fa269a691 100644 --- a/Assets/AWSIM/Scenes/Main/AutowareSimulation/AutowareSimulation.cs +++ b/Assets/AWSIM/Scenes/Main/AutowareSimulation/AutowareSimulation.cs @@ -12,7 +12,7 @@ public class AutowareSimulation : MonoBehaviour { [SerializeField] TrafficManager trafficManager; [SerializeField] Transform egoTransform; - private TimeSourceSelector timeSourceSelector; + [SerializeField] TimeSourceSelector timeSourceSelector; [Header("Player Config")] [SerializeField] string commandLineConfigParam = "--json_path"; @@ -42,7 +42,11 @@ public class Configuration void Awake() { - CollectComponents(); + // check if time source selector is present + if(timeSourceSelector == null) + { + Debug.LogWarning("TimeSource: There is no TimeSourceSelector object assigned in the inspector. The default time source will be used."); + } #if !UNITY_EDITOR // initialize @@ -70,15 +74,5 @@ void Awake() timeSourceSelector?.SetType(config.TimeSource); } } - - void CollectComponents() - { - // get time source selector - timeSourceSelector = FindObjectOfType(); - if(timeSourceSelector == null) - { - Debug.LogWarning("TimeSource: There is no TimeSourceSelector object in the active scene. The default time source will be used."); - } - } } } \ No newline at end of file