trajectory.hh
Go to the documentation of this file.
1 /*
2  * Copyright 2013,
3  * Olivier Stasse,
4  *
5  * CNRS
6  *
7  */
8 
9 #ifndef SOT_TRAJECTORY_H__
10 #define SOT_TRAJECTORY_H__
11 
12 // Matrix
15 
16 #include <boost/array.hpp>
17 #include <boost/assign/list_of.hpp>
18 #include <boost/regex.hpp>
19 #include <sot/core/api.hh>
20 
21 namespace dg = dynamicgraph;
22 namespace ba = boost::assign;
23 
24 namespace dynamicgraph {
25 namespace sot {
26 
27 class Trajectory;
28 
30  protected:
32 
33  public:
34  unsigned int dbg_level;
35 
44  std::vector<std::string> joint_names;
45 
48  RulesJointTrajectory(Trajectory &TrajectoryToFill);
49 
51  void parse_string(std::string &atext);
52 
53  protected:
57  std::string &text,
58  boost::match_results<std::string::const_iterator> &what, boost::regex &e,
59  std::string &sub_text);
65  void parse_header(std::string &text, std::string &sub_text1);
66 
69  void parse_joint_names(std::string &text, std::string &sub_text1,
70  std::vector<std::string> &joint_names);
71 
74  bool parse_seq(std::string &text, std::string &sub_text1,
75  std::vector<double> &seq);
76 
78  bool parse_point(std::string &trajectory, std::string &sub_text1);
79 
81  bool parse_points(std::string &trajectory, std::string &sub_text1);
82 };
83 
85  public:
86  unsigned long int secs_;
87  unsigned long int nsecs_;
88  timestamp() : secs_(0), nsecs_(0) {}
89  timestamp(const timestamp &ats) {
90  secs_ = ats.secs_;
91  nsecs_ = ats.nsecs_;
92  }
93  timestamp(unsigned long int lsecs, unsigned long int lnsecs) {
94  secs_ = lsecs;
95  nsecs_ = lnsecs;
96  }
97  bool operator==(const timestamp &other) const {
98  if ((secs_ != other.secs_) || (nsecs_ != other.nsecs_)) return false;
99  return true;
100  }
101  friend std::ostream &operator<<(std::ostream &stream, const timestamp &ats) {
102  stream << ats.secs_ + 0.000001 * (long double)ats.nsecs_;
103  return stream;
104  }
105 };
106 
108  public:
109  unsigned int seq_;
111  std::string frame_id_;
112  Header() : seq_(0), stamp_(0, 0), frame_id_("initial_trajectory") {}
113 };
114 
116  public:
117  std::vector<double> positions_;
118  std::vector<double> velocities_;
119  std::vector<double> accelerations_;
120  std::vector<double> efforts_;
121 
122  typedef std::vector<double> vec_ref;
123 
124  void display(std::ostream &os) const {
125  boost::array<std::string, 4> names = boost::assign::list_of("Positions")(
126  "Velocities")("Accelerations")("Effort");
127 
128  const std::vector<double> *points = 0;
129 
130  for (std::size_t arrayId = 0; arrayId < names.size(); ++arrayId) {
131  switch (arrayId) {
132  case (0):
133  points = &positions_;
134  break;
135  case (1):
136  points = &velocities_;
137  break;
138  case (2):
139  points = &accelerations_;
140  break;
141  case (3):
142  points = &efforts_;
143  break;
144  default:
145  assert(0);
146  }
147 
148  std::vector<double>::const_iterator it_db;
149  os << names[arrayId] << std::endl << "---------" << std::endl;
150  for (it_db = points->begin(); it_db != points->end(); it_db++) {
151  os << *it_db << std::endl;
152  }
153  }
154  }
155 
156  void transfer(const std::vector<double> &src, unsigned int vecId) {
157  switch (vecId) {
158  case (0):
159  positions_ = src;
160  break;
161  case (1):
162  velocities_ = src;
163  break;
164  case (2):
165  accelerations_ = src;
166  break;
167  case (3):
168  efforts_ = src;
169  break;
170  default:
171  assert(0);
172  }
173  }
174 };
175 
177  public:
178  Trajectory();
179  Trajectory(const Trajectory &copy);
180  virtual ~Trajectory();
181 
182  std::vector<std::string> joint_names_;
183 
186 
187  std::vector<JointTrajectoryPoint> points_;
188 
189  int deserialize(std::istringstream &is);
190  void display(std::ostream &) const;
191 };
192 } // namespace sot
193 
194 template <>
195 struct signal_io<sot::Trajectory> : signal_io_unimplemented<sot::Trajectory> {};
196 
197 } // namespace dynamicgraph
198 
199 #endif /* #ifndef SOT_TRAJECTORY_H__ */
ReturnMatrix copy(const Eigen::MatrixBase< Matrix > &mat)
std::vector< std::string > joint_names
Definition: trajectory.hh:44
bool parse_points(std::string &trajectory, std::string &sub_text1)
Extract a sequence of points.
Definition: trajectory.cpp:233
friend std::ostream & operator<<(std::ostream &stream, const timestamp &ats)
Definition: trajectory.hh:101
std::vector< std::string > joint_names_
Definition: trajectory.hh:182
void parse_string(std::string &atext)
parse_string will fill TrajectoryToFill with string atext.
Definition: trajectory.cpp:268
#define SOT_CORE_EXPORT
Definition: api.hh:20
std::string float_str_re
Strings specifying the grammar of the structure.
Definition: trajectory.hh:37
boost::regex header_re
Boost regular expressions implementing the grammar.
Definition: trajectory.hh:42
bool search_exp_sub_string(std::string &text, boost::match_results< std::string::const_iterator > &what, boost::regex &e, std::string &sub_text)
General parsing method of text with regexp e. The results are given in what. The remaining text is le...
Definition: trajectory.cpp:67
timestamp(const timestamp &ats)
Definition: trajectory.hh:89
std::vector< JointTrajectoryPoint > points_
Definition: trajectory.hh:187
timestamp(unsigned long int lsecs, unsigned long int lnsecs)
Definition: trajectory.hh:93
void transfer(const std::vector< double > &src, unsigned int vecId)
Definition: trajectory.hh:156
bool parse_point(std::string &trajectory, std::string &sub_text1)
Extract a point description.
Definition: trajectory.cpp:196
unsigned long int secs_
Definition: trajectory.hh:86
void parse_header(std::string &text, std::string &sub_text1)
Find and store the header. This method is looking for: unsigned int seq. unsigned int sec...
Definition: trajectory.cpp:99
bool operator==(const timestamp &other) const
Definition: trajectory.hh:97
RulesJointTrajectory(Trajectory &TrajectoryToFill)
Constructor TrajectoryToFill is the structure where to store the parsed information.
Definition: trajectory.cpp:32
void parse_joint_names(std::string &text, std::string &sub_text1, std::vector< std::string > &joint_names)
Understand joint_names. Extract a list of strings.
Definition: trajectory.cpp:126
bool parse_seq(std::string &text, std::string &sub_text1, std::vector< double > &seq)
Extract a sequence of doubles. To be used for position, velocities, accelerations and effort...
Definition: trajectory.cpp:154
std::vector< double > accelerations_
Definition: trajectory.hh:119
unsigned long int nsecs_
Definition: trajectory.hh:87
Vec3f * points
void display(std::ostream &os) const
Definition: trajectory.hh:124


sot-core
Author(s): Olivier Stasse, ostasse@laas.fr
autogenerated on Wed Jun 21 2023 02:51:26