Explorar o código

Merge branch 'main' into Tree_Anime

Starr Shaw %!s(int64=3) %!d(string=hai) anos
pai
achega
258ebb982c

+ 61 - 0
.clang-format

@@ -0,0 +1,61 @@
+Language: Cpp
+
+AccessModifierOffset: -4
+AlignAfterOpenBracket: AlwaysBreak
+AlignConsecutiveAssignments: false
+AlignConsecutiveDeclarations: false
+AlignEscapedNewlines: Right
+AlignOperands: false
+AlignTrailingComments: false
+AllowAllArgumentsOnNextLine: true
+AllowAllParametersOfDeclarationOnNextLine: true
+AllowShortFunctionsOnASingleLine: None
+AllowShortLambdasOnASingleLine: None
+AlwaysBreakAfterReturnType: None
+AlwaysBreakTemplateDeclarations: true
+BinPackArguments: false
+BinPackParameters: false
+BreakBeforeBraces: Custom
+BraceWrapping:
+    AfterClass: true
+    AfterControlStatement: true
+    AfterEnum: true
+    AfterFunction: true
+    AfterNamespace: true
+    BeforeLambdaBody: true
+    AfterStruct: true
+    BeforeElse: true
+    SplitEmptyFunction: true
+BreakBeforeTernaryOperators: true
+BreakConstructorInitializers: BeforeComma
+BreakInheritanceList: BeforeComma
+ColumnLimit: 140
+ConstructorInitializerIndentWidth: 4
+ContinuationIndentWidth: 4
+Cpp11BracedListStyle: false
+FixNamespaceComments: true
+IncludeBlocks: Preserve
+IndentCaseBlocks: true
+IndentCaseLabels: false
+IndentPPDirectives: None
+IndentWidth: 4
+KeepEmptyLinesAtTheStartOfBlocks: false
+MaxEmptyLinesToKeep: 1
+NamespaceIndentation: All
+PenaltyReturnTypeOnItsOwnLine: 1000
+PointerAlignment: Left
+SortIncludes: true
+SpaceAfterLogicalNot: false
+SpaceAfterTemplateKeyword: false
+SpaceBeforeAssignmentOperators: true
+SpaceBeforeCpp11BracedList: false
+SpaceBeforeCtorInitializerColon: true
+SpaceBeforeInheritanceColon: true
+SpaceBeforeParens: ControlStatements
+SpaceBeforeRangeBasedForLoopColon: true
+SpaceInEmptyParentheses: false
+SpacesInAngles: false
+SpacesInCStyleCastParentheses: false
+SpacesInParentheses: false
+Standard: c++17
+UseTab: Never

+ 2 - 0
Project/Assets/apple_tree/AppleTree.fbx

@@ -1,3 +1,5 @@
 version https://git-lfs.github.com/spec/v1
+
 oid sha256:f709775b08a7136ff884205bddaea1f09aff325db035f31739a289bf89be3b06
 size 3955916
+

+ 87 - 0
Project/Gem/Source/ApplePicker/ApplePickerComponent.cpp

