Skip to content
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

refactor ROS2SpawnerComponent #26

Open
wants to merge 6 commits into
base: forward_branch_wp2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion Gems/ROS2/Code/Include/ROS2/Spawner/SpawnerBus.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <AzCore/EBus/EBus.h>
#include <AzCore/Math/Transform.h>
#include <AzCore/RTTI/BehaviorContext.h>
#include <ROS2/Spawner/SpawnerInfo.h>

namespace ROS2
{
Expand All @@ -28,8 +29,9 @@ namespace ROS2
//! @return default spawn point coordinates set by user in Editor (by default: translation: {0, 0, 0}, rotation: {0, 0, 0, 1},
//! scale: 1.0)
virtual const AZ::Transform& GetDefaultSpawnPose() const = 0;

virtual AZStd::unordered_map<AZStd::string, SpawnPointInfo> GetAllSpawnPointInfos() const = 0;
};

using SpawnerRequestsBus = AZ::EBus<SpawnerRequests>;
using SpawnerInterface = AZ::Interface<SpawnerRequests>;
} // namespace ROS2
26 changes: 26 additions & 0 deletions Gems/ROS2/Code/Include/ROS2/Spawner/SpawnerInfo.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/Math/Transform.h>
#include <AzCore/Memory/Memory.h>
#include <AzCore/Memory/Memory_fwd.h>
#include <AzCore/Memory/SystemAllocator.h>
#include <AzCore/std/containers/unordered_map.h>
#include <AzCore/std/string/string.h>

namespace ROS2
{
struct SpawnPointInfo
{
AZStd::string info;
AZ::Transform pose;
};

using SpawnPointInfoMap = AZStd::unordered_map<AZStd::string, SpawnPointInfo>;
} // namespace ROS2
18 changes: 10 additions & 8 deletions Gems/ROS2/Code/Source/ROS2EditorModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
* SPDX-License-Identifier: Apache-2.0 OR MIT
*
*/
#include <Camera/ROS2CameraSensorEditorComponent.h>
#include <Lidar/LidarRegistrarEditorSystemComponent.h>
#include <ROS2EditorSystemComponent.h>
#include <ROS2ModuleInterface.h>
#include <Camera/ROS2CameraSensorEditorComponent.h>
#include <RobotImporter/ROS2RobotImporterEditorSystemComponent.h>
#include <Spawner/ROS2SpawnPointEditorComponent.h>
#include <Spawner/ROS2SpawnerEditorComponent.h>

#include <QtCore/qglobal.h>

Expand All @@ -30,19 +32,19 @@ namespace ROS2
ROS2EditorModule()
{
InitROS2Resources();

// Push results of [MyComponent]::CreateDescriptor() into m_descriptors here.
// Add ALL components descriptors associated with this gem to m_descriptors.
// This will associate the AzTypeInfo information for the components with the SerializeContext, BehaviorContext and
// EditContext. This happens through the [MyComponent]::Reflect() function.
m_descriptors.insert(
m_descriptors.end(),
{
ROS2EditorSystemComponent::CreateDescriptor(),
LidarRegistrarEditorSystemComponent::CreateDescriptor(),
ROS2RobotImporterEditorSystemComponent::CreateDescriptor(),
ROS2CameraSensorEditorComponent::CreateDescriptor(),
});
{ ROS2EditorSystemComponent::CreateDescriptor(),
LidarRegistrarEditorSystemComponent::CreateDescriptor(),
ROS2RobotImporterEditorSystemComponent::CreateDescriptor(),
ROS2CameraSensorEditorComponent::CreateDescriptor(),
ROS2SpawnerEditorComponent::CreateDescriptor(),
ROS2SpawnPointEditorComponent::CreateDescriptor() });
}

/**
Expand Down
51 changes: 51 additions & 0 deletions Gems/ROS2/Code/Source/RobotImporter/Pages/PrefabMakerPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,18 @@
*/

