Skip to content

Commit c33247d

Browse files
authored
Merge pull request #145 from Field-Robotics-Japan/develop
Release new version
2 parents 655478c + 30c7854 commit c33247d

File tree

17 files changed

+289
-1708
lines changed

17 files changed

+289
-1708
lines changed

Assets/Test.unity

Lines changed: 0 additions & 1684 deletions
This file was deleted.
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
%YAML 1.1
2+
%TAG !u! tag:unity3d.com,2011:
3+
--- !u!1 &6658069106543365610
4+
GameObject:
5+
m_ObjectHideFlags: 0
6+
m_CorrespondingSourceObject: {fileID: 0}
7+
m_PrefabInstance: {fileID: 0}
8+
m_PrefabAsset: {fileID: 0}
9+
serializedVersion: 6
10+
m_Component:
11+
- component: {fileID: 6658069106543365612}
12+
- component: {fileID: 6658069106543365611}
13+
m_Layer: 0
14+
m_Name: GeoCoordinateSystem
15+
m_TagString: Untagged
16+
m_Icon: {fileID: 0}
17+
m_NavMeshLayer: 0
18+
m_StaticEditorFlags: 0
19+
m_IsActive: 1
20+
--- !u!4 &6658069106543365612
21+
Transform:
22+
m_ObjectHideFlags: 0
23+
m_CorrespondingSourceObject: {fileID: 0}
24+
m_PrefabInstance: {fileID: 0}
25+
m_PrefabAsset: {fileID: 0}
26+
m_GameObject: {fileID: 6658069106543365610}
27+
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
28+
m_LocalPosition: {x: 0, y: 0, z: 0}
29+
m_LocalScale: {x: 1, y: 1, z: 1}
30+
m_ConstrainProportionsScale: 0
31+
m_Children: []
32+
m_Father: {fileID: 0}
33+
m_RootOrder: 0
34+
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
35+
--- !u!114 &6658069106543365611
36+
MonoBehaviour:
37+
m_ObjectHideFlags: 0
38+
m_CorrespondingSourceObject: {fileID: 0}
39+
m_PrefabInstance: {fileID: 0}
40+
m_PrefabAsset: {fileID: 0}
41+
m_GameObject: {fileID: 6658069106543365610}
42+
m_Enabled: 1
43+
m_EditorHideFlags: 0
44+
m_Script: {fileID: 11500000, guid: 5f2116b7f84275c4d877f9ac14990716, type: 3}
45+
m_Name:
46+
m_EditorClassIdentifier:
47+
_coordinate:
48+
latitude: 35.71020206575301
49+
longitude: 139.81070039691542
50+
altitude: 3

Assets/Test.unity.meta renamed to Assets/UnitySensors/Runtime/Prefabs/GNSS/GeoCoordinateSystem.prefab.meta

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