@@ -0,0 +1,87 @@
+/*
+ * Copyright (c) Contributors to the Open 3D Engine Project.
+ * For complete copyright and license terms please see the LICENSE at the root of this distribution.
+ *
+ * SPDX-License-Identifier: Apache-2.0 OR MIT
+ *
+ */
+
+#include "ApplePickerComponent.h"
+#include <AzCore/Serialization/EditContext.h>
+#include <AzCore/Serialization/EditContextConstants.inl>
+
+namespace AppleKraken
+{
+    namespace Internal
+    {
+        AZStd::string TaskString(const PickAppleTask& task)
+        {
+            if (!task.m_appleEntityId.IsValid())
+            {
+                return "|Task for an unspecified apple|";
+            }
+
+            return AZStd::string::format("|Task for entity id %s|", task.m_appleEntityId.ToString().c_str());
+        }
+
+        AZStd::string CurrentTaskString(const AZStd::queue<PickAppleTask>& taskQueue)
+        {
+            if (taskQueue.empty())
+            {
+                return "|No task, pick queue empty!|";
+            }
+
+            const auto& currentTask = taskQueue.front();
+            return TaskString(currentTask);
+        }
+    } // namespace Internal
+
+    void ApplePickerComponent::StartAutomatedOperation()
+    {
+    }
+
+    float ApplePickerComponent::ReportProgress()
+    {
+        return 0.0f;
+    }
+
+    void ApplePickerComponent::Activate()
+    {
+    }
+
+    void ApplePickerComponent::Deactivate()
+    {
+    }
+
+    void ApplePickerComponent::Reflect(AZ::ReflectContext* context)
+    {
+        if (AZ::SerializeContext* serialize = azrtti_cast<AZ::SerializeContext*>(context))
+        {
+            serialize->Class<ApplePickerComponent, AZ::Component>()->Version(1);
+            if (AZ::EditContext* ec = serialize->GetEditContext())
+            {
+                ec->Class<ApplePickerComponent>("Apple picking component", "A demo component for apple picking")
+                    ->ClassElement(AZ::Edit::ClassElements::EditorData, "")
+                    ->Attribute(AZ::Edit::Attributes::AppearsInAddComponentMenu, AZ_CRC("Game"))
+                    ->Attribute(AZ::Edit::Attributes::Category, "AppleKraken");
+            }
+        }
+    }
+
+    void ApplePickerComponent::ApplePicked()
+    {
+        AZ_TracePrintf("ApplePicker", "%s. Picked apple\n", Internal::CurrentTaskString(m_currentAppleTasks).c_str());
+    }
+
+    void ApplePickerComponent::AppleRetrieved()
+    {
+        AZ_TracePrintf(
+            "ApplePicker", "%s. An apple has been retrieved and stored\n", Internal::CurrentTaskString(m_currentAppleTasks).c_str());
+    }
+
+    void ApplePickerComponent::PickingFailed(const AZStd::string& reason)
+    {
+        AZ_TracePrintf(
+            "ApplePicker", "%s. Picking failed due to: %s\n", Internal::CurrentTaskString(m_currentAppleTasks).c_str(), reason.c_str());
+    }
+} // namespace AppleKraken

+ 46 - 0
Project/Gem/Source/ApplePicker/ApplePickerComponent.h

@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) Contributors to the Open 3D Engine Project.
+ * For complete copyright and license terms please see the LICENSE at the root of this distribution.
+ *
+ * SPDX-License-Identifier: Apache-2.0 OR MIT
+ *
+ */
+#pragma once
+
+#include "ApplePickingNotifications.h"
+#include "ApplePickingRequests.h"
+#include <AzCore/Component/Component.h>
+// #include <vision_msgs/msgs/detection_3d_array.h>
+
+namespace AppleKraken
+{
+    //! Demo component handling orchestration of apple picking
+    class ApplePickerComponent
+        : public AZ::Component
+        , private ApplePickingNotificationBus::Handler // Probably could use TickBus as well for timeouts
+
+    {
+    public:
+        AZ_COMPONENT(ApplePickerComponent, "{E9E83A4A-31A4-4E7A-AF88-7565AC8B9F27}", AZ::Component);
+        ApplePickerComponent() = default;
+        void Activate() override;
+        void Deactivate() override;
+        static void Reflect(AZ::ReflectContext* context);
+
+        //! Detect and pick all apples in manipulator range.
+        void StartAutomatedOperation();
+
+        //! Report overall progress of gathering task.
+        //! @returns how much of the task is complete (0: nothing, 1: all of it). The task is completed when all reachable apples are
+        //! gathered (or had a failure) and the effector is in IDLE state.
+        float ReportProgress();
+
+    private:
+        void ApplePicked() override;
+        void AppleRetrieved() override;
+        void PickingFailed(const AZStd::string& reason) override;
+
+        AZ::Obb m_gatheringArea;
+        AZStd::queue<PickAppleTask> m_currentAppleTasks; //! Populated in StartAutomatedOperation. Tasks are popped when completed or failed.
+    };
+} // namespace AppleKraken

+ 32 - 0
Project/Gem/Source/ApplePicker/ApplePickingNotifications.h

