MMMPlayer.h
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 #pragma once
26 
27 #include <mutex>
28 
30 
33 
34 #include <RobotComponents/interface/components/MMMPlayerInterface.h>
35 
36 namespace armarx
37 {
38  class MotionFileWrapper;
39  class MotionData;
40 
41  /**
42  * \class MMMPlayerPropertyDefinitions
43  * \brief
44  */
46  {
47  public:
49  {
50  defineOptionalProperty<std::string>(
51  "ArmarXProjects",
52  "",
53  "Comma-separated list with names of ArmarXProjects (e.g. 'Armar3,Armar4'). The MMM "
54  "XML File can be specified relatively to a data path of one of these projects.");
55  //defineOptionalProperty<std::string>("MMMFile", "", "Path to MMM XML File");
56  defineOptionalProperty<bool>(
57  "ApplyButterworthFilter",
58  false,
59  "If true a butterworth filter is applied on the trajectory.");
60  defineOptionalProperty<float>("ButterworthFilterCutOffFreq",
61  20,
62  "Cut off frequency for the butterworth lowpass filter.");
63  }
64  };
65 
66  /**
67  * \defgroup Component-MMMPlayer MMMPlayer
68  * \ingroup RobotComponents-Components
69  * \brief Replays an MMM trajectory from a file.
70  *
71  * MMMPlayer reads an MMM trajectory from an MMM XML file (component property) and replays the motion using the KinematicUnit and its currently loaded robot.
72  * The trajectory can be replayed using position control or velocity control.
73  * In the latter case, the control parameters (P, I, D) can be configured via component properties.
74  */
75 
76  /**
77  * @ingroup Component-MMMPlayer
78  * @brief The MMMPlayer class
79  */
80  class MMMPlayer : virtual public armarx::Component, public armarx::MMMPlayerInterface
81  {
82  public:
83  /**
84  * @see armarx::ManagedIceObject::getDefaultName()
85  */
86  std::string
87  getDefaultName() const override
88  {
89  return "MMMPlayer";
90  }
91 
92  protected:
93  /**
94  * @see armarx::ManagedIceObject::onInitComponent()
95  */
96  void onInitComponent() override;
97 
98  /**
99  * @see armarx::ManagedIceObject::onConnectComponent()
100  */
101  void onConnectComponent() override;
102 
103  /**
104  * @see armarx::ManagedIceObject::onDisconnectComponent()
105  */
106  void onDisconnectComponent() override;
107 
108  /**
109  * @see armarx::ManagedIceObject::onExitComponent()
110  */
111  void onExitComponent() override;
112 
113  /**
114  * @see PropertyUser::createPropertyDefinitions()
115  */
117 
118  private:
119  void load(const std::string& filename, const std::string& projects);
120 
121  std::shared_ptr<MotionFileWrapper> motionWrapper;
122  std::shared_ptr<MotionData> motionData;
123  std::string motionPath;
124 
125  std::recursive_mutex mmmMutex;
126 
127  public:
128  // MMMPlayerInterface
129  bool loadMMMFile(const std::string& filename,
130  const std::string& projects,
131  const Ice::Current&) override;
132  bool setMotionData(const std::string& motionName, const Ice::Current&) override;
133  int getNumberOfFrames(const Ice::Current&) override;
134  std::string getMotionPath(const Ice::Current&) override;
135  std::string getModelPath(const Ice::Current&) override;
136  Ice::StringSeq getJointNames(const Ice::Current&) override;
137  Ice::StringSeq getMotionNames(const Ice::Current&) override;
138  bool isMotionLoaded(const Ice::Current&) override;
139 
140  TrajectoryBasePtr getJointTraj(const Ice::Current&) override;
141  TrajectoryBasePtr getBasePoseTraj(const Ice::Current&) override;
142  };
143 
145 
146 } // namespace armarx
armarx::MMMPlayer::onConnectComponent
void onConnectComponent() override
Definition: MMMPlayer.cpp:57
armarx::MMMPlayer::getNumberOfFrames
int getNumberOfFrames(const Ice::Current &) override
Definition: MMMPlayer.cpp:156
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
Pose.h
armarx::PropertyDefinitionContainer::prefix
std::string prefix
Prefix of the properties such as namespace, domain, component name, etc.
Definition: PropertyDefinitionContainer.h:345
armarx::MMMPlayer::createPropertyDefinitions
PropertyDefinitionsPtr createPropertyDefinitions() override
Definition: MMMPlayer.cpp:218
armarx::MMMPlayer::onExitComponent
void onExitComponent() override
Definition: MMMPlayer.cpp:201
armarx::MMMPlayer
The MMMPlayer class.
Definition: MMMPlayer.h:80
IceInternal::Handle
Definition: forward_declarations.h:8
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::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
filename
std::string filename
Definition: VisualizationRobot.cpp:86
Component.h
armarx::Component
Baseclass for all ArmarX ManagedIceObjects requiring properties.
Definition: Component.h:91
armarx::MMMPlayer::getDefaultName
std::string getDefaultName() const override
Definition: MMMPlayer.h:87
Trajectory.h
armarx::ComponentPropertyDefinitions
Default component property definition container.
Definition: Component.h:69
IceUtil::Handle
Definition: forward_declarations.h:30
armarx::MMMPlayerPropertyDefinitions::MMMPlayerPropertyDefinitions
MMMPlayerPropertyDefinitions(std::string prefix)
Definition: MMMPlayer.h:48
armarx::MMMPlayer::getJointNames
Ice::StringSeq getJointNames(const Ice::Current &) override
Definition: MMMPlayer.cpp:174
armarx::MMMPlayer::isMotionLoaded
bool isMotionLoaded(const Ice::Current &) override
Definition: MMMPlayer.cpp:190
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::MMMPlayer::getMotionPath
std::string getMotionPath(const Ice::Current &) override
Definition: MMMPlayer.cpp:162