RigidBodyTwistControlComponent.h 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. #pragma once
  9. #include "RigidBodyTwistControlComponentConfig.h"
  10. #include <AzCore/Component/Component.h>
  11. #include <AzCore/Component/TickBus.h>
  12. #include <AzFramework/Physics/PhysicsSystem.h>
  13. #include <ROS2Controllers/RobotControl/Twist/TwistBus.h>
  14. namespace ROS2Controllers
  15. {
  16. //! A component with a simple handler for Twist type of control (linear and angular velocities).
  17. //! Velocities are directly applied to a selected body.
  18. class RigidBodyTwistControlComponent
  19. : public AZ::Component
  20. , private TwistNotificationBus::Handler
  21. , private AZ::TickBus::Handler
  22. {
  23. public:
  24. AZ_COMPONENT(RigidBodyTwistControlComponent, "{D994FE1A-AA6A-42B9-8B8E-B3B375891F5B}", AZ::Component);
  25. RigidBodyTwistControlComponent() = default;
  26. //////////////////////////////////////////////////////////////////////////
  27. // Component overrides
  28. void Activate() override;
  29. void Deactivate() override;
  30. //////////////////////////////////////////////////////////////////////////
  31. static void GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& required);
  32. static void GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible);
  33. static void Reflect(AZ::ReflectContext* context);
  34. private:
  35. //////////////////////////////////////////////////////////////////////////
  36. // TwistNotificationBus::Handler overrides
  37. void TwistReceived(const AZ::Vector3& linear, const AZ::Vector3& angular) override;
  38. //////////////////////////////////////////////////////////////////////////
  39. //////////////////////////////////////////////////////////////////////////
  40. // AZ::TickBus::Handler overrides
  41. void OnTick(float deltaTime, AZ::ScriptTimePoint time) override;
  42. //////////////////////////////////////////////////////////////////////////
  43. void OnSceneSimulationFinish(
  44. AzPhysics::SceneHandle sceneHandle,
  45. float fixedDeltaTime); //!< Handler for scene simulation finish event
  46. AZ::Vector3 m_linearVelocityLocal{ AZ::Vector3::CreateZero() }; //!< Linear velocity in local frame
  47. AZ::Vector3 m_angularVelocityLocal{ AZ::Vector3::CreateZero() }; //!< Angular velocity in local frame
  48. AzPhysics::SceneEvents::OnSceneSimulationFinishHandler m_sceneFinishSimHandler; //!< Handler called after every physics sub-step
  49. AzPhysics::SimulatedBodyHandle m_bodyHandle = AzPhysics::InvalidSimulatedBodyHandle; //!< Handle to the body to apply velocities to
  50. RigidBodyTwistControlComponentConfig m_config; //!< Configuration for the component
  51. };
  52. } // namespace ROS2Controllers