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
41  {
42  double factor = value / scaling;
43  for (auto& data : poseTrajData)
44  {
45  data.second[0] *= factor;
46  data.second[1] *= factor;
47  data.second[2] *= factor;
48  }
49  scaling = value;
50  }
51 
52  ::Ice::StringSeq jointNames;
53  DoubleSeqSeqSeq jointTrajData;
54  ::Ice::DoubleSeq timestamp;
55  std::map<double, Ice::DoubleSeq> poseTrajData;
56 
57  TrajectoryBasePtr
59  {
60  return TrajectoryBasePtr(new Trajectory(poseTrajData));
61  }
62 
63  TrajectoryBasePtr
65  {
66  return TrajectoryBasePtr(new Trajectory(jointTrajData, timestamp, jointNames));
67  }
68 
69  std::string modelPath;
70  unsigned int numberOfFrames;
71  float scaling;
72  };
73 
74  typedef std::shared_ptr<MotionData> MotionDataPtr;
75 
77 
78  typedef std::shared_ptr<MotionFileWrapper> MotionFileWrapperPtr;
79 
81  {
82  public:
83  static MotionFileWrapperPtr create(const std::string& motionFilePath,
84  double butterworthFilterCutOffFreq = 0.0,
85  const std::string relativeModelRoot = "mmm");
86 
88  MotionDataPtr getMotionDataByModel(const std::string& modelName);
89  MotionDataPtr getMotionData(const std::string& motionName);
90 
91  ::Ice::StringSeq getModelNames();
92  ::Ice::StringSeq getMotionNames();
93 
94  private:
95  MotionFileWrapper(int butterworthFilterCutOffFreq = 0);
96 
97  bool loadMotion(const std::string& motionFilePath,
98  const std::string relativeModelRoot = "mmm");
99  bool loadLegacyMotion(const std::string& motionFilePath,
100  const std::string relativeModelRoot = "mmm");
101 
102  ::Ice::DoubleSeq getTrajData(const Eigen::Matrix4f& rootPose);
103  DoubleSeqSeq getTrajData(const Eigen::VectorXf& jointAngles);
104 
105  std::map<std::string, MotionDataPtr> motionData;
106  std::vector<std::string> motionNames;
107  double butterworthFilterCutOffFreq;
108  };
109 } // namespace armarx
110 
111 #endif // _ARMARX_COMPONENT_RobotComponents_MotionFileWrapper_H
armarx::MotionFileWrapperPtr
std::shared_ptr< MotionFileWrapper > MotionFileWrapperPtr
Definition: MotionFileWrapper.h:76
armarx::MotionData::numberOfFrames
unsigned int numberOfFrames
Definition: MotionFileWrapper.h:70
GfxTL::Matrix4f
MatrixXX< 4, 4, float > Matrix4f
Definition: MatrixXX.h:650
armarx::MotionData::scaling
float scaling
Definition: MotionFileWrapper.h:71
armarx::MotionData::modelPath
std::string modelPath
Definition: MotionFileWrapper.h:69
armarx::MotionData::jointTrajData
DoubleSeqSeqSeq jointTrajData
Definition: MotionFileWrapper.h:53
armarx::MotionFileWrapper::getMotionDataByModel
MotionDataPtr getMotionDataByModel(const std::string &modelName)
Definition: MotionFileWrapper.cpp:389
cxxopts::value
std::shared_ptr< Value > value()
Definition: cxxopts.hpp:855
armarx::MotionData::getPoseTrajectory
TrajectoryBasePtr getPoseTrajectory()
Definition: MotionFileWrapper.h:58
armarx::MotionDataPtr
std::shared_ptr< MotionData > MotionDataPtr
Definition: MotionFileWrapper.h:74
data
uint8_t data[1]
Definition: EtherCATFrame.h:68
armarx::MotionFileWrapper::getMotionData
MotionDataPtr getMotionData(const std::string &motionName)
Definition: MotionFileWrapper.cpp:402
armarx::MotionFileWrapper
Definition: MotionFileWrapper.h:80
armarx::VariantType::Trajectory
const VariantTypeId Trajectory
Definition: Trajectory.h:44
armarx::MotionData::timestamp
::Ice::DoubleSeq timestamp
Definition: MotionFileWrapper.h:54
armarx::channels::KinematicUnitObserver::jointAngles
const KinematicUnitDatafieldCreator jointAngles("jointAngles")
Trajectory.h
armarx::MotionData::poseTrajData
std::map< double, Ice::DoubleSeq > poseTrajData
Definition: MotionFileWrapper.h:55
armarx::MotionFileWrapper::getFirstMotionData
MotionDataPtr getFirstMotionData()
Definition: MotionFileWrapper.cpp:376
armarx::MotionData::setScaling
void setScaling(float value)
Definition: MotionFileWrapper.h:40
armarx::MotionData::MotionData
MotionData()
Definition: MotionFileWrapper.h:35
armarx::MotionFileWrapper::getModelNames
::Ice::StringSeq getModelNames()
Definition: MotionFileWrapper.cpp:408
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:27
armarx::MotionFileWrapper::getMotionNames
::Ice::StringSeq getMotionNames()
Definition: MotionFileWrapper.cpp:419
armarx::MotionData::jointNames
::Ice::StringSeq jointNames
Definition: MotionFileWrapper.h:52
armarx::MotionFileWrapper::create
static MotionFileWrapperPtr create(const std::string &motionFilePath, double butterworthFilterCutOffFreq=0.0, const std::string relativeModelRoot="mmm")
Definition: MotionFileWrapper.cpp:50
armarx::MotionData::getJointTrajectory
TrajectoryBasePtr getJointTrajectory()
Definition: MotionFileWrapper.h:64
armarx::MotionData
Definition: MotionFileWrapper.h:32