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
47using namespace armarx;
48using namespace MMM;
49
50void
52{
53 // offeringTopic("DebugObserver");
54}
55
56void
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
97void
98MMMPlayer::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;
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
140bool
141MMMPlayer::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
148bool
149MMMPlayer::setMotionData(const std::string& motionName, const Ice::Current&)
150{
151 motionData = motionWrapper->getMotionData(motionName);
152 return motionData != nullptr;
153}
154
155int
157{
158 return (int)motionData->numberOfFrames;
159}
160
161std::string
162MMMPlayer::getMotionPath(const Ice::Current&)
163{
164 return motionPath;
165}
166
167std::string
168MMMPlayer::getModelPath(const Ice::Current&)
169{
170 return motionData->modelPath;
171}
172
173Ice::StringSeq
174MMMPlayer::getJointNames(const Ice::Current&)
175{
176 return motionData->jointNames;
177}
178
179Ice::StringSeq
180MMMPlayer::getMotionNames(const Ice::Current&)
181{
182 if (!motionWrapper)
183 {
184 return Ice::StringSeq();
185 }
186 return motionWrapper->getMotionNames();
187}
188
189bool
190MMMPlayer::isMotionLoaded(const Ice::Current&)
191{
192 return motionData != nullptr;
193}
194
195void
199
200void
204
205TrajectoryBasePtr
206MMMPlayer::getJointTraj(const Ice::Current&)
207{
208 return motionData->getJointTrajectory();
209}
210
211TrajectoryBasePtr
212MMMPlayer::getBasePoseTraj(const Ice::Current&)
213{
214 return motionData->getPoseTrajectory();
215}
216
static bool getAbsolutePath(const std::string &relativeFilename, std::string &storeAbsoluteFilename, const std::vector< std::string > &additionalSearchPaths={}, bool verbose=true)
static void addDataPaths(const std::string &dataPathList)
The CMakePackageFinder class provides an interface to the CMake Package finder capabilities.
bool packageFound() const
Returns whether or not this package was found with cmake.
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Definition Component.cpp:90
Property< PropertyType > getProperty(const std::string &name)
void onInitComponent() override
Definition MMMPlayer.cpp:51
std::string getMotionPath(const Ice::Current &) override
void onDisconnectComponent() override
bool isMotionLoaded(const Ice::Current &) override
Ice::StringSeq getMotionNames(const Ice::Current &) override
bool loadMMMFile(const std::string &filename, const std::string &projects, const Ice::Current &) override
std::string getModelPath(const Ice::Current &) override
int getNumberOfFrames(const Ice::Current &) override
void onConnectComponent() override
Definition MMMPlayer.cpp:57
PropertyDefinitionsPtr createPropertyDefinitions() override
Ice::StringSeq getJointNames(const Ice::Current &) override
TrajectoryBasePtr getJointTraj(const Ice::Current &) override
bool setMotionData(const std::string &motionName, const Ice::Current &) override
void onExitComponent() override
TrajectoryBasePtr getBasePoseTraj(const Ice::Current &) override
void terminate()
Initiates termination of this IceManagedObject.
static MotionFileWrapperPtr create(const std::string &motionFilePath, double butterworthFilterCutOffFreq=0.0, const std::string relativeModelRoot="mmm")
Property< PropertyType > getProperty(const std::string &name)
Property creation and retrieval.
#define ARMARX_INFO
The normal logging level.
Definition Logging.h:181
#define ARMARX_WARNING
The logging level for unexpected behaviour, but not a serious problem.
Definition Logging.h:193
#define ARMARX_VERBOSE
The logging level for verbose information.
Definition Logging.h:187
T getValue(nlohmann::json &userConfig, nlohmann::json &defaultConfig, const std::string &entryName)
Definition utils.h:80
This file offers overloads of toIce() and fromIce() functions for STL container types.
std::vector< std::string > Split(const std::string &source, const std::string &splitBy, bool trimElements=false, bool removeEmptyElements=false)
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.