JointsArticulationControllerComponent.cpp 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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 "JointsArticulationControllerComponent.h"
  9. #include <AzCore/Serialization/EditContext.h>
  10. #include <PhysX/ArticulationJointBus.h>
  11. namespace ROS2
  12. {
  13. void JointsArticulationControllerComponent::Activate()
  14. {
  15. JointsPositionControllerRequestBus::Handler::BusConnect(GetEntityId());
  16. }
  17. void JointsArticulationControllerComponent::Deactivate()
  18. {
  19. JointsPositionControllerRequestBus::Handler::BusDisconnect();
  20. }
  21. AZ::Outcome<void, AZStd::string> JointsArticulationControllerComponent::PositionControl(
  22. const AZStd::string& jointName,
  23. JointInfo joint,
  24. [[maybe_unused]] JointPosition currentPosition,
  25. JointPosition targetPosition,
  26. [[maybe_unused]] float deltaTime)
  27. {
  28. if (!joint.m_isArticulation)
  29. {
  30. return AZ::Failure(
  31. AZStd::string::format("Joint %s is not an articulation link, use JointsPIDControllerComponent instead", jointName.c_str()));
  32. }
  33. PhysX::ArticulationJointRequestBus::Event(
  34. joint.m_entityComponentIdPair.GetEntityId(), &PhysX::ArticulationJointRequests::SetDriveTarget, joint.m_axis, targetPosition);
  35. return AZ::Success();
  36. }
  37. void JointsArticulationControllerComponent::GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& required)
  38. {
  39. required.push_back(AZ_CRC_CE("ArticulationLinkService"));
  40. }
  41. void JointsArticulationControllerComponent::GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided)
  42. {
  43. provided.push_back(AZ_CRC_CE("JointsControllerService"));
  44. }
  45. void JointsArticulationControllerComponent::GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible)
  46. {
  47. incompatible.push_back(AZ_CRC_CE("JointsControllerService"));
  48. }
  49. void JointsArticulationControllerComponent::Reflect(AZ::ReflectContext* context)
  50. {
  51. if (AZ::SerializeContext* serialize = azrtti_cast<AZ::SerializeContext*>(context))
  52. {
  53. serialize->Class<JointsArticulationControllerComponent, AZ::Component>()->Version(0);
  54. if (AZ::EditContext* ec = serialize->GetEditContext())
  55. {
  56. ec->Class<JointsArticulationControllerComponent>(
  57. "JointsArticulationControllerComponent", "Component to move articulation joints")
  58. ->ClassElement(AZ::Edit::ClassElements::EditorData, "")
  59. ->Attribute(AZ::Edit::Attributes::AppearsInAddComponentMenu, AZ_CRC("Game"))
  60. ->Attribute(AZ::Edit::Attributes::Category, "ROS2")
  61. ->Attribute(AZ::Edit::Attributes::Icon, "Editor/Icons/Components/JointsArticulationControllerComponent.svg")
  62. ->Attribute(
  63. AZ::Edit::Attributes::ViewportIcon, "Editor/Icons/Components/Viewport/JointsArticulationControllerComponent.svg");
  64. }
  65. }
  66. }
  67. } // namespace ROS2