Skip to content

Commit 589ba12

Browse files
authored
Merge pull request #40 from Field-Robotics-Japan/develop
ROS2への対応・TFセンサの追加・VelodyneLiDARへのノイズ追加
2 parents 30bec3d + 47d584f commit 589ba12

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+1593
-47
lines changed

.vscode/settings.json

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
{
2+
"files.exclude":
3+
{
4+
"**/.DS_Store":true,
5+
"**/.git":true,
6+
"**/.gitmodules":true,
7+
"**/*.booproj":true,
8+
"**/*.pidb":true,
9+
"**/*.suo":true,
10+
"**/*.user":true,
11+
"**/*.userprefs":true,
12+
"**/*.unityproj":true,
13+
"**/*.dll":true,
14+
"**/*.exe":true,
15+
"**/*.pdf":true,
16+
"**/*.mid":true,
17+
"**/*.midi":true,
18+
"**/*.wav":true,
19+
"**/*.gif":true,
20+
"**/*.ico":true,
21+
"**/*.jpg":true,
22+
"**/*.jpeg":true,
23+
"**/*.png":true,
24+
"**/*.psd":true,
25+
"**/*.tga":true,
26+
"**/*.tif":true,
27+
"**/*.tiff":true,
28+
"**/*.3ds":true,
29+
"**/*.3DS":true,
30+
"**/*.fbx":true,
31+
"**/*.FBX":true,
32+
"**/*.lxo":true,
33+
"**/*.LXO":true,
34+
"**/*.ma":true,
35+
"**/*.MA":true,
36+
"**/*.obj":true,
37+
"**/*.OBJ":true,
38+
"**/*.asset":true,
39+
"**/*.cubemap":true,
40+
"**/*.flare":true,
41+
"**/*.mat":true,
42+
"**/*.meta":true,
43+
"**/*.prefab":true,
44+
"**/*.unity":true,
45+
"build/":true,
46+
"Build/":true,
47+
"Library/":true,
48+
"library/":true,
49+
"obj/":true,
50+
"Obj/":true,
51+
"ProjectSettings/":true,
52+
"temp/":true,
53+
"Temp/":true
54+
}
55+
}

Assets/UnitySensors/Runtime/Scripts/Sensors/LiDAR/Velodyne/VelodyneSensor.cs

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@ public class VelodyneSensor : Sensor
1717
[SerializeField]
1818
private RotatingLiDARScanPattern _scanPattern;
1919
[SerializeField]
20+
private float _minDistance = 0.0f;
21+
[SerializeField]
22+
private float _maxDistance = 100.0f;
23+
[SerializeField]
24+
private float _maxIntensity = 255.0f;
25+
[SerializeField]
2026
private float _gaussianNoiseSigma = 0.0f;
2127

2228
private Transform _transform;
@@ -30,11 +36,16 @@ public class VelodyneSensor : Sensor
3036
private NativeArray<RaycastHit> _raycastHits;
3137
private Random _random;
3238
private NativeArray<float> _noises;
39+
40+
public NativeArray<float> distances;
3341
public NativeArray<Vector3> points;
42+
public NativeArray<float> intensities;
3443

3544
private uint _randomSeed;
3645
private int _pointsNum;
3746
public uint pointsNum { get => (uint)_pointsNum; }
47+
public int layersNum { get => _scanPattern.numOfLayer; }
48+
public int azimuthResolution { get => _scanPattern.azimuthResolution; }
3849

3950
protected override void Init()
4051
{
@@ -56,7 +67,9 @@ private void SetupDirections()
5667

5768
private void SetupJobs()
5869
{
70+
distances = new NativeArray<float>(_pointsNum, Allocator.Persistent);
5971
points = new NativeArray<Vector3>(_pointsNum, Allocator.Persistent);
72+
intensities = new NativeArray<float>(_pointsNum, Allocator.Persistent);
6073
_raycastCommands = new NativeArray<RaycastCommand>(_pointsNum, Allocator.Persistent);
6174
_raycastHits = new NativeArray<RaycastHit>(_pointsNum, Allocator.Persistent);
6275

@@ -82,10 +95,16 @@ private void SetupJobs()
8295

8396
_raycastHitsToPointsJob = new RaycastHitsToPointsJob()
8497
{
98+
minDistance = _minDistance,
99+
minDistance_sqr = _minDistance * _minDistance,
100+
maxDistance = _maxDistance,
101+
maxIntensity = _maxIntensity,
85102
directions = _directions,
86103
raycastHits = _raycastHits,
87104
noises = _noises,
88-
points = points
105+
distances = distances,
106+
points = points,
107+
intensities = intensities
89108
};
90109
}
91110

@@ -119,7 +138,9 @@ private void OnDestroy()
119138
_directions.Dispose();
120139
_raycastCommands.Dispose();
121140
_raycastHits.Dispose();
141+
distances.Dispose();
122142
points.Dispose();
143+
intensities.Dispose();
123144
}
124145

