Skip to content

Commit 3eb51b8

Browse files
authored
Georeference Component (o3de#604)
Added GeoreferenceBus and GeoreferenceLevelComponent. Signed-off-by: Michał Pełka <[email protected]>
1 parent 8cad131 commit 3eb51b8

22 files changed

+739
-269
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* Copyright (c) Contributors to the Open 3D Engine Project.
3+
* For complete copyright and license terms please see the LICENSE at the root of this distribution.
4+
*
5+
* SPDX-License-Identifier: Apache-2.0 OR MIT
6+
*
7+
*/
8+
#pragma once
9+
10+
#include "GeoreferenceStructures.h"
11+
#include <AzCore/Component/EntityId.h>
12+
#include <AzCore/EBus/EBus.h>
13+
#include <AzCore/Math/Vector3.h>
14+
#include <AzCore/Math/Quaternion.h>
15+
16+
namespace ROS2
17+
{
18+
//! Interface that allows to convert between level and WSG84 coordinates.
19+
class GeoreferenceRequests
20+
{
21+
public:
22+
23+
//! Function converts from Level's coordinate system to WSG84.
24+
//! @param xyz Vector3 in Level's coordinate system.
25+
//! @return Vector3 in WSG84 coordinate system as @class WGS::WGS84Coordinate.
26+
virtual WGS::WGS84Coordinate ConvertFromLevelToWSG84(const AZ::Vector3& xyz) = 0;
27+
28+
//! Function converts from WSG84 coordinate system to Level's.
29+
//! @param latLon Vector3 in WSG84 coordinate system, where x is latitude, y is longitude and z is altitude.
30+
//! @return Vector3 in Level's coordinate system.
31+
virtual AZ::Vector3 ConvertFromWSG84ToLevel(const WGS::WGS84Coordinate& latLon) = 0;
32+
33+
//! Function returns rotation from Level's frame to ENU's (East-North-Up) rotation.
34+
//! Function is useful to fin georeference rotation of the level.
35+
//! @return Quaternion in ENU coordinate system.
36+
virtual AZ::Quaternion GetRotationFromLevelToENU() = 0;
37+
};
38+
39+
class GeoreferenceRequestsTraits : public AZ::EBusTraits
40+
{
41+
public:
42+
// EBusTraits overrides ...
43+
static constexpr AZ::EBusHandlerPolicy HandlerPolicy = AZ::EBusHandlerPolicy::Single;
44+
static constexpr AZ::EBusAddressPolicy AddressPolicy = AZ::EBusAddressPolicy::Single;
45+
};
46+
47+
using GeoreferenceRequestsBus = AZ::EBus<GeoreferenceRequests, GeoreferenceRequestsTraits>;
48+
} // namespace ROS2
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* Copyright (c) Contributors to the Open 3D Engine Project.
3+
* For complete copyright and license terms please see the LICENSE at the root of this distribution.
4+
*
5+
* SPDX-License-Identifier: Apache-2.0 OR MIT
6+
*
7+
*/
8+
#pragma once
9+
10+
#include <AzCore/RTTI/RTTI.h>
11+
#include <AzCore/Math/Vector3.h>
12+
13+
namespace ROS2::WGS
14+
{
15+
16+
//! WGS84Coordinate is a 3D vector with double precision.
17+
//! It is used to represent coordinates in WSG84 coordinate system.
18+
struct WGS84Coordinate
19+
{
20+
AZ_RTTI(WGS84Coordinate, "{577a5637-b31a-44c5-a33f-50df2922af2a}");
21+
static void Reflect(AZ::ReflectContext* context);
22+
23+
WGS84Coordinate();
24+
virtual ~WGS84Coordinate() = default;
25+
26+
WGS84Coordinate(double latitude, double longitude, double altitude);
27+
explicit WGS84Coordinate(const AZ::Vector3& latLonAlt);
28+
29+
[[nodiscard]] AZ::Vector3 ToVector3f() const;
30+
31+
double m_latitude = 0.0; //!< Latitude in degrees.
32+
double m_longitude = 0.0; //!< Longitude in degrees.
33+
double m_altitude = 0.0; //!< Altitude in meters.
34+
};
35+
36+
//! Vector3d is a 3D vector with double precision.
37+
//! It is used to represent coordinates in ECEF or ENU coordinate systems.
38+
struct Vector3d{
39+
Vector3d() = default;
40+
Vector3d(double x, double y, double z);
41+
explicit Vector3d(const AZ::Vector3& xyz);
42+
[[nodiscard]] AZ::Vector3 ToVector3f() const;
43+
44+
Vector3d operator+(Vector3d const& v) const;
45+
Vector3d operator-(Vector3d const& v) const;
46+
47+
double m_x = 0.0; //!< X coordinate in meters.
48+
double m_y = 0.0; //! Y coordinate in meters.
49+
double m_z = 0.0; //! Z coordinate in meters.
50+
};
51+
}

Gems/ROS2/Code/Source/GNSS/GNSSFormatConversions.cpp

Lines changed: 0 additions & 107 deletions
This file was deleted.

Gems/ROS2/Code/Source/GNSS/GNSSSensorConfiguration.cpp

Lines changed: 0 additions & 47 deletions
This file was deleted.

Gems/ROS2/Code/Source/GNSS/GNSSSensorConfiguration.h

Lines changed: 0 additions & 26 deletions
This file was deleted.

Gems/ROS2/Code/Source/GNSS/ROS2GNSSSensorComponent.cpp

Lines changed: 17 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,14 @@
66
*
77
*/
88

9-
#include <AzCore/Math/Matrix4x4.h>
109
#include "ROS2GNSSSensorComponent.h"
10+
#include <AzCore/Math/Matrix4x4.h>
1111
#include <ROS2/Frame/ROS2FrameComponent.h>
1212
#include <ROS2/ROS2GemUtilities.h>
1313
#include <ROS2/Utilities/ROS2Names.h>
1414

15-
#include "GNSSFormatConversions.h"
15+
#include "Georeference/GNSSFormatConversions.h"
16+
#include <ROS2/Georeference/GeoreferenceBus.h>
1617

1718
namespace ROS2
1819
{
@@ -23,12 +24,9 @@ namespace ROS2
2324

2425
void ROS2GNSSSensorComponent::Reflect(AZ::ReflectContext* context)
2526
{
26-
GNSSSensorConfiguration::Reflect(context);
27-
2827
if (auto* serialize = azrtti_cast<AZ::SerializeContext*>(context))
2928
{
30-
serialize->Class<ROS2GNSSSensorComponent, SensorBaseType>()->Version(3)->Field(
31-
"gnssSensorConfiguration", &ROS2GNSSSensorComponent::m_gnssConfiguration);
29+
serialize->Class<ROS2GNSSSensorComponent, SensorBaseType>()->Version(4);
3230

3331
if (auto* editContext = serialize->GetEditContext())
3432
{
@@ -38,11 +36,6 @@ namespace ROS2
3836
->Attribute(AZ::Edit::Attributes::AppearsInAddComponentMenu, AZ_CRC_CE("Game"))
3937
->Attribute(AZ::Edit::Attributes::Icon, "Editor/Icons/Components/ROS2GNSSSensor.svg")
4038
->Attribute(AZ::Edit::Attributes::ViewportIcon, "Editor/Icons/Components/Viewport/ROS2GNSSSensor.svg")
41-
->DataElement(
42-
AZ::Edit::UIHandlers::Default,
43-
&ROS2GNSSSensorComponent::m_gnssConfiguration,
44-
"GNSS sensor configuration",
45-
"GNSS sensor configuration")
4639
->Attribute(AZ::Edit::Attributes::Visibility, AZ::Edit::PropertyVisibility::ShowChildrenOnly);
4740
}
4841
}
@@ -57,9 +50,7 @@ namespace ROS2
5750
m_sensorConfiguration.m_publishersConfigurations.insert(AZStd::make_pair(GNSSMsgType, pc));
5851
}
5952

60-
ROS2GNSSSensorComponent::ROS2GNSSSensorComponent(
61-
const SensorConfiguration& sensorConfiguration, const GNSSSensorConfiguration& gnssConfiguration)
62-
: m_gnssConfiguration(gnssConfiguration)
53+
ROS2GNSSSensorComponent::ROS2GNSSSensorComponent(const SensorConfiguration& sensorConfiguration)
6354
{
6455
m_sensorConfiguration = sensorConfiguration;
6556
}
@@ -95,25 +86,23 @@ namespace ROS2
9586

9687
void ROS2GNSSSensorComponent::FrequencyTick()
9788
{
98-
const AZ::Vector3 currentPosition = GetCurrentPose().GetTranslation();
99-
const AZ::Vector3 currentPositionECEF = GNSS::ENUToECEF(
100-
{ m_gnssConfiguration.m_originLatitudeDeg, m_gnssConfiguration.m_originLongitudeDeg, m_gnssConfiguration.m_originAltitude },
101-
currentPosition);
102-
const AZ::Vector3 currentPositionWGS84 = GNSS::ECEFToWGS84(currentPositionECEF);
10389

104-
m_gnssMsg.latitude = currentPositionWGS84.GetX();
105-
m_gnssMsg.longitude = currentPositionWGS84.GetY();
106-
m_gnssMsg.altitude = currentPositionWGS84.GetZ();
90+
AZ::Vector3 currentPosition{ 0.0f };
91+
AZ::TransformBus::EventResult(currentPosition, GetEntityId(), &AZ::TransformBus::Events::GetWorldTranslation);
92+
93+
WGS::WGS84Coordinate currentPositionWGS84;
94+
ROS2::GeoreferenceRequestsBus::BroadcastResult(
95+
currentPositionWGS84, &GeoreferenceRequests::ConvertFromLevelToWSG84, currentPosition);
96+
97+
m_gnssMsg.latitude = currentPositionWGS84.m_latitude;
98+
m_gnssMsg.longitude = currentPositionWGS84.m_longitude;
99+
m_gnssMsg.altitude = currentPositionWGS84.m_altitude;
107100

108101
m_gnssMsg.status.status = sensor_msgs::msg::NavSatStatus::STATUS_SBAS_FIX;
109-
m_gnssMsg.status.service = sensor_msgs::msg::NavSatStatus::SERVICE_GALILEO;
102+
m_gnssMsg.status.service = sensor_msgs::msg::NavSatStatus::SERVICE_GPS;
110103

111104
m_gnssPublisher->publish(m_gnssMsg);
112105
}
113106

114-
AZ::Transform ROS2GNSSSensorComponent::GetCurrentPose() const
115-
{
116-
auto* ros2Frame = Utils::GetGameOrEditorComponent<ROS2FrameComponent>(GetEntity());
117-
return ros2Frame->GetFrameTransform();
118-
}
107+
119108
} // namespace ROS2

0 commit comments

Comments
 (0)