MMMPlayer.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of ArmarX.
3  *
4  * Copyright (C) 2015-2016, High Performance Humanoid Technologies (H2T), Karlsruhe Institute of Technology (KIT), all rights reserved.
5  *
6  * ArmarX is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation.
9  *
10  * ArmarX is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  *
18  * @package RobotComponents::ArmarXObjects::MMMPlayer
19  * @author Mirko Waechter ( mirko dot waechter at kit dot edu )
20  * @date 2014
21  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22  * GNU General Public License
23  */
24 
25 #include "MMMPlayer.h"
26 #include <MMM/Motion/Legacy/LegacyMotionReaderXML.h>
27 #include <MMM/Model/ModelReaderXML.h>
28 
30 
32 
34 #include <ArmarXCore/interface/observers/VariantBase.h>
37 #include <VirtualRobot/MathTools.h>
42 
43 #include <Ice/ObjectAdapter.h>
44 
45 using namespace armarx;
46 using namespace MMM;
47 
48 
50 {
51  // offeringTopic("DebugObserver");
52 }
53 
54 
56 {
57  ARMARX_INFO << "ON CONNECT";
58  std::string armarxProjects = getProperty<std::string>("ArmarXProjects").getValue();
59 
60  if (!armarxProjects.empty())
61  {
62  std::vector<std::string> projects = armarx::Split(armarxProjects, ",;", true, true);
63 
64  for (std::string& p : projects)
65  {
66  // ARMARX_INFO << "Adding to datapaths of " << p;
68 
69  if (!finder.packageFound())
70  {
71  ARMARX_WARNING << "ArmarX Package " << p << " has not been found!";
72  }
73  else
74  {
75  ARMARX_INFO << "Adding " << p << " to datapaths: " << finder.getDataDir();
77  }
78  }
79  }
80 
81  std::string motionDefault = getProperty<std::string>("MMMFile").getValue();
82 
83  if (!motionDefault.empty())
84  {
85  load(motionDefault, "Armar4"); // TODO remove?!
86  }
87 
88  /*std::string modelDefault = getProperty<std::string>("ModelFile").getValue();
89  if (!modelDefault.empty())
90  {
91  modelPath = modelDefault; // TODO dieses Attribut ist sinnlos!
92  }*/
93 }
94 
95 void MMMPlayer::load(const std::string& MMMFile, const std::string& projects)
96 {
97  std::unique_lock lock(mmmMutex);
98 
99  if (!projects.empty())
100  {
101  std::vector<std::string> proj = armarx::Split(projects, ",;", true, true);
102 
103  for (std::string& p : proj)
104  {
105  ARMARX_INFO << "Adding to datapaths of " << p;
106  armarx::CMakePackageFinder finder(p);
107 
108  if (!finder.packageFound())
109  {
110  ARMARX_WARNING << "ArmarX Package " << p << " has not been found!";
111  }
112  else
113  {
114  ARMARX_INFO << "Adding to datapaths: " << finder.getDataDir();
115  armarx::ArmarXDataPath::addDataPaths(finder.getDataDir());
116  }
117  }
118  }
119 
120  ArmarXDataPath::getAbsolutePath(MMMFile, motionPath);
121 
122  motionWrapper = MotionFileWrapper::create(motionPath, getProperty<bool>("ApplyButterworthFilter").getValue() ? getProperty<float>("ButterworthFilterCutOffFreq") : 0);
123  if (!motionWrapper)
124  {
125  terminate();
126  motionData = nullptr;
127  return;
128  }
129 
130  motionData = motionWrapper->getFirstMotionData();
131 }
132 
133 bool MMMPlayer::loadMMMFile(const std::string& MMMFile, const std::string& projects, const Ice::Current&)
134 {
135  ARMARX_VERBOSE << "loaded trajectory " << MMMFile;
136  load(MMMFile, projects);
137  return motionData != nullptr;
138 }
139 
140 bool MMMPlayer::setMotionData(const std::string& motionName, const Ice::Current&)
141 {
142  motionData = motionWrapper->getMotionData(motionName);
143  return motionData != nullptr;
144 }
145 
146 int MMMPlayer::getNumberOfFrames(const Ice::Current&)
147 {
148  return (int) motionData->numberOfFrames;
149 }
150 
151 std::string MMMPlayer::getMotionPath(const Ice::Current&)
152 {
153  return motionPath;
154 }
155 
156 std::string MMMPlayer::getModelPath(const Ice::Current&)
157 {
158  return motionData->modelPath;
159 }
160 
161 Ice::StringSeq MMMPlayer::getJointNames(const Ice::Current&)
162 {
163  return motionData->jointNames;
164 }
165 
166 Ice::StringSeq MMMPlayer::getMotionNames(const Ice::Current&)
167 {
168  if (!motionWrapper)
169  {
170  return Ice::StringSeq();
171  }
172  return motionWrapper->getMotionNames();
173 }
174 
175 bool MMMPlayer::isMotionLoaded(const Ice::Current&)
176 {
177  return motionData != nullptr;
178 }
179 
181 {
182 
183 }
184 
186 {
187 
188 }
189 
190 TrajectoryBasePtr MMMPlayer::getJointTraj(const Ice::Current&)
191 {
192  return motionData->getJointTrajectory();
193 }
194 
195 TrajectoryBasePtr MMMPlayer::getBasePoseTraj(const Ice::Current&)
196 {
197  return motionData->getPoseTrajectory();
198 }
199 
201 {
202  return PropertyDefinitionsPtr(new MMMPlayerPropertyDefinitions(getConfigIdentifier()));
203 }
armarx::MMMPlayer::onConnectComponent
void onConnectComponent() override
Definition: MMMPlayer.cpp:55
ARMARX_VERBOSE
#define ARMARX_VERBOSE
Definition: Logging.h:180
armarx::MMMPlayer::getNumberOfFrames
int getNumberOfFrames(const Ice::Current &) override
Definition: MMMPlayer.cpp:146
armarx::CMakePackageFinder::packageFound
bool packageFound() const
Returns whether or not this package was found with cmake.
Definition: CMakePackageFinder.cpp:485
armarx::MMMPlayer::loadMMMFile
bool loadMMMFile(const std::string &filename, const std::string &projects, const Ice::Current &) override
Definition: MMMPlayer.cpp:133
armarx::MMMPlayer::onDisconnectComponent
void onDisconnectComponent() override
Definition: MMMPlayer.cpp:180
armarx::MMMPlayer::setMotionData
bool setMotionData(const std::string &motionName, const Ice::Current &) override
Definition: MMMPlayer.cpp:140
armarx::Split
std::vector< std::string > Split(const std::string &source, const std::string &splitBy, bool trimElements=false, bool removeEmptyElements=false)
Definition: StringHelperTemplates.h:35
armarx::CMakePackageFinder
The CMakePackageFinder class provides an interface to the CMake Package finder capabilities.
Definition: CMakePackageFinder.h:53
armarx::MMMPlayer::createPropertyDefinitions
PropertyDefinitionsPtr createPropertyDefinitions() override
Definition: MMMPlayer.cpp:200
ButterworthFilter.h
armarx::MMMPlayer::onExitComponent
void onExitComponent() override
Definition: MMMPlayer.cpp:185
StringHelpers.h
armarx::MMMPlayer::getMotionNames
Ice::StringSeq getMotionNames(const Ice::Current &) override
Definition: MMMPlayer.cpp:166
armarx::MMMPlayer::onInitComponent
void onInitComponent() override
Definition: MMMPlayer.cpp:49
armarx::MMMPlayer::getBasePoseTraj
TrajectoryBasePtr getBasePoseTraj(const Ice::Current &) override
Definition: MMMPlayer.cpp:195
armarx::CMakePackageFinder::getDataDir
std::string getDataDir() const
Definition: CMakePackageFinder.h:176
boost::process::posix::terminate
void terminate(const Process &p)
Definition: terminate.hpp:20
armarx::MMMPlayer::getJointTraj
TrajectoryBasePtr getJointTraj(const Ice::Current &) override
Definition: MMMPlayer.cpp:190
armarx::MMMPlayer::getModelPath
std::string getModelPath(const Ice::Current &) override
Definition: MMMPlayer.cpp:156
ExpressionException.h
armarx::control::common::getValue
T getValue(nlohmann::json &userConfig, nlohmann::json &defaultConfig, const std::string &entryName)
Definition: utils.h:68
Trajectory.h
CMakePackageFinder.h
TimeUtil.h
ARMARX_INFO
#define ARMARX_INFO
Definition: Logging.h:174
armarx::ArmarXDataPath::addDataPaths
static void addDataPaths(const std::string &dataPathList)
Definition: ArmarXDataPath.cpp:559
MMMPlayer.h
IceUtil::Handle< class PropertyDefinitionContainer >
MotionFileWrapper.h
armarx::ArmarXDataPath::getAbsolutePath
static bool getAbsolutePath(const std::string &relativeFilename, std::string &storeAbsoluteFilename, const std::vector< std::string > &additionalSearchPaths={}, bool verbose=true)
Definition: ArmarXDataPath.cpp:111
ARMARX_WARNING
#define ARMARX_WARNING
Definition: Logging.h:186
armarx::PropertyDefinitionsPtr
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
Definition: forward_declarations.h:34
ArmarXDataPath.h
armarx::MMMPlayer::getJointNames
Ice::StringSeq getJointNames(const Ice::Current &) override
Definition: MMMPlayer.cpp:161
Variant.h
armarx::MMMPlayer::isMotionLoaded
bool isMotionLoaded(const Ice::Current &) override
Definition: MMMPlayer.cpp:175
armarx::armem::server::ltm::mongodb::util::load
void load(const mongocxx::database &db, armem::wm::Memory &m)
Definition: operations.cpp:40
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
armarx::MMMPlayerPropertyDefinitions
Definition: MMMPlayer.h:45
armarx::MotionFileWrapper::create
static MotionFileWrapperPtr create(const std::string &motionFilePath, double butterworthFilterCutOffFreq=0.0, const std::string relativeModelRoot="mmm")
Definition: MotionFileWrapper.cpp:49
armarx::MMMPlayer::getMotionPath
std::string getMotionPath(const Ice::Current &) override
Definition: MMMPlayer.cpp:151