Skip to content

Commit 1e79b24

Browse files
committed
Add model specific options to the lidar sensor component
1 parent 47f2e85 commit 1e79b24

File tree

3 files changed

+105
-15
lines changed

3 files changed

+105
-15
lines changed

Diff for: AGXUnity/Sensor/LidarSensor.cs

+55-5
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,26 @@
88

99
namespace AGXUnity.Sensor
1010
{
11+
public interface IModelData { }
12+
13+
[Serializable]
14+
public class OusterData : IModelData
15+
{
16+
public LidarModelOusterOS.ChannelCount ChannelCount = LidarModelOusterOS.ChannelCount.ch_32;
17+
public LidarModelOusterOS.BeamSpacing BeamSpacing = LidarModelOusterOS.BeamSpacing.Uniform;
18+
public LidarModelOusterOS.LidarMode LidarMode = LidarModelOusterOS.LidarMode.Mode_512x20;
19+
}
20+
21+
[Serializable]
22+
public class GenericSweepData : IModelData
23+
{
24+
public float Frequency = 10.0f;
25+
public float HorizontalFoV = 360.0f;
26+
public float VerticalFoV = 35.0f;
27+
public float HorizontalResolution = 0.5f;
28+
public float VerticalResolution = 0.5f;
29+
}
30+
1131
public enum LidarModelPreset
1232
{
1333
NONE,
@@ -34,7 +54,29 @@ public class LidarSensor : ScriptComponent
3454
* The Model, or preset, of this Lidar.
3555
* Changing this will assign Model specific properties to this Lidar.
3656
*/
37-
public LidarModelPreset LidarModelPreset = LidarModelPreset.LidarModelOusterOS1;
57+
[SerializeField]
58+
private LidarModelPreset m_lidarModelPreset = LidarModelPreset.LidarModelOusterOS1;
59+
60+
public LidarModelPreset LidarModelPreset
61+
{
62+
get => m_lidarModelPreset;
63+
set
64+
{
65+
m_lidarModelPreset = value;
66+
ModelData = value switch
67+
{
68+
LidarModelPreset.LidarModelOusterOS0 => new OusterData(),
69+
LidarModelPreset.LidarModelOusterOS1 => new OusterData(),
70+
LidarModelPreset.LidarModelOusterOS2 => new OusterData(),
71+
LidarModelPreset.LidarModelGeneric360HorizontalSweep => new GenericSweepData(),
72+
LidarModelPreset.NONE => null,
73+
};
74+
}
75+
}
76+
77+
78+
[field: SerializeReference]
79+
public IModelData ModelData { get; private set; } = new OusterData();
3880

3981
/**
4082
* The minimum and maximum range of the Lidar Sensor [m].
@@ -183,19 +225,27 @@ private LidarModel CreateLidarModel( LidarModelPreset preset )
183225

184226
switch ( preset ) {
185227
case LidarModelPreset.LidarModelGeneric360HorizontalSweep:
186-
lidarModel = new LidarModelGeneric360HorizontalSweep( 10f ); // TODO Default frequency for now, implement lidar settings
228+
GenericSweepData sweepData = ModelData as GenericSweepData;
229+
lidarModel = new LidarModelHorizontalSweep(
230+
Mathf.Deg2Rad * new agx.Vec2( sweepData.HorizontalFoV, sweepData.VerticalFoV ),
231+
Mathf.Deg2Rad * new agx.Vec2( sweepData.HorizontalResolution, sweepData.VerticalResolution ),
232+
sweepData.Frequency
233+
); // TODO Default frequency for now, implement lidar settings
187234
break;
188235

189236
case LidarModelPreset.LidarModelOusterOS0:
190-
lidarModel = new LidarModelOusterOS0();
237+
OusterData ousterData = ModelData as OusterData;
238+
lidarModel = new LidarModelOusterOS0( ousterData.ChannelCount, ousterData.BeamSpacing, ousterData.LidarMode );
191239
break;
192240

193241
case LidarModelPreset.LidarModelOusterOS1:
194-
lidarModel = new LidarModelOusterOS1();
242+
ousterData = ModelData as OusterData;
243+
lidarModel = new LidarModelOusterOS1( ousterData.ChannelCount, ousterData.BeamSpacing, ousterData.LidarMode );
195244
break;
196245

197246
case LidarModelPreset.LidarModelOusterOS2:
198-
lidarModel = new LidarModelOusterOS2();
247+
ousterData = ModelData as OusterData;
248+
lidarModel = new LidarModelOusterOS2( ousterData.ChannelCount, ousterData.BeamSpacing, ousterData.LidarMode );
199249
break;
200250

201251
case LidarModelPreset.NONE:

Diff for: AGXUnity/Sensor/SensorEnvironment.cs

+11-10
Original file line numberDiff line numberDiff line change
@@ -294,20 +294,21 @@ protected override bool Initialize()
294294

295295
FindValidComponents<MeshFilter>( true ).ForEach( RegisterMeshfilter );
296296

297-
FindValidComponents<DeformableTerrain>( true ).ForEach( c => m_agxComponents.Add( c, c.gameObject.activeInHierarchy ) );
298-
FindValidComponents<DeformableTerrainPager>( true ).ForEach( c => m_agxComponents.Add( c, c.gameObject.activeInHierarchy ) );
299-
FindValidComponents<Wire>( true ).ForEach( c => m_agxComponents.Add( c, c.gameObject.activeInHierarchy ) );
300-
FindValidComponents<Cable>( true ).ForEach( c => m_agxComponents.Add( c, c.gameObject.activeInHierarchy ) );
301-
302-
foreach ( var entry in m_agxComponents ) {
303-
if ( entry.Value )
304-
AddAGXModel( entry.Key.GetInitialized() );
305-
}
297+
FindValidComponents<DeformableTerrain>( true ).ForEach( c => m_agxComponents.TryAdd( c, false ) );
298+
FindValidComponents<HeightField>( true ).ForEach( c => m_agxComponents.TryAdd( c, false ) );
299+
FindValidComponents<DeformableTerrainPager>( true ).ForEach( c => m_agxComponents.TryAdd( c, false ) );
300+
FindValidComponents<Wire>( true ).ForEach( c => m_agxComponents.TryAdd( c, false ) );
301+
FindValidComponents<Cable>( true ).ForEach( c => m_agxComponents.TryAdd( c, false ) );
302+
FindValidComponents<Track>( true ).ForEach( c => m_agxComponents.TryAdd( c, false ) );
303+
304+
UpdateEnvironment()
305+
306+
Simulation.Instance.StepCallbacks.PreSynchronizeTransforms += UpdateEnvironment;
306307

307308
return true;
308309
}
309310

310-
public void FixedUpdate()
311+
public void UpdateEnvironment()
311312
{
312313
if ( Native == null )
313314
return;

Diff for: Editor/AGXUnityEditor/InvokeWrapperInspectorDrawer.cs

+39
Original file line numberDiff line numberDiff line change
@@ -1113,5 +1113,44 @@ public static object UrdfElementDrawer( object[] objects, InvokeWrapper wrapper
11131113

11141114
return null;
11151115
}
1116+
1117+
public static void DrawOusterModelData( AGXUnity.Sensor.OusterData data )
1118+
{
1119+
data.ChannelCount = (agxSensor.LidarModelOusterOS.ChannelCount)EditorGUILayout.EnumPopup( "Channel Count", data.ChannelCount );
1120+
data.BeamSpacing = (agxSensor.LidarModelOusterOS.BeamSpacing)EditorGUILayout.EnumPopup( "Beam Spacing", data.BeamSpacing );
1121+
data.LidarMode = (agxSensor.LidarModelOusterOS.LidarMode)EditorGUILayout.EnumPopup( "Lidar Mode", data.LidarMode );
1122+
}
1123+
1124+
public static void DrawGenericSweepModelData( AGXUnity.Sensor.GenericSweepData data )
1125+
{
1126+
data.Frequency = EditorGUILayout.FloatField( "Frequency", data.Frequency );
1127+
data.HorizontalFoV = EditorGUILayout.FloatField( "HorizontalFoV", data.HorizontalFoV );
1128+
data.VerticalFoV = EditorGUILayout.FloatField( "VerticalFoV", data.VerticalFoV );
1129+
data.HorizontalResolution = EditorGUILayout.FloatField( "HorizontalResolution", data.HorizontalResolution );
1130+
data.VerticalResolution = EditorGUILayout.FloatField( "VerticalResolution", data.VerticalResolution );
1131+
}
1132+
1133+
[InspectorDrawer( typeof( AGXUnity.Sensor.IModelData ) )]
1134+
public static object ModelDataDrawer( object[] objects, InvokeWrapper wrapper )
1135+
{
1136+
if ( objects.Length != 1 ) {
1137+
InspectorGUI.WarningLabel( "Multi-select of ModelData Elements isn't supported." );
1138+
return null;
1139+
}
1140+
1141+
var data = wrapper.Get<AGXUnity.Sensor.IModelData>( objects[0] );
1142+
using ( new InspectorGUI.IndentScope() ) {
1143+
switch ( data ) {
1144+
case AGXUnity.Sensor.OusterData ousterData:
1145+
DrawOusterModelData( ousterData );
1146+
break;
1147+
case AGXUnity.Sensor.GenericSweepData sweepData:
1148+
DrawGenericSweepModelData( sweepData );
1149+
break;
1150+
}
1151+
}
1152+
1153+
return null;
1154+
}
11161155
}
11171156
}

0 commit comments

Comments
 (0)