MPPool.h
Go to the documentation of this file.
1 /**
2  * This file is part of ArmarX.
3  *
4  * ArmarX is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation.
7  *
8  * ArmarX is distributed in the hope that it will be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  *
16  * @author Jianfeng Gao ( jianfeng dot gao at kit dot edu )
17  * @date 2022
18  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
19  * GNU General Public License
20  */
21 
22 
23 #pragma once
24 #include <VirtualRobot/RobotNodeSet.h>
25 
26 #include <armarx/control/common/mp/MPPoolInterface.h>
27 #include <armarx/control/common/mp/aron/MPConfig.aron.generated.h>
28 
29 #include "MP.h"
30 #include <mplib/representation/vmp/PrincipalComponentVMP.h>
31 
33 {
34  BETTER_ENUM(mpClass, int, JSMP, JSVelMP, TSMP, TSVelMP, KeypointsMP)
35 
36  using namespace arondto;
37 
39  {
43  };
44 
45  using MPInputOutputPtr = std::shared_ptr<MPInputOutput>;
46 
47  class MPPool : public virtual MPPoolInterface
48  {
49  public:
50  MPPool(){};
51  ~MPPool(){};
52 
53  void runMPs(const bool rtSafe);
54  void createMPs(const MPListConfig& mpListConfig);
55  void reconfigureMPs(const MPListConfig& mpListConfig);
56 
57  public:
58  /// Interface functions
59  std::string getNames(const Ice::Current& iceCurrent = Ice::emptyCurrent) override;
60 
61  /// config
63  getMPConfig(const Ice::Current& iceCurrent = Ice::emptyCurrent) override;
64  void updateMPConfig(const ::armarx::aron::data::dto::DictPtr& dto,
65  const Ice::Current& iceCurrent = Ice::emptyCurrent) override;
67  const std::map<std::string, VirtualRobot::RobotNodeSetPtr>& rnsMap);
68 
69  /// control
70  void start(const std::string& mpName = "all",
71  const DVec& startVec = std::vector<double>(),
72  const DVec& goalVec = std::vector<double>(),
73  Ice::Double timeDuration = -1.0,
74  const Ice::Current& iceCurrent = Ice::emptyCurrent) override;
75  void startAll(const Ice::Current& iceCurrent = Ice::emptyCurrent) override;
79  const ::Ice::Current& iceCurrent = ::Ice::emptyCurrent) override;
80 
81  void stop(const std::string& mpName = "all",
82  const Ice::Current& iceCurrent = Ice::emptyCurrent) override;
83  void stopAll(const Ice::Current& iceCurrent = Ice::emptyCurrent) override;
84  void pause(const std::string& mpName = "all",
85  const Ice::Current& iceCurrent = Ice::emptyCurrent) override;
86  void pauseAll(const Ice::Current& iceCurrent = Ice::emptyCurrent) override;
87  void resume(const std::string& mpName = "all",
88  const Ice::Current& iceCurrent = Ice::emptyCurrent) override;
89  void resumeAll(const Ice::Current& iceCurrent = Ice::emptyCurrent) override;
90  void reset(const std::string& mpName = "all",
91  const Ice::Current& iceCurrent = Ice::emptyCurrent) override;
92  void resetAll(const Ice::Current& iceCurrent = Ice::emptyCurrent) override;
93  bool isFinished(const std::string& mpName = "all",
94  const Ice::Current& iceCurrent = Ice::emptyCurrent) override;
95  bool isFinishedAll(const Ice::Current& iceCurrent = Ice::emptyCurrent) override;
96 
97  /// setting
98  void learnFromCSV(const Ice::StringSeq& fileNames = std::vector<std::string>(),
99  const Ice::Current& iceCurrent = Ice::emptyCurrent) override;
100  void learnFromTrajs(const ::armarx::aron::data::dto::DictPtr& dto,
101  const Ice::Current& iceCurrent = Ice::emptyCurrent) override;
102  void trainMP(const Ice::Current& iceCurrent = Ice::emptyCurrent) override;
103 
104  void setGoal(const DVec& goals,
105  const Ice::Current& iceCurrent = Ice::emptyCurrent) override;
106  void setStartAndGoal(const DVec& starts,
107  const DVec& goals,
108  const Ice::Current& iceCurrent = Ice::emptyCurrent) override;
109  void setViaPoint(Ice::Double u,
110  const DVec& viapoint,
111  const Ice::Current& iceCurrent = Ice::emptyCurrent) override;
112  void removeAllViaPoint(const Ice::Current& iceCurrent = Ice::emptyCurrent) override;
113 
114  /// serialize
115  // void setWeight(const DVecSeq& weights, const Ice::Current& iceCurrent = Ice::emptyCurrent) override;
116  // DVecSeq getWeight(const Ice::Current& iceCurrent = Ice::emptyCurrent) override;
117  std::string serialize(const Ice::Current& iceCurrent = Ice::emptyCurrent) override;
118  DVec deserialize(const std::string&,
119  const Ice::Current& iceCurrent = Ice::emptyCurrent) override;
120 
121  ///
122  Ice::Double getCanVal(const std::string& mpName,
123  const Ice::Current& iceCurrent = Ice::emptyCurrent) override;
124  bool getMPEnabled(const Ice::Current&) override;
125 
126  protected:
127  std::map<std::string, MPInputOutput> mps;
128  mutable std::recursive_mutex mtx_mps;
129  std::atomic<bool> isMPReady{false};
130  // std::atomic_bool isAnyMPRunning{false};
131 
132  /// this variable is only needed when constructing the MP instances, therefore you don't
133  /// need to use triple buffers
134  MPListConfig mpConfig;
135  void
136  reInitMPInputOutputData(const std::map<std::string, VirtualRobot::RobotNodeSetPtr>& rnsMap);
137 
138  std::atomic_bool mpTaskRunning{false};
139  };
140 
141  using MPPoolPtr = std::shared_ptr<MPPool>;
142 } // namespace armarx::control::common::mp
armarx::control::common::mp::MPInputOutput::output
MPOutputPtr output
Definition: MPPool.h:42
armarx::control::common::mp::MPPoolPtr
std::shared_ptr< MPPool > MPPoolPtr
Definition: MPPool.h:141
armarx::control::common::mp::MPInputOutput::mp
MPPtr mp
Definition: MPPool.h:40
armarx::MPPoolInterface
Definition: MPPoolInterface.ice:38
armarx::control::common::mp::MPInputOutput
Definition: MPPool.h:38
armarx::control::common::mp
This file is part of ArmarX.
Definition: aron_conversions.cpp:331
armarx::control::common::mp::MPPool::MPPool
MPPool()
Definition: MPPool.h:50
MP.h
armarx::VariantType::Double
const VariantTypeId Double
Definition: Variant.h:919
armarx::control::common::mp::MPPtr
std::shared_ptr< MP > MPPtr
Definition: MP.h:158
armarx::control::common::mp::MPInputOutput::input
MPInputPtr input
Definition: MPPool.h:41
armarx::control::common::mp::DVec
Ice::DoubleSeq DVec
Definition: MP.h:46
armarx::control::common::mp::MPPool::mtx_mps
std::recursive_mutex mtx_mps
Definition: MPPool.h:128
armarx::control::common::mp::MPInputPtr
std::shared_ptr< MPInput > MPInputPtr
Definition: MP.h:63
armarx::aron::data::DictPtr
std::shared_ptr< Dict > DictPtr
Definition: Dict.h:41
armarx::control::common::mp::MPOutputPtr
std::shared_ptr< MPOutput > MPOutputPtr
Definition: MP.h:64
set
set(LIBS ArmarXCoreInterfaces ${CMAKE_THREAD_LIBS_INIT} ${dl_LIBRARIES} ${rt_LIBRARIES} ${QT_LIBRARIES} ${Boost_LIBRARIES} BoostAssertionHandler ArmarXCPPUtility SimoxUtility) set(LIB_FILES ArmarXManager.cpp ArmarXMultipleObjectsScheduler.cpp ArmarXObjectScheduler.cpp ManagedIceObject.cpp ManagedIceObjectPlugin.cpp Component.cpp ComponentPlugin.cpp IceGridAdmin.cpp ArmarXObjectObserver.cpp IceManager.cpp PackagePath.cpp RemoteReferenceCount.cpp logging/LoggingUtil.cpp logging/Logging.cpp logging/LogSender.cpp logging/ArmarXLogBuf.cpp system/ArmarXDataPath.cpp system/DynamicLibrary.cpp system/ProcessWatcher.cpp system/FactoryCollectionBase.cpp system/cmake/CMakePackageFinder.cpp system/cmake/CMakePackageFinderCache.cpp system/cmake/ArmarXPackageToolInterface.cpp system/RemoteObjectNode.cpp services/sharedmemory/HardwareId.cpp services/tasks/RunningTask.cpp services/tasks/ThreadList.cpp services/tasks/ThreadPool.cpp services/profiler/Profiler.cpp services/profiler/FileLoggingStrategy.cpp services/profiler/IceLoggingStrategy.cpp application/Application.cpp application/ApplicationOptions.cpp application/ApplicationProcessFacet.cpp application/ApplicationNetworkStats.cpp application/properties/PropertyUser.cpp application/properties/Property.cpp application/properties/PropertyDefinition.cpp application/properties/PropertyDefinitionContainer.cpp application/properties/PropertyDefinitionHelpFormatter.cpp application/properties/PropertyDefinitionConfigFormatter.cpp application/properties/PropertyDefinitionBriefHelpFormatter.cpp application/properties/PropertyDefinitionXmlFormatter.cpp application/properties/PropertyDefinitionDoxygenFormatter.cpp application/properties/PropertyDefinitionDoxygenComponentPagesFormatter.cpp application/properties/PropertyDefinitionContainerBriefHelpFormatter.cpp application/properties/IceProperties.cpp exceptions/Exception.cpp exceptions/local/UnexpectedEnumValueException.cpp util/FileSystemPathBuilder.cpp util/StringHelpers.cpp util/IceReportSkipper.cpp util/Throttler.cpp util/distributed/AMDCallbackCollection.cpp util/distributed/RemoteHandle/ClientSideRemoteHandleControlBlock.cpp util/distributed/RemoteHandle/RemoteHandle.cpp util/distributed/RemoteHandle/RemoteHandleControlBlock.cpp time/ice_conversions.cpp time/json_conversions.cpp time/CallbackWaitLock.cpp time/Clock.cpp time/ClockType.cpp time/ClockTypeNames.cpp time/CycleUtil.cpp time/DateTime.cpp time/Duration.cpp time/Frequency.cpp time/LocalTimeServer.cpp time/Metronome.cpp time/ScopedStopWatch.cpp time/StopWatch.cpp time/Timer.cpp time/TimeKeeper.cpp time/TimeUtil.cpp csv/CsvWriter.cpp csv/CsvReader.cpp eigen/conversions.cpp eigen/ice_conversions.cpp) set(LIB_HEADERS ArmarXManager.h ArmarXDummyManager.h ArmarXMultipleObjectsScheduler.h ArmarXObjectObserver.h ArmarXObjectScheduler.h ArmarXFwd.h Component.h ComponentPlugin.h ComponentFactories.h CoreObjectFactories.h IceGridAdmin.h IceManager.h IceManagerImpl.h json_conversions.h ManagedIceObject.h ManagedIceObjectPlugin.h ManagedIceObjectImpl.h ManagedIceObjectDependency.h ManagedIceObjectRegistryInterface.h PackagePath.h RemoteReferenceCount.h system/ImportExport.h system/ImportExportComponent.h system/AbstractFactoryMethod.h system/FactoryCollectionBase.h system/Synchronization.h system/ArmarXDataPath.h system/DynamicLibrary.h system/ProcessWatcher.h system/ConditionSynchronization.h system/cmake/CMakePackageFinder.h system/cmake/CMakePackageFinderCache.h system/cmake/FindPackageX.cmake system/cmake/ArmarXPackageToolInterface.h system/RemoteObjectNode.h logging/LoggingUtil.h logging/LogSender.h logging/Logging.h logging/ArmarXLogBuf.h logging/SpamFilterData.h services/tasks/RunningTask.h services/tasks/PeriodicTask.h services/tasks/ThreadList.h services/tasks/TaskUtil.h services/tasks/ThreadPool.h services/sharedmemory/SharedMemoryProvider.h services/sharedmemory/SharedMemoryConsumer.h services/sharedmemory/IceSharedMemoryProvider.h services/sharedmemory/IceSharedMemoryConsumer.h services/sharedmemory/HardwareIdentifierProvider.h services/sharedmemory/HardwareId.h services/sharedmemory/exceptions/SharedMemoryExceptions.h services/profiler/Profiler.h services/profiler/LoggingStrategy.h services/profiler/FileLoggingStrategy.h services/profiler/IceLoggingStrategy.h application/Application.h application/ApplicationOptions.h application/ApplicationProcessFacet.h application/ApplicationNetworkStats.h application/properties/forward_declarations.h application/properties/Properties.h application/properties/Property.h application/properties/PluginEigen.h application/properties/PluginEnumNames.h application/properties/PluginCfgStruct.h application/properties/PluginAll.h application/properties/PropertyUser.h application/properties/PropertyDefinition.h application/properties/PropertyDefinition.hpp application/properties/PropertyDefinitionInterface.h application/properties/PropertyDefinitionContainer.h application/properties/PropertyDefinitionFormatter.h application/properties/PropertyDefinitionContainerFormatter.h application/properties/PropertyDefinitionConfigFormatter.h application/properties/PropertyDefinitionHelpFormatter.h application/properties/PropertyDefinitionBriefHelpFormatter.h application/properties/PropertyDefinitionXmlFormatter.h application/properties/PropertyDefinitionDoxygenFormatter.h application/properties/PropertyDefinitionDoxygenComponentPagesFormatter.h application/properties/PropertyDefinitionContainerBriefHelpFormatter.h application/properties/ProxyPropertyDefinition.h application/properties/IceProperties.h exceptions/Exception.h exceptions/LocalException.h exceptions/local/DynamicLibraryException.h exceptions/local/ExpressionException.h exceptions/local/FileIOException.h exceptions/local/InvalidPropertyValueException.h exceptions/local/MissingRequiredPropertyException.h exceptions/local/PropertyInheritanceCycleException.h exceptions/local/ProxyNotInitializedException.h exceptions/local/UnexpectedEnumValueException.h exceptions/local/UnmappedValueException.h exceptions/local/ValueRangeExceededException.h exceptions/user/NotImplementedYetException.h rapidxml/rapidxml.hpp rapidxml/rapidxml_print.hpp rapidxml/rapidxml_iterators.hpp rapidxml/rapidxml_utils.hpp rapidxml/wrapper/RapidXmlReader.h rapidxml/wrapper/RapidXmlWriter.h rapidxml/wrapper/DefaultRapidXmlReader.h rapidxml/wrapper/MultiNodeRapidXMLReader.h util/IceBlobToObject.h util/ObjectToIceBlob.h util/FileSystemPathBuilder.h util/FiniteStateMachine.h util/StringHelpers.h util/StringHelperTemplates.h util/algorithm.h util/OnScopeExit.h util/Predicates.h util/Preprocessor.h util/PropagateConst.h util/Registrar.h util/TemplateMetaProgramming.h util/TripleBuffer.h util/IceReportSkipper.h util/Throttler.h util/distributed/AMDCallbackCollection.h util/distributed/RemoteHandle/ClientSideRemoteHandleControlBlock.h util/distributed/RemoteHandle/RemoteHandle.h util/distributed/RemoteHandle/RemoteHandleControlBlock.h util/SimpleStatemachine.h time.h time_minimal.h time/forward_declarations.h time/ice_conversions.h time/json_conversions.h time/CallbackWaitLock.h time/Clock.h time/ClockType.h time/ClockTypeNames.h time/CycleUtil.h time/DateTime.h time/Duration.h time/Frequency.h time/LocalTimeServer.h time/Metronome.h time/ScopedStopWatch.h time/StopWatch.h time/Timer.h time/TimeUtil.h time/TimeKeeper.h csv/CsvWriter.h csv/CsvReader.h eigen/conversions.h eigen/ice_conversions.h ice_conversions.h ice_conversions/ice_conversions_boost_templates.h ice_conversions/ice_conversions_templates.h ice_conversions/ice_conversions_templates.tpp $
Definition: CMakeLists.txt:12
armarx::control::common::mp::MPPool::~MPPool
~MPPool()
Definition: MPPool.h:51
armarx::StringDoubleMap
dictionary< string, double > StringDoubleMap
Definition: MPPoolInterface.ice:35
armarx::control::common::mp::MPPool
Definition: MPPool.h:47
armarx::control::common::mp::MPInputOutputPtr
std::shared_ptr< MPInputOutput > MPInputOutputPtr
Definition: MPPool.h:45
armarx::control::common::mp::MPPool::mps
std::map< std::string, MPInputOutput > mps
Definition: MPPool.h:127
armarx::StringDoubleSeqMap
dictionary< string, Ice::DoubleSeq > StringDoubleSeqMap
Definition: MPPoolInterface.ice:34
armarx::control::common::MPStatus::reset
@ reset
armarx::control::common::mp::MPPool::mpConfig
MPListConfig mpConfig
this variable is only needed when constructing the MP instances, therefore you don't need to use trip...
Definition: MPPool.h:134