ROS2Lidar2DSensorComponent.h 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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/LidarRegistrarBus.h>
  16. #include <ROS2Sensors/Lidar/LidarSystemBus.h>
  17. #include <ROS2Sensors/Sensor/ROS2SensorComponentBase.h>
  18. #include <rclcpp/publisher.hpp>
  19. #include <sensor_msgs/msg/laser_scan.hpp>
  20. namespace ROS2Sensors
  21. {
  22. //! Lidar 2D 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 ROS2Lidar2DSensorComponent
  27. : public ROS2SensorComponentBase<ROS2::TickBasedSource>
  28. , protected LidarConfigurationRequestBus::Handler
  29. {
  30. public:
  31. AZ_COMPONENT(ROS2Lidar2DSensorComponent, ROS2Sensors::ROS2Lidar2DSensorComponentTypeId, SensorBaseType);
  32. ROS2Lidar2DSensorComponent();
  33. ROS2Lidar2DSensorComponent(const SensorConfiguration& sensorConfiguration, const LidarSensorConfiguration& lidarConfiguration);
  34. ~ROS2Lidar2DSensorComponent() = default;
  35. static void GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& required);
  36. static void Reflect(AZ::ReflectContext* context);
  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. unsigned int GetNumberOfIncrements() override;
  59. void SetNumberOfIncrements(unsigned int increments) override;
  60. float GetMinRange() override;
  61. void SetMinRange(float range) override;
  62. float GetMaxRange() override;
  63. void SetMaxRange(float range) override;
  64. const LidarTemplate::NoiseParameters& GetNoiseParameters() override;
  65. void SetNoiseParameters(const LidarTemplate::NoiseParameters& params) override;
  66. //////////////////////////////////////////////////////////////////////////
  67. void FrequencyTick();
  68. void PublishRaycastResults(const RaycastResults& results);
  69. std::shared_ptr<rclcpp::Publisher<sensor_msgs::msg::LaserScan>> m_laserScanPublisher;
  70. LidarCore m_lidarCore;
  71. };
  72. } // namespace ROS2Sensors