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