Assets/UnitySensors/Runtime/Scripts/Sensors/GNSS/GNSSSensor.cs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ namespace UnitySensors.Sensor.GNSS
1010
public class GNSSSensor : UnitySensor
1111
{
1212
[SerializeField]
13-
private GeoCoordinate _baseCoordinate = new GeoCoordinate(35.71020206575301, 139.81070039691542, 3.0f);
13+
private GeoCoordinateSystem _coordinateSystem;
1414

1515
private Transform _transform;
1616
private GeoCoordinateConverter _gcc;
@@ -22,16 +22,11 @@ public class GNSSSensor : UnitySensor
2222
protected override void Init()
2323
{
2424
_transform = this.transform;
25-
_gcc = new GeoCoordinateConverter(_baseCoordinate.latitude, _baseCoordinate.longitude);
26-
_coordinate = new GeoCoordinate(_baseCoordinate.latitude, _baseCoordinate.longitude, _baseCoordinate.altitude);
2725
}
2826

2927
protected override void UpdateSensor()
3028
{
31-
Vector3 position = _transform.position;
32-
(_coordinate.latitude, _coordinate.longitude) = _gcc.XZ2LatLon(position.x, position.z);
33-
_coordinate.altitude = _baseCoordinate.altitude + position.y;
34-
29+
_coordinate = _coordinateSystem.GetCoordinate(_transform.position);
3530
if (onSensorUpdated != null)
3631
onSensorUpdated.Invoke();
3732
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
using System.Collections;
2+
using System.Collections.Generic;
3+
using UnityEngine;
4+
5+
using UnitySensors.Utils.GeoCoordinate;
6+
7+
namespace UnitySensors.Sensor.GNSS
8+
{
9+
public class GeoCoordinateSystem : MonoBehaviour
10+
{
11+
[SerializeField]
12+
private GeoCoordinate _coordinate = new GeoCoordinate(35.71020206575301, 139.81070039691542, 3.0f);
13+
14+
private Transform _transform;
15+
private GeoCoordinateConverter _converter;
16+
17+
private void Awake()
18+
{
19+
_transform = this.transform;
20+
_converter = new GeoCoordinateConverter(_coordinate.latitude, _coordinate.longitude);
21+
}
22+
23+
public GeoCoordinate GetCoordinate(Vector3 worldPosition)
24+
{
25+
Vector3 localPosition = _transform.InverseTransformPoint(worldPosition);
26+
double latitude, longitude;
27+
(latitude, longitude) = _converter.XZ2LatLon(localPosition.x, localPosition.z);
28+
return new GeoCoordinate(latitude, longitude, localPosition.y + _coordinate.altitude);
29+
}
30+
}
31+
}

Assets/UnitySensors/Runtime/Scripts/Sensors/GNSS/GeoCoordinateSystem.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/Sensors/TF/TF.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,15 @@ public TFData[] GetTFData(string frame_id_parent, Matrix4x4 worldToLocalMatrix,
5555
tfData_self.frame_id_parent = frame_id_parent;
5656
tfData_self.frame_id_child = _frame_id;
5757
tfData_self.position = (Vector3)(worldToLocalMatrix * new Vector4(_transform.position.x, _transform.position.y, _transform.position.z, 1.0f));
58+
Vector3 localScale = _transform.localScale;
59+
Vector3 lossyScale = _transform.lossyScale;
60+
Vector3 scaleVector = new Vector3()
61+
{
62+
x = localScale.x != 0 ? lossyScale.x / localScale.x : 0,
63+
y = localScale.y != 0 ? lossyScale.y / localScale.y : 0,
64+
z = localScale.z != 0 ? lossyScale.z / localScale.z : 0
65+
};
66+
tfData_self.position.Scale(scaleVector);
5867
tfData_self.rotation = worldToLocalQuaternion * _transform.rotation;
5968
tfData.Add(tfData_self);
6069

Assets/UnitySensors/Runtime/Scripts/Utils/GeoCoordinates/GeoCoordinates.cs renamed to Assets/UnitySensors/Runtime/Scripts/Utils/GeoCoordinates/GeoCoordinate.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
namespace UnitySensors.Utils.GeoCoordinate
22
{
33
[System.Serializable]
4-
public class GeoCoordinate
4+
public struct GeoCoordinate
55
{
66
public GeoCoordinate(double lat, double lon, double alt)
77
{

Assets/UnitySensors/Runtime/Scripts/Utils/GeoCoordinates/GeoCoordinates.cs.meta renamed to Assets/UnitySensors/Runtime/Scripts/Utils/GeoCoordinates/GeoCoordinate.cs.meta

File renamed without changes.

Assets/UnitySensors/Runtime/Scripts/Utils/GeoCoordinates/GeoCoordinatesConverter.cs renamed to Assets/UnitySensors/Runtime/Scripts/Utils/GeoCoordinates/GeoCoordinateConverter.cs

File renamed without changes.

0 commit comments

Comments
 (0)