JointsManipulationRequests.h 5.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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 <AzCore/EBus/EBus.h>
  10. #include <AzCore/Outcome/Outcome.h>
  11. #include <AzCore/std/containers/vector.h>
  12. #include <AzCore/std/string/string.h>
  13. #include <ROS2Controllers/Manipulation/JointInfo.h>
  14. namespace ROS2
  15. {
  16. //! Interface for general requests for joint systems such as manipulator arms.
  17. //! This interface supports only systems with joints or articulation links with a single degree of freedom (DOF) each.
  18. class JointsManipulationRequests : public AZ::EBusTraits
  19. {
  20. public:
  21. using BusIdType = AZ::EntityId;
  22. static constexpr AZ::EBusAddressPolicy AddressPolicy = AZ::EBusAddressPolicy::ById;
  23. using JointsPositionsMap = AZStd::unordered_map<AZStd::string, JointPosition>;
  24. using JointsVelocitiesMap = AZStd::unordered_map<AZStd::string, JointVelocity>;
  25. using JointsEffortsMap = AZStd::unordered_map<AZStd::string, JointEffort>;
  26. //! Get all entity tree joints, including joint or articulation component hierarchy.
  27. //! @return An unordered map of joint names to joint info structure.
  28. //! @note Only free joints are returned (no fixed ones).
  29. virtual ManipulationJoints GetJoints() = 0;
  30. //! Get position of a joint by name.
  31. //! Works with hinge joints and articulation links.
  32. //! @param jointName name of the joint. Use names acquired from GetJoints() query.
  33. //! @return outcome with relative position in degree of motion range if joint exists.
  34. //! If it does not exist or some other error happened, error message is returned.
  35. virtual AZ::Outcome<JointPosition, AZStd::string> GetJointPosition(const AZStd::string& jointName) = 0;
  36. //! Get velocity of a joint by name.
  37. //! Works with hinge joints and articulation links.
  38. //! @param jointName name of the joint. Use names acquired from GetJoints() query.
  39. //! @return outcome with velocity if joint exists.
  40. //! If it does not exist or some other error happened, error message is returned.
  41. virtual AZ::Outcome<JointVelocity, AZStd::string> GetJointVelocity(const AZStd::string& jointName) = 0;
  42. //! Return positions of all single DOF joints.
  43. //! @return a vector of all joints relative positions in degree of motion range or error message.
  44. virtual JointsPositionsMap GetAllJointsPositions() = 0;
  45. //! Return velocities of all single DOF joints.
  46. //! @return a vector of all joints velocities or error message.
  47. virtual JointsVelocitiesMap GetAllJointsVelocities() = 0;
  48. //! Get effort of a force-driven articulation link by name.
  49. //! If the joint is not an articulation link, or it's acceleration-driven, returns 0.
  50. //! @param jointName name of the joint. Use names acquired from GetJoints() query.
  51. //! @return outcome with effort if joint exists.
  52. //! If it does not exist or some other error happened, error message is returned.
  53. virtual AZ::Outcome<JointEffort, AZStd::string> GetJointEffort(const AZStd::string& jointName) = 0;
  54. //! Return efforts of all single DOF joints.
  55. //! @return a vector of all joints efforts or error message.
  56. virtual JointsEffortsMap GetAllJointsEfforts() = 0;
  57. //! Move specified joints into positions.
  58. //! @param new positions for each named joint. Use names queried through GetJoints().
  59. //! @return nothing on success, error message on failure.
  60. //! @note the movement is realized by a specific controller and not instant. The joints will then keep these positions.
  61. virtual AZ::Outcome<void, AZStd::string> MoveJointsToPositions(const JointsPositionsMap& positions) = 0;
  62. //! Move a single joint into desired relative position.
  63. //! @param jointName name of the joint. Use names acquired from GetJoints() query.
  64. //! @param position relative position in degree of motion range to achieve.
  65. //! @return nothing on success, error message on failure.
  66. //! @note the movement is realized by a specific controller and not instant. The joints will then keep this position.
  67. virtual AZ::Outcome<void, AZStd::string> MoveJointToPosition(const AZStd::string& jointName, JointPosition position) = 0;
  68. //! Set max effort of an articulation link by name.
  69. //! If the joint is not an articulation link, doesn't do anything
  70. //! @param jointName name of the joint. Use names acquired from GetJoints() query.
  71. //! @return outcome with effort if joint exists.
  72. //! If it does not exist or some other error happened, error message is returned.
  73. virtual AZ::Outcome<void, AZStd::string> SetMaxJointEffort(const AZStd::string& jointName, JointEffort maxEffort) = 0;
  74. //! Stop the joints movement in progress. It will keep the position in which it stopped.
  75. virtual void Stop() = 0;
  76. };
  77. using JointsManipulationRequestBus = AZ::EBus<JointsManipulationRequests>;
  78. } // namespace ROS2