From 120e0cde7dae4ef4040fb97820d25b33afdaa58c Mon Sep 17 00:00:00 2001 From: Masaaki Hijikata Date: Mon, 28 Apr 2025 13:15:23 +0900 Subject: [PATCH 1/5] [change] Made it possible to initialize LiDARSensor later so that it works with the built app. --- .../Runtime/Scripts/Sensors/LiDAR/LiDARSensor.cs | 9 +++++++++ .../Sensors/LiDAR/RaycastLiDAR/RaycastLiDARSensor.cs | 11 ++++++++++- .../PointCloud2Msg/LiDARPointCloud2MsgPublisher.cs | 5 +++++ 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/Assets/UnitySensors/Runtime/Scripts/Sensors/LiDAR/LiDARSensor.cs b/Assets/UnitySensors/Runtime/Scripts/Sensors/LiDAR/LiDARSensor.cs index febec48a..db91a30b 100644 --- a/Assets/UnitySensors/Runtime/Scripts/Sensors/LiDAR/LiDARSensor.cs +++ b/Assets/UnitySensors/Runtime/Scripts/Sensors/LiDAR/LiDARSensor.cs @@ -34,6 +34,15 @@ public abstract class LiDARSensor : UnitySensor, IPointCloudInterface public int pointsNum { get => _pointsNumPerScan; } protected override void Init() + { + if (_scanPattern == null) + { + return; + } + Initialize(); + } + + public virtual void Initialize() { _pointsNumPerScan = Mathf.Clamp(_pointsNumPerScan, 1, scanPattern.size); _pointCloud = new PointCloud() diff --git a/Assets/UnitySensors/Runtime/Scripts/Sensors/LiDAR/RaycastLiDAR/RaycastLiDARSensor.cs b/Assets/UnitySensors/Runtime/Scripts/Sensors/LiDAR/RaycastLiDAR/RaycastLiDARSensor.cs index eee45f04..b9d21e5a 100644 --- a/Assets/UnitySensors/Runtime/Scripts/Sensors/LiDAR/RaycastLiDAR/RaycastLiDARSensor.cs +++ b/Assets/UnitySensors/Runtime/Scripts/Sensors/LiDAR/RaycastLiDAR/RaycastLiDARSensor.cs @@ -30,7 +30,16 @@ public class RaycastLiDARSensor : LiDARSensor protected override void Init() { - base.Init(); + if (scanPattern == null) + { + return; + } + Initialize(); + } + + public override void Initialize() + { + base.Initialize(); _transform = this.transform; diff --git a/Assets/UnitySensorsROS/Runtime/Scripts/Publishers/SensorMsgs/PointCloud2Msg/LiDARPointCloud2MsgPublisher.cs b/Assets/UnitySensorsROS/Runtime/Scripts/Publishers/SensorMsgs/PointCloud2Msg/LiDARPointCloud2MsgPublisher.cs index 171836a7..0b998acb 100644 --- a/Assets/UnitySensorsROS/Runtime/Scripts/Publishers/SensorMsgs/PointCloud2Msg/LiDARPointCloud2MsgPublisher.cs +++ b/Assets/UnitySensorsROS/Runtime/Scripts/Publishers/SensorMsgs/PointCloud2Msg/LiDARPointCloud2MsgPublisher.cs @@ -12,6 +12,11 @@ public class LiDARPointCloud2MsgPublisher : PointCloud2MsgPublisher private void Awake() { + if (_source == null) + { + Debug.LogError("Source is not set."); + return; + } _serializer.SetSource(_source as IPointCloudInterface); } } From 4442fe65e51089567314c124611d103f50cd0ccd Mon Sep 17 00:00:00 2001 From: Masaaki Hijikata Date: Mon, 28 Apr 2025 18:25:26 +0900 Subject: [PATCH 2/5] [change] Made it possible to initialize DepthBufferLiDARSensor later so that it works with the built app. --- .../LiDAR/DepthBufferLiDAR/DepthBufferLiDARSensor.cs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/Assets/UnitySensors/Runtime/Scripts/Sensors/LiDAR/DepthBufferLiDAR/DepthBufferLiDARSensor.cs b/Assets/UnitySensors/Runtime/Scripts/Sensors/LiDAR/DepthBufferLiDAR/DepthBufferLiDARSensor.cs index 46092a91..8993a9b9 100644 --- a/Assets/UnitySensors/Runtime/Scripts/Sensors/LiDAR/DepthBufferLiDAR/DepthBufferLiDARSensor.cs +++ b/Assets/UnitySensors/Runtime/Scripts/Sensors/LiDAR/DepthBufferLiDAR/DepthBufferLiDARSensor.cs @@ -38,7 +38,16 @@ public class DepthBufferLiDARSensor : LiDARSensor protected override void Init() { - base.Init(); + if (scanPattern == null) + { + return; + } + Initialize(); + } + + public override void Initialize() + { + base.Initialize(); _transform = this.transform; SetupCamera(); LoadScanData(); From 3babe95a999ad92ee1f8180102c1929e54692cf2 Mon Sep 17 00:00:00 2001 From: Ryodo Tanaka Date: Tue, 29 Apr 2025 20:05:25 +0900 Subject: [PATCH 3/5] Update Assets/UnitySensorsROS/Runtime/Scripts/Publishers/SensorMsgs/PointCloud2Msg/LiDARPointCloud2MsgPublisher.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- .../SensorMsgs/PointCloud2Msg/LiDARPointCloud2MsgPublisher.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Assets/UnitySensorsROS/Runtime/Scripts/Publishers/SensorMsgs/PointCloud2Msg/LiDARPointCloud2MsgPublisher.cs b/Assets/UnitySensorsROS/Runtime/Scripts/Publishers/SensorMsgs/PointCloud2Msg/LiDARPointCloud2MsgPublisher.cs index 0b998acb..7a3fd5c8 100644 --- a/Assets/UnitySensorsROS/Runtime/Scripts/Publishers/SensorMsgs/PointCloud2Msg/LiDARPointCloud2MsgPublisher.cs +++ b/Assets/UnitySensorsROS/Runtime/Scripts/Publishers/SensorMsgs/PointCloud2Msg/LiDARPointCloud2MsgPublisher.cs @@ -14,7 +14,7 @@ private void Awake() { if (_source == null) { - Debug.LogError("Source is not set."); + Debug.LogError("Source is not set in LiDARPointCloud2MsgPublisher. Please ensure that the '_source' field is assigned in the Unity Editor or via code. Expected type: IPointCloudInterface."); return; } _serializer.SetSource(_source as IPointCloudInterface); From 3f31351cb1773f1763e7591fe9c73d76c6f14bcd Mon Sep 17 00:00:00 2001 From: Ryodo Tanaka Date: Tue, 29 Apr 2025 20:05:34 +0900 Subject: [PATCH 4/5] Update Assets/UnitySensors/Runtime/Scripts/Sensors/LiDAR/DepthBufferLiDAR/DepthBufferLiDARSensor.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- .../Sensors/LiDAR/DepthBufferLiDAR/DepthBufferLiDARSensor.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/Assets/UnitySensors/Runtime/Scripts/Sensors/LiDAR/DepthBufferLiDAR/DepthBufferLiDARSensor.cs b/Assets/UnitySensors/Runtime/Scripts/Sensors/LiDAR/DepthBufferLiDAR/DepthBufferLiDARSensor.cs index 8993a9b9..3588394c 100644 --- a/Assets/UnitySensors/Runtime/Scripts/Sensors/LiDAR/DepthBufferLiDAR/DepthBufferLiDARSensor.cs +++ b/Assets/UnitySensors/Runtime/Scripts/Sensors/LiDAR/DepthBufferLiDAR/DepthBufferLiDARSensor.cs @@ -40,6 +40,7 @@ protected override void Init() { if (scanPattern == null) { + Debug.LogWarning("Initialization postponed: scanPattern is null. Ensure that scanPattern is assigned before calling Init."); return; } Initialize(); From f03347f70a580a0ed3f9a2775099fe7c1c93ecb0 Mon Sep 17 00:00:00 2001 From: Ryodo Tanaka Date: Tue, 29 Apr 2025 20:06:17 +0900 Subject: [PATCH 5/5] Update Assets/UnitySensors/Runtime/Scripts/Sensors/LiDAR/RaycastLiDAR/RaycastLiDARSensor.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- .../Scripts/Sensors/LiDAR/RaycastLiDAR/RaycastLiDARSensor.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/Assets/UnitySensors/Runtime/Scripts/Sensors/LiDAR/RaycastLiDAR/RaycastLiDARSensor.cs b/Assets/UnitySensors/Runtime/Scripts/Sensors/LiDAR/RaycastLiDAR/RaycastLiDARSensor.cs index b9d21e5a..8c378f6b 100644 --- a/Assets/UnitySensors/Runtime/Scripts/Sensors/LiDAR/RaycastLiDAR/RaycastLiDARSensor.cs +++ b/Assets/UnitySensors/Runtime/Scripts/Sensors/LiDAR/RaycastLiDAR/RaycastLiDARSensor.cs @@ -32,6 +32,7 @@ protected override void Init() { if (scanPattern == null) { + Debug.LogWarning("RaycastLiDARSensor: scanPattern is null. Initialization is delayed until scanPattern is set."); return; } Initialize();