AxleConfiguration.cpp 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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 <AzCore/Serialization/EditContextConstants.inl>
  10. #include <ROS2Controllers/VehicleDynamics/AxleConfiguration.h>
  11. namespace ROS2Controllers::VehicleDynamics
  12. {
  13. void AxleConfiguration::Reflect(AZ::ReflectContext* context)
  14. {
  15. if (AZ::SerializeContext* serialize = azrtti_cast<AZ::SerializeContext*>(context))
  16. {
  17. serialize->Class<AxleConfiguration>()
  18. ->Version(2)
  19. ->Field("AxleTag", &AxleConfiguration::m_axleTag)
  20. ->Field("AxleWheels", &AxleConfiguration::m_axleWheels)
  21. ->Field("WheelRadius", &AxleConfiguration::m_wheelRadius)
  22. ->Field("IsSteering", &AxleConfiguration::m_isSteering)
  23. ->Field("IsDrive", &AxleConfiguration::m_isDrive);
  24. if (AZ::EditContext* ec = serialize->GetEditContext())
  25. {
  26. ec->Class<AxleConfiguration>("Axle configuration", "Axles of the vehicle model")
  27. ->ClassElement(AZ::Edit::ClassElements::EditorData, "")
  28. ->Attribute(AZ::Edit::Attributes::Category, "ROS2")
  29. ->DataElement(
  30. AZ::Edit::UIHandlers::Default, &AxleConfiguration::m_axleTag, "Axle tag", "Helpful description of the axle")
  31. ->DataElement(
  32. AZ::Edit::UIHandlers::Default,
  33. &AxleConfiguration::m_isSteering,
  34. "Is it a steering axle",
  35. "Is this axle used for steering (all attached wheels)")
  36. ->DataElement(
  37. AZ::Edit::UIHandlers::Default,
  38. &AxleConfiguration::m_isDrive,
  39. "Is it a drive axle",
  40. "Is this axle used for drive (all attached wheels)")
  41. ->DataElement(
  42. AZ::Edit::UIHandlers::Default,
  43. &AxleConfiguration::m_wheelRadius,
  44. "Wheel radius",
  45. "Radius of each wheel attached to axle")
  46. ->Attribute(AZ::Edit::Attributes::Min, 0.01f)
  47. ->Attribute(AZ::Edit::Attributes::Max, 10.0f)
  48. ->DataElement(
  49. AZ::Edit::UIHandlers::Default,
  50. &AxleConfiguration::m_axleWheels,
  51. "Axle wheels",
  52. "One or more wheels attached to this axle. First wheel is the leftmost, last is the rightmost")
  53. ->Attribute(AZ::Edit::Attributes::AutoExpand, true);
  54. }
  55. }
  56. }
  57. AZ::EntityId AxleConfiguration::GetLeftWheelEntityId() const
  58. {
  59. if (m_axleWheels.empty())
  60. {
  61. return AZ::EntityId();
  62. }
  63. return m_axleWheels.front();
  64. }
  65. AZ::EntityId AxleConfiguration::GetRightWheelEntityId() const
  66. {
  67. if (m_axleWheels.empty())
  68. {
  69. return AZ::EntityId();
  70. }
  71. return m_axleWheels.back();
  72. }
  73. } // namespace ROS2Controllers::VehicleDynamics