forked from o3de/o3de-extras
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Robot Importer: add sensor maker (o3de#503)
* add SensorsMaker for SDFormat data * publish hooks for processing * revert output filename change * code review: cache list of sensor hooks --------- Signed-off-by: Jan Hanca <[email protected]> Signed-off-by: Michał Pełka <[email protected]>
- Loading branch information
1 parent
51de032
commit 5ce38c9
Showing
11 changed files
with
175 additions
and
28 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
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
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
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 "SensorsMaker.h" | ||
|
||
#include <AzCore/Component/EntityId.h> | ||
#include <AzToolsFramework/Entity/EditorEntityHelpers.h> | ||
#include <ROS2/RobotImporter/RobotImporterBus.h> | ||
#include <ROS2/RobotImporter/SDFormatSensorImporterHook.h> | ||
|
||
#include <sdf/Link.hh> | ||
#include <sdf/Sensor.hh> | ||
|
||
namespace ROS2 | ||
{ | ||
bool AddSensor(AZ::EntityId entityId, const sdf::Sensor* sensor) | ||
{ | ||
SDFormat::SensorImporterHooksStorage sensorHooks; | ||
ROS2::RobotImporterRequestBus::BroadcastResult(sensorHooks, &ROS2::RobotImporterRequest::GetSensorHooks); | ||
for (const auto& hook : sensorHooks) | ||
{ | ||
if (hook.m_sensorTypes.contains(sensor->Type())) | ||
{ | ||
AZ::Entity* entity = AzToolsFramework::GetEntityById(entityId); | ||
hook.m_sdfSensorToComponentCallback(*entity, *sensor); | ||
return true; | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
|
||
void SensorsMaker::AddSensors(const sdf::Model& model, const sdf::Link* link, AZ::EntityId entityId) const | ||
{ | ||
for (size_t si = 0; si < link->SensorCount(); ++si) | ||
{ | ||
const auto* sensor = link->SensorByIndex(si); | ||
const bool success = AddSensor(entityId, sensor); | ||
AZ_Warning("SensorMaker", success, "Cannot find a sensor hook for sensor %d", sensor->Type()); | ||
} | ||
} | ||
} // namespace ROS2 |
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,32 @@ | ||
/* | ||
* 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 "UrdfParser.h" | ||
#include <AzCore/Component/ComponentBus.h> | ||
#include <AzCore/Component/EntityId.h> | ||
#include <AzCore/Outcome/Outcome.h> | ||
|
||
#include <sdf/sdf.hh> | ||
|
||
namespace ROS2 | ||
{ | ||
//! Populates a given entity with all the contents of the <sensor> tag. | ||
//! Sensors are specified as children of link or joint in SDFormat. | ||
class SensorsMaker | ||
{ | ||
public: | ||
//! Adds a sensor to an entity and sets it accordingly based on SDFormat description. | ||
//! @param model A parsed SDF model which could hold information about sensor to be made. | ||
//! @param link A parsed SDF tree link node used to identify link being currently processed. | ||
//! @param entityId A non-active entity which will be affected. | ||
//! @returns created components Id or string with fail | ||
void AddSensors(const sdf::Model& model, const sdf::Link* link, AZ::EntityId entityId) const; | ||
}; | ||
} // namespace ROS2 |
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.