From 4a54ff8e0a7fe4ff4d53427731aec4020d4f1155 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Liberadzki?= Date: Tue, 17 Sep 2024 14:45:22 +0200 Subject: [PATCH] Make adjustments to rain simulation. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Paweł Liberadzki --- .../Scripts/LidarRainManager.cs | 32 +++++++++++++------ Assets/RGLUnityPlugin/Scripts/LidarSensor.cs | 22 +++++++------ .../Scripts/LowLevelWrappers/RGLNativeAPI.cs | 17 ++++++++-- .../LowLevelWrappers/RGLNodeSequence.cs | 15 ++++++--- 4 files changed, 61 insertions(+), 25 deletions(-) diff --git a/Assets/RGLUnityPlugin/Scripts/LidarRainManager.cs b/Assets/RGLUnityPlugin/Scripts/LidarRainManager.cs index caca268ed..79c9c5de0 100644 --- a/Assets/RGLUnityPlugin/Scripts/LidarRainManager.cs +++ b/Assets/RGLUnityPlugin/Scripts/LidarRainManager.cs @@ -25,28 +25,42 @@ public class LidarRainManager : MonoBehaviour // Singleton pattern public static LidarRainManager Instance { get; private set; } - // Delegate to notify that the snow model has been changed + // Delegate to notify that the rain model has been changed public delegate void OnNewConfigDelegate(); public OnNewConfigDelegate OnNewConfig; + [field: Header("Base Settings")] + [field: SerializeField] [field: Tooltip("Enable/disable rain effect on devices.r")] public bool IsRainEnabled { get; set; } = false; - // Snow model properties + // Rain model properties [field: SerializeField] [field: Tooltip("The precipitation rate for rain is expressed in mm per hour")] - [field: Range(0.0f, 50.0f)] - public float RainRate { get; private set; } = 9.0f; + [field: Range(0.0f, 10.0f)] + public float RainRate { get; private set; } = 5.0f; [field: SerializeField] - [field: Tooltip("If true, a more sophisticated method is used, which takes into account the energy loss of the lidar beam when hitting snowflakes")] - public bool DoSimulateEnergyLoss { get; private set; } = true; + [field: Tooltip("Maximal number of droplets which not obstruct the lidar beam")] + [field: Range(1, 5)] + public int RainNumericalThreshold { get; private set; } = 3; [field: SerializeField] - [field: Tooltip("Maximal number of droplets which not obstruct the lidar beam")] - [field: Range(1, 10)] - public int RainNumericalThreshold { get; private set; } = 1; + [field: Tooltip("Minimal beam aperture occupancy (ratio) that means a hit, both for droplets and for original hit")] + [field: Range(0.0f, 1.0f)] + public float OccupancyThreshold { get; private set; } = 0.2f; + + [field: Header("Defaults")] + + [field: SerializeField] + [field: Tooltip("Entity ID that is assigned to cloud points resulting from droplet hits")] + public int DropletsId { get; private set; } = 268435455; // Default RGL entity ID. + + [field: SerializeField] + [field: Tooltip("Initial intensity of each LiDAR laser beam, used to evaluate energy loss based on beam aperture occupancy")] + [field: Min(0.0f)] + public float FullBeamIntensity { get; private set; } = 1.0f; private void Awake() { diff --git a/Assets/RGLUnityPlugin/Scripts/LidarSensor.cs b/Assets/RGLUnityPlugin/Scripts/LidarSensor.cs index 5f6bb051b..f78838520 100644 --- a/Assets/RGLUnityPlugin/Scripts/LidarSensor.cs +++ b/Assets/RGLUnityPlugin/Scripts/LidarSensor.cs @@ -155,7 +155,7 @@ public void Start() if (LidarRainManager.Instance != null) { // Add deactivated node with some initial values. To be activated and updated when validating. - rglGraphLidar.AddNodePointsSimulateRain(rainNodeId, 0.0f, 1.0f, 0.0001f, 1, 0.01f, false, 1); + rglGraphLidar.AddNodePointsSimulateRain(rainNodeId, 0.0f, 1.0f, 0.0001f, 1, 0.01f, 1, 0.1f); rglGraphLidar.SetActive(rainNodeId, false); LidarRainManager.Instance.OnNewConfig += OnValidate; } @@ -271,14 +271,18 @@ private void ApplyConfiguration(BaseLidarConfiguration newConfig) if (LidarRainManager.Instance.IsRainEnabled) { rglGraphLidar.UpdateNodePointsSimulateRain(rainNodeId, - newConfig.GetRayRanges()[0].x, - newConfig.GetRayRanges()[0].y, - LidarRainManager.Instance.RainRate, - newConfig.laserArray.GetLaserRingIds().Length, - newConfig.horizontalBeamDivergence * Mathf.Deg2Rad, - LidarRainManager.Instance.DoSimulateEnergyLoss, - LidarRainManager.Instance.RainNumericalThreshold); - } + newConfig.GetRayRanges()[0].x, + newConfig.GetRayRanges()[0].y, + LidarRainManager.Instance.RainRate, + newConfig.laserArray.GetLaserRingIds().Length, + newConfig.horizontalBeamDivergence * Mathf.Deg2Rad, + LidarRainManager.Instance.RainNumericalThreshold, + LidarRainManager.Instance.OccupancyThreshold); + rglGraphLidar.UpdateNodePointsRainDefaults(rainNodeId, + LidarRainManager.Instance.DropletsId, + LidarRainManager.Instance.FullBeamIntensity, + 0.0f); // Default, because it is not supported in AWSIM. + } rglGraphLidar.SetActive(rainNodeId, LidarRainManager.Instance.IsRainEnabled); } diff --git a/Assets/RGLUnityPlugin/Scripts/LowLevelWrappers/RGLNativeAPI.cs b/Assets/RGLUnityPlugin/Scripts/LowLevelWrappers/RGLNativeAPI.cs index 2d7fa7218..98cda72ea 100644 --- a/Assets/RGLUnityPlugin/Scripts/LowLevelWrappers/RGLNativeAPI.cs +++ b/Assets/RGLUnityPlugin/Scripts/LowLevelWrappers/RGLNativeAPI.cs @@ -184,7 +184,11 @@ public static extern int rgl_node_points_simulate_snow_configure_defaults(IntPtr [DllImport("RobotecGPULidar")] public static extern int rgl_node_points_simulate_rain(ref IntPtr node, float min_range, float max_range, float rain_rate, - Int32 num_channels, float beam_divergence, bool simulate_energy_loss, Int32 numerical_threshold); + Int32 num_channels, float beam_divergence, Int32 numerical_threshold, float occupancy_threshold); + + [DllImport("RobotecGPULidar")] + public static extern int rgl_node_points_simulate_rain_configure_defaults(IntPtr node, int droplets_id, float full_beam_intensity, + float droplets_laser_retro); [DllImport("RobotecGPULidar")] public static extern int rgl_node_points_simulate_fog(ref IntPtr node, float attenuationCoefficient, float r1, float r2); @@ -660,9 +664,16 @@ public static void NodePointsSimulateSnowConfigureDefaults(IntPtr node, int snow } public static void NodePointsSimulateRain(ref IntPtr node, float minRange, float maxRange, float rainRate, - Int32 numChannels, float beamDivergence, bool doSimulateEnergyLoss, Int32 numericalThreshold) + Int32 numChannels, float beamDivergence, Int32 numericalThreshold, float occupancyThreshold) + { + CheckErr(rgl_node_points_simulate_rain(ref node, minRange, maxRange, rainRate,numChannels, beamDivergence, numericalThreshold, + occupancyThreshold)); + } + + public static void NodePointsSimulateRainConfigureDefaults(IntPtr node, int dropletsId, float fullBeamIntensity, + float dropletsLaserRetro) { - CheckErr(rgl_node_points_simulate_rain(ref node, minRange, maxRange, rainRate,numChannels, beamDivergence, doSimulateEnergyLoss, numericalThreshold)); + CheckErr(rgl_node_points_simulate_rain_configure_defaults(node, dropletsId, fullBeamIntensity, dropletsLaserRetro)); } public static void NodePointsSimulateFog(ref IntPtr node, float attenuationCoefficient, float r1, float r2) diff --git a/Assets/RGLUnityPlugin/Scripts/LowLevelWrappers/RGLNodeSequence.cs b/Assets/RGLUnityPlugin/Scripts/LowLevelWrappers/RGLNodeSequence.cs index c1e6ee5fc..fa03ddc08 100644 --- a/Assets/RGLUnityPlugin/Scripts/LowLevelWrappers/RGLNodeSequence.cs +++ b/Assets/RGLUnityPlugin/Scripts/LowLevelWrappers/RGLNodeSequence.cs @@ -351,12 +351,12 @@ public RGLNodeSequence AddNodePointsSimulateSnow(string identifier, float minRan } public RGLNodeSequence AddNodePointsSimulateRain(string identifier, float minRange, float maxRange, float rainRate, - Int32 numChannels, float beamDivergence, bool doSimulateEnergyLoss, Int32 numericalThreshold) + Int32 numChannels, float beamDivergence, Int32 numericalThreshold, float occupancyThreshold) { CheckNodeNotExist(identifier); RGLNodeHandle handle = new RGLNodeHandle(); RGLNativeAPI.NodePointsSimulateRain(ref handle.Node, minRange, maxRange, rainRate, - numChannels, beamDivergence, doSimulateEnergyLoss, numericalThreshold); + numChannels, beamDivergence, numericalThreshold, occupancyThreshold); handle.Type = RGLNodeType.POINTS_SIMULATE_RAIN; handle.Identifier = identifier; AddNode(handle); @@ -504,11 +504,11 @@ public RGLNodeSequence UpdateNodePointsSimulateSnow(string identifier, float min } public RGLNodeSequence UpdateNodePointsSimulateRain(string identifier, float minRange, float maxRange, - float rainRate, Int32 numChannels, float beamDivergence, bool doSimulateEnergyLoss, Int32 numericalThreshold) + float rainRate, Int32 numChannels, float beamDivergence, Int32 numericalThreshold, float occupancyThreshold) { RGLNodeHandle handle = ValidateNode(identifier, RGLNodeType.POINTS_SIMULATE_RAIN); RGLNativeAPI.NodePointsSimulateRain(ref handle.Node, minRange, maxRange, rainRate, numChannels, - beamDivergence, doSimulateEnergyLoss, numericalThreshold); + beamDivergence, numericalThreshold, occupancyThreshold); return this; } @@ -526,6 +526,13 @@ public RGLNodeSequence UpdateNodePointsSnowDefaults(string identifier, int snowf return this; } + public RGLNodeSequence UpdateNodePointsRainDefaults(string identifier, int dropletsId, float fullBeamIntensity, float dropletsLaserRetro) + { + RGLNodeHandle handle = ValidateNode(identifier, RGLNodeType.POINTS_SIMULATE_RAIN); + RGLNativeAPI.NodePointsSimulateRainConfigureDefaults(handle.Node, dropletsId, fullBeamIntensity, dropletsLaserRetro); + return this; + } + //// CONFIGURE NODES //// public RGLNodeSequence ConfigureNodeRaytraceVelocity(string identifier, Vector3 linearVelocity, Vector3 angularVelocity)