PickingStructs.h 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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/Component/EntityId.h>
  10. #include <AzCore/Math/Aabb.h>
  11. namespace AppleKraken
  12. {
  13. //! Important states of the Kraken effector (manipulator with a vacuum nozzle)
  14. enum class EffectorState : int16_t
  15. {
  16. INVALID = -1, //!< Invalid state. Requires an additional context that could help user understand what happened. @see PickingState.
  17. IDLE = 0, //!< Idle state / position, suitable for robot moving around the environment.
  18. PREPARED = 10, //!< State and position which are ready for picking tasks.
  19. PICKING = 20, //!< The effector is on its way to pick fruit.
  20. PICKING_STABILIZE = 25, //!< The effector waits vacuum being built up
  21. RETRIEVING_NOSE = 30, //!< The effector is retrieving a fruit to storage position.
  22. RETRIEVING = 35, //!< The effector is retrieving a fruit to storage position.
  23. RETRIEVING_STABILIZE = 40, //!< The effector is retrieving, wait for apple to drop
  24. RETRIEVING_FAILED = 50 //!< The effector is retrieving after failing to pick the apple.
  25. };
  26. //! A task to pick a single apple.
  27. struct PickAppleTask
  28. {
  29. bool IsValid() const
  30. {
  31. return m_appleEntityId.IsValid();
  32. }
  33. void Invalidate()
  34. {
  35. m_appleEntityId = AZ::EntityId();
  36. }
  37. AZ::EntityId m_appleEntityId; //!< EntityId of the apple. Can be Invalid if the information is not available (check IsValid()).
  38. AZ::Aabb m_appleBoundingBox; //!< Bounding box of the apple to pick.
  39. AZ::Vector3 m_middle; //!< Middle point of Apple
  40. };
  41. //! A structure holding a state of effector, including optional progress and descriptive information.
  42. struct PickingState
  43. {
  44. EffectorState m_effectorState = EffectorState::IDLE; //!< Current state of effector.
  45. PickAppleTask m_currentTask; //!< Only valid for EffectorState::PICKING and EffectorState::RETRIEVING
  46. float m_taskProgress = 0.0f; //!< Optional field signalling progress within current state (picking/retrieving).
  47. AZStd::string m_description; //!< Optional descriptive field to inform the user.
  48. };
  49. using StateTransition = AZStd::pair<EffectorState, EffectorState>;
  50. struct TransitionHash
  51. {
  52. size_t operator()(const AZStd::pair<EffectorState, EffectorState>& p) const
  53. {
  54. int16_t first = static_cast<int16_t>(p.first);
  55. int16_t second = static_cast<int16_t>(p.second);
  56. size_t combined = (size_t)first << 16 | second;
  57. return combined;
  58. }
  59. };
  60. } // namespace AppleKraken