LidarCore.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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 "LidarRaycaster.h"
  10. #include <Atom/RPI.Public/AuxGeom/AuxGeomDraw.h>
  11. #include <AzCore/Component/EntityId.h>
  12. #include <AzCore/Serialization/SerializeContext.h>
  13. #include <ROS2Sensors/Lidar/LidarRegistrarBus.h>
  14. #include <ROS2Sensors/Lidar/LidarSensorConfiguration.h>
  15. #include <ROS2Sensors/Lidar/LidarSystemBus.h>
  16. namespace ROS2Sensors
  17. {
  18. //! A class for executing lidar operations, such as data acquisition and visualization.
  19. class LidarCore
  20. {
  21. public:
  22. AZ_TYPE_INFO(LidarCore, "{e46126a2-7a86-bb65-367a-416f2cab393c}");
  23. static void Reflect(AZ::ReflectContext* context);
  24. LidarCore(const AZStd::vector<LidarTemplate::LidarModel>& availableModels = {});
  25. LidarCore(const LidarSensorConfiguration& lidarConfiguration);
  26. ~LidarCore() = default;
  27. //! Initialize when activating the lidar.
  28. //! @param entityId Entity from which the rays are sent.
  29. void Init(AZ::EntityId entityId);
  30. //! Deinitialize when deactivating the lidar.
  31. void Deinit();
  32. //! Perform a raycast.
  33. //! @return Results of the raycast.
  34. AZStd::optional<RaycastResults> PerformRaycast();
  35. //! Visualize the results of the last performed raycast.
  36. void VisualizeResults() const;
  37. //! Get the raycaster used by this lidar.
  38. //! @return Used raycaster's id.
  39. LidarId GetLidarRaycasterId() const;
  40. //! Get the result flags used by this lidar.
  41. //! @return Used result flags.
  42. RaycastResultFlags GetResultFlags() const;
  43. //! Configuration according to which the lidar performs its raycasts.
  44. //! Note: the configuration can be changed only when the lidar is not active.
  45. LidarSensorConfiguration m_lidarConfiguration;
  46. private:
  47. static RaycastResultFlags GetRaycastResultFlagsForConfig(const LidarSensorConfiguration& configuration);
  48. void ConnectToLidarRaycaster();
  49. void ConfigureLidarRaycaster();
  50. void UpdatePoints(const RaycastResults& results);
  51. //! An unordered map of lidar implementations to their raycasters created by this LidarSensorComponent.
  52. AZStd::unordered_map<AZStd::string, LidarId> m_implementationToRaycasterMap;
  53. LidarId m_lidarRaycasterId;
  54. AZ::RPI::AuxGeomDrawPtr m_drawQueue;
  55. AZStd::vector<AZ::Vector3> m_lastRotations;
  56. AZStd::vector<AZ::Vector3> m_lastPoints;
  57. AZ::EntityId m_entityId;
  58. RaycastResultFlags m_resultFlags;
  59. };
  60. } // namespace ROS2Sensors