From 53e80855edfb6e6919761d96ab021eda2d1e4c97 Mon Sep 17 00:00:00 2001 From: Autumn60 Date: Sat, 17 Feb 2024 00:23:05 +0900 Subject: [PATCH 1/3] Change GeoCoordinate to struct and Fix file names --- .../GeoCoordinates/{GeoCoordinates.cs => GeoCoordinate.cs} | 2 +- .../{GeoCoordinates.cs.meta => GeoCoordinate.cs.meta} | 0 .../{GeoCoordinatesConverter.cs => GeoCoordinateConverter.cs} | 0 ...rdinatesConverter.cs.meta => GeoCoordinateConverter.cs.meta} | 0 4 files changed, 1 insertion(+), 1 deletion(-) rename Assets/UnitySensors/Runtime/Scripts/Utils/GeoCoordinates/{GeoCoordinates.cs => GeoCoordinate.cs} (91%) rename Assets/UnitySensors/Runtime/Scripts/Utils/GeoCoordinates/{GeoCoordinates.cs.meta => GeoCoordinate.cs.meta} (100%) rename Assets/UnitySensors/Runtime/Scripts/Utils/GeoCoordinates/{GeoCoordinatesConverter.cs => GeoCoordinateConverter.cs} (100%) rename Assets/UnitySensors/Runtime/Scripts/Utils/GeoCoordinates/{GeoCoordinatesConverter.cs.meta => GeoCoordinateConverter.cs.meta} (100%) diff --git a/Assets/UnitySensors/Runtime/Scripts/Utils/GeoCoordinates/GeoCoordinates.cs b/Assets/UnitySensors/Runtime/Scripts/Utils/GeoCoordinates/GeoCoordinate.cs similarity index 91% rename from Assets/UnitySensors/Runtime/Scripts/Utils/GeoCoordinates/GeoCoordinates.cs rename to Assets/UnitySensors/Runtime/Scripts/Utils/GeoCoordinates/GeoCoordinate.cs index ceba08e2..40afbcfa 100644 --- a/Assets/UnitySensors/Runtime/Scripts/Utils/GeoCoordinates/GeoCoordinates.cs +++ b/Assets/UnitySensors/Runtime/Scripts/Utils/GeoCoordinates/GeoCoordinate.cs @@ -1,7 +1,7 @@ namespace UnitySensors.Utils.GeoCoordinate { [System.Serializable] - public class GeoCoordinate + public struct GeoCoordinate { public GeoCoordinate(double lat, double lon, double alt) { diff --git a/Assets/UnitySensors/Runtime/Scripts/Utils/GeoCoordinates/GeoCoordinates.cs.meta b/Assets/UnitySensors/Runtime/Scripts/Utils/GeoCoordinates/GeoCoordinate.cs.meta similarity index 100% rename from Assets/UnitySensors/Runtime/Scripts/Utils/GeoCoordinates/GeoCoordinates.cs.meta rename to Assets/UnitySensors/Runtime/Scripts/Utils/GeoCoordinates/GeoCoordinate.cs.meta diff --git a/Assets/UnitySensors/Runtime/Scripts/Utils/GeoCoordinates/GeoCoordinatesConverter.cs b/Assets/UnitySensors/Runtime/Scripts/Utils/GeoCoordinates/GeoCoordinateConverter.cs similarity index 100% rename from Assets/UnitySensors/Runtime/Scripts/Utils/GeoCoordinates/GeoCoordinatesConverter.cs rename to Assets/UnitySensors/Runtime/Scripts/Utils/GeoCoordinates/GeoCoordinateConverter.cs diff --git a/Assets/UnitySensors/Runtime/Scripts/Utils/GeoCoordinates/GeoCoordinatesConverter.cs.meta b/Assets/UnitySensors/Runtime/Scripts/Utils/GeoCoordinates/GeoCoordinateConverter.cs.meta similarity index 100% rename from Assets/UnitySensors/Runtime/Scripts/Utils/GeoCoordinates/GeoCoordinatesConverter.cs.meta rename to Assets/UnitySensors/Runtime/Scripts/Utils/GeoCoordinates/GeoCoordinateConverter.cs.meta From 21d849a75e4d919b0d08db34cdf0cddc92f204d0 Mon Sep 17 00:00:00 2001 From: Autumn60 Date: Sat, 17 Feb 2024 00:23:19 +0900 Subject: [PATCH 2/3] Update GNSSSensor --- .../Scripts/Sensors/GNSS/GNSSSensor.cs | 9 ++---- .../Sensors/GNSS/GeoCoordinateSystem.cs | 31 +++++++++++++++++++ .../Sensors/GNSS/GeoCoordinateSystem.cs.meta | 11 +++++++ 3 files changed, 44 insertions(+), 7 deletions(-) create mode 100644 Assets/UnitySensors/Runtime/Scripts/Sensors/GNSS/GeoCoordinateSystem.cs create mode 100644 Assets/UnitySensors/Runtime/Scripts/Sensors/GNSS/GeoCoordinateSystem.cs.meta diff --git a/Assets/UnitySensors/Runtime/Scripts/Sensors/GNSS/GNSSSensor.cs b/Assets/UnitySensors/Runtime/Scripts/Sensors/GNSS/GNSSSensor.cs index be21ad84..b9f366b6 100644 --- a/Assets/UnitySensors/Runtime/Scripts/Sensors/GNSS/GNSSSensor.cs +++ b/Assets/UnitySensors/Runtime/Scripts/Sensors/GNSS/GNSSSensor.cs @@ -10,7 +10,7 @@ namespace UnitySensors.Sensor.GNSS public class GNSSSensor : UnitySensor { [SerializeField] - private GeoCoordinate _baseCoordinate = new GeoCoordinate(35.71020206575301, 139.81070039691542, 3.0f); + private GeoCoordinateSystem _coordinateSystem; private Transform _transform; private GeoCoordinateConverter _gcc; @@ -22,16 +22,11 @@ public class GNSSSensor : UnitySensor protected override void Init() { _transform = this.transform; - _gcc = new GeoCoordinateConverter(_baseCoordinate.latitude, _baseCoordinate.longitude); - _coordinate = new GeoCoordinate(_baseCoordinate.latitude, _baseCoordinate.longitude, _baseCoordinate.altitude); } protected override void UpdateSensor() { - Vector3 position = _transform.position; - (_coordinate.latitude, _coordinate.longitude) = _gcc.XZ2LatLon(position.x, position.z); - _coordinate.altitude = _baseCoordinate.altitude + position.y; - + _coordinate = _coordinateSystem.GetCoordinate(_transform.position); if (onSensorUpdated != null) onSensorUpdated.Invoke(); } diff --git a/Assets/UnitySensors/Runtime/Scripts/Sensors/GNSS/GeoCoordinateSystem.cs b/Assets/UnitySensors/Runtime/Scripts/Sensors/GNSS/GeoCoordinateSystem.cs new file mode 100644 index 00000000..8484b257 --- /dev/null +++ b/Assets/UnitySensors/Runtime/Scripts/Sensors/GNSS/GeoCoordinateSystem.cs @@ -0,0 +1,31 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +using UnitySensors.Utils.GeoCoordinate; + +namespace UnitySensors.Sensor.GNSS +{ + public class GeoCoordinateSystem : MonoBehaviour + { + [SerializeField] + private GeoCoordinate _coordinate = new GeoCoordinate(35.71020206575301, 139.81070039691542, 3.0f); + + private Transform _transform; + private GeoCoordinateConverter _converter; + + private void Awake() + { + _transform = this.transform; + _converter = new GeoCoordinateConverter(_coordinate.latitude, _coordinate.longitude); + } + + public GeoCoordinate GetCoordinate(Vector3 worldPosition) + { + Vector3 localPosition = _transform.InverseTransformPoint(worldPosition); + double latitude, longitude; + (latitude, longitude) = _converter.XZ2LatLon(localPosition.x, localPosition.z); + return new GeoCoordinate(latitude, longitude, localPosition.y + _coordinate.altitude); + } + } +} \ No newline at end of file diff --git a/Assets/UnitySensors/Runtime/Scripts/Sensors/GNSS/GeoCoordinateSystem.cs.meta b/Assets/UnitySensors/Runtime/Scripts/Sensors/GNSS/GeoCoordinateSystem.cs.meta new file mode 100644 index 00000000..867353f6 --- /dev/null +++ b/Assets/UnitySensors/Runtime/Scripts/Sensors/GNSS/GeoCoordinateSystem.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 5f2116b7f84275c4d877f9ac14990716 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: From d21c4fef0547a1babc936e23a7292725ac179b2d Mon Sep 17 00:00:00 2001 From: Autumn60 Date: Sat, 17 Feb 2024 00:23:39 +0900 Subject: [PATCH 3/3] Update prefab and demo --- .../Prefabs/GNSS/GeoCoordinateSystem.prefab | 50 +++++++++++ .../GNSS/GeoCoordinateSystem.prefab.meta | 7 ++ .../UnitySensors/Samples/GNSS/Demo_GNSS.unity | 86 +++++++++++++++++++ .../Runtime/Prefabs/GNSS/GNSS_ros.prefab | 15 ++-- .../Samples/GNSS/Demo_GNSS_ros.unity | 86 +++++++++++++++++++ 5 files changed, 235 insertions(+), 9 deletions(-) create mode 100644 Assets/UnitySensors/Runtime/Prefabs/GNSS/GeoCoordinateSystem.prefab create mode 100644 Assets/UnitySensors/Runtime/Prefabs/GNSS/GeoCoordinateSystem.prefab.meta diff --git a/Assets/UnitySensors/Runtime/Prefabs/GNSS/GeoCoordinateSystem.prefab b/Assets/UnitySensors/Runtime/Prefabs/GNSS/GeoCoordinateSystem.prefab new file mode 100644 index 00000000..ac987642 --- /dev/null +++ b/Assets/UnitySensors/Runtime/Prefabs/GNSS/GeoCoordinateSystem.prefab @@ -0,0 +1,50 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!1 &6658069106543365610 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 6658069106543365612} + - component: {fileID: 6658069106543365611} + m_Layer: 0 + m_Name: GeoCoordinateSystem + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &6658069106543365612 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 6658069106543365610} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_ConstrainProportionsScale: 0 + m_Children: [] + m_Father: {fileID: 0} + m_RootOrder: 0 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!114 &6658069106543365611 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 6658069106543365610} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 5f2116b7f84275c4d877f9ac14990716, type: 3} + m_Name: + m_EditorClassIdentifier: + _coordinate: + latitude: 35.71020206575301 + longitude: 139.81070039691542 + altitude: 3 diff --git a/Assets/UnitySensors/Runtime/Prefabs/GNSS/GeoCoordinateSystem.prefab.meta b/Assets/UnitySensors/Runtime/Prefabs/GNSS/GeoCoordinateSystem.prefab.meta new file mode 100644 index 00000000..78a6cac6 --- /dev/null +++ b/Assets/UnitySensors/Runtime/Prefabs/GNSS/GeoCoordinateSystem.prefab.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: bfbdcabf0c3de544d92e2b824ec5a3a6 +PrefabImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/UnitySensors/Samples/GNSS/Demo_GNSS.unity b/Assets/UnitySensors/Samples/GNSS/Demo_GNSS.unity index cb092eda..a27b26fd 100644 --- a/Assets/UnitySensors/Samples/GNSS/Demo_GNSS.unity +++ b/Assets/UnitySensors/Samples/GNSS/Demo_GNSS.unity @@ -123,6 +123,18 @@ NavMeshSettings: debug: m_Flags: 0 m_NavMeshData: {fileID: 0} +--- !u!114 &2054003459 stripped +MonoBehaviour: + m_CorrespondingSourceObject: {fileID: 6658069106543365611, guid: bfbdcabf0c3de544d92e2b824ec5a3a6, + type: 3} + m_PrefabInstance: {fileID: 6658069108059838184} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 5f2116b7f84275c4d877f9ac14990716, type: 3} + m_Name: + m_EditorClassIdentifier: --- !u!1001 &6460962622283155330 PrefabInstance: m_ObjectHideFlags: 0 @@ -135,6 +147,11 @@ PrefabInstance: propertyPath: m_Name value: GNSS objectReference: {fileID: 0} + - target: {fileID: 6460962621012238590, guid: a0db7cd58a019da4d84328d3f8cb748a, + type: 3} + propertyPath: _coordinateSystem + value: + objectReference: {fileID: 2054003459} - target: {fileID: 6460962621012238591, guid: a0db7cd58a019da4d84328d3f8cb748a, type: 3} propertyPath: m_RootOrder @@ -192,3 +209,72 @@ PrefabInstance: objectReference: {fileID: 0} m_RemovedComponents: [] m_SourcePrefab: {fileID: 100100000, guid: a0db7cd58a019da4d84328d3f8cb748a, type: 3} +--- !u!1001 &6658069108059838184 +PrefabInstance: + m_ObjectHideFlags: 0 + serializedVersion: 2 + m_Modification: + m_TransformParent: {fileID: 0} + m_Modifications: + - target: {fileID: 6658069106543365610, guid: bfbdcabf0c3de544d92e2b824ec5a3a6, + type: 3} + propertyPath: m_Name + value: GeoCoordinateSystem + objectReference: {fileID: 0} + - target: {fileID: 6658069106543365612, guid: bfbdcabf0c3de544d92e2b824ec5a3a6, + type: 3} + propertyPath: m_RootOrder + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 6658069106543365612, guid: bfbdcabf0c3de544d92e2b824ec5a3a6, + type: 3} + propertyPath: m_LocalPosition.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 6658069106543365612, guid: bfbdcabf0c3de544d92e2b824ec5a3a6, + type: 3} + propertyPath: m_LocalPosition.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 6658069106543365612, guid: bfbdcabf0c3de544d92e2b824ec5a3a6, + type: 3} + propertyPath: m_LocalPosition.z + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 6658069106543365612, guid: bfbdcabf0c3de544d92e2b824ec5a3a6, + type: 3} + propertyPath: m_LocalRotation.w + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 6658069106543365612, guid: bfbdcabf0c3de544d92e2b824ec5a3a6, + type: 3} + propertyPath: m_LocalRotation.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 6658069106543365612, guid: bfbdcabf0c3de544d92e2b824ec5a3a6, + type: 3} + propertyPath: m_LocalRotation.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 6658069106543365612, guid: bfbdcabf0c3de544d92e2b824ec5a3a6, + type: 3} + propertyPath: m_LocalRotation.z + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 6658069106543365612, guid: bfbdcabf0c3de544d92e2b824ec5a3a6, + type: 3} + propertyPath: m_LocalEulerAnglesHint.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 6658069106543365612, guid: bfbdcabf0c3de544d92e2b824ec5a3a6, + type: 3} + propertyPath: m_LocalEulerAnglesHint.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 6658069106543365612, guid: bfbdcabf0c3de544d92e2b824ec5a3a6, + type: 3} + propertyPath: m_LocalEulerAnglesHint.z + value: 0 + objectReference: {fileID: 0} + m_RemovedComponents: [] + m_SourcePrefab: {fileID: 100100000, guid: bfbdcabf0c3de544d92e2b824ec5a3a6, type: 3} diff --git a/Assets/UnitySensorsROS/Runtime/Prefabs/GNSS/GNSS_ros.prefab b/Assets/UnitySensorsROS/Runtime/Prefabs/GNSS/GNSS_ros.prefab index b4f59d85..67a6d7cc 100644 --- a/Assets/UnitySensorsROS/Runtime/Prefabs/GNSS/GNSS_ros.prefab +++ b/Assets/UnitySensorsROS/Runtime/Prefabs/GNSS/GNSS_ros.prefab @@ -10,7 +10,7 @@ GameObject: m_Component: - component: {fileID: 3192925013080293983} - component: {fileID: 3192925013080293982} - - component: {fileID: 3192925013080293981} + - component: {fileID: 3192925012673096858} m_Layer: 0 m_Name: GNSS_ros m_TagString: Untagged @@ -46,15 +46,12 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: _frequency: 10 - _baseCoordinate: - latitude: 35.71020206575301 - longitude: 139.81070039691542 - altitude: 3 + _coordinateSystem: {fileID: 0} _coordinate: latitude: 0 longitude: 0 altitude: 0 ---- !u!114 &3192925013080293981 +--- !u!114 &3192925012673096858 MonoBehaviour: m_ObjectHideFlags: 0 m_CorrespondingSourceObject: {fileID: 0} @@ -63,13 +60,13 @@ MonoBehaviour: m_GameObject: {fileID: 3192925013080293980} m_Enabled: 1 m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 397c445553a6f3a40ac4d6892894ff7f, type: 3} + m_Script: {fileID: 11500000, guid: c11ec5602b9e12544b78d1d2a4bdd5c6, type: 3} m_Name: m_EditorClassIdentifier: _frequency: 10 - _topicName: /navsat/fix + _topicName: navsat _serializer: _header: - _frame_id: /gnss_link + _frame_id: map _status: 1 _service: 0 diff --git a/Assets/UnitySensorsROS/Samples/GNSS/Demo_GNSS_ros.unity b/Assets/UnitySensorsROS/Samples/GNSS/Demo_GNSS_ros.unity index f26b1f9a..4c17a0cf 100644 --- a/Assets/UnitySensorsROS/Samples/GNSS/Demo_GNSS_ros.unity +++ b/Assets/UnitySensorsROS/Samples/GNSS/Demo_GNSS_ros.unity @@ -123,6 +123,87 @@ NavMeshSettings: debug: m_Flags: 0 m_NavMeshData: {fileID: 0} +--- !u!1001 &2000407512 +PrefabInstance: + m_ObjectHideFlags: 0 + serializedVersion: 2 + m_Modification: + m_TransformParent: {fileID: 0} + m_Modifications: + - target: {fileID: 6658069106543365610, guid: bfbdcabf0c3de544d92e2b824ec5a3a6, + type: 3} + propertyPath: m_Name + value: GeoCoordinateSystem + objectReference: {fileID: 0} + - target: {fileID: 6658069106543365612, guid: bfbdcabf0c3de544d92e2b824ec5a3a6, + type: 3} + propertyPath: m_RootOrder + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 6658069106543365612, guid: bfbdcabf0c3de544d92e2b824ec5a3a6, + type: 3} + propertyPath: m_LocalPosition.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 6658069106543365612, guid: bfbdcabf0c3de544d92e2b824ec5a3a6, + type: 3} + propertyPath: m_LocalPosition.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 6658069106543365612, guid: bfbdcabf0c3de544d92e2b824ec5a3a6, + type: 3} + propertyPath: m_LocalPosition.z + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 6658069106543365612, guid: bfbdcabf0c3de544d92e2b824ec5a3a6, + type: 3} + propertyPath: m_LocalRotation.w + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 6658069106543365612, guid: bfbdcabf0c3de544d92e2b824ec5a3a6, + type: 3} + propertyPath: m_LocalRotation.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 6658069106543365612, guid: bfbdcabf0c3de544d92e2b824ec5a3a6, + type: 3} + propertyPath: m_LocalRotation.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 6658069106543365612, guid: bfbdcabf0c3de544d92e2b824ec5a3a6, + type: 3} + propertyPath: m_LocalRotation.z + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 6658069106543365612, guid: bfbdcabf0c3de544d92e2b824ec5a3a6, + type: 3} + propertyPath: m_LocalEulerAnglesHint.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 6658069106543365612, guid: bfbdcabf0c3de544d92e2b824ec5a3a6, + type: 3} + propertyPath: m_LocalEulerAnglesHint.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 6658069106543365612, guid: bfbdcabf0c3de544d92e2b824ec5a3a6, + type: 3} + propertyPath: m_LocalEulerAnglesHint.z + value: 0 + objectReference: {fileID: 0} + m_RemovedComponents: [] + m_SourcePrefab: {fileID: 100100000, guid: bfbdcabf0c3de544d92e2b824ec5a3a6, type: 3} +--- !u!114 &2000407513 stripped +MonoBehaviour: + m_CorrespondingSourceObject: {fileID: 6658069106543365611, guid: bfbdcabf0c3de544d92e2b824ec5a3a6, + type: 3} + m_PrefabInstance: {fileID: 2000407512} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 5f2116b7f84275c4d877f9ac14990716, type: 3} + m_Name: + m_EditorClassIdentifier: --- !u!1001 &3192925012673096856 PrefabInstance: m_ObjectHideFlags: 0 @@ -135,6 +216,11 @@ PrefabInstance: propertyPath: m_Name value: GNSS_ros objectReference: {fileID: 0} + - target: {fileID: 3192925013080293982, guid: 6c364f20083a9cf4c8e7a2c139d4c571, + type: 3} + propertyPath: _coordinateSystem + value: + objectReference: {fileID: 2000407513} - target: {fileID: 3192925013080293983, guid: 6c364f20083a9cf4c8e7a2c139d4c571, type: 3} propertyPath: m_RootOrder