Skip to content

Commit

Permalink
Constructors with parameters in ROS2SensorComponents (#433)
Browse files Browse the repository at this point in the history
* pass config to ROS2CameraSensorEditorComponent
* pass config to ROS2GNSSSensorComponent
* pass config to ROS2LidarSensorComponent and ROS2Lidar2DSensorComponent
* pass config to ROS2ImuSensorComponent
* modify editor view: ShowChildrenOnly
* update prefabs to new format
* EN_UK -> EN_US: visualise -> visualize
---------
Signed-off-by: Jan Hanca <[email protected]>
  • Loading branch information
jhanca-robotecai authored Aug 8, 2023
1 parent 3d40c2d commit 76e6569
Show file tree
Hide file tree
Showing 28 changed files with 814 additions and 480 deletions.
6 changes: 3 additions & 3 deletions Gems/ROS2/Code/Include/ROS2/Sensor/ROS2SensorComponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ namespace ROS2
virtual void FrequencyTick(){};

private:
//! Visualise sensor operation.
//! Visualize sensor operation.
//! For example, draw points or rays for a lidar, viewport for a camera, etc.
//! Visualisation can be turned on or off in SensorConfiguration.
virtual void Visualise(){};
//! Visualization can be turned on or off in SensorConfiguration.
virtual void Visualize(){};

//! The number of ticks that are expected to pass to trigger next measurement.
AZ::s32 m_tickCountDown{ 0 };
Expand Down
4 changes: 2 additions & 2 deletions Gems/ROS2/Code/Include/ROS2/Sensor/SensorConfiguration.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace ROS2
{
//! General configuration for sensors.
//! All sensors can be set to a certain frequency, have their data published or not,
//! and visualised or not.
//! and visualized or not.
struct SensorConfiguration
{
public:
Expand All @@ -34,7 +34,7 @@ namespace ROS2
float m_frequency = 10;

bool m_publishingEnabled = true; //!< Determines whether the sensor is publishing (sending data to ROS 2 ecosystem).
bool m_visualise = true; //!< Determines whether the sensor is visualised in O3DE (for example, point cloud is drawn for LIDAR).
bool m_visualize = true; //!< Determines whether the sensor is visualized in O3DE (for example, point cloud is drawn for LIDAR).
private:
// Frequency limit is once per day.
static constexpr float m_minFrequency = AZStd::numeric_limits<float>::epsilon();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ namespace ROS2
void ROS2CameraSensorEditorComponent::DisplayEntityViewport(
[[maybe_unused]] const AzFramework::ViewportInfo& viewportInfo, AzFramework::DebugDisplayRequests& debugDisplay)
{
if (!m_sensorConfiguration.m_visualise)
if (!m_sensorConfiguration.m_visualize)
{
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ namespace ROS2

AZStd::pair<AZStd::string, TopicConfiguration> MakeTopicConfigurationPair(
const AZStd::string& topic, const AZStd::string& messageType, const AZStd::string& configName) const;

SensorConfiguration m_sensorConfiguration;
CameraSensorConfiguration m_cameraSensorConfiguration;
};
Expand Down
47 changes: 47 additions & 0 deletions Gems/ROS2/Code/Source/GNSS/GNSSSensorConfiguration.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* 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 "GNSSSensorConfiguration.h"
#include <AzCore/Serialization/EditContext.h>
#include <AzCore/Serialization/EditContextConstants.inl>

namespace ROS2
{
void GNSSSensorConfiguration::Reflect(AZ::ReflectContext* context)
{
if (AZ::SerializeContext* serialize = azrtti_cast<AZ::SerializeContext*>(context))
{
serialize->Class<GNSSSensorConfiguration>()
->Version(1)
->Field("originLatitude", &GNSSSensorConfiguration::m_originLatitudeDeg)
->Field("originLongitude", &GNSSSensorConfiguration::m_originLongitudeDeg)
->Field("originAltitude", &GNSSSensorConfiguration::m_originAltitude);

if (AZ::EditContext* ec = serialize->GetEditContext())
{
ec->Class<GNSSSensorConfiguration>("ROS2 GNSS Sensor", "GNSS sensor component")
->DataElement(
AZ::Edit::UIHandlers::Default,
&GNSSSensorConfiguration::m_originLatitudeDeg,
"Latitude offset",
"GNSS latitude position offset in degrees")
->DataElement(
AZ::Edit::UIHandlers::Default,
&GNSSSensorConfiguration::m_originLongitudeDeg,
"Longitude offset",
"GNSS longitude position offset in degrees")
->DataElement(
AZ::Edit::UIHandlers::Default,
&GNSSSensorConfiguration::m_originAltitude,
"Altitude offset",
"GNSS altitude position offset in meters");
}
}
}

} // namespace ROS2
26 changes: 26 additions & 0 deletions Gems/ROS2/Code/Source/GNSS/GNSSSensorConfiguration.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* 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/RTTI/RTTI.h>
#include <AzCore/Serialization/SerializeContext.h>
#include <AzCore/std/string/string.h>

namespace ROS2
{
//! A structure capturing configuration of a Global Navigation Satellite Systems (GNSS) sensor.
struct GNSSSensorConfiguration
{
AZ_TYPE_INFO(GNSSSensorConfiguration, "{8bc39c6b-2f2c-4612-bcc7-0cc7033001d4}");
static void Reflect(AZ::ReflectContext* context);

float m_originLatitudeDeg = 0.0f;
float m_originLongitudeDeg = 0.0f;
float m_originAltitude = 0.0f;
};
} // namespace ROS2
38 changes: 18 additions & 20 deletions Gems/ROS2/Code/Source/GNSS/ROS2GNSSSensorComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,12 @@ namespace ROS2

void ROS2GNSSSensorComponent::Reflect(AZ::ReflectContext* context)
{
GNSSSensorConfiguration::Reflect(context);

if (AZ::SerializeContext* serialize = azrtti_cast<AZ::SerializeContext*>(context))
{
serialize->Class<ROS2GNSSSensorComponent, ROS2SensorComponent>()
->Version(1)
->Field("gnssOriginLatitude", &ROS2GNSSSensorComponent::m_gnssOriginLatitudeDeg)
->Field("gnssOriginLongitude", &ROS2GNSSSensorComponent::m_gnssOriginLongitudeDeg)
->Field("gnssOriginAltitude", &ROS2GNSSSensorComponent::m_gnssOriginAltitude);
serialize->Class<ROS2GNSSSensorComponent, ROS2SensorComponent>()->Version(2)->Field(
"gnssSensorConfiguration", &ROS2GNSSSensorComponent::m_gnssConfiguration);

if (AZ::EditContext* ec = serialize->GetEditContext())
{
Expand All @@ -44,19 +43,10 @@ namespace ROS2
->Attribute(AZ::Edit::Attributes::AppearsInAddComponentMenu, AZ_CRC_CE("Game"))
->DataElement(
AZ::Edit::UIHandlers::Default,
&ROS2GNSSSensorComponent::m_gnssOriginLatitudeDeg,
"Latitude offset",
"GNSS latitude position offset in degrees")
->DataElement(
AZ::Edit::UIHandlers::Default,
&ROS2GNSSSensorComponent::m_gnssOriginLongitudeDeg,
"Longitude offset",
"GNSS longitude position offset in degrees")
->DataElement(
AZ::Edit::UIHandlers::Default,
&ROS2GNSSSensorComponent::m_gnssOriginAltitude,
"Altitude offset",
"GNSS altitude position offset in meters");
&ROS2GNSSSensorComponent::m_gnssConfiguration,
"GNSS sensor configuration",
"GNSS sensor configuration")
->Attribute(AZ::Edit::Attributes::Visibility, AZ::Edit::PropertyVisibility::ShowChildrenOnly);
}
}
}
Expand All @@ -70,6 +60,13 @@ namespace ROS2
m_sensorConfiguration.m_publishersConfigurations.insert(AZStd::make_pair(Internal::kGNSSMsgType, pc));
}

ROS2GNSSSensorComponent::ROS2GNSSSensorComponent(
const SensorConfiguration& sensorConfiguration, const GNSSSensorConfiguration& gnssConfiguration)
: m_gnssConfiguration(gnssConfiguration)
{
m_sensorConfiguration = sensorConfiguration;
}

void ROS2GNSSSensorComponent::Activate()
{
ROS2SensorComponent::Activate();
Expand All @@ -92,8 +89,9 @@ namespace ROS2
void ROS2GNSSSensorComponent::FrequencyTick()
{
const AZ::Vector3 currentPosition = GetCurrentPose().GetTranslation();
const AZ::Vector3 currentPositionECEF =
GNSS::ENUToECEF({ m_gnssOriginLatitudeDeg, m_gnssOriginLongitudeDeg, m_gnssOriginAltitude }, currentPosition);
const AZ::Vector3 currentPositionECEF = GNSS::ENUToECEF(
{ m_gnssConfiguration.m_originLatitudeDeg, m_gnssConfiguration.m_originLongitudeDeg, m_gnssConfiguration.m_originAltitude },
currentPosition);
const AZ::Vector3 currentPositionWGS84 = GNSS::ECEFToWGS84(currentPositionECEF);

m_gnssMsg.latitude = currentPositionWGS84.GetX();
Expand Down
7 changes: 4 additions & 3 deletions Gems/ROS2/Code/Source/GNSS/ROS2GNSSSensorComponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
#include <rclcpp/publisher.hpp>
#include <sensor_msgs/msg/nav_sat_fix.hpp>

#include "GNSSSensorConfiguration.h"

namespace ROS2
{
//! Global Navigation Satellite Systems (GNSS) sensor component class
Expand All @@ -24,6 +26,7 @@ namespace ROS2
public:
AZ_COMPONENT(ROS2GNSSSensorComponent, "{55B4A299-7FA3-496A-88F0-764C75B0E9A7}", ROS2SensorComponent);
ROS2GNSSSensorComponent();
ROS2GNSSSensorComponent(const SensorConfiguration& sensorConfiguration, const GNSSSensorConfiguration& gnssConfiguration);
~ROS2GNSSSensorComponent() = default;
static void Reflect(AZ::ReflectContext* context);
//////////////////////////////////////////////////////////////////////////
Expand All @@ -33,9 +36,7 @@ namespace ROS2
//////////////////////////////////////////////////////////////////////////

private:
float m_gnssOriginLatitudeDeg = 0.0f;
float m_gnssOriginLongitudeDeg = 0.0f;
float m_gnssOriginAltitude = 0.0f;
GNSSSensorConfiguration m_gnssConfiguration;

//////////////////////////////////////////////////////////////////////////
// ROS2SensorComponent overrides
Expand Down
67 changes: 67 additions & 0 deletions Gems/ROS2/Code/Source/Imu/ImuSensorConfiguration.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* 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 "ImuSensorConfiguration.h"
#include <AzCore/Serialization/EditContext.h>
#include <AzCore/Serialization/EditContextConstants.inl>

namespace ROS2
{
void ImuSensorConfiguration::Reflect(AZ::ReflectContext* context)
{
if (AZ::SerializeContext* serialize = azrtti_cast<AZ::SerializeContext*>(context))
{
serialize->Class<ImuSensorConfiguration>()
->Version(1)
->Field("FilterSize", &ImuSensorConfiguration::m_filterSize)
->Field("IncludeGravity", &ImuSensorConfiguration::m_includeGravity)
->Field("AbsoluteRotation", &ImuSensorConfiguration::m_absoluteRotation)
->Field("AccelerationVariance", &ImuSensorConfiguration::m_linearAccelerationVariance)
->Field("AngularVelocityVariance", &ImuSensorConfiguration::m_angularVelocityVariance)
->Field("OrientationVariance", &ImuSensorConfiguration::m_orientationVariance);

if (AZ::EditContext* ec = serialize->GetEditContext())
{
ec->Class<ImuSensorConfiguration>("ROS2 IMU sensor configuration", "IMU sensor configuration")
->DataElement(
AZ::Edit::UIHandlers::Slider,
&ImuSensorConfiguration::m_filterSize,
"Filter Length",
"Filter Length, Large value reduce numeric noise but increase lag")
->Attribute(AZ::Edit::Attributes::Max, &ImuSensorConfiguration::m_maxFilterSize)
->Attribute(AZ::Edit::Attributes::Min, &ImuSensorConfiguration::m_minFilterSize)
->DataElement(
AZ::Edit::UIHandlers::Default,
&ImuSensorConfiguration::m_includeGravity,
"Include Gravitation",
"Enable accelerometer to observe gravity force.")
->DataElement(
AZ::Edit::UIHandlers::Default,
&ImuSensorConfiguration::m_absoluteRotation,
"Absolute Rotation",
"Include Absolute rotation in message.")
->DataElement(
AZ::Edit::UIHandlers::Default,
&ImuSensorConfiguration::m_linearAccelerationVariance,
"Linear Acceleration Variance",
"Variance of linear acceleration.")
->DataElement(
AZ::Edit::UIHandlers::Default,
&ImuSensorConfiguration::m_angularVelocityVariance,
"Angular Velocity Variance",
"Variance of angular velocity.")
->DataElement(
AZ::Edit::UIHandlers::Default,
&ImuSensorConfiguration::m_orientationVariance,
"Orientation Variance",
"Variance of orientation.");
}
}
}

} // namespace ROS2
38 changes: 38 additions & 0 deletions Gems/ROS2/Code/Source/Imu/ImuSensorConfiguration.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* 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/Matrix3x3.h>
#include <AzCore/RTTI/RTTI.h>
#include <AzCore/Serialization/SerializeContext.h>
#include <AzCore/std/string/string.h>

namespace ROS2
{
//! A structure capturing configuration of a IMU sensor.
struct ImuSensorConfiguration
{
AZ_TYPE_INFO(ImuSensorConfiguration, "{6788e84f-b985-4413-8e2b-46fbfb667c95}");
static void Reflect(AZ::ReflectContext* context);

//! Length of filter that removes numerical noise
int m_filterSize = 10;
int m_minFilterSize = 1;
int m_maxFilterSize = 200;

//! Include gravity acceleration
bool m_includeGravity = true;

//! Measure also absolute rotation
bool m_absoluteRotation = true;

AZ::Vector3 m_orientationVariance = AZ::Vector3::CreateZero();
AZ::Vector3 m_angularVelocityVariance = AZ::Vector3::CreateZero();
AZ::Vector3 m_linearAccelerationVariance = AZ::Vector3::CreateZero();
};
} // namespace ROS2
Loading

0 comments on commit 76e6569

Please sign in to comment.