125146
[BurstCompile]
@@ -161,18 +182,34 @@ public void Execute(int index)
161182
[BurstCompile]
162183
private struct RaycastHitsToPointsJob : IJobParallelFor
163184
{
185+
[ReadOnly]
186+
public float minDistance;
187+
[ReadOnly]
188+
public float minDistance_sqr;
189+
[ReadOnly]
190+
public float maxDistance;
191+
[ReadOnly]
192+
public float maxIntensity;
164193
[ReadOnly]
165194
public NativeArray<Vector3> directions;
166195
[ReadOnly]
167196
public NativeArray<RaycastHit> raycastHits;
168197
[ReadOnly]
169198
public NativeArray<float> noises;
170199

200+
public NativeArray<float> distances;
171201
public NativeArray<Vector3> points;
202+
public NativeArray<float> intensities;
172203

173204
public void Execute(int index)
174205
{
175-
points[index] = directions[index] * (raycastHits[index].distance + noises[index]);
206+
float distance = raycastHits[index].distance + noises[index];
207+
bool isValid = (minDistance <= distance && distance <= maxDistance);
208+
if (!isValid) distance = 0;
209+
distances[index] = distance;
210+
points[index] = directions[index] * distance;
211+
float distance_sqr = distance * distance;
212+
intensities[index] = isValid ? maxIntensity * minDistance_sqr / distance_sqr : 0;
176213
}
177214
}
178215
}

Assets/UnitySensors/Runtime/Scripts/Sensors/TF.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using UnityEngine;
2+
using UnitySensors;
3+
4+
public class TFSensor : Sensor {
5+
6+
[ReadOnly]
7+
private Vector3 _position;
8+
9+
[ReadOnly]
10+
private Quaternion _rotation;
11+
12+
public Vector3 position { get => _position; }
13+
public Quaternion rotation { get => _rotation; }
14+
}

Assets/UnitySensors/Runtime/Scripts/Sensors/TF/TFSensor.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/UnitySensors/Runtime/Scripts/Utils/ScanPattern/CSVLiDARScanPattern/CSVLiDARScanPattern.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public override void GenerateScanPattern()
1919
_loadedFile = "";
2020
_maxAzimuth = _maxZenith = 0;
2121

22-
if(_file == null)
22+
if (_file == null)
2323
{
2424
Debug.LogWarning(this.name + ": CSV file is not set.");
2525
return;
@@ -70,8 +70,10 @@ public override void GenerateScanPattern()
7070
_size = lines.Length - 2;
7171

7272
_generated = true;
73+
#if UNITY_EDITOR
7374
EditorUtility.SetDirty(this);
7475
AssetDatabase.SaveAssets();
76+
#endif
7577
}
7678
}
7779
}

Assets/UnitySensors/Runtime/Scripts/Utils/ScanPattern/RotatingLiDARScanPattern/RotatingLiDARScanPattern.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ private enum RotationDirection
2424
private int _azimuthResolution = 360;
2525

2626
public int numOfLayer { get => _zenithAngles.Length; }
27+
public int azimuthResolution { get => _azimuthResolution; }
2728

2829
public override void GenerateScanPattern()
2930
{
@@ -35,11 +36,11 @@ public override void GenerateScanPattern()
3536
_scans = new Vector3[_size];
3637

3738
int index = 0;
38-
for(int azimuth = 0; azimuth < _azimuthResolution; azimuth++)
39+
for (int azimuth = 0; azimuth < _azimuthResolution; azimuth++)
3940
{
4041
float azimuthAngle = 360.0f / _azimuthResolution * azimuth;
4142
if (_rotationDirection == RotationDirection.CCW) azimuthAngle *= -1;
42-
foreach(float zenithAngle in _zenithAngles)
43+
foreach (float zenithAngle in _zenithAngles)
4344
{
4445
_scans[index] = Quaternion.Euler(-zenithAngle, azimuthAngle, 0) * Vector3.forward;
4546
index++;
@@ -54,8 +55,10 @@ public override void GenerateScanPattern()
5455

5556
_generated = true;
5657

58+
#if UNITY_EDITOR
5759
EditorUtility.SetDirty(this);
5860
AssetDatabase.SaveAssets();
61+
#endif
5962
}
6063
}
6164
}

Assets/UnitySensors/Samples/TF.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)