NimbRo ROS Soccer Package
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
motionfile.h
1 //Library to manage motion files
2 //Author: Sebastian Schüller <schuell1@cs.uni-bonn.de>, Hafez Farazi <farazi@ais.uni-bonn.de>, Dmytro Pavlichenko <dm.mark999@gmail.com>
3 
4 #ifndef MOTIONFILE_H
5 #define MOTIONFILE_H
6 
7 #include <map>
8 #include <vector>
9 #include <string>
10 #include <yaml-cpp/yaml.h>
11 #include <boost/shared_ptr.hpp>
12 #include <boost/make_shared.hpp>
13 #include <ros/common.h>
14 
15 #include "keyframe_player/Keyframe.h"
16 #include <motion_file/ruleapplier.h>
17 
18 namespace motionfile
19 {
20 
21 struct FrameJoint
22 {
23  FrameJoint();
24 
25  double position;
26  double velocity;
27  double effort;
28  double pGain; double iGain; double dGain;
29  double limit;
30  kf_player::gainSelectEnum gainSelect;
31 };
32 
33 struct Keyframe
34 {
35  int id;
36  std::string name;
37  std::vector<FrameJoint> joints;
38  double duration;
39  double roll; double pitch;double yaw;
40  std::string support;
41 };
42 
43 struct RulePart
44 {
45  std::string type;
46  std::string frameName;
47  std::string jointName;
48  double scale;
49 };
50 
51 struct Rule
52 {
53  std::string name;
54  std::vector<RulePart> parts;
55 };
56 
57 class Motion
58 {
59 public:
60  Motion();
61  ~Motion(){};
62 
63  Motion(const Motion& _in) :
64  motionName(_in.motionName) ,
65  preState(_in.preState) ,
66  playState(_in.playState) ,
67  postState(_in.postState) ,
68  pidEnabled(_in.pidEnabled) ,
69  jointList(_in.jointList) ,
70  filePath(_in.filePath)
71  {
72  frames.clear();
73  for(size_t i=0;i<_in.frames.size();i++)
74  {
75  frames.push_back(boost::make_shared<Keyframe>(*_in.frames[i]));
76  }
77 
78  rules.clear();
79  for(size_t i=0;i<_in.rules.size();i++)
80  {
81  rules.push_back(Rule());
82  rules.back().name = _in.rules[i].name;
83 
84  for(size_t j = 0; j < _in.rules[i].parts.size(); j++)
85  rules[i].parts.push_back((_in.rules[i].parts[j]));
86  }
87 
88  } // copy ctor
89 
90  Motion& operator=(Motion _in)
91  {
92  if (this != &_in)
93  {
94  motionName=(_in.motionName);
95  preState=(_in.preState);
96  playState=(_in.playState);
97  postState=(_in.postState);
98  pidEnabled=(_in.pidEnabled);
99  jointList=(_in.jointList);
100  filePath=(_in.filePath);
101 
102  frames.clear();
103  for(size_t i=0;i<_in.frames.size();i++)
104  {
105  frames.push_back(boost::make_shared<Keyframe>(*_in.frames[i]));
106  }
107 
108  rules.clear();
109  for(size_t i=0;i<_in.rules.size();i++)
110  {
111  rules.push_back(Rule());
112  rules.back().name = _in.rules[i].name;
113 
114  for(size_t j = 0; j < _in.rules[i].parts.size(); j++)
115  rules[i].parts.push_back((_in.rules[i].parts[j]));
116  }
117  }
118  return *this;
119  }
120 
121  bool load(std::string name);
122  bool parse(std::string motion);
123  bool save(std::string name);
124  std::string dump();
125 
126  int findFrame(const std::string name);
127  int findJoint(const std::string name);
128 
129  bool isRuleValid(int index);
130  bool canApplyRule(int index, double delta, bool limit_inverse, double epsilon);
131  bool applyRule(int index, double delta, bool limit_inverse, double epsilon);
132 
133  static int nameToIndex(const std::vector<std::string>& jointList, const std::string& name);
134 
135  // Returns true if motions are exactly the same
136  static bool isIdentical(motionfile::Motion& motion_1, motionfile::Motion& motion_2);
137 
138  // Provides detailed output about each not equal variable
139  static void detailedComparison(motionfile::Motion& motion_1, motionfile::Motion& motion_2);
140 
141  typedef boost::shared_ptr<Keyframe> KeyframePtr;
142 
143 //header
144  std::string motionName;
145  std::string preState;
146  std::string playState;
147  std::string postState;
148  bool pidEnabled;
149 
150  std::vector<std::string> jointList;
151  std::vector<Rule> rules;
152 
153  std::string filePath; // Path to file from which the motion was loaded
154 
155 //keyframes
156  std::vector<KeyframePtr> frames;
157 
158 private:
159  void nodeToMotion(const YAML::Node& node);
160  void parseRule(const YAML::Node& node);
161  void motionToNode(YAML::Emitter& em);
162 
163  motionfile::RuleApplier ruleApplier;
164 };
165 
166 
167 
168 }
169 
170 #endif
const std::string jointName[NUM_JOINTS]
List of names of the joints that are required by the gait motion module (indexed by the JointID enum)...
Definition: gait_common.h:57