Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add rain and fog simulation features #359

Merged
merged 32 commits into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from 28 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
5c50072
Initial commit with draft files
PiotrMrozik Aug 21, 2024
fb58bb3
Revert "Initial commit with draft files"
PiotrMrozik Aug 21, 2024
6593f0a
proper skeleton of new files
PiotrMrozik Aug 21, 2024
2219c60
add missing prefab
PiotrMrozik Aug 21, 2024
135a298
fix broken enum
PiotrMrozik Aug 21, 2024
53564a9
add fog feature setting initial commit
PiotrMrozik Sep 4, 2024
0668404
Add GPU skinning in RGL (#345)
msz-rai Aug 20, 2024
17a9613
Sync LiDAR's timer when enabling it (#349)
msz-rai Aug 26, 2024
3079d62
Add multi-return for snow simulation (#348)
PawelLiberadzki Aug 28, 2024
4c9eb78
Add test for multi-return modes.
PawelLiberadzki Aug 28, 2024
9799dcc
fix api and add .so
PiotrMrozik Sep 5, 2024
308db61
update docs libssl version
mackierx111 Aug 20, 2024
ac862cf
Initial commit with draft files
PiotrMrozik Aug 21, 2024
bfcd2f4
Revert "Initial commit with draft files"
PiotrMrozik Aug 21, 2024
1e9aa88
proper skeleton of new files
PiotrMrozik Aug 21, 2024
7d96886
add missing prefab
PiotrMrozik Aug 21, 2024
994a6ce
fix broken enum
PiotrMrozik Aug 21, 2024
f745b0d
add fog feature setting initial commit
PiotrMrozik Sep 4, 2024
e9f331b
Add multi-return for snow simulation (#348)
PawelLiberadzki Aug 28, 2024
d5807da
fix api and add .so
PiotrMrozik Sep 5, 2024
3776a89
Merge remote-tracking branch 'origin/feature/rgl-fog-simulation' into…
PiotrMrozik Sep 16, 2024
4a54ff8
Make adjustments to rain simulation.
PawelLiberadzki Sep 17, 2024
6a13690
add missing meta file
PiotrMrozik Sep 18, 2024
0d30be8
tweak r's params
PiotrMrozik Sep 18, 2024
fdd4830
Merge pull request #358 from tier4/feature/rgl-rain-multi-return
PiotrMrozik Sep 18, 2024
04318fe
fix merge mistake
PiotrMrozik Sep 23, 2024
f757478
replace binary with old file
PiotrMrozik Sep 23, 2024
0420fbc
Update RGL binary for Linux
msz-rai Sep 25, 2024
69ef867
pr fixes v1
PiotrMrozik Sep 25, 2024
228aee9
Update RGL binary for Windows
msz-rai Sep 25, 2024
7609ce6
Merge branch 'feature/rgl-fog-simulation' of github.com:tier4/AWSIM i…
PiotrMrozik Sep 25, 2024
6dc2e45
Add minor code formatting updates.
PawelLiberadzki Sep 25, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 87 additions & 0 deletions Assets/AWSIM/Prefabs/RGLWeatherManager.prefab
PiotrMrozik marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1 &6956985947121104793
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 6197961024456584825}
- component: {fileID: -8569641881512349866}
- component: {fileID: 5029029592669420807}
- component: {fileID: 2635114183252318215}
m_Layer: 0
m_Name: RGLWeatherManager
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &6197961024456584825
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6956985947121104793}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: -17.985855, y: -8.897016, z: 19.096115}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &-8569641881512349866
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6956985947121104793}
m_Enabled: 0
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: ac280d5abd54451082c0627a0d08b1b9, type: 3}
m_Name:
m_EditorClassIdentifier:
<IsSnowEnabled>k__BackingField: 0
<RainRate>k__BackingField: 9
<MeanSnowflakeDiameter>k__BackingField: 0.003
<TerminalVelocity>k__BackingField: 1.6
<Density>k__BackingField: 0.07
<OccupancyThreshold>k__BackingField: 0
<SnowflakesId>k__BackingField: 268435455
<FullBeamIntensity>k__BackingField: 1
--- !u!114 &5029029592669420807
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6956985947121104793}
m_Enabled: 0
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: aa72d4643994ea2d4b9e731c9454694c, type: 3}
m_Name:
m_EditorClassIdentifier:
<IsRainEnabled>k__BackingField: 0
<RainRate>k__BackingField: 9
<DoSimulateEnergyLoss>k__BackingField: 1
<RainNumericalThreshold>k__BackingField: 1
--- !u!114 &2635114183252318215
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6956985947121104793}
m_Enabled: 0
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: e537672f1e918b452802a824b8840e70, type: 3}
m_Name:
m_EditorClassIdentifier:
<IsFogEnabled>k__BackingField: 0
<AttenuationCoefficient>k__BackingField: 0.03
<nearCrossPoint>k__BackingField: 0.001
<farCrossPoint>k__BackingField: 1
7 changes: 7 additions & 0 deletions Assets/AWSIM/Prefabs/RGLWeatherManager.prefab.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

