Skip to content

Commit

Permalink
Review changes
Browse files Browse the repository at this point in the history
Signed-off-by: Aleksander Kamiński <[email protected]>
  • Loading branch information
alek-kam-robotec-ai committed Aug 26, 2024
1 parent 929629f commit 9ee4ac6
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 33 deletions.
9 changes: 0 additions & 9 deletions Gems/ROS2/Code/Include/ROS2/Lidar/RaycastResults.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,6 @@ namespace ROS2
RaycastResults(RaycastResults&& other);

[[nodiscard]] bool IsEmpty() const;
template<RaycastResultFlags F>
[[nodiscard]] bool IsFlagSatisfied(RaycastResultFlags requestedFlags) const;
[[nodiscard]] bool SatisfiesResultFlags(RaycastResultFlags flags) const;

template<RaycastResultFlags F>
[[nodiscard]] bool IsFieldPresent() const;
Expand Down Expand Up @@ -109,12 +106,6 @@ namespace ROS2
FieldInternal<RaycastResultFlags::Intensity> m_intensities;
};

template<RaycastResultFlags F>
bool RaycastResults::IsFlagSatisfied(RaycastResultFlags requestedFlags) const
{
return !IsFlagEnabled(F, requestedFlags) || IsFieldPresent<F>();
}

template<RaycastResultFlags F>
bool RaycastResults::IsFieldPresent() const
{
Expand Down
2 changes: 1 addition & 1 deletion Gems/ROS2/Code/Source/Lidar/LidarCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ namespace ROS2
AZ::ComponentApplicationBus::BroadcastResult(entity, &AZ::ComponentApplicationRequests::FindEntity, m_entityId);
const auto entityTransform = entity->FindComponent<AzFramework::TransformComponent>();

AZ::Outcome<RaycastResults, const char*> results = AZ::Failure("EBus failure occured.");
AZ::Outcome<RaycastResults, const char*> results = AZ::Failure("EBus failure occurred.");
LidarRaycasterRequestBus::EventResult(
results, m_lidarRaycasterId, &LidarRaycasterRequestBus::Events::PerformRaycast, entityTransform->GetWorldTM());
if (!results.IsSuccess())
Expand Down
19 changes: 6 additions & 13 deletions Gems/ROS2/Code/Source/Lidar/PointCloudMessageBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,30 +24,23 @@ namespace ROS2

PointCloud2MessageBuilder& PointCloud2MessageBuilder::AddField(const char* name, uint8_t dataType, size_t count)
{
AZ_Assert(m_message.has_value(), "Programmer error: Message builder was invalid. Double result retrieval.");

sensor_msgs::msg::PointField point_field;
point_field.name = name;
point_field.count = count;
point_field.datatype = dataType;
point_field.offset = m_offset;
m_message.value().fields.push_back(point_field);
m_message.fields.push_back(point_field);

m_offset += point_field.count * sizeOfPointField(dataType);
return *this;
}

sensor_msgs::msg::PointCloud2 PointCloud2MessageBuilder::Build()
sensor_msgs::msg::PointCloud2 PointCloud2MessageBuilder::Get()
{
AZ_Assert(m_message.has_value(), "Programmer error: Message builder was invalid. Double result retrieval.");
auto& message = m_message.value();

message.point_step = m_offset;
message.row_step = message.width * message.point_step;
message.data.resize(message.height * message.row_step);
m_message.point_step = m_offset;
m_message.row_step = m_message.width * m_message.point_step;
m_message.data.resize(m_message.row_step);

sensor_msgs::msg::PointCloud2 result = m_message.value();
m_message = {}; // Builder invalidated.
return result;
return m_message;
}
} // namespace ROS2
4 changes: 2 additions & 2 deletions Gems/ROS2/Code/Source/Lidar/PointCloudMessageBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ namespace ROS2
public:
PointCloud2MessageBuilder(const AZStd::string& frameId, builtin_interfaces::msg::Time timeStamp, size_t count);
PointCloud2MessageBuilder& AddField(const char* name, uint8_t dataType, size_t count = 1);
sensor_msgs::msg::PointCloud2 Build();
sensor_msgs::msg::PointCloud2 Get();

private:
size_t m_offset = 0U;
AZStd::optional<sensor_msgs::msg::PointCloud2> m_message;
sensor_msgs::msg::PointCloud2 m_message;
};
} // namespace ROS2
2 changes: 1 addition & 1 deletion Gems/ROS2/Code/Source/Lidar/ROS2LidarSensorComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ namespace ROS2
{
builder.AddField("intensity", sensor_msgs::msg::PointField::FLOAT32);
}
sensor_msgs::msg::PointCloud2 message = builder.Build();
sensor_msgs::msg::PointCloud2 message = builder.Get();


sensor_msgs::PointCloud2Iterator<float> messageXIt(message, "x");
Expand Down
12 changes: 5 additions & 7 deletions Gems/ROS2/Code/Source/Lidar/RaycastResults.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,12 @@ namespace ROS2
}

RaycastResults::RaycastResults(RaycastResults&& other)
: m_count{ other.m_count }
, m_points{ AZStd::move(other.m_points) }
, m_ranges{ AZStd::move(other.m_ranges) }
, m_intensities{ AZStd::move(other.m_intensities) }
{
*this = other;
other.m_count = 0U;
}

void RaycastResults::Clear()
Expand Down Expand Up @@ -60,12 +64,6 @@ namespace ROS2
return GetCount() == 0U;
}

bool RaycastResults::SatisfiesResultFlags(RaycastResultFlags flags) const
{
return IsFlagSatisfied<RaycastResultFlags::Point>(flags) && IsFlagSatisfied<RaycastResultFlags::Range>(flags) &&
IsFlagSatisfied<RaycastResultFlags::Intensity>(flags);
}

size_t RaycastResults::GetCount() const
{
return m_count;
Expand Down

0 comments on commit 9ee4ac6

Please sign in to comment.