Skip to content

Commit

Permalink
Make adjustments to rain simulation.
Browse files Browse the repository at this point in the history
Signed-off-by: Paweł Liberadzki <[email protected]>
  • Loading branch information
PawelLiberadzki committed Sep 17, 2024
1 parent 3776a89 commit 4a54ff8
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 25 deletions.
32 changes: 23 additions & 9 deletions Assets/RGLUnityPlugin/Scripts/LidarRainManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down
22 changes: 13 additions & 9 deletions Assets/RGLUnityPlugin/Scripts/LidarSensor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);
}
Expand Down
17 changes: 14 additions & 3 deletions Assets/RGLUnityPlugin/Scripts/LowLevelWrappers/RGLNativeAPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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)
Expand Down
15 changes: 11 additions & 4 deletions Assets/RGLUnityPlugin/Scripts/LowLevelWrappers/RGLNodeSequence.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}

Expand All @@ -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)
Expand Down

0 comments on commit 4a54ff8

Please sign in to comment.