-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Map component #110
base: development
Are you sure you want to change the base?
Map component #110
Changes from all commits
b792975
9a773e5
46ec3a0
ae4c7b3
b93cfc5
d0e0c92
86010bb
02d5e89
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
/* | ||
* Copyright (c) Contributors to the Open 3D Engine Project. | ||
* For complete copyright and license terms please see the LICENSE at the root of this distribution. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 OR MIT | ||
* | ||
*/ | ||
|
||
#include <AzCore/Component/ComponentApplicationBus.h> | ||
#include <AzCore/Component/TransformBus.h> | ||
#include <AzCore/StringFunc/StringFunc.h> | ||
#include <AzCore/Serialization/EditContext.h> | ||
|
||
#include "Map/GeodeticConfiguration.h" | ||
|
||
namespace ROS2::Map | ||
{ | ||
AZ::Outcome<void, AZStd::string> GeodeticConfiguration::ValidateHandle(void* newValue, [[maybe_unused]] const AZ::Uuid& valueType) | ||
{ | ||
// Check if the object type is valid | ||
if (azrtti_typeid<AZ::EntityId>() != valueType) | ||
{ | ||
AZ_Assert(false, "Unexpected value type"); | ||
return AZ::Failure(AZStd::string("Trying to set an entity ID to something that isn't an entity ID.")); | ||
} | ||
|
||
// Check if entity id is valid | ||
AZ::EntityId actualEntityId = *reinterpret_cast<AZ::EntityId*>(newValue); | ||
if (!actualEntityId.IsValid()) | ||
{ | ||
return AZ::Failure(AZStd::string("Invalid entity ID.")); | ||
} | ||
|
||
// Check if entity exists | ||
AZ::Entity* entity = nullptr; | ||
AZ::ComponentApplicationBus::BroadcastResult(entity, &AZ::ComponentApplicationBus::Events::FindEntity, actualEntityId); | ||
if (entity == nullptr) | ||
{ | ||
return AZ::Failure(AZStd::string("Can't find entity.")); | ||
} | ||
|
||
// Check if entity has transform | ||
AZ::TransformInterface* transformInterface = entity->GetTransform(); | ||
if (transformInterface == nullptr) | ||
{ | ||
return AZ::Failure(AZStd::string("Entity doesn't have transform component.")); | ||
} | ||
|
||
return AZ::Success(); | ||
} | ||
|
||
void GeodeticConfiguration::SetHook() | ||
{ | ||
if(m_useMapHook && !m_isMapHookSet) { | ||
if (!m_mapHook.IsValid()) { | ||
AZ_Warning("GeodeticConfiguration", false, "Map hook not set. Using identity on (0,0,0)."); | ||
} else { | ||
AZ::TransformBus::EventResult( | ||
m_mapHookTransform, | ||
m_mapHook, | ||
&AZ::TransformBus::Events::GetWorldTM); | ||
} | ||
m_isMapHookSet = true; | ||
} | ||
} | ||
|
||
bool GeodeticConfiguration::IsMapHookUsed() const | ||
{ | ||
return m_useMapHook; | ||
} | ||
|
||
void GeodeticConfiguration::Reflect(AZ::ReflectContext* context) | ||
{ | ||
if (auto serializeContext = azrtti_cast<AZ::SerializeContext*>(context)) | ||
{ | ||
serializeContext->Class<GeodeticConfiguration>() | ||
->Version(1) | ||
->Field("useMapHook", &GeodeticConfiguration::m_useMapHook) | ||
->Field("mapHook", &GeodeticConfiguration::m_mapHook) | ||
->Field("originLatitude", &GeodeticConfiguration::m_originLatitudeDeg) | ||
->Field("originLongitude", &GeodeticConfiguration::m_originLongitudeDeg) | ||
->Field("originAltitude", &GeodeticConfiguration::m_originAltitude) | ||
|
||
; | ||
|
||
if (AZ::EditContext* ec = serializeContext->GetEditContext()) | ||
{ | ||
ec->Class<GeodeticConfiguration>("Map configuration", "Map origin configuration") | ||
->DataElement(AZ::Edit::UIHandlers::Default, &GeodeticConfiguration::m_useMapHook, | ||
"Use map hook", "Should a map hook be used to position the scene in the world.") | ||
->Attribute(AZ::Edit::Attributes::ChangeNotify, AZ::Edit::PropertyRefreshLevels::EntireTree) | ||
->DataElement(AZ::Edit::UIHandlers::Default, &GeodeticConfiguration::m_mapHook, "Map hook", "Map origin handle.") | ||
->Attribute(AZ::Edit::Attributes::ChangeValidate, &GeodeticConfiguration::ValidateHandle) | ||
->Attribute(AZ::Edit::Attributes::Visibility, &GeodeticConfiguration::IsMapHookUsed) | ||
->DataElement(AZ::Edit::UIHandlers::Default, &GeodeticConfiguration::m_originLatitudeDeg, | ||
"Origin latitude", "Latitude position offset in degrees") | ||
->DataElement(AZ::Edit::UIHandlers::Default, &GeodeticConfiguration::m_originLongitudeDeg, | ||
"Origin longitude", "Longitude position offset in degrees") | ||
->DataElement(AZ::Edit::UIHandlers::Default, &GeodeticConfiguration::m_originAltitude, | ||
"Origin altitude", "Altitude position offset in meters") | ||
; | ||
} | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* Copyright (c) Contributors to the Open 3D Engine Project. | ||
* For complete copyright and license terms please see the LICENSE at the root of this distribution. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 OR MIT | ||
* | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <AzCore/Math/Transform.h> | ||
#include <AzCore/Component/Entity.h> | ||
#include <AzCore/std/string/string.h> | ||
|
||
namespace ROS2::Map | ||
{ | ||
//! Configuration for handling geodetic map info. | ||
//! This configuration allows setting a geographic coordinate system hook to a simulation scene. | ||
//! System hook points to the real-world location in latitude, longitude, and altitude offsets. | ||
class GeodeticConfiguration | ||
{ | ||
public: | ||
AZ_TYPE_INFO(GeodeticConfiguration, "{094e5059-698a-42ad-ae2d-36be20868004}"); | ||
|
||
static void Reflect(AZ::ReflectContext* context); | ||
|
||
//! Updates the hook Transform | ||
void SetHook(); | ||
|
||
bool m_useMapHook = false; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think members of this class should be made private. |
||
bool m_isMapHookSet = false; | ||
AZ::EntityId m_mapHook = AZ::EntityId{}; | ||
AZ::Transform m_mapHookTransform = AZ::Transform::CreateIdentity(); | ||
|
||
float m_originLatitudeDeg = 0.0f; | ||
float m_originLongitudeDeg = 0.0f; | ||
float m_originAltitude = 0.0f; | ||
|
||
private: | ||
AZ::Outcome<void, AZStd::string> ValidateHandle(void* newValue, [[maybe_unused]] const AZ::Uuid& valueType); | ||
bool IsMapHookUsed() const; | ||
}; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* | ||
* Copyright (c) Contributors to the Open 3D Engine Project. | ||
* For complete copyright and license terms please see the LICENSE at the root of this distribution. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 OR MIT | ||
* | ||
*/ | ||
#pragma once | ||
|
||
#include <AzCore/std/string/string.h> | ||
#include <AzCore/EBus/EBus.h> | ||
#include <AzCore/Math/Vector3.h> | ||
#include <AzCore/Math/Transform.h> | ||
#include <AzCore/Interface/Interface.h> | ||
|
||
namespace ROS2 | ||
{ | ||
class MapRequests | ||
{ | ||
public: | ||
AZ_RTTI(MapRequests, "{a95c07bd-d8d6-4e24-b089-e96d34d79ebb}"); | ||
virtual ~MapRequests() = default; | ||
|
||
//! Convert Transform to the map coordinate system. | ||
//! @param transform - Transform to be converted. | ||
//! @return Copy of a Transform in the map coordinate system. | ||
virtual AZ::Transform ConvertToMapCoordinateSystem(AZ::Transform transform) = 0; | ||
|
||
//! Convert Transform from the map coordinate system. | ||
//! @param transform - Transform to be converted. | ||
//! @return Copy of a Transform in the world coordinate system. | ||
virtual AZ::Transform ConvertFromMapCoordinateSystem(AZ::Transform transform) = 0; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. here and above, if transforms will not be changed in the overriding functions it will be better to use |
||
|
||
//! Convert the position vector in WorldTM to longitude, latitude, and altitude in the | ||
//! geographic coordinate system relative to the map frame. | ||
//! @param worldPosition - position vector to be converted. | ||
//! @return Vector where x: longitude, y: latitude, z: altitude. | ||
virtual AZ::Vector3 WorldPositionToLatLon(const AZ::Vector3 &worldPosition) = 0; | ||
|
||
//! Convert the geographic position relative to the map frame to the global o3de coordinate system. | ||
//! @param latLonAlt - geographic position in degrees, x: latitude, y: longitude, z: altitude. | ||
//! @return Vector where x: x position, y: y position, z: z position in o3de WorldTM. | ||
virtual AZ::Vector3 LatLonToWorldPosition(const AZ::Vector3 &latLonAlt) = 0; | ||
|
||
|
||
//! Get map frame id. | ||
//! @return Map frame id. | ||
virtual AZStd::string GetMapFrameId() = 0; | ||
|
||
//! Get odometry frame id. | ||
//! @return Odometry frame id. | ||
virtual AZStd::string GetOdomFrameId() = 0; | ||
}; | ||
|
||
class MapBusTraits | ||
: public AZ::EBusTraits | ||
{ | ||
public: | ||
////////////////////////////////////////////////////////////////////////// | ||
// EBusTraits overrides | ||
static constexpr AZ::EBusHandlerPolicy HandlerPolicy = AZ::EBusHandlerPolicy::Single; | ||
static constexpr AZ::EBusAddressPolicy AddressPolicy = AZ::EBusAddressPolicy::Single; | ||
////////////////////////////////////////////////////////////////////////// | ||
}; | ||
|
||
using MapRequestBus = AZ::EBus<MapRequests, MapBusTraits>; | ||
using MapRequestInterface = AZ::Interface<MapRequests>; | ||
|
||
} // namespace ROS2 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see any constructor defined for this class. Is it omitted on purpose?