#include "PrefabMakerPage.h"
#include <AzCore/Component/Entity.h>
#include <AzCore/Debug/Trace.h>
#include <AzCore/EBus/Results.h>
#include <AzCore/Math/Transform.h>
#include <AzCore/std/smart_ptr/make_shared.h>
#include <AzCore/std/string/string.h>
#include <ROS2/Spawner/SpawnerBus.h>
#include <ROS2/Spawner/SpawnerInfo.h>
#include <RobotImporter/RobotImporterWidget.h>
#include <optional>
#include <qcombobox.h>
#include <qvariant.h>

namespace ROS2
{
Expand All @@ -17,6 +28,20 @@ namespace ROS2
, m_parentImporterWidget(parent)
, m_success(false)
{
AZ::EBusAggregateResults<AZStd::unordered_map<AZStd::string, SpawnPointInfo>> allActiveSpawnPoints;
SpawnerRequestsBus::BroadcastResult(allActiveSpawnPoints, &SpawnerRequestsBus::Events::GetAllSpawnPointInfos);

m_spawnPointsComboBox = new QComboBox(this);
m_spawnPointsInfos = allActiveSpawnPoints.values;

for (int i = 0; i < allActiveSpawnPoints.values.size(); i++)
{
for (const auto& element : allActiveSpawnPoints.values[i])
{
m_spawnPointsComboBox->addItem(element.first.c_str(), QVariant(i));
}
}

m_prefabName = new QLineEdit(this);
m_createButton = new QPushButton(tr("Create Prefab"), this);
m_log = new QTextEdit(this);
Expand All @@ -28,6 +53,17 @@ namespace ROS2
layoutInner->addWidget(m_createButton);
layout->addLayout(layoutInner);
layout->addWidget(m_useArticulation);
QLabel* spawnPointListLabel;
if (allActiveSpawnPoints.values.size() == 0)
{
spawnPointListLabel = new QLabel("Select spawn position (No spawn positions were detected)", this);
}
else
{
spawnPointListLabel = new QLabel("Select spawn position", this);
}
layout->addWidget(spawnPointListLabel);
layout->addWidget(m_spawnPointsComboBox);
layout->addWidget(m_log);
setLayout(layout);
connect(m_createButton, &QPushButton::pressed, this, &PrefabMakerPage::onCreateButtonPressed);
Expand Down Expand Up @@ -60,5 +96,20 @@ namespace ROS2
{
return m_useArticulation->isChecked();
}
AZStd::optional<AZ::Transform> PrefabMakerPage::getSelectedSpawnPoint() const
{
if (!m_spawnPointsInfos.empty())
{
int vectorIndex = m_spawnPointsComboBox->currentData().toInt();
AZStd::string mapKey(m_spawnPointsComboBox->currentText().toStdString().c_str());
auto& map = m_spawnPointsInfos[vectorIndex];
if (auto spawnInfo = map.find(mapKey);
spawnInfo != map.end())
{
return spawnInfo->second.pose;
}
}
return AZStd::nullopt;
}

} // namespace ROS2
6 changes: 6 additions & 0 deletions Gems/ROS2/Code/Source/RobotImporter/Pages/PrefabMakerPage.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@

#pragma once

#include "ROS2/Spawner/SpawnerInfo.h"
#include <AzCore/Component/Entity.h>
#include <qcombobox.h>
#if !defined(Q_MOC_RUN)
#include <AzCore/Math/Crc.h>
#include <AzCore/std/string/string.h>
Expand All @@ -34,6 +37,7 @@ namespace ROS2
void setSuccess(bool success);
bool isComplete() const override;
bool IsUseArticulations() const;
AZStd::optional<AZ::Transform> getSelectedSpawnPoint() const;
Q_SIGNALS:
void onCreateButtonPressed();

Expand All @@ -43,6 +47,8 @@ namespace ROS2
QPushButton* m_createButton;
QTextEdit* m_log;
QCheckBox* m_useArticulation;
QComboBox* m_spawnPointsComboBox;
AZStd::vector<SpawnPointInfoMap> m_spawnPointsInfos;
RobotImporterWidget* m_parentImporterWidget;
};
} // namespace ROS2
7 changes: 6 additions & 1 deletion Gems/ROS2/Code/Source/RobotImporter/RobotImporterWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,12 @@ namespace ROS2
}
const bool useArticulation = m_prefabMakerPage->IsUseArticulations();
m_prefabMaker = AZStd::make_unique<URDFPrefabMaker>(
m_urdfPath.String(), m_parsedUrdf, prefabPath.String(), m_urdfAssetsMapping, useArticulation);
m_urdfPath.String(),
m_parsedUrdf,
prefabPath.String(),
m_urdfAssetsMapping,
useArticulation,
m_prefabMakerPage->getSelectedSpawnPoint());

