FingerGripperComponent.h 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. #pragma once
  10. #include <AzCore/Component/Component.h>
  11. #include <AzCore/Component/TickBus.h>
  12. #include <AzFramework/Physics/Common/PhysicsEvents.h>
  13. #include <ImGuiBus.h>
  14. #include <ROS2Controllers/Gripper/GripperRequestBus.h>
  15. #include <ROS2Controllers/Manipulation/JointsManipulationRequests.h>
  16. #include <ROS2Controllers/ROS2ControllersTypeIds.h>
  17. #include <Utilities/ArticulationsUtilities.h>
  18. namespace ROS2
  19. {
  20. //! This component implements finger gripper functionality.
  21. class FingerGripperComponent
  22. : public AZ::Component
  23. , public GripperRequestBus::Handler
  24. , public ImGui::ImGuiUpdateListenerBus::Handler
  25. , public AZ::TickBus::Handler
  26. {
  27. public:
  28. AZ_COMPONENT(FingerGripperComponent, ROS2Controllers::FingerGripperComponentTypeId, AZ::Component);
  29. FingerGripperComponent() = default;
  30. ~FingerGripperComponent() = default;
  31. // AZ::Component overrides...
  32. void Activate() override;
  33. void Deactivate() override;
  34. static void GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided);
  35. static void GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible);
  36. static void Reflect(AZ::ReflectContext* context);
  37. private:
  38. // GripperRequestBus::Handler overrides...
  39. AZ::Outcome<void, AZStd::string> GripperCommand(float position, float maxEffort) override;
  40. AZ::Outcome<void, AZStd::string> CancelGripperCommand() override;
  41. bool HasGripperCommandBeenCancelled() const override;
  42. // Sum of all joint positions
  43. float GetGripperPosition() const override;
  44. // Sum of all efforts exerted by fingers
  45. float GetGripperEffort() const override;
  46. // Non-articulation fingers return 0 effort!
  47. bool IsGripperNotMoving() const override;
  48. // Doesn't check if the max force is applied, only checks speed
  49. bool HasGripperReachedGoal() const override;
  50. // ImGui::ImGuiUpdateListenerBus::Handler overrides...
  51. void OnImGuiUpdate() override;
  52. // AZ::TickBus::Handler overrides...
  53. void OnTick(float delta, AZ::ScriptTimePoint timePoint) override;
  54. ManipulationJoints& GetFingerJoints();
  55. AZ::EntityId m_rootOfArticulation; //!< The root of the articulation chain
  56. float GetDefaultPosition();
  57. void SetPosition(float position, float maxEffort);
  58. bool IsGripperVelocity0() const;
  59. void PublishFeedback() const;
  60. ManipulationJoints m_fingerJoints;
  61. bool m_grippingInProgress{ false };
  62. bool m_cancelled{ false };
  63. bool m_initialised{ false };
  64. float m_desiredPosition{ false };
  65. float m_stallingFor{ 0.f };
  66. float m_ImGuiPosition{ 0.1f };
  67. float m_velocityEpsilon{ 0.01f }; //!< The epsilon value used to determine whether the gripper is moving
  68. float m_goalTolerance{ 0.001f }; //!< The epsilon value used to determine whether the gripper reached it's goal
  69. float m_stallTime{ 0.1f }; //!< The time in seconds to wait before determining the gripper is stalled
  70. float m_initialPosition{ 0.0f }; //!< The initial position of the gripper in units of the gripper's joints
  71. };
  72. } // namespace ROS2