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 
27 #include <Ice/ObjectAdapter.h>
28 
29 #include <VirtualRobot/MathTools.h>
30 
36 #include <ArmarXCore/interface/observers/VariantBase.h>
39 
41 
43 
44 #include <MMM/Model/ModelReaderXML.h>
45 #include <MMM/Motion/Legacy/LegacyMotionReaderXML.h>
46 
47 using namespace armarx;
48 using namespace MMM;
49 
50 void
52 {
53  // offeringTopic("DebugObserver");
54 }
55 
56 void
58 {
59  ARMARX_INFO << "ON CONNECT";
60  std::string armarxProjects = getProperty<std::string>("ArmarXProjects").getValue();
61 
62  if (!armarxProjects.empty())
63  {
64  std::vector<std::string> projects = armarx::Split(armarxProjects, ",;", true, true);
65 
66  for (std::string& p : projects)
67  {
68  // ARMARX_INFO << "Adding to datapaths of " << p;
70 
71  if (!finder.packageFound())
72  {
73  ARMARX_WARNING << "ArmarX Package " << p << " has not been found!";
74  }
75  else
76  {
77  ARMARX_INFO << "Adding " << p << " to datapaths: " << finder.getDataDir();
79  }
80  }
81  }
82 
83  std::string motionDefault = getProperty<std::string>("MMMFile").getValue();
84 
85  if (!motionDefault.empty())
86  {
87  load(motionDefault, "Armar4"); // TODO remove?!
88  }
89 
90  /*std::string modelDefault = getProperty<std::string>("ModelFile").getValue();
91  if (!modelDefault.empty())
92  {
93  modelPath = modelDefault; // TODO dieses Attribut ist sinnlos!
94  }*/
95 }
96 
97 void
98 MMMPlayer::load(const std::string& MMMFile, const std::string& projects)
99 {
100  std::unique_lock lock(mmmMutex);
101 
102  if (!projects.empty())
103  {
104  std::vector<std::string> proj = armarx::Split(projects, ",;", true, true);
105 
106  for (std::string& p : proj)
107  {
108  ARMARX_INFO << "Adding to datapaths of " << p;
109  armarx::CMakePackageFinder finder(p);
110 
111  if (!finder.packageFound())
112  {
113  ARMARX_WARNING << "ArmarX Package " << p << " has not been found!";
114  }
115  else
116  {
117  ARMARX_INFO << "Adding to datapaths: " << finder.getDataDir();
118  armarx::ArmarXDataPath::addDataPaths(finder.getDataDir());
119  }
120  }
121  }
122 
123  ArmarXDataPath::getAbsolutePath(MMMFile, motionPath);
124 
125  motionWrapper =
126  MotionFileWrapper::create(motionPath,
127  getProperty<bool>("ApplyButterworthFilter").getValue()
128  ? getProperty<float>("ButterworthFilterCutOffFreq")
129  : 0);
130  if (!motionWrapper)
131  {
132  terminate();
133  motionData = nullptr;
134  return;
135  }
136 
137  motionData = motionWrapper->getFirstMotionData();
138 }
139 
140 bool
141 MMMPlayer::loadMMMFile(const std::string& MMMFile, const std::string& projects, const Ice::Current&)
142 {
143  ARMARX_VERBOSE << "loaded trajectory " << MMMFile;
144  load(MMMFile, projects);
145  return motionData != nullptr;
146 }
147 
148 bool
149 MMMPlayer::setMotionData(const std::string& motionName, const Ice::Current&)
150 {
151  motionData = motionWrapper->getMotionData(motionName);
152  return motionData != nullptr;
153 }
154 
155 int
156 MMMPlayer::getNumberOfFrames(const Ice::Current&)
157 {
158  return (int)motionData->numberOfFrames;
159 }
160 
161 std::string
162 MMMPlayer::getMotionPath(const Ice::Current&)
163 {
164  return motionPath;
165 }
166 
167 std::string
168 MMMPlayer::getModelPath(const Ice::Current&)
169 {
170  return motionData->modelPath;
171 }
172 
173 Ice::StringSeq
174 MMMPlayer::getJointNames(const Ice::Current&)
175 {
176  return motionData->jointNames;
177 }
178 
179 Ice::StringSeq
180 MMMPlayer::getMotionNames(const Ice::Current&)
181 {
182  if (!motionWrapper)
183  {
184  return Ice::StringSeq();
185  }
186  return motionWrapper->getMotionNames();
187 }
188 
189 bool
190 MMMPlayer::isMotionLoaded(const Ice::Current&)
191 {
192  return motionData != nullptr;
193 }
194 
195 void
197 {
198 }
199 
200 void
202 {
203 }
204 
205 TrajectoryBasePtr
206 MMMPlayer::getJointTraj(const Ice::Current&)
207 {
208  return motionData->getJointTrajectory();
209 }
210 
211 TrajectoryBasePtr
212 MMMPlayer::getBasePoseTraj(const Ice::Current&)
213 {
214  return motionData->getPoseTrajectory();
215 }
216 
219 {
220  return PropertyDefinitionsPtr(new MMMPlayerPropertyDefinitions(getConfigIdentifier()));
221 }
armarx::MMMPlayer::onConnectComponent
void onConnectComponent() override
Definition: MMMPlayer.cpp:57
ARMARX_VERBOSE
#define ARMARX_VERBOSE
Definition: Logging.h:187
armarx::MMMPlayer::getNumberOfFrames
int getNumberOfFrames(const Ice::Current &) override
Definition: MMMPlayer.cpp:156
armarx::CMakePackageFinder::packageFound
bool packageFound() const
Returns whether or not this package was found with cmake.
Definition: CMakePackageFinder.cpp:511
armarx::MMMPlayer::loadMMMFile
bool loadMMMFile(const std::string &filename, const std::string &projects, const Ice::Current &) override
Definition: MMMPlayer.cpp:141
armarx::MMMPlayer::onDisconnectComponent
void onDisconnectComponent() override
Definition: MMMPlayer.cpp:196
armarx::MMMPlayer::setMotionData
bool setMotionData(const std::string &motionName, const Ice::Current &) override
Definition: MMMPlayer.cpp:149
armarx::Split
std::vector< std::string > Split(const std::string &source, const std::string &splitBy, bool trimElements=false, bool removeEmptyElements=false)
Definition: StringHelperTemplates.h:36
armarx::CMakePackageFinder
The CMakePackageFinder class provides an interface to the CMake Package finder capabilities.
Definition: CMakePackageFinder.h:52
armarx::MMMPlayer::createPropertyDefinitions
PropertyDefinitionsPtr createPropertyDefinitions() override
Definition: MMMPlayer.cpp:218
ButterworthFilter.h
armarx::MMMPlayer::onExitComponent
void onExitComponent() override
Definition: MMMPlayer.cpp:201
StringHelpers.h
armarx::MMMPlayer::getMotionNames
Ice::StringSeq getMotionNames(const Ice::Current &) override
Definition: MMMPlayer.cpp:180
armarx::MMMPlayer::onInitComponent
void onInitComponent() override
Definition: MMMPlayer.cpp:51
armarx::MMMPlayer::getBasePoseTraj
TrajectoryBasePtr getBasePoseTraj(const Ice::Current &) override
Definition: MMMPlayer.cpp:212
armarx::CMakePackageFinder::getDataDir
std::string getDataDir() const
Definition: CMakePackageFinder.h:194
boost::process::posix::terminate
void terminate(const Process &p)
Definition: terminate.hpp:22
armarx::MMMPlayer::getJointTraj
TrajectoryBasePtr getJointTraj(const Ice::Current &) override
Definition: MMMPlayer.cpp:206
armarx::MMMPlayer::getModelPath
std::string getModelPath(const Ice::Current &) override
Definition: MMMPlayer.cpp:168
ExpressionException.h
armarx::control::common::getValue
T getValue(nlohmann::json &userConfig, nlohmann::json &defaultConfig, const std::string &entryName)
Definition: utils.h:71
Trajectory.h
CMakePackageFinder.h
TimeUtil.h
ARMARX_INFO
#define ARMARX_INFO
Definition: Logging.h:181
armarx::ArmarXDataPath::addDataPaths
static void addDataPaths(const std::string &dataPathList)
Definition: ArmarXDataPath.cpp:554
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:109
ARMARX_WARNING
#define ARMARX_WARNING
Definition: Logging.h:193
armarx::PropertyDefinitionsPtr
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
Definition: forward_declarations.h:35
ArmarXDataPath.h
armarx::MMMPlayer::getJointNames
Ice::StringSeq getJointNames(const Ice::Current &) override
Definition: MMMPlayer.cpp:174
Variant.h
armarx::MMMPlayer::isMotionLoaded
bool isMotionLoaded(const Ice::Current &) override
Definition: MMMPlayer.cpp:190
armarx::armem::server::ltm::mongodb::util::load
void load(const mongocxx::database &db, armem::wm::Memory &m)
Definition: operations.cpp:48
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:27
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:50
armarx::MMMPlayer::getMotionPath
std::string getMotionPath(const Ice::Current &) override
Definition: MMMPlayer.cpp:162