LidarTemplate.cpp 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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. #include <AzCore/Serialization/EditContext.h>
  9. #include <ROS2Sensors/Lidar/LidarTemplate.h>
  10. namespace ROS2Sensors
  11. {
  12. void LidarTemplate::NoiseParameters::Reflect(AZ::ReflectContext* context)
  13. {
  14. if (auto serializeContext = azrtti_cast<AZ::SerializeContext*>(context))
  15. {
  16. serializeContext->Class<NoiseParameters>()
  17. ->Version(1)
  18. ->Field("Angular noise standard deviation", &NoiseParameters::m_angularNoiseStdDev)
  19. ->Field("Distance noise standard deviation base", &NoiseParameters::m_distanceNoiseStdDevBase)
  20. ->Field("Distance noise standard deviation slope", &NoiseParameters::m_distanceNoiseStdDevRisePerMeter);
  21. if (AZ::EditContext* editContext = serializeContext->GetEditContext())
  22. {
  23. editContext->Class<NoiseParameters>("Noise Parameters", "Noise Parameters")
  24. ->DataElement(
  25. AZ::Edit::UIHandlers::Default,
  26. &NoiseParameters::m_angularNoiseStdDev,
  27. "Angular noise std dev [Deg]",
  28. "Angular noise standard deviation")
  29. ->Attribute(AZ::Edit::Attributes::Min, 0.0f)
  30. ->Attribute(AZ::Edit::Attributes::Max, 180.0f)
  31. ->DataElement(
  32. AZ::Edit::UIHandlers::Default,
  33. &NoiseParameters::m_distanceNoiseStdDevBase,
  34. "Distance noise std dev base [m]",
  35. "Distance noise standard deviation base")
  36. ->Attribute(AZ::Edit::Attributes::Min, 0.0f)
  37. ->DataElement(
  38. AZ::Edit::UIHandlers::Default,
  39. &NoiseParameters::m_distanceNoiseStdDevRisePerMeter,
  40. "Distance noise std dev slope [m]",
  41. "Distance noise standard deviation slope")
  42. ->Attribute(AZ::Edit::Attributes::Min, 0.0f);
  43. }
  44. }
  45. }
  46. bool LidarTemplate::IsLayersVisible() const
  47. {
  48. return !m_is2D;
  49. }
  50. void LidarTemplate::Reflect(AZ::ReflectContext* context)
  51. {
  52. NoiseParameters::Reflect(context);
  53. if (auto serializeContext = azrtti_cast<AZ::SerializeContext*>(context))
  54. {
  55. serializeContext->Class<LidarTemplate>()
  56. ->Version(2)
  57. ->Field("Name", &LidarTemplate::m_name)
  58. ->Field("Layers", &LidarTemplate::m_layers)
  59. ->Field("Points per layer", &LidarTemplate::m_numberOfIncrements)
  60. ->Field("Min horizontal angle", &LidarTemplate::m_minHAngle)
  61. ->Field("Max horizontal angle", &LidarTemplate::m_maxHAngle)
  62. ->Field("Min vertical angle", &LidarTemplate::m_minVAngle)
  63. ->Field("Max vertical angle", &LidarTemplate::m_maxVAngle)
  64. ->Field("Min range", &LidarTemplate::m_minRange)
  65. ->Field("Max range", &LidarTemplate::m_maxRange)
  66. ->Field("Enable Noise", &LidarTemplate::m_isNoiseEnabled)
  67. ->Field("Noise Parameters", &LidarTemplate::m_noiseParameters);
  68. if (AZ::EditContext* ec = serializeContext->GetEditContext())
  69. {
  70. ec->Class<LidarTemplate>("Lidar Template", "Lidar Template")
  71. ->DataElement(AZ::Edit::UIHandlers::Default, &LidarTemplate::m_name, "Name", "Custom lidar name")
  72. ->DataElement(AZ::Edit::UIHandlers::Default, &LidarTemplate::m_layers, "Layers", "Vertical dimension")
  73. ->Attribute(AZ::Edit::Attributes::Visibility, &LidarTemplate::IsLayersVisible)
  74. ->DataElement(
  75. AZ::Edit::UIHandlers::Default, &LidarTemplate::m_numberOfIncrements, "Points per layer", "Horizontal dimension")
  76. ->DataElement(
  77. AZ::Edit::UIHandlers::Default, &LidarTemplate::m_minHAngle, "Min horizontal angle [Deg]", "Left-most reach of fov")
  78. ->Attribute(AZ::Edit::Attributes::Min, -180.0f)
  79. ->Attribute(AZ::Edit::Attributes::Max, 180.0f)
  80. ->DataElement(
  81. AZ::Edit::UIHandlers::Default, &LidarTemplate::m_maxHAngle, "Max horizontal angle [Deg]", "Right-most reach of fov")
  82. ->Attribute(AZ::Edit::Attributes::Min, -180.0f)
  83. ->Attribute(AZ::Edit::Attributes::Max, 180.0f)
  84. ->DataElement(
  85. AZ::Edit::UIHandlers::Default, &LidarTemplate::m_minVAngle, "Min vertical angle [Deg]", "Downwards reach of fov")
  86. ->Attribute(AZ::Edit::Attributes::Min, -90.0f)
  87. ->Attribute(AZ::Edit::Attributes::Max, 90.0f)
  88. ->Attribute(AZ::Edit::Attributes::Visibility, &LidarTemplate::IsLayersVisible)
  89. ->DataElement(
  90. AZ::Edit::UIHandlers::Default, &LidarTemplate::m_maxVAngle, "Max vertical angle [Deg]", "Upwards reach of fov")
  91. ->Attribute(AZ::Edit::Attributes::Min, -90.0f)
  92. ->Attribute(AZ::Edit::Attributes::Max, 90.0f)
  93. ->Attribute(AZ::Edit::Attributes::Visibility, &LidarTemplate::IsLayersVisible)
  94. ->DataElement(AZ::Edit::UIHandlers::Default, &LidarTemplate::m_minRange, "Min range", "Minimum beam range [m]")
  95. ->Attribute(AZ::Edit::Attributes::ChangeValidate, &LidarTemplate::ValidateMinRange)
  96. ->DataElement(AZ::Edit::UIHandlers::Default, &LidarTemplate::m_maxRange, "Max range", "Maximum beam range [m]")
  97. ->Attribute(AZ::Edit::Attributes::ChangeValidate, &LidarTemplate::ValidateMaxRange)
  98. ->DataElement(
  99. AZ::Edit::UIHandlers::Default,
  100. &LidarTemplate::m_isNoiseEnabled,
  101. "Enable noise",
  102. "Enable the use of noise and it's configuration")
  103. ->Attribute(AZ::Edit::Attributes::Visibility, &LidarTemplate::m_showNoiseConfig)
  104. ->Attribute(AZ::Edit::Attributes::ChangeNotify, AZ::Edit::PropertyRefreshLevels::EntireTree)
  105. ->DataElement(
  106. AZ::Edit::UIHandlers::Default,
  107. &LidarTemplate::m_noiseParameters,
  108. "Noise parameters",
  109. "Parameters for Noise Configuration")
  110. ->Attribute(AZ::Edit::Attributes::Visibility, &LidarTemplate::IsNoiseConfigVisible);
  111. }
  112. }
  113. }
  114. bool LidarTemplate::IsNoiseConfigVisible() const
  115. {
  116. return m_showNoiseConfig && m_isNoiseEnabled;
  117. }
  118. AZ::Outcome<void, AZStd::string> LidarTemplate::ValidateRange(float minRange, float maxRange)
  119. {
  120. if (0.0f <= minRange && minRange <= maxRange)
  121. {
  122. return AZ::Success();
  123. }
  124. return AZ::Failure(AZStd::string::format(
  125. "Provided ray range (%.2f, %.2f) was of incorrect value: Max range must be greater than or equal to min range,"
  126. " and both must be greater than zero.",
  127. minRange,
  128. maxRange));
  129. }
  130. AZ::Outcome<void, AZStd::string> LidarTemplate::ValidateMinRange(void* newValue, const AZ::TypeId& valueType) const
  131. {
  132. if (azrtti_typeid<float>() != valueType)
  133. {
  134. AZ_Assert(false, "Unexpected value type");
  135. return AZ::Failure(AZStd::string("Unexpectedly received a non-float type for the min range!"));
  136. }
  137. return ValidateRange(*reinterpret_cast<float*>(newValue), m_maxRange);
  138. }
  139. AZ::Outcome<void, AZStd::string> LidarTemplate::ValidateMaxRange(void* newValue, const AZ::TypeId& valueType) const
  140. {
  141. if (azrtti_typeid<float>() != valueType)
  142. {
  143. AZ_Assert(false, "Unexpected value type");
  144. return AZ::Failure(AZStd::string("Unexpectedly received a non-float type for the max range!"));
  145. }
  146. return ValidateRange(m_minRange, *reinterpret_cast<float*>(newValue));
  147. }
  148. } // namespace ROS2Sensors