Skip to content

Commit

Permalink
do not create duplicate components; check for required components
Browse files Browse the repository at this point in the history
Signed-off-by: Jan Hanca <jan.hanca@robotec.ai>
  • Loading branch information
jhanca-robotecai committed Aug 29, 2023
1 parent 080bfdf commit 0a85c2e
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,11 @@ namespace ROS2::SDFormat
sensorConfiguration, "depth_camera_info", CameraConstants::CameraInfoMessageType, CameraConstants::DepthInfoConfig);
}

if (Utils::CreateComponent<ROS2FrameComponent>(entity) &&
Utils::CreateComponent<ROS2CameraSensorEditorComponent>(entity, sensorConfiguration, cameraConfiguration))
// Create required components
Utils::CreateComponent<ROS2FrameComponent>(entity);

// Create Camera component
if (Utils::CreateComponent<ROS2CameraSensorEditorComponent>(entity, sensorConfiguration, cameraConfiguration))
{
return AZ::Success();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,12 @@ namespace ROS2::SDFormat
const AZStd::string messageType = "sensor_msgs::msg::Imu";
Utils::AddTopicConfiguration(sensorConfiguration, "imu", messageType, messageType);

if (Utils::CreateComponent<PhysX::EditorStaticRigidBodyComponent>(entity) &&
Utils::CreateComponent<ROS2FrameComponent>(entity) &&
Utils::CreateComponent<ROS2ImuSensorComponent>(entity, sensorConfiguration, imuConfiguration))
// 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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,11 @@ namespace ROS2::SDFormat
lidarConfiguration.m_lidarParameters.m_minRange = lidarSensor->RangeMin();
lidarConfiguration.m_lidarParameters.m_maxRange = lidarSensor->RangeMax();

if (Utils::CreateComponent<ROS2FrameComponent>(entity) &&
Utils::CreateComponent<ROS2LidarSensorComponent>(entity, sensorConfiguration, lidarConfiguration))
// Create required components
Utils::CreateComponent<ROS2FrameComponent>(entity);

// Create Lidar component
if (Utils::CreateComponent<ROS2LidarSensorComponent>(entity, sensorConfiguration, lidarConfiguration))
{
return AZ::Success();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ namespace ROS2::SDFormat
template<class ComponentType, typename... Args>
AZ::Component* CreateComponent(AZ::Entity& entity, Args&&... args)
{
// Do not create a component if the same type is already added.
if (entity.FindComponent<ComponentType>())
{
return nullptr;
}

// Create component.
// If it's not an "editor component" then wrap it in a GenericComponentWrapper.
AZ::Component* component = nullptr;
Expand All @@ -59,7 +65,7 @@ namespace ROS2::SDFormat

if (component)
{
if (!entity.AddComponent(component))
if (!entity.IsComponentReadyToAdd(component) || !entity.AddComponent(component))
{
delete component;
component = nullptr;
Expand Down

0 comments on commit 0a85c2e

Please sign in to comment.