-
Notifications
You must be signed in to change notification settings - Fork 64
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
Add SDFormat importer hooks #453
Merged
adamdbrw
merged 15 commits into
o3de:development
from
jhanca-robotecai:jh/sdformat_hooks
Sep 4, 2023
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
0419530
add GNSS sensor SDF importer hook
jhanca-robotecai d58c85a
add Imu sensor SDF importer hook
jhanca-robotecai ab9ae52
Imu sensor SDF importer hook tests
jhanca-robotecai c0ab8a9
add Lidar sensor SDF importer hook
jhanca-robotecai ac0f3cf
fix sensor types mappings
jhanca-robotecai 4bf2791
code review: split into files
jhanca-robotecai 460fbe5
add get/set to conf in ROS2 Sensors; refactor hooks
jhanca-robotecai 665d12d
revert AZStd::move addition
jhanca-robotecai 2fec1ee
add ROS2SensorHooksUtils
jhanca-robotecai 21b836a
remove get/set methods; revert component create method
jhanca-robotecai 080bfdf
add custom CreateComponent method to use with hooks
jhanca-robotecai 0a85c2e
do not create duplicate components; check for required components
jhanca-robotecai a47a65b
fix camera field of view
jhanca-robotecai f641d5f
review comment: possible division by zero
jhanca-robotecai 0a90328
redo aspect ratio calculation
jhanca-robotecai File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
Gems/ROS2/Code/Source/RobotImporter/SDFormat/Hooks/ROS2GNSSSensorHook.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* 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 <GNSS/ROS2GNSSSensorComponent.h> | ||
#include <RobotImporter/SDFormat/ROS2SensorHooks.h> | ||
#include <RobotImporter/SDFormat/ROS2SensorHooksUtils.h> | ||
|
||
#include <sdf/NavSat.hh> | ||
#include <sdf/Sensor.hh> | ||
|
||
namespace ROS2::SDFormat | ||
{ | ||
SensorImporterHook ROS2SensorHooks::ROS2GNSSSensor() | ||
{ | ||
SensorImporterHook importerHook; | ||
importerHook.m_sensorTypes = AZStd::unordered_set<sdf::SensorType>{ sdf::SensorType::NAVSAT }; | ||
importerHook.m_supportedSensorParams = AZStd::unordered_set<AZStd::string>{ ">update_rate" }; | ||
importerHook.m_pluginNames = AZStd::unordered_set<AZStd::string>{ "libgazebo_ros_gps_sensor.so" }; | ||
importerHook.m_supportedPluginParams = AZStd::unordered_set<AZStd::string>{}; | ||
importerHook.m_sdfSensorToComponentCallback = [](AZ::Entity& entity, | ||
const sdf::Sensor& sdfSensor) -> SensorImporterHook::ConvertSensorOutcome | ||
{ | ||
if (!sdfSensor.NavSatSensor()) | ||
{ | ||
return AZ::Failure(AZStd::string("Failed to read parsed SDFormat data of %s NavSat sensor", sdfSensor.Name().c_str())); | ||
} | ||
|
||
SensorConfiguration sensorConfiguration; | ||
sensorConfiguration.m_frequency = sdfSensor.UpdateRate(); | ||
const AZStd::string messageType = "sensor_msgs::msg::NavSatFix"; | ||
Utils::AddTopicConfiguration(sensorConfiguration, "gnss", messageType, messageType); | ||
|
||
if (Utils::CreateComponent<ROS2GNSSSensorComponent>(entity, sensorConfiguration, GNSSSensorConfiguration())) | ||
{ | ||
return AZ::Success(); | ||
} | ||
else | ||
{ | ||
return AZ::Failure(AZStd::string("Failed to create ROS2 GNSS Sensor component")); | ||
} | ||
}; | ||
|
||
return importerHook; | ||
} | ||
} // namespace ROS2::SDFormat |
101 changes: 101 additions & 0 deletions
101
Gems/ROS2/Code/Source/RobotImporter/SDFormat/Hooks/ROS2ImuSensorHook.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
/* | ||
* 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 <Imu/ROS2ImuSensorComponent.h> | ||
#include <ROS2/Frame/ROS2FrameComponent.h> | ||
#include <RobotImporter/SDFormat/ROS2SensorHooks.h> | ||
#include <RobotImporter/SDFormat/ROS2SensorHooksUtils.h> | ||
#include <Source/EditorStaticRigidBodyComponent.h> | ||
|
||
#include <sdf/Imu.hh> | ||
#include <sdf/Sensor.hh> | ||
|
||
namespace ROS2::SDFormat | ||
{ | ||
SensorImporterHook ROS2SensorHooks::ROS2ImuSensor() | ||
{ | ||
SensorImporterHook importerHook; | ||
importerHook.m_sensorTypes = AZStd::unordered_set<sdf::SensorType>{ sdf::SensorType::IMU }; | ||
importerHook.m_supportedSensorParams = AZStd::unordered_set<AZStd::string>{ ">update_rate", | ||
">imu>angular_velocity>x>noise>mean", | ||
">imu>angular_velocity>x>noise>stddev", | ||
">imu>angular_velocity>y>noise>mean", | ||
">imu>angular_velocity>y>noise>stddev", | ||
">imu>angular_velocity>z>noise>mean", | ||
">imu>angular_velocity>z>noise>stddev", | ||
">imu>linear_acceleration>x>noise>mean", | ||
">imu>linear_acceleration>x>noise>stddev", | ||
">imu>linear_acceleration>y>noise>mean", | ||
">imu>linear_acceleration>y>noise>stddev", | ||
">imu>linear_acceleration>z>noise>mean", | ||
">imu>linear_acceleration>z>noise>stddev" }; | ||
importerHook.m_pluginNames = AZStd::unordered_set<AZStd::string>{ "libgazebo_ros_imu_sensor.so" }; | ||
importerHook.m_supportedPluginParams = AZStd::unordered_set<AZStd::string>{}; | ||
importerHook.m_sdfSensorToComponentCallback = [](AZ::Entity& entity, | ||
const sdf::Sensor& sdfSensor) -> SensorImporterHook::ConvertSensorOutcome | ||
{ | ||
auto* imuSensor = sdfSensor.ImuSensor(); | ||
if (!imuSensor) | ||
{ | ||
return AZ::Failure(AZStd::string("Failed to read parsed SDFormat data of %s imu sensor", sdfSensor.Name().c_str())); | ||
} | ||
|
||
ImuSensorConfiguration imuConfiguration; | ||
const auto& angVelXNoise = imuSensor->AngularVelocityXNoise(); | ||
const auto& angVelYNoise = imuSensor->AngularVelocityYNoise(); | ||
const auto& angVelZNoise = imuSensor->AngularVelocityZNoise(); | ||
if (angVelXNoise.Type() == sdf::NoiseType::GAUSSIAN && angVelYNoise.Type() == sdf::NoiseType::GAUSSIAN && | ||
angVelZNoise.Type() == sdf::NoiseType::GAUSSIAN) | ||
{ | ||
if (angVelXNoise.Mean() == 0.0 && angVelYNoise.Mean() == 0.0 && angVelZNoise.Mean() == 0.0) | ||
{ | ||
imuConfiguration.m_angularVelocityVariance = AZ::Vector3( | ||
static_cast<float>(angVelXNoise.StdDev() * angVelXNoise.StdDev()), | ||
static_cast<float>(angVelYNoise.StdDev() * angVelYNoise.StdDev()), | ||
static_cast<float>(angVelZNoise.StdDev() * angVelZNoise.StdDev())); | ||
} | ||
} | ||
|
||
const auto& linAccXNoise = imuSensor->LinearAccelerationXNoise(); | ||
const auto& linAccYNoise = imuSensor->LinearAccelerationYNoise(); | ||
const auto& linAccZNoise = imuSensor->LinearAccelerationZNoise(); | ||
if (linAccXNoise.Type() == sdf::NoiseType::GAUSSIAN && linAccYNoise.Type() == sdf::NoiseType::GAUSSIAN && | ||
linAccZNoise.Type() == sdf::NoiseType::GAUSSIAN) | ||
{ | ||
if (linAccXNoise.Mean() == 0.0 && linAccYNoise.Mean() == 0.0 && linAccZNoise.Mean() == 0.0) | ||
{ | ||
imuConfiguration.m_linearAccelerationVariance = AZ::Vector3( | ||
static_cast<float>(linAccXNoise.StdDev() * linAccXNoise.StdDev()), | ||
static_cast<float>(linAccYNoise.StdDev() * linAccYNoise.StdDev()), | ||
static_cast<float>(linAccZNoise.StdDev() * linAccZNoise.StdDev())); | ||
} | ||
} | ||
|
||
SensorConfiguration sensorConfiguration; | ||
sensorConfiguration.m_frequency = sdfSensor.UpdateRate(); | ||
const AZStd::string messageType = "sensor_msgs::msg::Imu"; | ||
Utils::AddTopicConfiguration(sensorConfiguration, "imu", messageType, messageType); | ||
|
||
// Create required components | ||
Utils::CreateComponent<ROS2FrameComponent>(entity); | ||
Utils::CreateComponent<PhysX::EditorStaticRigidBodyComponent>(entity); | ||
|
||
// Create Imu component | ||
if (Utils::CreateComponent<ROS2ImuSensorComponent>(entity, sensorConfiguration, imuConfiguration)) | ||
{ | ||
return AZ::Success(); | ||
} | ||
else | ||
{ | ||
return AZ::Failure(AZStd::string("Failed to create ROS2 Imu Sensor component")); | ||
} | ||
}; | ||
|
||
return importerHook; | ||
} | ||
} // namespace ROS2::SDFormat |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
What should the value of
m_verticalFieldOfViewDeg
be if thecameraConfiguration.m_width
is zero?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.
Mathematically vertical FoV for image width equal to zero would be infinity. In the practical case camera with zero width (or height) makes no sense. The parameters (including FoV) are checked later in the pipeline - this test is added to avoid software crashes while importing robots with improper parameters.