ROS2ControllersEditorSystemComponent.cpp 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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
  4. * of this distribution.
  5. *
  6. * SPDX-License-Identifier: Apache-2.0 OR MIT
  7. *
  8. */
  9. #include "ROS2ControllersEditorSystemComponent.h"
  10. #include <AzCore/Serialization/SerializeContext.h>
  11. #include <Manipulation/Controllers/JointsArticulationControllerComponent.h>
  12. #include <Manipulation/Controllers/JointsPIDControllerComponent.h>
  13. #include <Manipulation/JointsManipulationEditorComponent.h>
  14. #include <Manipulation/JointsTrajectoryComponent.h>
  15. #include <ROS2Controllers/ROS2ControllersTypeIds.h>
  16. #include <RobotControl/Controllers/AckermannController/AckermannControlComponent.h>
  17. #include <RobotControl/Controllers/SkidSteeringController/SkidSteeringControlComponent.h>
  18. #include <RobotControl/ROS2RobotControlComponent.h>
  19. #include <VehicleDynamics/ModelComponents/AckermannModelComponent.h>
  20. #include <VehicleDynamics/ModelComponents/SkidSteeringModelComponent.h>
  21. #include <VehicleDynamics/ModelLimits/AckermannModelLimits.h>
  22. #include <VehicleDynamics/WheelControllerComponent.h>
  23. namespace ROS2Controllers
  24. {
  25. AZ_COMPONENT_IMPL(
  26. ROS2ControllersEditorSystemComponent,
  27. "ROS2ControllersEditorSystemComponent",
  28. ROS2ControllersEditorSystemComponentTypeId,
  29. BaseSystemComponent);
  30. void ROS2ControllersEditorSystemComponent::Reflect(AZ::ReflectContext* context)
  31. {
  32. if (auto serializeContext = azrtti_cast<AZ::SerializeContext*>(context))
  33. {
  34. serializeContext->Class<ROS2ControllersEditorSystemComponent, ROS2ControllersSystemComponent>()->Version(1)->Attribute(
  35. AZ::Edit::Attributes::SystemComponentTags, AZStd::vector<AZ::Crc32>({ AZ_CRC_CE("AssetBuilder") }));
  36. }
  37. }
  38. ROS2ControllersEditorSystemComponent::ROS2ControllersEditorSystemComponent()
  39. {
  40. if (ROS2ControllersEditorInterface::Get() == nullptr)
  41. {
  42. ROS2ControllersEditorInterface::Register(this);
  43. }
  44. }
  45. ROS2ControllersEditorSystemComponent::~ROS2ControllersEditorSystemComponent()
  46. {
  47. if (ROS2ControllersEditorInterface::Get() == this)
  48. {
  49. ROS2ControllersEditorInterface::Unregister(this);
  50. }
  51. }
  52. void ROS2ControllersEditorSystemComponent::GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided)
  53. {
  54. BaseSystemComponent::GetProvidedServices(provided);
  55. provided.push_back(AZ_CRC_CE("ROS2ControllersEditorService"));
  56. }
  57. void ROS2ControllersEditorSystemComponent::GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible)
  58. {
  59. BaseSystemComponent::GetIncompatibleServices(incompatible);
  60. incompatible.push_back(AZ_CRC_CE("ROS2ControllersEditorService"));
  61. }
  62. void ROS2ControllersEditorSystemComponent::GetRequiredServices([[maybe_unused]] AZ::ComponentDescriptor::DependencyArrayType& required)
  63. {
  64. BaseSystemComponent::GetRequiredServices(required);
  65. }
  66. void ROS2ControllersEditorSystemComponent::GetDependentServices(
  67. [[maybe_unused]] AZ::ComponentDescriptor::DependencyArrayType& dependent)
  68. {
  69. BaseSystemComponent::GetDependentServices(dependent);
  70. }
  71. void ROS2ControllersEditorSystemComponent::Activate()
  72. {
  73. ROS2ControllersSystemComponent::Activate();
  74. AzToolsFramework::EditorEvents::Bus::Handler::BusConnect();
  75. }
  76. void ROS2ControllersEditorSystemComponent::Deactivate()
  77. {
  78. AzToolsFramework::EditorEvents::Bus::Handler::BusDisconnect();
  79. ROS2ControllersSystemComponent::Deactivate();
  80. }
  81. AZ::Component* ROS2ControllersEditorSystemComponent::CreateWheelControllerComponent(
  82. AZ::Entity& entity, const AZ::EntityId& steeringEntity, const float steeringScale)
  83. {
  84. return CreateComponent<VehicleDynamics::WheelControllerComponent>(entity, steeringEntity, steeringScale);
  85. }
  86. AZ::Component* ROS2ControllersEditorSystemComponent::CreateROS2RobotControlComponent(
  87. AZ::Entity& entity, const ControlConfiguration& configuration)
  88. {
  89. return CreateComponent<ROS2Controllers::ROS2RobotControlComponent>(entity, configuration);
  90. }
  91. AZ::Component* ROS2ControllersEditorSystemComponent::CreateAckermannVehicleModelComponent(
  92. AZ::Entity& entity,
  93. const VehicleDynamics::VehicleConfiguration& configuration,
  94. const float speedLimit,
  95. const float steeringLimit,
  96. const float acceleration,
  97. const PidConfiguration& steeringPid)
  98. {
  99. VehicleDynamics::AckermannModelLimits modelLimits(speedLimit, steeringLimit, acceleration);
  100. return CreateComponent<VehicleDynamics::AckermannVehicleModelComponent>(
  101. entity, configuration, VehicleDynamics::AckermannDriveModel(modelLimits, steeringPid));
  102. }
  103. AZ::Component* ROS2ControllersEditorSystemComponent::CreateAckermannControlComponent(AZ::Entity& entity)
  104. {
  105. return CreateComponent<AckermannControlComponent>(entity);
  106. }
  107. AZ::Component* ROS2ControllersEditorSystemComponent::CreateSkidSteeringModelComponent(
  108. AZ::Entity& entity,
  109. const VehicleDynamics::VehicleConfiguration& configuration,
  110. const float linearLimit,
  111. const float angularLimit,
  112. const float linearAcceleration,
  113. const float angularAcceleration)
  114. {
  115. VehicleDynamics::SkidSteeringModelLimits modelLimits(linearLimit, angularLimit, linearAcceleration, angularAcceleration);
  116. return CreateComponent<VehicleDynamics::SkidSteeringModelComponent>(
  117. entity, configuration, VehicleDynamics::SkidSteeringDriveModel(modelLimits));
  118. }
  119. AZ::Component* ROS2ControllersEditorSystemComponent::CreateSkidSteeringControlComponent(AZ::Entity& entity)
  120. {
  121. return CreateComponent<ROS2Controllers::SkidSteeringControlComponent>(entity);
  122. }
  123. AZ::Component* ROS2ControllersEditorSystemComponent::CreateJointsArticulationControllerComponent(AZ::Entity& entity)
  124. {
  125. return CreateComponent<ROS2Controllers::JointsArticulationControllerComponent>(entity);
  126. }
  127. AZ::Component* ROS2ControllersEditorSystemComponent::CreateJointsPIDControllerComponent(AZ::Entity& entity)
  128. {
  129. return CreateComponent<ROS2Controllers::JointsPIDControllerComponent>(entity);
  130. }
  131. AZ::Component* ROS2ControllersEditorSystemComponent::CreateJointsManipulationEditorComponent(
  132. AZ::Entity& entity, const ROS2::PublisherConfiguration& publisherConfig)
  133. {
  134. return CreateComponent<ROS2Controllers::JointsManipulationEditorComponent>(entity, publisherConfig);
  135. }
  136. AZ::Component* ROS2ControllersEditorSystemComponent::CreateJointsTrajectoryComponent(
  137. AZ::Entity& entity, const AZStd::string& actionName)
  138. {
  139. return CreateComponent<ROS2Controllers::JointsTrajectoryComponent>(entity, actionName);
  140. }
  141. } // namespace ROS2Controllers