-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add SDFormat sensor importer hooks (#446)
add SDFormat importer hooks Signed-off-by: Jan Hanca <[email protected]>
- Loading branch information
1 parent
e4b1313
commit 3d40c2d
Showing
12 changed files
with
522 additions
and
11 deletions.
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
59 changes: 59 additions & 0 deletions
59
Gems/ROS2/Code/Include/ROS2/RobotImporter/SDFormatSensorImporterHook.h
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,59 @@ | ||
/* | ||
* 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/Component/Entity.h> | ||
#include <AzCore/Outcome/Outcome.h> | ||
#include <AzCore/std/containers/unordered_set.h> | ||
#include <AzCore/std/function/function_template.h> | ||
#include <AzCore/std/string/string.h> | ||
|
||
namespace sdf | ||
{ | ||
inline namespace v13 | ||
{ | ||
enum class SensorType; | ||
class Sensor; | ||
} // namespace v13 | ||
} // namespace sdf | ||
|
||
namespace ROS2::SDFormat | ||
{ | ||
//! Hook used in ROS2 Gem Robot Importer to create ROS2 sensor components based on SDFormat model description. | ||
//! It implements the parameters mapping between the SDFormat sensor and the particular O3DE component. | ||
//! It should be registered as a serialization attribute in the component's reflection to make the it visible in the SDFormat model | ||
//! parser. See the sensor element at http://sdformat.org/spec?ver=1.10&elem=sensor for more details on SDFormat. | ||
struct SensorImporterHook | ||
{ | ||
AZ_TYPE_INFO(SensorImporterHook, "{23f189e3-8da4-4498-9b89-1ef6c900940a}"); | ||
|
||
//! Types of sensors in SDFormat description that can be mapped to the particular O3DE component. | ||
//! Multiple SDFormat sensors can map to one O3DE component. | ||
AZStd::unordered_set<sdf::SensorType> m_sensorTypes; | ||
|
||
//! Names of the sensor's parameters in SDFormat description that are supported by the particular O3DE component. | ||
AZStd::unordered_set<AZStd::string> m_supportedSensorParams; | ||
|
||
//! Names of plugins associated with the sensor in SDFormat description that are supported by the particular O3DE component. | ||
//! Multiple SDFormat plugins can map to one O3DE component. | ||
AZStd::unordered_set<AZStd::string> m_pluginNames; | ||
|
||
//! Names of the plugin's parameters associated with the sensor in SDFormat description that are supported | ||
//! by the particular O3DE component. | ||
AZStd::unordered_set<AZStd::string> m_supportedPluginParams; | ||
|
||
//! Registered function that is invoked when a sensor of the specified type is processed by the SDFormat Importer. | ||
//! @param AZ::Entity& a reference to the Entity in which one or more O3DE component is created by the importer | ||
//! @param sdf::Sensor& a reference to the sensor data in SDFormat, which is used to configure O3DE component | ||
using ErrorString = AZStd::string; | ||
using ConvertSensorOutcome = AZ::Outcome<void, AZStd::string>; | ||
using ConvertSDFSensorCallback = AZStd::function<ConvertSensorOutcome(AZ::Entity&, const sdf::Sensor&)>; | ||
ConvertSDFSensorCallback m_sdfSensorToComponentCallback; | ||
}; | ||
} // namespace ROS2::SDFormat |
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
101 changes: 101 additions & 0 deletions
101
Gems/ROS2/Code/Source/RobotImporter/SDFormat/ROS2SensorHooks.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 "ROS2SensorHooks.h" | ||
|
||
#include <Camera/CameraConstants.h> | ||
#include <Camera/ROS2CameraSensorEditorComponent.h> | ||
#include <GNSS/ROS2GNSSSensorComponent.h> | ||
#include <RobotImporter/Utils/RobotImporterUtils.h> | ||
|
||
#include <sdf/Camera.hh> | ||
#include <sdf/NavSat.hh> | ||
|
||
namespace ROS2::SDFormat | ||
{ | ||
namespace Internal | ||
{ | ||
void AddTopicConfiguration( | ||
SensorConfiguration& sensorConfig, | ||
const AZStd::string& topic, | ||
const AZStd::string& messageType, | ||
const AZStd::string& configName) | ||
{ | ||
TopicConfiguration config; | ||
config.m_topic = topic; | ||
config.m_type = messageType; | ||
sensorConfig.m_publishersConfigurations.insert(AZStd::make_pair(configName, config)); | ||
} | ||
} // namespace Internal | ||
|
||
SensorImporterHook ROS2SensorHooks::ROS2CameraSensor() | ||
{ | ||
SensorImporterHook importerHook; | ||
importerHook.m_sensorTypes = | ||
AZStd::unordered_set<sdf::SensorType>{ sdf::SensorType::CAMERA, sdf::SensorType::DEPTH_CAMERA, sdf::SensorType::RGBD_CAMERA }; | ||
importerHook.m_supportedSensorParams = | ||
AZStd::unordered_set<AZStd::string>{ ">update_rate", ">camera>horizontal_fov", ">camera>image>width", | ||
">camera>image>height", ">camera>clip>near", ">camera>clip>far" }; | ||
importerHook.m_pluginNames = AZStd::unordered_set<AZStd::string>{ "libgazebo_ros_camera.so", | ||
"libgazebo_ros_depth_camera.so", | ||
"libgazebo_ros_openni_kinect.so" }; | ||
importerHook.m_supportedPluginParams = AZStd::unordered_set<AZStd::string>{}; | ||
importerHook.m_sdfSensorToComponentCallback = [](AZ::Entity& entity, | ||
const sdf::Sensor& sdfSensor) -> SensorImporterHook::ConvertSensorOutcome | ||
{ | ||
auto* cameraSensor = sdfSensor.CameraSensor(); | ||
|
||
CameraSensorConfiguration cameraConfiguration; | ||
cameraConfiguration.m_depthCamera = cameraSensor->HasDepthCamera(); | ||
cameraConfiguration.m_colorCamera = (sdfSensor.Type() != sdf::SensorType::DEPTH_CAMERA) ? true : false; | ||
cameraConfiguration.m_width = cameraSensor->ImageWidth(); | ||
cameraConfiguration.m_height = cameraSensor->ImageHeight(); | ||
cameraConfiguration.m_verticalFieldOfViewDeg = | ||
cameraSensor->HorizontalFov().Degree() * (cameraConfiguration.m_height / cameraConfiguration.m_width); | ||
if (sdfSensor.Type() != sdf::SensorType::DEPTH_CAMERA) | ||
{ | ||
cameraConfiguration.m_nearClipDistance = static_cast<float>(cameraSensor->NearClip()); | ||
cameraConfiguration.m_farClipDistance = static_cast<float>(cameraSensor->FarClip()); | ||
} | ||
else | ||
{ | ||
cameraConfiguration.m_nearClipDistance = static_cast<float>(cameraSensor->DepthNearClip()); | ||
cameraConfiguration.m_farClipDistance = static_cast<float>(cameraSensor->DepthFarClip()); | ||
} | ||
|
||
SensorConfiguration sensorConfiguration; | ||
sensorConfiguration.m_frequency = sdfSensor.UpdateRate(); | ||
if (sdfSensor.Type() != sdf::SensorType::DEPTH_CAMERA) | ||
{ | ||
Internal::AddTopicConfiguration( | ||
sensorConfiguration, "camera_image_color", CameraConstants::ImageMessageType, CameraConstants::ColorImageConfig); | ||
Internal::AddTopicConfiguration( | ||
sensorConfiguration, "color_camera_info", CameraConstants::CameraInfoMessageType, CameraConstants::ColorInfoConfig); | ||
} | ||
if (sdfSensor.Type() != sdf::SensorType::CAMERA) | ||
{ | ||
Internal::AddTopicConfiguration( | ||
sensorConfiguration, "camera_image_depth", CameraConstants::ImageMessageType, CameraConstants::DepthImageConfig); | ||
Internal::AddTopicConfiguration( | ||
sensorConfiguration, "depth_camera_info", CameraConstants::CameraInfoMessageType, CameraConstants::DepthInfoConfig); | ||
} | ||
|
||
if (entity.CreateComponent<ROS2CameraSensorEditorComponent>(sensorConfiguration, cameraConfiguration)) | ||
{ | ||
return AZ::Success(); | ||
} | ||
else | ||
{ | ||
return AZ::Failure(AZStd::string("Failed to create ROS2 Camera Sensor component")); | ||
} | ||
}; | ||
|
||
return importerHook; | ||
} | ||
|
||
} // namespace ROS2::SDFormat |
19 changes: 19 additions & 0 deletions
19
Gems/ROS2/Code/Source/RobotImporter/SDFormat/ROS2SensorHooks.h
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,19 @@ | ||
/* | ||
* 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 <ROS2/RobotImporter/SDFormatSensorImporterHook.h> | ||
|
||
namespace ROS2::SDFormat | ||
{ | ||
namespace ROS2SensorHooks | ||
{ | ||
SensorImporterHook ROS2CameraSensor(); | ||
} // namespace ROS2SensorHooks | ||
} // namespace ROS2::SDFormat |
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
Oops, something went wrong.