91 changes: 91 additions & 0 deletions Assets/RGLUnityPlugin/Scripts/LidarFogManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
// Copyright 2024 Robotec.ai.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

using UnityEngine;

namespace RGLUnityPlugin
{
/// <summary>
/// The singleton component to activate and configure the fog model for the LiDAR sensors.
/// Note: This is a private feature. It requires replacing the RGL binary with the RGL private build binary.
/// </summary>
public class LidarFogManager : MonoBehaviour
{
// Singleton pattern
public static LidarFogManager Instance { get; private set; }

// Delegate to notify that the snow model has been changed
public delegate void OnNewConfigDelegate();
public OnNewConfigDelegate OnNewConfig;

[field: SerializeField]
PiotrMrozik marked this conversation as resolved.
Show resolved Hide resolved
[field: Tooltip("Enable/disable fog effect on devices.r")]
public bool IsFogEnabled { get; set; } = false;

[field: SerializeField]
[field: Tooltip("The attenuation coefficient for fog corresponding to amount of fog in the air")]
[field: Range(0.003f, 0.5f)]
public float AttenuationCoefficient { get; private set; } = 0.03f;

[field: SerializeField]
[field: Tooltip("Near cross-point of transmitter and receiver beams of Lidar device in meters. Model assumes that lidar is working in bistatic beam configuration.")]
[field: Range(0.0f, 1.0f)]
public float nearCrossPoint { get; private set; } = 0.01f;

[field: SerializeField]
[field: Tooltip("far cross-point of transmitter and receiver beams of Lidar device. Model assumes that lidar is working in bistatic beam configuration.")]
[field: Range(1.0f, 10.0f)]
public float farCrossPoint { get; private set; } = 2.0f;
PiotrMrozik marked this conversation as resolved.
Show resolved Hide resolved

private void Awake()
{
if (!IsFogFeatureAvailable())
{
Debug.LogError("Loaded RGL plugin does not include support for Lidar Fog Model, removing component");
Destroy(this);
return;
}

if (Instance != null && Instance != this)
{
Debug.LogError("LidarFogManager is already on the scene. Removing this component");
Destroy(this);
return;
}
Instance = this;
}

private void OnValidate()
{
OnNewConfig?.Invoke();
}

private void OnEnable()
{
IsFogEnabled = true;
OnNewConfig?.Invoke();
}

private void OnDisable()
{
IsFogEnabled = false;
OnNewConfig?.Invoke();
}

public bool IsFogFeatureAvailable()
{
return RGLNativeAPI.HasExtension(RGLExtension.RGL_EXTENSION_WEATHER);
}
}
}
11 changes: 11 additions & 0 deletions Assets/RGLUnityPlugin/Scripts/LidarFogManager.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

105 changes: 105 additions & 0 deletions Assets/RGLUnityPlugin/Scripts/LidarRainManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
// Copyright 2024 Robotec.ai.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

using UnityEngine;

