TwistControl.cpp 1012 B

123456789101112131415161718192021222324252627
  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 <AzFramework/Physics/RigidBodyBus.h>
  9. #include "TwistControl.h"
  10. #include "Utilities/ROS2Conversions.h"
  11. namespace ROS2
  12. {
  13. void TwistControl::SetTargetComponent(const AZ::Entity* entity)
  14. {
  15. m_entityID = entity->GetId();
  16. }
  17. void TwistControl::ApplyControl(const geometry_msgs::msg::Twist& message)
  18. {
  19. const AZ::Vector3 linearVelocity = ROS2Conversions::FromROS2Vector3(message.linear);
  20. const AZ::Vector3 angularVelocity = ROS2Conversions::FromROS2Vector3(message.angular);
  21. Physics::RigidBodyRequestBus::Event(m_entityID, &Physics::RigidBodyRequests::SetLinearVelocity, linearVelocity);
  22. Physics::RigidBodyRequestBus::Event(m_entityID, &Physics::RigidBodyRequests::SetAngularVelocity, angularVelocity);
  23. }
  24. } // namespace ROS2