MotionFileWrapper.h
Go to the documentation of this file.
1 /*
2  * This file is part of ArmarX.
3  *
4  * Copyright (C) 2020, 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::Libraries::MMM
19  * @author Andre Meixner
20  * @date 2020
21  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22  * GNU General Public License
23  */
24 
26 
27 #ifndef _ARMARX_COMPONENT_RobotComponents_MotionFileWrapper_H
28 #define _ARMARX_COMPONENT_RobotComponents_MotionFileWrapper_H
29 
30 namespace armarx
31 {
32  class MotionData
33  {
34  public:
36  {
37  }
38 
39  void setScaling(float value)
40  {
41  double factor = value / scaling;
42  for (auto& data : poseTrajData)
43  {
44  data.second[0] *= factor;
45  data.second[1] *= factor;
46  data.second[2] *= factor;
47  }
48  scaling = value;
49  }
50 
51  ::Ice::StringSeq jointNames;
52  DoubleSeqSeqSeq jointTrajData;
53  ::Ice::DoubleSeq timestamp;
54  std::map<double, Ice::DoubleSeq> poseTrajData;
55 
56  TrajectoryBasePtr getPoseTrajectory()
57  {
58  return TrajectoryBasePtr(new Trajectory(poseTrajData));
59  }
60 
61  TrajectoryBasePtr getJointTrajectory()
62  {
63  return TrajectoryBasePtr(new Trajectory(jointTrajData, timestamp, jointNames));
64  }
65 
66  std::string modelPath;
67  unsigned int numberOfFrames;
68  float scaling;
69  };
70 
71  typedef std::shared_ptr<MotionData> MotionDataPtr;
72 
74 
75  typedef std::shared_ptr<MotionFileWrapper> MotionFileWrapperPtr;
76 
78  {
79  public:
80  static MotionFileWrapperPtr create(const std::string& motionFilePath, double butterworthFilterCutOffFreq = 0.0, const std::string relativeModelRoot = "mmm");
81 
83  MotionDataPtr getMotionDataByModel(const std::string& modelName);
84  MotionDataPtr getMotionData(const std::string& motionName);
85 
86  ::Ice::StringSeq getModelNames();
87  ::Ice::StringSeq getMotionNames();
88 
89  private:
90  MotionFileWrapper(int butterworthFilterCutOffFreq = 0);
91 
92  bool loadMotion(const std::string& motionFilePath, const std::string relativeModelRoot = "mmm");
93  bool loadLegacyMotion(const std::string& motionFilePath, const std::string relativeModelRoot = "mmm");
94 
95  ::Ice::DoubleSeq getTrajData(const Eigen::Matrix4f& rootPose);
96  DoubleSeqSeq getTrajData(const Eigen::VectorXf& jointAngles);
97 
98  std::map<std::string, MotionDataPtr> motionData;
99  std::vector<std::string> motionNames;
100  double butterworthFilterCutOffFreq;
101  };
102 }
103 
104 #endif // _ARMARX_COMPONENT_RobotComponents_MotionFileWrapper_H
armarx::MotionFileWrapperPtr
std::shared_ptr< MotionFileWrapper > MotionFileWrapperPtr
Definition: MotionFileWrapper.h:73
armarx::MotionData::numberOfFrames
unsigned int numberOfFrames
Definition: MotionFileWrapper.h:67
armarx::MotionData::scaling
float scaling
Definition: MotionFileWrapper.h:68
armarx::MotionData::modelPath
std::string modelPath
Definition: MotionFileWrapper.h:66
armarx::MotionData::jointTrajData
DoubleSeqSeqSeq jointTrajData
Definition: MotionFileWrapper.h:52
armarx::MotionFileWrapper::getMotionDataByModel
MotionDataPtr getMotionDataByModel(const std::string &modelName)
Definition: MotionFileWrapper.cpp:358
cxxopts::value
std::shared_ptr< Value > value()
Definition: cxxopts.hpp:926
armarx::MotionData::getPoseTrajectory
TrajectoryBasePtr getPoseTrajectory()
Definition: MotionFileWrapper.h:56
armarx::MotionDataPtr
std::shared_ptr< MotionData > MotionDataPtr
Definition: MotionFileWrapper.h:71
data
uint8_t data[1]
Definition: EtherCATFrame.h:68
armarx::MotionFileWrapper::getMotionData
MotionDataPtr getMotionData(const std::string &motionName)
Definition: MotionFileWrapper.cpp:370
armarx::MotionFileWrapper
Definition: MotionFileWrapper.h:77
armarx::VariantType::Trajectory
const VariantTypeId Trajectory
Definition: Trajectory.h:44
armarx::MotionData::timestamp
::Ice::DoubleSeq timestamp
Definition: MotionFileWrapper.h:53
armarx::channels::KinematicUnitObserver::jointAngles
const KinematicUnitDatafieldCreator jointAngles("jointAngles")
Trajectory.h
GfxTL::Matrix4f
MatrixXX< 4, 4, float > Matrix4f
Definition: MatrixXX.h:601
armarx::MotionData::poseTrajData
std::map< double, Ice::DoubleSeq > poseTrajData
Definition: MotionFileWrapper.h:54
armarx::MotionFileWrapper::getFirstMotionData
MotionDataPtr getFirstMotionData()
Definition: MotionFileWrapper.cpp:345
armarx::MotionData::setScaling
void setScaling(float value)
Definition: MotionFileWrapper.h:39
armarx::MotionData::MotionData
MotionData()
Definition: MotionFileWrapper.h:35
armarx::MotionFileWrapper::getModelNames
::Ice::StringSeq getModelNames()
Definition: MotionFileWrapper.cpp:375
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
armarx::MotionFileWrapper::getMotionNames
::Ice::StringSeq getMotionNames()
Definition: MotionFileWrapper.cpp:385
armarx::MotionData::jointNames
::Ice::StringSeq jointNames
Definition: MotionFileWrapper.h:51
armarx::MotionFileWrapper::create
static MotionFileWrapperPtr create(const std::string &motionFilePath, double butterworthFilterCutOffFreq=0.0, const std::string relativeModelRoot="mmm")
Definition: MotionFileWrapper.cpp:49
armarx::MotionData::getJointTrajectory
TrajectoryBasePtr getJointTrajectory()
Definition: MotionFileWrapper.h:61
armarx::MotionData
Definition: MotionFileWrapper.h:32