@@ -0,0 +1,32 @@
+/*
+ * Copyright (c) Contributors to the Open 3D Engine Project.
+ * For complete copyright and license terms please see the LICENSE at the root of this distribution.
+ *
+ * SPDX-License-Identifier: Apache-2.0 OR MIT
+ *
+ */
+#pragma once
+
+#include "PickingStructs.h"
+#include <AzCore/EBus/EBus.h>
+#include <AzCore/RTTI/BehaviorContext.h>
+
+namespace AppleKraken
+{
+    //! Notifications related to apple picking.
+    class ApplePickingNotifications : public AZ::EBusTraits
+    {
+    public:
+        //! An apple was successfully picked.
+        virtual void ApplePicked() = 0;
+
+        //! An apple was successfully retrieved to storage and can count as harvested.
+        virtual void AppleRetrieved() = 0;
+
+        //! Apple picking failed
+        //! @param reason reason for failure, e.g. "out of reach", "apple not found", "approach obstructed", etc.
+        virtual void PickingFailed(const AZStd::string& reason) = 0;
+    };
+
+    using ApplePickingNotificationBus = AZ::EBus<ApplePickingNotifications>;
+} // namespace AppleKraken

+ 58 - 0
Project/Gem/Source/ApplePicker/ApplePickingRequests.h

@@ -0,0 +1,58 @@
+/*
+ * Copyright (c) Contributors to the Open 3D Engine Project.
+ * For complete copyright and license terms please see the LICENSE at the root of this distribution.
+ *
+ * SPDX-License-Identifier: Apache-2.0 OR MIT
+ *
+ */
+#pragma once
+
+#include "PickingStructs.h"
+#include <AzCore/EBus/EBus.h>
+#include <AzCore/Interface/Interface.h>
+#include <AzCore/Math/Aabb.h>
+#include <AzCore/Math/Obb.h>
+
+namespace AppleKraken
+{
+    //! Requests for apple picking effector (manipulator)
+    class ApplePickingRequests
+    {
+    public:
+        AZ_RTTI(ApplePickingRequests, "{E70BC163-4AE0-4660-9769-1C3C7C3493A6}");
+        virtual ~ApplePickingRequests() = default;
+
+        //! Request to prepare for incoming apple picking tasks. Could be empty if manipulator is always ready.
+        virtual void PrepareForPicking() = 0;
+
+        //! PickApple by its global bounding box.
+        //! @param appleTask task structure specifying which apple to pick.
+        //! This task should only be issued if effector state is PREPARED.
+        //! Note that the task can get a while and result will be signalled through ApplePickingNotifications.
+        //! Progress can be checked @see GetEffectorState.
+        //! This function returns immediately.
+        virtual void PickApple(const PickAppleTask& appleTask) = 0;
+
+        //! Request to store currently held apple and retrieve manipulator into a travel position.
+        //! This function returns immediately. The effector should respond by transitioning to an IDLE state.
+        virtual void FinishPicking() = 0;
+
+        //! Request current effector state.
+        //! This request should be called to inform about whether a task can be issued and whether the robot could start moving.
+        //! @returns current state of the effector.
+        virtual PickingState GetEffectorState() = 0;
+
+        //! Return area covered by effector.
+        //! @returns a global object bounding box which is a region where apples can be picked.
+        virtual AZ::Obb GetEffectorReachArea() = 0;
+    };
+
+    class ApplePickingBusTraits : public AZ::EBusTraits
+    {
+    public:
+        static constexpr AZ::EBusHandlerPolicy HandlerPolicy = AZ::EBusHandlerPolicy::Multiple;
+        static constexpr AZ::EBusAddressPolicy AddressPolicy = AZ::EBusAddressPolicy::Single;
+    };
+    using ApplePickingRequestBus = AZ::EBus<ApplePickingRequests, ApplePickingBusTraits>;
+    using ApplePickingInterface = AZ::Interface<ApplePickingRequests>;
+} // namespace AppleKraken

+ 39 - 0
Project/Gem/Source/ApplePicker/PickingStructs.h

