2
0

ROS2LidarSensorComponent.h 4.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #pragma once
  9. #include "LidarCore.h"
  10. #include "LidarRaycaster.h"
  11. #include <Atom/RPI.Public/AuxGeom/AuxGeomDraw.h>
  12. #include <AzCore/Serialization/SerializeContext.h>
  13. #include <ROS2/Sensor/Events/TickBasedSource.h>
  14. #include <ROS2Sensors/Lidar/LidarConfigurationRequestBus.h>
  15. #include <ROS2Sensors/Lidar/LidarSensorConfiguration.h>
  16. #include <ROS2Sensors/Sensor/ROS2SensorComponentBase.h>
  17. #include <rclcpp/publisher.hpp>
  18. #include <sensor_msgs/msg/point_cloud2.hpp>
  19. #include <vision_msgs/msg/label_info.hpp>
  20. namespace ROS2Sensors
  21. {
  22. //! Lidar sensor Component.
  23. //! Lidars (Light Detection and Ranging) emit laser light and measure it after reflection.
  24. //! Lidar Component allows customization of lidar type and behavior and encapsulates both simulation
  25. //! and data publishing. It requires ROS2FrameComponent.
  26. class ROS2LidarSensorComponent
  27. : public ROS2SensorComponentBase<ROS2::TickBasedSource>
  28. , protected LidarConfigurationRequestBus::Handler
  29. {
  30. public:
  31. AZ_COMPONENT(ROS2LidarSensorComponent, ROS2Sensors::ROS2LidarSensorComponentTypeId, SensorBaseType);
  32. ROS2LidarSensorComponent();
  33. ROS2LidarSensorComponent(const SensorConfiguration& sensorConfiguration, const LidarSensorConfiguration& lidarConfiguration);
  34. ~ROS2LidarSensorComponent() = default;
  35. static void Reflect(AZ::ReflectContext* context);
  36. static void GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& required);
  37. //////////////////////////////////////////////////////////////////////////
  38. // Component overrides
  39. void Activate() override;
  40. void Deactivate() override;
  41. //////////////////////////////////////////////////////////////////////////
  42. private:
  43. //////////////////////////////////////////////////////////////////////////
  44. // LidarConfigurationRequestBus::Handler overrides
  45. const LidarSensorConfiguration GetConfiguration() override;
  46. void SetConfiguration(const LidarSensorConfiguration& configuration) override;
  47. AZStd::string GetModelName() override;
  48. void SetModelName(const AZStd::string& name) override;
  49. bool IsSegmentationEnabled() override;
  50. void SetSegmentationEnabled(bool enabled) override;
  51. bool IsAddPointsAtMaxEnabled() override;
  52. void SetAddPointsAtMaxEnabled(bool addPoints) override;
  53. bool Is2D() override;
  54. float GetMinHAngle() override;
  55. void SetMinHAngle(float angle) override;
  56. float GetMaxHAngle() override;
  57. void SetMaxHAngle(float angle) override;
  58. float GetMinVAngle() override;
  59. void SetMinVAngle(float angle) override;
  60. float GetMaxVAngle() override;
  61. void SetMaxVAngle(float angle) override;
  62. unsigned int GetLayers() override;
  63. void SetLayers(unsigned int layers) override;
  64. unsigned int GetNumberOfIncrements() override;
  65. void SetNumberOfIncrements(unsigned int increments) override;
  66. float GetMinRange() override;
  67. void SetMinRange(float range) override;
  68. float GetMaxRange() override;
  69. void SetMaxRange(float range) override;
  70. const LidarTemplate::NoiseParameters& GetNoiseParameters() override;
  71. void SetNoiseParameters(const LidarTemplate::NoiseParameters& params) override;
  72. //////////////////////////////////////////////////////////////////////////
  73. void FrequencyTick();
  74. void PublishRaycastResults(const RaycastResults& results);
  75. bool m_canRaycasterPublish = false;
  76. std::shared_ptr<rclcpp::Publisher<sensor_msgs::msg::PointCloud2>> m_pointCloudPublisher;
  77. std::shared_ptr<rclcpp::Publisher<vision_msgs::msg::LabelInfo>> m_segmentationClassesPublisher;
  78. LidarCore m_lidarCore;
  79. LidarId m_lidarRaycasterId;
  80. };
  81. } // namespace ROS2Sensors