-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Jan Hanca <[email protected]>
- Loading branch information
1 parent
bfda9e7
commit ccb5bd7
Showing
5 changed files
with
100 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
* 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/SDFormatSensorImporterHook.h> | ||
|
||
#include <sdf/Link.hh> | ||
#include <sdf/Sensor.hh> | ||
|
||
namespace ROS2 | ||
{ | ||
void AddSensor(AZ::EntityId entityId, const sdf::Sensor* sensor) | ||
{ | ||
AZ::Entity* entity = AzToolsFramework::GetEntityById(entityId); | ||
auto serializeContext = AZ::Interface<AZ::ComponentApplicationRequests>::Get()->GetSerializeContext(); | ||
serializeContext->EnumerateAll( | ||
[&](const AZ::SerializeContext::ClassData* classData, const AZ::Uuid& typeId) -> bool | ||
{ | ||
auto* attribute = AZ::FindAttribute(AZ::Crc32("SDFormatSensorImporter"), classData->m_attributes); | ||
if (attribute == nullptr) | ||
{ | ||
return true; | ||
} | ||
|
||
AZ::AttributeReader reader(nullptr, attribute); | ||
SDFormat::SensorImporterHook sensorHook; | ||
if (reader.Read<SDFormat::SensorImporterHook>(sensorHook)) | ||
{ | ||
for (const auto& t : sensorHook.m_sensorTypes) | ||
{ | ||
if (sensor->Type() == t) | ||
{ | ||
sensorHook.m_sdfSensorToComponentCallback(*entity, *sensor); | ||
return false; | ||
} | ||
} | ||
} | ||
|
||
return true; | ||
}); | ||
} | ||
|
||
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); | ||
AddSensor(entityId, sensor); | ||
} | ||
} | ||
} // 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 in robot description of Gazebo. | ||
//! In SDFormat, sensors are specified as children of link of joint. | ||
class SensorsMaker | ||
{ | ||
public: | ||
//! Adds a Gazebo sensor to an entity and sets it accordingly | ||
//! @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
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