@@ -0,0 +1,39 @@
+/*
+ * Copyright (c) Contributors to the Open 3D Engine Project.
+ * For complete copyright and license terms please see the LICENSE at the root of this distribution.
+ *
+ * SPDX-License-Identifier: Apache-2.0 OR MIT
+ *
+ */
+#pragma once
+
+#include <AzCore/Component/EntityId.h>
+#include <AzCore/Math/Aabb.h>
+
+namespace AppleKraken
+{
+    //! Important states of the Kraken effector (manipulator with a vacuum nozzle)
+    enum class EffectorState
+    {
+        IDLE = 0, //!< Idle state / position, suitable for robot moving around the environment.
+        PREPARED = 10, //!< State and position which are ready for picking tasks.
+        PICKING = 20, //!< The effector is on its way to pick fruit.
+        RETRIEVING = 30, //!< The effector is retrieving a fruit to storage position.
+        INVALID = -1 //!< Invalid state. Requires an additional context that could help user understand what happened. @see PickingState.
+    };
+
+    //! A structure holding a state of effector, including optional progress and descriptive information.
+    struct PickingState
+    {
+        EffectorState m_effectorState = EffectorState::IDLE; //!< Current state of effector.
+        float m_taskProgress = 0.0f; //!< Optional field signalling progress within current state (picking/retrieving).
+        AZStd::string m_description; //!< Optional descriptive field to inform the user.
+    };
+
+    //! A task to pick a single apple.
+    struct PickAppleTask
+    {
+        AZ::EntityId m_appleEntityId; //!< EntityId of the apple. Can be Invalid if the information is not available (check IsValid()).
+        AZ::Aabb m_appleBoundingBox; //!< Bounding box of the apple to pick.
+    };
+} // namespace AppleKraken

+ 10 - 5
Project/Gem/roscondemo_files.cmake

@@ -1,7 +1,12 @@
 
 set(FILES
-    Include/ROSConDemo/ROSConDemoBus.h
-    Source/ROSConDemoSystemComponent.cpp
-    Source/ROSConDemoSystemComponent.h
-    enabled_gems.cmake
-)
+        Include/ROSConDemo/ROSConDemoBus.h
+        Source/ApplePicker/ApplePickerComponent.cpp
+        Source/ApplePicker/ApplePickerComponent.h
+        Source/ApplePicker/ApplePickingNotifications.h
+        Source/ApplePicker/ApplePickingRequests.h
+        Source/ApplePicker/PickingStructs.h
+        Source/ROSConDemoSystemComponent.cpp
+        Source/ROSConDemoSystemComponent.h
+        enabled_gems.cmake
+        )

+ 8 - 0
Project/Prefabs/AppleTree.prefab

@@ -159,6 +159,7 @@
                     "$type": "EditorOnlyEntityComponent",
                     "Id": 15752591005564428774
                 },
+
                 "Component_[16858712213851843499]": {
                     "$type": "EditorMaterialComponent",
                     "Id": 16858712213851843499,
@@ -167,6 +168,7 @@
                             "materials": [
                                 {
                                     "Key": {
+
                                         "materialSlotStableId": 1276229897
                                     },
                                     "Value": {
@@ -181,20 +183,25 @@
                                 {
                                     "Key": {
                                         "materialSlotStableId": 2950014666
+
                                     },
                                     "Value": {
                                         "MaterialAsset": {
                                             "assetId": {
                                                 "guid": "{A9A7956A-79C1-53A1-95C1-342AC7C3E8FB}"
+
                                             },
                                             "assetHint": "assets/apple_tree/appletree_leaf_sss_mat.azmaterial"
+
                                         }
                                     }
                                 },
                                 {
                                     "Key": {
+
                                         "lodIndex": 0,
                                         "materialSlotStableId": 1276229897
+
                                     },
                                     "Value": {
                                         "MaterialAsset": {
@@ -340,6 +347,7 @@
                 "Component_[8148146872807561086]": {
                     "$type": "EditorPendingCompositionComponent",
                     "Id": 8148146872807561086
+
                 }
             }
         }

+ 6 - 0
README.md

@@ -7,6 +7,12 @@ For information about contributing to Open 3D Engine, visit [https://o3de.org/do
 
 ## Download and Install
 
+### Additional ROS 2 packages
+
+This project uses Vision messages, which can be obtained:
+
+`sudo apt install ros-${ROS_DISTRO}-vision-msgs`
+
 ### Clone the repository 
 
 ```shell