namespace RGLUnityPlugin
{
/// <summary>
/// The singleton component to activate and configure the rain model for the LiDAR sensors.
/// Note: This is a private feature. It requires replacing the RGL binary with the RGL private build binary.
/// </summary>
public class LidarRainManager : MonoBehaviour
{
// Singleton pattern
public static LidarRainManager Instance { get; private set; }

// 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;

// Rain model properties
[field: SerializeField]
[field: Tooltip("The precipitation rate for rain is expressed in mm per hour")]
[field: Range(0.0f, 10.0f)]
public float RainRate { get; private set; } = 5.0f;

[field: SerializeField]
[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("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()
{
if (!IsRainFeatureAvailable())
{
Debug.LogError("Loaded RGL plugin does not include support for Lidar Rain Model, removing component");
Destroy(this);
return;
}

if (Instance != null && Instance != this)
{
Debug.LogError("LidarRainManager is already on the scene. Removing this component");
Destroy(this);
return;
}
Instance = this;
}

private void OnValidate()
{
OnNewConfig?.Invoke();
}

private void OnEnable()
{
IsRainEnabled = true;
OnNewConfig?.Invoke();
}

private void OnDisable()
{
IsRainEnabled = false;
OnNewConfig?.Invoke();
}

public bool IsRainFeatureAvailable()
{
return RGLNativeAPI.HasExtension(RGLExtension.RGL_EXTENSION_WEATHER);
}
}
}
11 changes: 11 additions & 0 deletions Assets/RGLUnityPlugin/Scripts/LidarRainManager.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

56 changes: 56 additions & 0 deletions Assets/RGLUnityPlugin/Scripts/LidarSensor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ public class LidarSensor : MonoBehaviour
private const string pointsCompactNodeId = "POINTS_COMPACT";
private const string toLidarFrameNodeId = "TO_LIDAR_FRAME";
private const string snowNodeId = "SNOW";
private const string rainNodeId = "RAIN";
private const string fogNodeId = "FOG";

private LidarModel? validatedPreset;
private float timer;
Expand Down Expand Up @@ -150,6 +152,22 @@ public void Start()
LidarSnowManager.Instance.OnNewConfig += OnValidate;
}

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, 1, 0.1f);
rglGraphLidar.SetActive(rainNodeId, false);
LidarRainManager.Instance.OnNewConfig += OnValidate;
}

if(LidarFogManager.Instance != null)
{
// Add deactivated node with some initial values. To be activated and updated when validating.
rglGraphLidar.AddNodePointsSimulateFog(fogNodeId, 0.03f, 0.1f, 2.0f);
rglGraphLidar.SetActive(fogNodeId, false);
LidarFogManager.Instance.OnNewConfig += OnValidate;
}

OnValidate();

if (doValidateConfigurationOnStartup)
Expand Down Expand Up @@ -246,6 +264,44 @@ private void ApplyConfiguration(BaseLidarConfiguration newConfig)
rglGraphLidar.SetActive(snowNodeId, LidarSnowManager.Instance.IsSnowEnabled);
}

// Rain model updates
if (rglGraphLidar.HasNode(rainNodeId))
{
// Update rain parameters only if feature is enabled (expensive operation)
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.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);
}

// Fog model updates
if (rglGraphLidar.HasNode(fogNodeId))
{
// Update fog parameters only if feature is enabled (expensive operation)
if (LidarFogManager.Instance.IsFogEnabled)
{
rglGraphLidar.UpdateNodePointsSimulateFog(fogNodeId,
LidarFogManager.Instance.AttenuationCoefficient,
LidarFogManager.Instance.nearCrossPoint,
LidarFogManager.Instance.farCrossPoint);
PiotrMrozik marked this conversation as resolved.
Show resolved Hide resolved
}

rglGraphLidar.SetActive(fogNodeId, LidarFogManager.Instance.IsFogEnabled);
}

rglGraphLidar.ConfigureNodeRaytraceDistortion(lidarRaytraceNodeId, applyVelocityDistortion);

if (outputRestriction.enablePeriodicRestriction && outputRestriction.applyRestriction)
Expand Down
Loading
Loading