From af839a4fad44e6cea12dd82baa1eab9061d57fa8 Mon Sep 17 00:00:00 2001 From: "fabian.peller-konrad@kit.edu" <fabian.peller-konrad@kit.edu> Date: Fri, 23 Jul 2021 16:40:44 +0200 Subject: [PATCH] motionMemory and subjectMemory (first draft, not ready yet) --- .../components/armem/server/CMakeLists.txt | 2 + .../armem/server/MotionMemory/CMakeLists.txt | 28 ++++ .../server/MotionMemory/MotionMemory.cpp | 73 +++++++++ .../armem/server/MotionMemory/MotionMemory.h | 71 +++++++++ .../server/MotionMemory/test/CMakeLists.txt | 5 + .../MotionMemory/test/MotionMemoryTest.cpp | 40 +++++ .../armem/server/SubjectMemory/CMakeLists.txt | 28 ++++ .../server/SubjectMemory/SubjectMemory.cpp | 73 +++++++++ .../server/SubjectMemory/SubjectMemory.h | 71 +++++++++ .../server/SubjectMemory/test/CMakeLists.txt | 5 + .../SubjectMemory/test/SubjectMemoryTest.cpp | 40 +++++ source/RobotAPI/interface/CMakeLists.txt | 2 + .../RobotAPI/interface/mdb/MotionDatabase.ice | 146 ++++++++++++++++++ source/RobotAPI/libraries/CMakeLists.txt | 2 + .../libraries/PriorKnowledge/CMakeLists.txt | 4 + .../PriorKnowledge/core/CMakeLists.txt | 21 +++ .../PriorKnowledge/core/FinderBase.cpp | 1 + .../PriorKnowledge/core/FinderBase.h | 132 ++++++++++++++++ .../PriorKnowledge/core/FinderInfoBase.cpp | 1 + .../PriorKnowledge/core/FinderInfoBase.h | 115 ++++++++++++++ .../PriorKnowledge/motions/CMakeLists.txt | 19 +++ .../PriorKnowledge/motions/MotionFinder.cpp | 133 ++++++++++++++++ .../PriorKnowledge/motions/MotionFinder.h | 50 ++++++ .../RobotAPI/libraries/armem/CMakeLists.txt | 2 + .../libraries/armem/server/Segment.cpp | 1 + .../RobotAPI/libraries/armem/server/Segment.h | 99 ++++++++++++ .../libraries/armem_motions/CMakeLists.txt | 26 ++++ .../libraries/armem_motions/aron/MMM.xml | 44 ++++++ .../server/MotionDatabase/MotionConverter.cpp | 0 .../server/MotionDatabase/MotionConverter.h | 0 .../server/MotionDatabase/Segment.cpp | 55 +++++++ .../server/MotionDatabase/Segment.h | 38 +++++ .../libraries/aron/common/CMakeLists.txt | 13 +- .../libraries/aron/common/aron/SimplePose.xml | 27 ++++ .../aron/common/aron/SimplePosition.xml | 26 ++++ .../aron/common/aron/SimpleTrajectory.xml | 26 ++++ .../libraries/aron/converter/CMakeLists.txt | 5 +- .../libraries/aron/core/CMakeLists.txt | 2 + 38 files changed, 1419 insertions(+), 7 deletions(-) create mode 100644 source/RobotAPI/components/armem/server/MotionMemory/CMakeLists.txt create mode 100644 source/RobotAPI/components/armem/server/MotionMemory/MotionMemory.cpp create mode 100644 source/RobotAPI/components/armem/server/MotionMemory/MotionMemory.h create mode 100644 source/RobotAPI/components/armem/server/MotionMemory/test/CMakeLists.txt create mode 100644 source/RobotAPI/components/armem/server/MotionMemory/test/MotionMemoryTest.cpp create mode 100644 source/RobotAPI/components/armem/server/SubjectMemory/CMakeLists.txt create mode 100644 source/RobotAPI/components/armem/server/SubjectMemory/SubjectMemory.cpp create mode 100644 source/RobotAPI/components/armem/server/SubjectMemory/SubjectMemory.h create mode 100644 source/RobotAPI/components/armem/server/SubjectMemory/test/CMakeLists.txt create mode 100644 source/RobotAPI/components/armem/server/SubjectMemory/test/SubjectMemoryTest.cpp create mode 100644 source/RobotAPI/interface/mdb/MotionDatabase.ice create mode 100644 source/RobotAPI/libraries/PriorKnowledge/CMakeLists.txt create mode 100644 source/RobotAPI/libraries/PriorKnowledge/core/CMakeLists.txt create mode 100644 source/RobotAPI/libraries/PriorKnowledge/core/FinderBase.cpp create mode 100644 source/RobotAPI/libraries/PriorKnowledge/core/FinderBase.h create mode 100644 source/RobotAPI/libraries/PriorKnowledge/core/FinderInfoBase.cpp create mode 100644 source/RobotAPI/libraries/PriorKnowledge/core/FinderInfoBase.h create mode 100644 source/RobotAPI/libraries/PriorKnowledge/motions/CMakeLists.txt create mode 100644 source/RobotAPI/libraries/PriorKnowledge/motions/MotionFinder.cpp create mode 100644 source/RobotAPI/libraries/PriorKnowledge/motions/MotionFinder.h create mode 100644 source/RobotAPI/libraries/armem/server/Segment.cpp create mode 100644 source/RobotAPI/libraries/armem/server/Segment.h create mode 100644 source/RobotAPI/libraries/armem_motions/CMakeLists.txt create mode 100644 source/RobotAPI/libraries/armem_motions/aron/MMM.xml create mode 100644 source/RobotAPI/libraries/armem_motions/server/MotionDatabase/MotionConverter.cpp create mode 100644 source/RobotAPI/libraries/armem_motions/server/MotionDatabase/MotionConverter.h create mode 100644 source/RobotAPI/libraries/armem_motions/server/MotionDatabase/Segment.cpp create mode 100644 source/RobotAPI/libraries/armem_motions/server/MotionDatabase/Segment.h create mode 100644 source/RobotAPI/libraries/aron/common/aron/SimplePose.xml create mode 100644 source/RobotAPI/libraries/aron/common/aron/SimplePosition.xml create mode 100644 source/RobotAPI/libraries/aron/common/aron/SimpleTrajectory.xml diff --git a/source/RobotAPI/components/armem/server/CMakeLists.txt b/source/RobotAPI/components/armem/server/CMakeLists.txt index 48313a312..824eaa493 100644 --- a/source/RobotAPI/components/armem/server/CMakeLists.txt +++ b/source/RobotAPI/components/armem/server/CMakeLists.txt @@ -3,3 +3,5 @@ add_subdirectory(GeneralPurposeMemory) add_subdirectory(ObjectMemory) add_subdirectory(RobotStateMemory) add_subdirectory(SkillsMemory) +#add_subdirectory(SubjectMemory) +add_subdirectory(MotionMemory) diff --git a/source/RobotAPI/components/armem/server/MotionMemory/CMakeLists.txt b/source/RobotAPI/components/armem/server/MotionMemory/CMakeLists.txt new file mode 100644 index 000000000..2bb05c404 --- /dev/null +++ b/source/RobotAPI/components/armem/server/MotionMemory/CMakeLists.txt @@ -0,0 +1,28 @@ +armarx_component_set_name("MotionMemory") + + +set(COMPONENT_LIBS + ArmarXCore ArmarXCoreInterfaces # for DebugObserverInterface + ArmarXGuiComponentPlugins + RobotAPICore RobotAPIInterfaces armem armem_motions + # RobotAPIComponentPlugins # for ArViz and other plugins +) + +set(SOURCES + MotionMemory.cpp +) +set(HEADERS + MotionMemory.h +) + +armarx_add_component("${SOURCES}" "${HEADERS}") + + +# add unit tests +add_subdirectory(test) + +#generate the application +armarx_generate_and_add_component_executable() + + + diff --git a/source/RobotAPI/components/armem/server/MotionMemory/MotionMemory.cpp b/source/RobotAPI/components/armem/server/MotionMemory/MotionMemory.cpp new file mode 100644 index 000000000..6e49ca1cc --- /dev/null +++ b/source/RobotAPI/components/armem/server/MotionMemory/MotionMemory.cpp @@ -0,0 +1,73 @@ +/* + * This file is part of ArmarX. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * ArmarX is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @package RobotAPI::ArmarXObjects::ExampleMemory + * @author Rainer Kartmann ( rainer dot kartmann at kit dot edu ) + * @date 2020 + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + +#include "MotionMemory.h" + +#include <ArmarXCore/core/exceptions/local/ExpressionException.h> + +#include <SimoxUtility/algorithm/string.h> + +#include <RobotAPI/libraries/armem/core/error.h> + + +namespace armarx +{ + armarx::PropertyDefinitionsPtr MotionMemory::createPropertyDefinitions() + { + armarx::PropertyDefinitionsPtr defs = new ComponentPropertyDefinitions(getConfigIdentifier()); + + const std::string prefix = "mem."; + defs->optional(memoryName, prefix + "MemoryName", "Name of this memory (server)."); + mdbMotions.defineProperties(defs, prefix + "mdb."); + return defs; + } + + MotionMemory::MotionMemory() : + mdbMotions(armem::server::ComponentPluginUser::iceMemory, armem::server::ComponentPluginUser::workingMemoryMutex) + { + + } + + + std::string MotionMemory::getDefaultName() const + { + return "MotionMemory"; + } + + void MotionMemory::onInitComponent() + { + workingMemory.name() = memoryName; + longtermMemory.name() = memoryName; + } + + void MotionMemory::onConnectComponent() + { + } + + void MotionMemory::onDisconnectComponent() + { + } + + void MotionMemory::onExitComponent() + { + } +} diff --git a/source/RobotAPI/components/armem/server/MotionMemory/MotionMemory.h b/source/RobotAPI/components/armem/server/MotionMemory/MotionMemory.h new file mode 100644 index 000000000..e1bc19268 --- /dev/null +++ b/source/RobotAPI/components/armem/server/MotionMemory/MotionMemory.h @@ -0,0 +1,71 @@ +/* + * This file is part of ArmarX. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * ArmarX is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @package RobotAPI::ArmarXObjects::ExampleMemory + * @author Rainer Kartmann ( rainer dot kartmann at kit dot edu ) + * @date 2020 + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + +#pragma once + + +#include <ArmarXCore/core/Component.h> +#include <RobotAPI/libraries/armem/server/ComponentPlugin.h> + +#include <RobotAPI/libraries/armem_motions/server/MotionDatabase/Segment.h> + +namespace armarx +{ + /** + * @defgroup Component-ExampleMemory ExampleMemory + * @ingroup RobotAPI-Components + * A description of the component ExampleMemory. + * + * @class ExampleMemory + * @ingroup Component-ExampleMemory + * @brief Brief description of class ExampleMemory. + * + * Detailed description of class ExampleMemory. + */ + class MotionMemory : + virtual public armarx::Component + , virtual public armem::server::ComponentPluginUser + { + public: + + MotionMemory(); + + /// @see armarx::ManagedIceObject::getDefaultName() + std::string getDefaultName() const override; + + protected: + + armarx::PropertyDefinitionsPtr createPropertyDefinitions() override; + + void onInitComponent() override; + void onConnectComponent() override; + void onDisconnectComponent() override; + void onExitComponent() override; + + + private: + std::string memoryName = "Motion"; + + armem::server::motions::mdb::Segment mdbMotions; + + }; +} diff --git a/source/RobotAPI/components/armem/server/MotionMemory/test/CMakeLists.txt b/source/RobotAPI/components/armem/server/MotionMemory/test/CMakeLists.txt new file mode 100644 index 000000000..42be84a2d --- /dev/null +++ b/source/RobotAPI/components/armem/server/MotionMemory/test/CMakeLists.txt @@ -0,0 +1,5 @@ + +# Libs required for the tests +SET(LIBS ${LIBS} ArmarXCore MotionMemory) + +armarx_add_test(MotionMemoryTest MotionMemoryTest.cpp "${LIBS}") diff --git a/source/RobotAPI/components/armem/server/MotionMemory/test/MotionMemoryTest.cpp b/source/RobotAPI/components/armem/server/MotionMemory/test/MotionMemoryTest.cpp new file mode 100644 index 000000000..5eda6d831 --- /dev/null +++ b/source/RobotAPI/components/armem/server/MotionMemory/test/MotionMemoryTest.cpp @@ -0,0 +1,40 @@ +/* + * This file is part of ArmarX. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * ArmarX is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @package RobotAPI::ArmarXObjects::ExampleMemory + * @author Rainer Kartmann ( rainer dot kartmann at kit dot edu ) + * @date 2020 + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + +#define BOOST_TEST_MODULE RobotAPI::ArmarXObjects::ExampleMemory + +#define ARMARX_BOOST_TEST + +#include <RobotAPI/Test.h> +#include "../MotionMemory.h" + +#include <RobotAPI/libraries/armem/core.h> + +#include <iostream> + +namespace armem = armarx::armem; + + +BOOST_AUTO_TEST_CASE(test_ExampleData_type) +{ + +} diff --git a/source/RobotAPI/components/armem/server/SubjectMemory/CMakeLists.txt b/source/RobotAPI/components/armem/server/SubjectMemory/CMakeLists.txt new file mode 100644 index 000000000..bf9a3ba66 --- /dev/null +++ b/source/RobotAPI/components/armem/server/SubjectMemory/CMakeLists.txt @@ -0,0 +1,28 @@ +armarx_component_set_name("SubjectMemory") + + +set(COMPONENT_LIBS + ArmarXCore ArmarXCoreInterfaces # for DebugObserverInterface + ArmarXGuiComponentPlugins + RobotAPICore RobotAPIInterfaces armem armem_motions + # RobotAPIComponentPlugins # for ArViz and other plugins +) + +set(SOURCES + SubjectMemory.cpp +) +set(HEADERS + SubjectMemory.h +) + +armarx_add_component("${SOURCES}" "${HEADERS}") + + +# add unit tests +add_subdirectory(test) + +#generate the application +armarx_generate_and_add_component_executable() + + + diff --git a/source/RobotAPI/components/armem/server/SubjectMemory/SubjectMemory.cpp b/source/RobotAPI/components/armem/server/SubjectMemory/SubjectMemory.cpp new file mode 100644 index 000000000..d23b8cd13 --- /dev/null +++ b/source/RobotAPI/components/armem/server/SubjectMemory/SubjectMemory.cpp @@ -0,0 +1,73 @@ +/* + * This file is part of ArmarX. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * ArmarX is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @package RobotAPI::ArmarXObjects::ExampleMemory + * @author Rainer Kartmann ( rainer dot kartmann at kit dot edu ) + * @date 2020 + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + +#include "SubjectMemory.h" + +#include <ArmarXCore/core/exceptions/local/ExpressionException.h> + +#include <SimoxUtility/algorithm/string.h> + +#include <RobotAPI/libraries/armem/core/error.h> + + +namespace armarx +{ + armarx::PropertyDefinitionsPtr SubjectMemory::createPropertyDefinitions() + { + armarx::PropertyDefinitionsPtr defs = new ComponentPropertyDefinitions(getConfigIdentifier()); + + const std::string prefix = "mem."; + defs->optional(memoryName, prefix + "MemoryName", "Name of this memory (server)."); + mdbMotions.defineProperties(defs, prefix + "mdb."); + return defs; + } + + SubjectMemory::SubjectMemory() : + mdbMotions(armem::server::ComponentPluginUser::iceMemory, armem::server::ComponentPluginUser::workingMemoryMutex) + { + + } + + + std::string SubjectMemory::getDefaultName() const + { + return "MotionMemory"; + } + + void SubjectMemory::onInitComponent() + { + workingMemory.name() = memoryName; + longtermMemory.name() = memoryName; + } + + void SubjectMemory::onConnectComponent() + { + } + + void SubjectMemory::onDisconnectComponent() + { + } + + void SubjectMemory::onExitComponent() + { + } +} diff --git a/source/RobotAPI/components/armem/server/SubjectMemory/SubjectMemory.h b/source/RobotAPI/components/armem/server/SubjectMemory/SubjectMemory.h new file mode 100644 index 000000000..2382459ee --- /dev/null +++ b/source/RobotAPI/components/armem/server/SubjectMemory/SubjectMemory.h @@ -0,0 +1,71 @@ +/* + * This file is part of ArmarX. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * ArmarX is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @package RobotAPI::ArmarXObjects::ExampleMemory + * @author Rainer Kartmann ( rainer dot kartmann at kit dot edu ) + * @date 2020 + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + +#pragma once + + +#include <ArmarXCore/core/Component.h> +#include <RobotAPI/libraries/armem/server/ComponentPlugin.h> + +#include <RobotAPI/libraries/armem_subjects/server/MotionDatabase/Segment.h> + +namespace armarx +{ + /** + * @defgroup Component-ExampleMemory ExampleMemory + * @ingroup RobotAPI-Components + * A description of the component ExampleMemory. + * + * @class ExampleMemory + * @ingroup Component-ExampleMemory + * @brief Brief description of class ExampleMemory. + * + * Detailed description of class ExampleMemory. + */ + class SubjectMemory : + virtual public armarx::Component + , virtual public armem::server::ComponentPluginUser + { + public: + + SubjectMemory(); + + /// @see armarx::ManagedIceObject::getDefaultName() + std::string getDefaultName() const override; + + protected: + + armarx::PropertyDefinitionsPtr createPropertyDefinitions() override; + + void onInitComponent() override; + void onConnectComponent() override; + void onDisconnectComponent() override; + void onExitComponent() override; + + + private: + std::string memoryName = "Subject"; + + armem::server::subjects::mdb::Segment mdbSubjects; + + }; +} diff --git a/source/RobotAPI/components/armem/server/SubjectMemory/test/CMakeLists.txt b/source/RobotAPI/components/armem/server/SubjectMemory/test/CMakeLists.txt new file mode 100644 index 000000000..c5f60466c --- /dev/null +++ b/source/RobotAPI/components/armem/server/SubjectMemory/test/CMakeLists.txt @@ -0,0 +1,5 @@ + +# Libs required for the tests +SET(LIBS ${LIBS} ArmarXCore SubjectMemory) + +armarx_add_test(SubjectMemoryTest SubjectMemoryTest.cpp "${LIBS}") diff --git a/source/RobotAPI/components/armem/server/SubjectMemory/test/SubjectMemoryTest.cpp b/source/RobotAPI/components/armem/server/SubjectMemory/test/SubjectMemoryTest.cpp new file mode 100644 index 000000000..5eda6d831 --- /dev/null +++ b/source/RobotAPI/components/armem/server/SubjectMemory/test/SubjectMemoryTest.cpp @@ -0,0 +1,40 @@ +/* + * This file is part of ArmarX. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * ArmarX is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @package RobotAPI::ArmarXObjects::ExampleMemory + * @author Rainer Kartmann ( rainer dot kartmann at kit dot edu ) + * @date 2020 + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + +#define BOOST_TEST_MODULE RobotAPI::ArmarXObjects::ExampleMemory + +#define ARMARX_BOOST_TEST + +#include <RobotAPI/Test.h> +#include "../MotionMemory.h" + +#include <RobotAPI/libraries/armem/core.h> + +#include <iostream> + +namespace armem = armarx::armem; + + +BOOST_AUTO_TEST_CASE(test_ExampleData_type) +{ + +} diff --git a/source/RobotAPI/interface/CMakeLists.txt b/source/RobotAPI/interface/CMakeLists.txt index b2913fb4c..a026e17c6 100644 --- a/source/RobotAPI/interface/CMakeLists.txt +++ b/source/RobotAPI/interface/CMakeLists.txt @@ -136,6 +136,8 @@ set(SLICE_FILES skills/SkillObserverInterface.ice skills/SkillProviderInterface.ice + + mdb/MotionDatabase.ice ) #core/RobotIK.ice set(SLICE_FILES_ADDITIONAL_HEADERS diff --git a/source/RobotAPI/interface/mdb/MotionDatabase.ice b/source/RobotAPI/interface/mdb/MotionDatabase.ice new file mode 100644 index 000000000..2ca77b0b9 --- /dev/null +++ b/source/RobotAPI/interface/mdb/MotionDatabase.ice @@ -0,0 +1,146 @@ +#include <Glacier2/Session.ice> + +module MotionDatabase { + exception InternalErrorException { + string errorMessage; + }; + + exception InvalidParameterException { + string parameterName; + }; + + exception NotAuthorizedException {}; + exception TooManyOpenFilesException {}; + + class Institution; + class MotionDescriptionTreeNode; + class File; + class Motion; + class Project; + class Subject; + class MoCapObject; + + sequence<byte> ByteSequence; + sequence<long> LongSequence; + sequence<string> StringSequence; + sequence<Institution> InstitutionList; + sequence<MotionDescriptionTreeNode> MotionDescriptionTreeNodeList; + sequence<File> FileList; + sequence<Motion> MotionList; + sequence<Project> ProjectList; + sequence<Subject> SubjectList; + sequence<MoCapObject> MoCapObjectList; + + dictionary<string, short> StringShortDictionary; + + enum VisibilityLevel { Public, Protected, Internal }; + + class Institution { + long id; + string acronym; + string name; + }; + + class MotionDescriptionTreeNode { + long id; + string label; + MotionDescriptionTreeNodeList children; + }; + + class DatabaseObject { + long id; + long createdDate; + string createdUser; + long modifiedDate; + string modifiedUser; + StringSequence writeGroups; + StringSequence readProtectedGroups; + StringShortDictionary fileTypeCounts; + }; + + class File { + long id; + long createdDate; + string createdUser; + string fileName; + string fileType; + long attachedToId; + string description; + VisibilityLevel visibility; + File originatedFrom; + }; + + class Motion extends DatabaseObject { + Institution associatedInstitution; + MotionDescriptionTreeNodeList motionDescriptions; + Project associatedProject; + SubjectList associatedSubjects; + MoCapObjectList associatedObjects; + string date; + string comment; + }; + + class Project extends DatabaseObject { + string name; + string comment; + }; + + class Subject extends DatabaseObject { + string firstName; + string lastName; + string comment; + byte gender; + short age; + short weight; + short height; + StringShortDictionary anthropometricsTable; + }; + + class MoCapObject extends DatabaseObject { + string label; + string comment; + string modelSettingsJSON; + }; + + interface FileReader { + void destroy(); + + idempotent long getSize() throws InternalErrorException; + ByteSequence readChunk(long length) throws InternalErrorException, InvalidParameterException; + idempotent void seek(long pos) throws InternalErrorException, InvalidParameterException; + }; + + interface FileWriter { + void destroy(); + + void writeChunk(ByteSequence data) throws InternalErrorException; + }; + + interface MotionDatabaseSession extends Glacier2::Session { + idempotent string pingServer(string echoString); + + idempotent InstitutionList listInstitutions() throws InternalErrorException; + idempotent MotionDescriptionTreeNodeList getMotionDescriptionTree() throws InternalErrorException; + + idempotent Motion getMotion(long motionId) throws InternalErrorException, InvalidParameterException; + idempotent long countMotions(LongSequence filterMotionDescription, LongSequence filterProject, LongSequence filterInstitution, + LongSequence filterSubject, LongSequence filterObject, string motionDescriptionSearchTerm) throws InternalErrorException, + InvalidParameterException; + idempotent MotionList listMotions(LongSequence filterMotionDescription, LongSequence filterProject, LongSequence filterInstitution, + LongSequence filterSubject, LongSequence filterObject, string motionDescriptionSearchTerm, string sortField, long limit, + long offset) throws InternalErrorException, InvalidParameterException; + idempotent ProjectList listProjects() throws InternalErrorException; + idempotent SubjectList listSubjects() throws InternalErrorException; + idempotent MoCapObjectList listObjects() throws InternalErrorException; + + idempotent File getFile(long fileId) throws InternalErrorException, InvalidParameterException; + idempotent FileList listFiles(long databaseObjectId) throws InternalErrorException, InvalidParameterException; + idempotent FileReader* getFileReader(long fileId) throws InternalErrorException, InvalidParameterException, NotAuthorizedException, + TooManyOpenFilesException; + + FileWriter* getFileWriter(long databaseObjectId, string fileName, string fileType, string description, VisibilityLevel visibility, + optional(1) long originatedFromId) throws InternalErrorException, InvalidParameterException, NotAuthorizedException, + TooManyOpenFilesException; + void deleteFile(long fileId) throws InternalErrorException, InvalidParameterException, NotAuthorizedException; + }; +}; diff --git a/source/RobotAPI/libraries/CMakeLists.txt b/source/RobotAPI/libraries/CMakeLists.txt index 02e5c638b..c5f89815a 100644 --- a/source/RobotAPI/libraries/CMakeLists.txt +++ b/source/RobotAPI/libraries/CMakeLists.txt @@ -1,5 +1,6 @@ add_subdirectory(ArmarXEtherCAT) add_subdirectory(ArmarXObjects) +add_subdirectory(PriorKnowledge) add_subdirectory(ControllerUIUtility) add_subdirectory(core) add_subdirectory(DebugDrawerConfigWidget) @@ -24,6 +25,7 @@ add_subdirectory(armem_robot) add_subdirectory(armem_robot_state) add_subdirectory(armem_vision) add_subdirectory(armem_skills) +add_subdirectory(armem_motions) add_subdirectory(aron) add_subdirectory(NJointControllerGuiPluginUtility) diff --git a/source/RobotAPI/libraries/PriorKnowledge/CMakeLists.txt b/source/RobotAPI/libraries/PriorKnowledge/CMakeLists.txt new file mode 100644 index 000000000..596f554c1 --- /dev/null +++ b/source/RobotAPI/libraries/PriorKnowledge/CMakeLists.txt @@ -0,0 +1,4 @@ +add_subdirectory(core) +add_subdirectory(motions) +#add_subdirectory(subjects) + diff --git a/source/RobotAPI/libraries/PriorKnowledge/core/CMakeLists.txt b/source/RobotAPI/libraries/PriorKnowledge/core/CMakeLists.txt new file mode 100644 index 000000000..d9adff9e0 --- /dev/null +++ b/source/RobotAPI/libraries/PriorKnowledge/core/CMakeLists.txt @@ -0,0 +1,21 @@ +set(LIB_NAME ${PROJECT_NAME}PriorKnowledgeCore) + +armarx_component_set_name("${LIB_NAME}") +armarx_set_target("Library: ${LIB_NAME}") + +armarx_add_library( + LIBS + RobotAPI::Core + RobotAPI::Aron::Common + SOURCES + FinderBase.cpp + FinderInfoBase.cpp + HEADERS + FinderBase.h + FinderInfoBase.h +) + +add_library(${PROJECT_NAME}::PriorKnowledge::Core ALIAS ${PROJECT_NAME}PriorKnowledgeCore) + +# add unit tests +#add_subdirectory(test) diff --git a/source/RobotAPI/libraries/PriorKnowledge/core/FinderBase.cpp b/source/RobotAPI/libraries/PriorKnowledge/core/FinderBase.cpp new file mode 100644 index 000000000..6b7847a51 --- /dev/null +++ b/source/RobotAPI/libraries/PriorKnowledge/core/FinderBase.cpp @@ -0,0 +1 @@ +#include "FinderBase.h" diff --git a/source/RobotAPI/libraries/PriorKnowledge/core/FinderBase.h b/source/RobotAPI/libraries/PriorKnowledge/core/FinderBase.h new file mode 100644 index 000000000..14d469934 --- /dev/null +++ b/source/RobotAPI/libraries/PriorKnowledge/core/FinderBase.h @@ -0,0 +1,132 @@ +#pragma once + +// STD/STL +#include <string> +#include <filesystem> +#include <optional> + +// Base Class +#include <ArmarXCore/core/logging/Logging.h> + +// ArmarX +#include <ArmarXCore/core/system/ArmarXDataPath.h> +#include <ArmarXCore/core/exceptions/local/ExpressionException.h> +#include <ArmarXCore/core/system/cmake/CMakePackageFinder.h> + + +namespace armarx::priorknowledge::core +{ + template <class IDType, class FinderInfoType> + class FinderBase : public Logging + { + public: + FinderBase() = delete; + FinderBase(const std::string& packageName, const std::filesystem::path& relDir) : + packageName(packageName), + relPackageDataPath(relDir) + {} + + FinderBase(FinderBase&&) = default; + FinderBase(const FinderBase&) = default; + FinderBase& operator=(FinderBase&&) = default; + FinderBase& operator=(const FinderBase&) = default; + + void setPackageNameAndReinitialize(const std::string& p) + { + packageName = p; + onInit(); + } + + void setRelativePath(const std::filesystem::path& p) + { + relPackageDataPath = p; + } + + std::string getPackageName() const + { + return packageName; + } + + std::filesystem::path getRelativePath() const + { + return relPackageDataPath; + } + + std::filesystem::path getAbsolutePackagePath() const + { + checkAbsolutePathIsValid(); + return absPackageDataDir; + } + + std::filesystem::path getFullPath() const + { + checkAbsolutePathIsValid(); + return absPackageDataDir / packageName / relPackageDataPath; + } + + virtual bool checkAll() const = 0; + virtual bool check(const IDType& id) const = 0; + virtual std::optional<FinderInfoType> find(const IDType& id) const = 0; + virtual std::vector<FinderInfoType> findAll() const = 0; + + protected: + void checkAbsolutePathIsValid() const + { + if (std::filesystem::exists(absPackageDataDir)) + { + ARMARX_ERROR << "PriorKnowledgeFinder is not initialized yet. Could not resolve absolute path for package '" << packageName << "'."; + } + } + + virtual void onInit() + { + if (absPackageDataDir.empty()) + { + CMakePackageFinder packageFinder(packageName); + absPackageDataDir = packageFinder.getDataDir(); + if (absPackageDataDir.empty()) + { + ARMARX_WARNING << "Could not find package '" << packageName << "'."; + // throw LocalException() << "Could not find package '" << packageName << "'."; + } + else + { + ARMARX_DEBUG << "PriorKnowledgeFinder root directory: " << getFullPath(); + + // make sure this data path is available => e.g. for findArticulatedObjects + armarx::ArmarXDataPath::addDataPaths(std::vector<std::string> {absPackageDataDir}); + } + } + } + + protected: + + private: + std::string packageName; + std::filesystem::path relPackageDataPath; + std::filesystem::path absPackageDataDir; + }; + + + template <class IDType, class DatasetType, class FinderInfoType> // TODO: concept DatasetFinderInfoType + class DatasetFinderBase : public FinderBase<IDType, FinderInfoType> + { + + public: + using Base = FinderBase<IDType, FinderInfoType>; + + DatasetFinderBase(const std::string& packageName, const std::filesystem::path& relDir) : + Base(packageName, relDir) + {} + + std::filesystem::path getFullPath(const std::filesystem::path& relDatasetPath) const + { + return Base::getFullPath() / relDatasetPath; + } + + virtual bool checkAll(const DatasetType& dataset) const = 0; + virtual bool check(const DatasetType& dataset, const IDType& id) const = 0; + virtual std::optional<FinderInfoType> find(const DatasetType& dataset, const IDType& id) const = 0; + virtual std::vector<FinderInfoType> findAll(const DatasetType& dataset) const = 0; + }; +} diff --git a/source/RobotAPI/libraries/PriorKnowledge/core/FinderInfoBase.cpp b/source/RobotAPI/libraries/PriorKnowledge/core/FinderInfoBase.cpp new file mode 100644 index 000000000..46ed5497b --- /dev/null +++ b/source/RobotAPI/libraries/PriorKnowledge/core/FinderInfoBase.cpp @@ -0,0 +1 @@ +#include "FinderInfoBase.h" diff --git a/source/RobotAPI/libraries/PriorKnowledge/core/FinderInfoBase.h b/source/RobotAPI/libraries/PriorKnowledge/core/FinderInfoBase.h new file mode 100644 index 000000000..d4cf689be --- /dev/null +++ b/source/RobotAPI/libraries/PriorKnowledge/core/FinderInfoBase.h @@ -0,0 +1,115 @@ +#pragma once + +// STD/STL +#include <string> +#include <filesystem> +#include <optional> + +// Base Class +#include <ArmarXCore/core/logging/Logging.h> + +// ArmarX +#include <ArmarXCore/core/system/ArmarXDataPath.h> +#include <ArmarXCore/core/exceptions/local/ExpressionException.h> + + +namespace armarx::priorknowledge::core +{ + + struct PackageFileLocation + { + /// Name of the ArmarX package. + std::string package; + + /// Relative to the package's data directory. + std::filesystem::path relativePath; + + /// The absolute path (in the host's file system). + std::filesystem::path absolutePath; + }; + + template <class IDType> + class FinderInfoBase + { + public: + FinderInfoBase(const std::string& packageName, const std::filesystem::path& absPackageDataDir, const std::filesystem::path& relPackageDataPath, const IDType& id) : + packageName(packageName), + absPackageDataDir(absPackageDataDir), + relPackageDataPath(relPackageDataPath), + id(id) + {} + + std::string getPackageName() const + { + return packageName; + } + + std::filesystem::path getRelativePath() const + { + return relPackageDataPath; + } + + std::filesystem::path getAbsolutePackagePath() const + { + checkAbsolutePathIsValid(); + return absPackageDataDir; + } + + virtual std::filesystem::path getFullPath() const + { + checkAbsolutePathIsValid(); + return absPackageDataDir / packageName / relPackageDataPath; + } + + IDType getID() const + { + return id; + } + + protected: + void checkAbsolutePathIsValid() const + { + if (std::filesystem::exists(absPackageDataDir)) + { + ARMARX_ERROR << "Could not resolve absolute path for package '" << packageName << "'."; + } + } + + + protected: + bool logError = true; + + private: + std::string packageName; + std::filesystem::path absPackageDataDir; + std::filesystem::path relPackageDataPath; + IDType id; + }; + + template <class IDType, class DatasetType> + class DatasetFinderInfoBase : public FinderInfoBase<IDType> + { + + public: + using Base = FinderInfoBase<IDType>; + + DatasetFinderInfoBase(const std::string& packageName, const std::filesystem::path& absPackageDataDir, const std::filesystem::path& relPackageDataPath, const std::filesystem::path& relDatasetPath, const DatasetType& dataset, const IDType& id) : + Base(packageName, absPackageDataDir, relPackageDataPath, id), + dataset(dataset) + {} + + virtual std::filesystem::path getFullPath() const override + { + return Base::getFullPath() / relDatasetPath; + } + + DatasetType getDataset() const + { + return dataset; + } + + private: + DatasetType dataset; + std::filesystem::path relDatasetPath; + }; +} diff --git a/source/RobotAPI/libraries/PriorKnowledge/motions/CMakeLists.txt b/source/RobotAPI/libraries/PriorKnowledge/motions/CMakeLists.txt new file mode 100644 index 000000000..7f4b2c007 --- /dev/null +++ b/source/RobotAPI/libraries/PriorKnowledge/motions/CMakeLists.txt @@ -0,0 +1,19 @@ +set(LIB_NAME ${PROJECT_NAME}PriorKnowledgeMotions) + +armarx_component_set_name("${LIB_NAME}") +armarx_set_target("Library: ${LIB_NAME}") + +armarx_add_library( + LIBS + RobotAPI::Core + RobotAPI::Aron::Common + SOURCES + MotionFinder.cpp + HEADERS + MotionFinder.h +) + +add_library(${PROJECT_NAME}::PriorKnowledge::Motions ALIAS ${PROJECT_NAME}PriorKnowledgeMotions) + +# add unit tests +#add_subdirectory(test) diff --git a/source/RobotAPI/libraries/PriorKnowledge/motions/MotionFinder.cpp b/source/RobotAPI/libraries/PriorKnowledge/motions/MotionFinder.cpp new file mode 100644 index 000000000..8fa71a62b --- /dev/null +++ b/source/RobotAPI/libraries/PriorKnowledge/motions/MotionFinder.cpp @@ -0,0 +1,133 @@ +// Simox +#include <SimoxUtility/algorithm/vector.hpp> + +// BaseClass +#include "MotionFinder.h" + +// ArmarX + +namespace armarx::priorknowledge::motions +{ + bool MotionFinder::checkAll() const + { + return true; + } + + bool MotionFinder::check(const std::string &id) const + { + return true; + } + + std::optional<MotionFinderInfo> MotionFinder::find(const std::string &id) const + { + const std::filesystem::path absPath = Base::Base::getFullPath(); + if (std::filesystem::is_regular_file(absPath)) + { + ARMARX_WARNING << "The entered path is leading to a file!"; + return std::nullopt; + } + + for (const auto& d : std::filesystem::directory_iterator(absPath)) + { + if (!d.is_directory()) + { + ARMARX_WARNING << "Found invalid path: " << d.path(); + continue; + } + std::string k = d.path().filename(); + if (simox::alg::contains(DATASET_FOLDERS_BLACKLIST, k)) + { + continue; + } + + if (const auto op = this->find(k, id); op.has_value()) + { + return op; + } + } + return std::nullopt; + } + + std::vector<MotionFinderInfo> MotionFinder::findAll() const + { + const std::filesystem::path absPath = Base::Base::getFullPath(); + if (std::filesystem::is_regular_file(absPath)) + { + ARMARX_WARNING << "The entered path is leading to a file!"; + return {}; + } + + std::vector<MotionFinderInfo> ret; + for (const auto& d : std::filesystem::directory_iterator(absPath)) + { + if (!d.is_directory()) + { + ARMARX_WARNING << "Found invalid path: " << d.path(); + continue; + } + std::string k = d.path().filename(); + if (simox::alg::contains(DATASET_FOLDERS_BLACKLIST, k)) + { + continue; + } + + auto motionsForDataset = this->findAll(k); + simox::alg::append(ret, motionsForDataset); + } + return ret; + } + + bool MotionFinder::checkAll(const std::string &dataset) const + { + return true; + } + + bool MotionFinder::check(const std::string &dataset, const std::string &id) const + { + return true; + } + + std::optional<MotionFinderInfo> MotionFinder::find(const std::string &dataset, const std::string &id) const + { + const std::filesystem::path absPathToMotion = this->getFullPath(dataset) / id; + if (std::filesystem::is_regular_file(absPathToMotion)) + { + ARMARX_WARNING << "The entered path is leading to a file!"; + return std::nullopt; + } + + return std::make_optional(MotionFinderInfo(this->getPackageName(), this->getAbsolutePackagePath(), this->getRelativePath(), dataset, dataset, id)); + } + + std::vector<MotionFinderInfo> MotionFinder::findAll(const std::string &dataset) const + { + const std::filesystem::path absPathToDataset = this->getFullPath(dataset); + if (std::filesystem::is_regular_file(absPathToDataset)) + { + ARMARX_WARNING << "The entered path is leading to a file!"; + return {}; + } + + std::vector<MotionFinderInfo> ret; + for (const auto& d : std::filesystem::directory_iterator(absPathToDataset)) + { + if (!d.is_directory()) + { + ARMARX_WARNING << "Found invalid path: " << d.path(); + continue; + } + std::string k = d.path().filename(); + if (simox::alg::contains(MOTION_ID_FOLDERS_BLACKLIST, k)) + { + continue; + } + + if(auto op = this->find(dataset, k); op.has_value()) + { + ret.emplace_back(op.value()); + } + } + return ret; + } + +} diff --git a/source/RobotAPI/libraries/PriorKnowledge/motions/MotionFinder.h b/source/RobotAPI/libraries/PriorKnowledge/motions/MotionFinder.h new file mode 100644 index 000000000..cc0136572 --- /dev/null +++ b/source/RobotAPI/libraries/PriorKnowledge/motions/MotionFinder.h @@ -0,0 +1,50 @@ +#include <RobotAPI/libraries/PriorKnowledge/core/FinderBase.h> +#include <RobotAPI/libraries/PriorKnowledge/core/FinderInfoBase.h> + + +namespace armarx::priorknowledge::motions +{ + class MotionFinderInfo : public core::DatasetFinderInfoBase<std::string, std::string> + { + using Base = core::DatasetFinderInfoBase<std::string, std::string>; + + public: + MotionFinderInfo(const std::string& packageName, + const std::filesystem::path& absPackageDataDir, + const std::filesystem::path& relPackageDataPath, + const std::filesystem::path& relDatasetPath, + const std::string& dataset, + const std::string& id) : + Base(packageName, absPackageDataDir, relPackageDataPath, relDatasetPath, dataset, id) + { + + } + + + }; + + class MotionFinder : public core::DatasetFinderBase<std::string, std::string, MotionFinderInfo> + { + using Base = core::DatasetFinderBase<std::string, std::string, MotionFinderInfo>; + + public: + MotionFinder(const std::string& packageName, const std::filesystem::path& relDir) : + Base(packageName, relDir) + {} + + bool checkAll() const; + bool check(const std::string &id) const; + std::optional<MotionFinderInfo> find(const std::string &id) const; + std::vector<MotionFinderInfo> findAll() const; + + bool checkAll(const std::string &dataset) const; + bool check(const std::string &dataset, const std::string &id) const; + std::optional<MotionFinderInfo> find(const std::string &dataset, const std::string &id) const; + std::vector<MotionFinderInfo> findAll(const std::string &dataset) const; + + private: + std::vector<std::string> DATASET_FOLDERS_BLACKLIST = {}; + std::vector<std::string> MOTION_ID_FOLDERS_BLACKLIST = {"script"}; + }; + +} diff --git a/source/RobotAPI/libraries/armem/CMakeLists.txt b/source/RobotAPI/libraries/armem/CMakeLists.txt index 7f949da56..61aa0d1f9 100644 --- a/source/RobotAPI/libraries/armem/CMakeLists.txt +++ b/source/RobotAPI/libraries/armem/CMakeLists.txt @@ -103,6 +103,7 @@ set(LIB_FILES server/ComponentPlugin.cpp server/MemoryRemoteGui.cpp server/RemoteGuiAronDataVisitor.cpp + server/Segment.cpp server/query_proc/base/BaseQueryProcessorBase.cpp server/query_proc/base/EntityQueryProcessorBase.cpp @@ -223,6 +224,7 @@ set(LIB_HEADERS server/MemoryToIceAdapter.h server/MemoryRemoteGui.h server/RemoteGuiAronDataVisitor.h + server/Segment.h server/query_proc.h server/query_proc/base/BaseQueryProcessorBase.h diff --git a/source/RobotAPI/libraries/armem/server/Segment.cpp b/source/RobotAPI/libraries/armem/server/Segment.cpp new file mode 100644 index 000000000..ec25ce784 --- /dev/null +++ b/source/RobotAPI/libraries/armem/server/Segment.cpp @@ -0,0 +1 @@ +#include "Segment.h" diff --git a/source/RobotAPI/libraries/armem/server/Segment.h b/source/RobotAPI/libraries/armem/server/Segment.h new file mode 100644 index 000000000..3d6e5871c --- /dev/null +++ b/source/RobotAPI/libraries/armem/server/Segment.h @@ -0,0 +1,99 @@ +#pragma once + +// STD/STL +#include <mutex> +#include <string> + +// ArmarX +#include <ArmarXCore/core/logging/Logging.h> +#include <ArmarXCore/core/application/properties/PropertyDefinitionContainer.h> + +#include "MemoryToIceAdapter.h" + + +namespace armarx::armem::server +{ + /** + * @brief A base class for memory servers to manage their segments. + * A segment can inherit this base class and add segment specific code. + * TODO (fabian.peller): add concept to only accept coresegments, providersegments or entitysegments + */ + template <class SegmentType> + class SegmentBase : public armarx::Logging + { + public: + SegmentBase() = delete; + SegmentBase(armem::server::MemoryToIceAdapter& iceMemory, std::mutex& memoryMutex) : + iceMemory(iceMemory), + memoryMutex(memoryMutex) + { + Logging::setTag("armarx::armem::Segment"); + } + + virtual void defineProperties(armarx::PropertyDefinitionsPtr defs, const std::string& prefix = "") = 0; + virtual void onInit() = 0; + virtual void onConnect() = 0; + + protected: + private: + + public: + protected: + // Memory connection + armem::server::MemoryToIceAdapter& iceMemory; + std::mutex& memoryMutex; + + SegmentType* segment; + + private: + }; + + namespace wm + { + template <class BusinessClassObject> + class CoreSegmentBase : public SegmentBase<armarx::armem::wm::CoreSegment> + { + using Base = SegmentBase<armarx::armem::wm::CoreSegment>; + + public: + CoreSegmentBase(armem::server::MemoryToIceAdapter& iceMemory, std::mutex& memoryMutex): + Base(iceMemory, memoryMutex) + { + Logging::setTag("armarx::armem::wm::Segment"); + } + + virtual void defineProperties(armarx::PropertyDefinitionsPtr defs, const std::string& prefix = "") override + { + ARMARX_CHECK_NOT_NULL(defs); + + defs->optional(p.coreSegmentName, prefix + "CoreSegmentName", "Name of the '" + p.coreSegmentName + "' core segment."); + defs->optional(p.maxHistorySize, prefix + "MaxHistorySize", "Maximal size of '" + p.coreSegmentName + "' history (-1 for infinite)."); + } + + virtual void onInit() override + { + ARMARX_CHECK_NOT_NULL(iceMemory.workingMemory); + + segment = &iceMemory.workingMemory->addCoreSegment(p.coreSegmentName, BusinessClassObject::toAronType()); + segment->setMaxHistorySize(p.maxHistorySize); + } + + virtual void onConnect() override + { + + } + + protected: + private: + + public: + protected: + struct Properties + { + std::string coreSegmentName = ""; + int maxHistorySize = -1; + }; + Properties p; + }; + } +} diff --git a/source/RobotAPI/libraries/armem_motions/CMakeLists.txt b/source/RobotAPI/libraries/armem_motions/CMakeLists.txt new file mode 100644 index 000000000..0dd3aa640 --- /dev/null +++ b/source/RobotAPI/libraries/armem_motions/CMakeLists.txt @@ -0,0 +1,26 @@ +set(LIB_NAME armem_motions) + +armarx_component_set_name("${LIB_NAME}") +armarx_set_target("Library: ${LIB_NAME}") + +armarx_add_library( + LIBS + ArmarXCoreInterfaces + ArmarXCore + ArmarXCoreObservers + + RobotAPI::Core + RobotAPI::armem + RobotAPI::PriorKnowledge::Motions + SOURCES + ./server/MotionDatabase/MotionConverter.cpp + ./server/MotionDatabase/Segment.cpp + HEADERS + ./server/MotionDatabase/MotionConverter.h + ./server/MotionDatabase/Segment.h + ARON_FILES + #./aron/MMM.xml +) + + +add_library(RobotAPI::armem_motions ALIAS armem_motions) diff --git a/source/RobotAPI/libraries/armem_motions/aron/MMM.xml b/source/RobotAPI/libraries/armem_motions/aron/MMM.xml new file mode 100644 index 000000000..06339c07c --- /dev/null +++ b/source/RobotAPI/libraries/armem_motions/aron/MMM.xml @@ -0,0 +1,44 @@ +<!--Some fancy comment --> +<?xml version="1.0" encoding="UTF-8" ?> +<AronTypeDefinition> + + <CodeIncludes> + <Include include="<Eigen/Core>" /> + </CodeIncludes> + + <AronIncludes> + <Include include="<RobotAPI/libraries/armem/aron/MemoryID.xml>" autoinclude="true"/> + </AronIncludes> + + <GenerateTypes> + <Object name='armarx::armem::mmm::MMM'> + + <ObjectChild key='name'> + <String /> + </ObjectChild> + + <ObjectChild key='MoCapMarkerTrajectories'> + <Dict> + <List> + <Pair> + + </Pair> + </List> + </Dict> + </ObjectChild> + + <ObjectChild key='JointTrajectories'> + <Dict> + <List> + <Pair> + <Time /> <!-- Timestamp --> + <Float /> <!-- JointAngle --> + </Pair> + </List> + </Dict> + </ObjectChild> + + </Object> + </GenerateTypes> + +</AronTypeDefinition> diff --git a/source/RobotAPI/libraries/armem_motions/server/MotionDatabase/MotionConverter.cpp b/source/RobotAPI/libraries/armem_motions/server/MotionDatabase/MotionConverter.cpp new file mode 100644 index 000000000..e69de29bb diff --git a/source/RobotAPI/libraries/armem_motions/server/MotionDatabase/MotionConverter.h b/source/RobotAPI/libraries/armem_motions/server/MotionDatabase/MotionConverter.h new file mode 100644 index 000000000..e69de29bb diff --git a/source/RobotAPI/libraries/armem_motions/server/MotionDatabase/Segment.cpp b/source/RobotAPI/libraries/armem_motions/server/MotionDatabase/Segment.cpp new file mode 100644 index 000000000..a3276cb6f --- /dev/null +++ b/source/RobotAPI/libraries/armem_motions/server/MotionDatabase/Segment.cpp @@ -0,0 +1,55 @@ +// BaseClass +#include "Segment.h" + +// ArmarX +#include <RobotAPI/libraries/PriorKnowledge/motions/MotionFinder.h> + +namespace armarx::armem::server::motions::mdb +{ + Segment::Segment(armem::server::MemoryToIceAdapter& memoryToIceAdapter, std::mutex& memoryMutex) : + Base(memoryToIceAdapter, memoryMutex) + { + } + + void Segment::defineProperties(armarx::PropertyDefinitionsPtr defs, const std::string& prefix) + { + Base::defineProperties(defs, prefix); + + defs->optional(p.motionsPackage, prefix + "MotionsPackage", "Name of the prior knowledge package to load from."); + defs->optional(p.loadFromMotionsPackage, prefix + "LoadFromMotionsPackage", "If true, load the motions from the motions package on startup."); + } + + void Segment::onInit() + { + Base::onInit(); + + if (p.loadFromMotionsPackage) + { + loadByMotionFinder(p.motionsPackage); + } + } + + void Segment::onConnect() + { + + } + + int Segment::loadByMotionFinder(const std::string& packageName) + { + priorknowledge::motions::MotionFinder motionFinder(packageName, "motions/"); + int loadedMotions = 0; + + { + // Load MDB Motions + auto allMotions = motionFinder.findAll("mdb"); + for (const auto& motionFinderInfo : allMotions) + { + std::cout << "Found a motionfile at: " << motionFinderInfo.getFullPath() << std::endl; + } + + loadedMotions += allMotions.size(); + } + + return loadedMotions; + } +} diff --git a/source/RobotAPI/libraries/armem_motions/server/MotionDatabase/Segment.h b/source/RobotAPI/libraries/armem_motions/server/MotionDatabase/Segment.h new file mode 100644 index 000000000..fbb11bb43 --- /dev/null +++ b/source/RobotAPI/libraries/armem_motions/server/MotionDatabase/Segment.h @@ -0,0 +1,38 @@ +#pragma once + +// STD/STL +#include <mutex> +#include <string> + +// BaseClass +#include <RobotAPI/libraries/armem/server/Segment.h> + +// ArmarX +#include <RobotAPI/libraries/aron/core/test/aron/NaturalIKTest.aron.generated.h> // <-- dummy for now. replace with motion type + + +namespace armarx::armem::server::motions::mdb +{ + class Segment : public armem::server::wm::CoreSegmentBase<armarx::NaturalIKResult> + { + using Base = armem::server::wm::CoreSegmentBase<armarx::NaturalIKResult>; + + public: + Segment(armem::server::MemoryToIceAdapter& iceMemory, std::mutex& memoryMutex); + + virtual void defineProperties(armarx::PropertyDefinitionsPtr defs, const std::string& prefix = "") override; + virtual void onInit() override; + virtual void onConnect() override; + + private: + int loadByMotionFinder(const std::string&); + + private: + struct Properties + { + std::string motionsPackage = "PriorKnowledgeData"; + bool loadFromMotionsPackage = true; + }; + Properties p; + }; +} diff --git a/source/RobotAPI/libraries/aron/common/CMakeLists.txt b/source/RobotAPI/libraries/aron/common/CMakeLists.txt index ec6c74d9e..491e3dec3 100644 --- a/source/RobotAPI/libraries/aron/common/CMakeLists.txt +++ b/source/RobotAPI/libraries/aron/common/CMakeLists.txt @@ -25,19 +25,20 @@ armarx_add_library( aron_conversions/simox.cpp aron_conversions/stl.cpp aron_conversions/eigen.cpp -) - -armarx_enable_aron_file_generation_for_target( - TARGET_NAME - "${LIB_NAME}" ARON_FILES + #aron/SimplePosition.xml + #aron/SimplePose.xml + #aron/SimpleTrajectory.xml aron/AxisAlignedBoundingBox.xml aron/OrientedBox.xml aron/PackagePath.xml - ) +add_library(aron::common ALIAS aroncommon) +add_library(Aron::Common ALIAS aroncommon) +add_library(${PROJECT_NAME}::Aron::Common ALIAS aroncommon) +add_library(${PROJECT_NAME}::aron::common ALIAS aroncommon) # add unit tests add_subdirectory(test) diff --git a/source/RobotAPI/libraries/aron/common/aron/SimplePose.xml b/source/RobotAPI/libraries/aron/common/aron/SimplePose.xml new file mode 100644 index 000000000..add970d13 --- /dev/null +++ b/source/RobotAPI/libraries/aron/common/aron/SimplePose.xml @@ -0,0 +1,27 @@ +<!--Some fancy comment +<?xml version="1.0" encoding="UTF-8" ?> +<AronTypeDefinition> + + <CodeIncludes> + <Include include="<Eigen/Core>" /> + </CodeIncludes> + + <AronIncludes> + <Include include="<RobotAPI/libraries/armem/aron/MemoryID.xml>" autoinclude="true"/> + </AronIncludes> + + <GenerateTypes> + <Object name='armarx::armem::mmm::KeyPoint'> + + </Object> + <Object name='armarx::armem::mmm::SingleKeyPointTrajectory'> + + <ObjectChild key='name'> + < /> + </ObjectChild> + + </Object> + </GenerateTypes> + +</AronTypeDefinition> +--> diff --git a/source/RobotAPI/libraries/aron/common/aron/SimplePosition.xml b/source/RobotAPI/libraries/aron/common/aron/SimplePosition.xml new file mode 100644 index 000000000..42faeef90 --- /dev/null +++ b/source/RobotAPI/libraries/aron/common/aron/SimplePosition.xml @@ -0,0 +1,26 @@ +<!--Some fancy comment +<?xml version="1.0" encoding="UTF-8" ?> +<AronTypeDefinition> + + <CodeIncludes> + <Include include="<Eigen/Core>" /> + </CodeIncludes> + + <AronIncludes> + <Include include="<RobotAPI/libraries/armem/aron/MemoryID.xml>" autoinclude="true"/> + </AronIncludes> + + <GenerateTypes> + <Object name='armarx::armem::mmm::KeyPoint'> + + </Object> + <Object name='armarx::armem::mmm::SingleKeyPointTrajectory'> + + <ObjectChild key='name'> + < /> + </ObjectChild> + + </Object> + </GenerateTypes> + +</AronTypeDefinition>--> diff --git a/source/RobotAPI/libraries/aron/common/aron/SimpleTrajectory.xml b/source/RobotAPI/libraries/aron/common/aron/SimpleTrajectory.xml new file mode 100644 index 000000000..42faeef90 --- /dev/null +++ b/source/RobotAPI/libraries/aron/common/aron/SimpleTrajectory.xml @@ -0,0 +1,26 @@ +<!--Some fancy comment +<?xml version="1.0" encoding="UTF-8" ?> +<AronTypeDefinition> + + <CodeIncludes> + <Include include="<Eigen/Core>" /> + </CodeIncludes> + + <AronIncludes> + <Include include="<RobotAPI/libraries/armem/aron/MemoryID.xml>" autoinclude="true"/> + </AronIncludes> + + <GenerateTypes> + <Object name='armarx::armem::mmm::KeyPoint'> + + </Object> + <Object name='armarx::armem::mmm::SingleKeyPointTrajectory'> + + <ObjectChild key='name'> + < /> + </ObjectChild> + + </Object> + </GenerateTypes> + +</AronTypeDefinition>--> diff --git a/source/RobotAPI/libraries/aron/converter/CMakeLists.txt b/source/RobotAPI/libraries/aron/converter/CMakeLists.txt index a99bfccfd..5f8db702e 100644 --- a/source/RobotAPI/libraries/aron/converter/CMakeLists.txt +++ b/source/RobotAPI/libraries/aron/converter/CMakeLists.txt @@ -16,4 +16,7 @@ target_link_libraries(AronConverter RobotAPI::aron::converter::opencv ) -add_library(RobotAPI::aron::converter ALIAS AronConverter) +add_library(aron::converter ALIAS AronConverter) +add_library(Aron::Converter ALIAS AronConverter) +add_library(${PROJECT_NAME}::Aron::Converter ALIAS AronConverter) +add_library(${PROJECT_NAME}::aron::converter ALIAS AronConverter) diff --git a/source/RobotAPI/libraries/aron/core/CMakeLists.txt b/source/RobotAPI/libraries/aron/core/CMakeLists.txt index af2caf057..62548c297 100644 --- a/source/RobotAPI/libraries/aron/core/CMakeLists.txt +++ b/source/RobotAPI/libraries/aron/core/CMakeLists.txt @@ -281,6 +281,8 @@ armarx_add_library( "${LIBS}" ) +add_library(Aron ALIAS "${LIB_NAME}") +add_library(RobotAPI::Aron ALIAS "${LIB_NAME}") add_library(RobotAPI::aron ALIAS "${LIB_NAME}") # add unit tests -- GitLab