auto prefabOutcome = m_prefabMaker->CreatePrefabFromURDF();
if (prefabOutcome.IsSuccess())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ namespace ROS2
AZ::Entity* entity = AzToolsFramework::GetEntityById(entityId);
AZ_Assert(entity, "No entity for id %s", entityId.ToString().c_str());

AZ_TracePrintf("ArticulationsMaker", "Processing inertial for entity id: %s\n", entityId.ToString().c_str());
AZ_Trace("ArticulationsMaker", "Processing inertial for entity id: %s\n", entityId.ToString().c_str());
PhysX::EditorArticulationLinkConfiguration articulationLinkConfiguration;

articulationLinkConfiguration = AddToArticulationConfig(articulationLinkConfiguration, link->inertial);
Expand Down
6 changes: 3 additions & 3 deletions Gems/ROS2/Code/Source/RobotImporter/URDF/CollidersMaker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ namespace ROS2
{
m_wheelMaterial =
AZ::Data::Asset<Physics::MaterialAsset>(assetId, Physics::MaterialAsset::TYPEINFO_Uuid(), physicsMaterialAssetRelPath);
AZ_TracePrintf(Internal::CollidersMakerLoggingTag, "Waiting for asset load\n");
AZ_Trace(Internal::CollidersMakerLoggingTag, "Waiting for asset load\n");
m_wheelMaterial.BlockUntilLoadComplete();
}
else
Expand Down Expand Up @@ -150,7 +150,7 @@ namespace ROS2

if (result.GetResult() != AZ::SceneAPI::Events::ProcessingResult::Success)
{
AZ_TracePrintf(Internal::CollidersMakerLoggingTag, "Scene updated\n");
AZ_Trace(Internal::CollidersMakerLoggingTag, "Scene updated\n");
return;
}

Expand Down Expand Up @@ -242,7 +242,7 @@ namespace ROS2
{ // it is ok not to have collision in a link
return;
}
AZ_TracePrintf(Internal::CollidersMakerLoggingTag, "Processing collisions for entity id:%s\n", entityId.ToString().c_str());
AZ_Trace(Internal::CollidersMakerLoggingTag, "Processing collisions for entity id:%s\n", entityId.ToString().c_str());

auto geometry = collision->geometry;
if (!geometry)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace ROS2
{ // it is ok not to have inertia in a link
return;
}
AZ_TracePrintf("AddInertial", "Processing inertial for entity id: %s\n", entityId.ToString().c_str());
AZ_Trace("AddInertial", "Processing inertial for entity id: %s\n", entityId.ToString().c_str());

AZ::Entity* entity = AzToolsFramework::GetEntityById(entityId);
PhysX::EditorRigidBodyConfiguration rigidBodyConfiguration;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ namespace ROS2::PrefabMakerUtils
return AZ::Failure(AZStd::string("Invalid id for created entity"));
}

AZ_TracePrintf("CreateEntity", "Processing entity id: %s with name: %s\n", entityId.ToString().c_str(), name.c_str());
AZ_Trace("CreateEntity", "Processing entity id: %s with name: %s\n", entityId.ToString().c_str(), name.c_str());
AZ::Entity* entity = AzToolsFramework::GetEntityById(entityId);
entity->SetName(name);
entity->Deactivate();
Expand Down
Loading