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  std::size_t 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  timestamp &operator=(const timestamp &other) {
102  secs_ = other.secs_;
103  nsecs_ = other.nsecs_;
104  return *this;
105  }
106  friend std::ostream &operator<<(std::ostream &stream, const timestamp &ats) {
107  stream << ats.secs_ + 0.000001 * (long double)ats.nsecs_;
108  return stream;
109  }
110 };
111 
113  public:
114  std::size_t seq_;
116  std::string frame_id_;
117  Header() : seq_(0), stamp_(0, 0), frame_id_("initial_trajectory") {}
118 };
119 
121  public:
122  std::vector<double> positions_;
123  std::vector<double> velocities_;
124  std::vector<double> accelerations_;
125  std::vector<double> efforts_;
126 
127  typedef std::vector<double> vec_ref;
128 
129  void display(std::ostream &os) const {
130  boost::array<std::string, 4> names = boost::assign::list_of("Positions")(
131  "Velocities")("Accelerations")("Effort");
132 
133  const std::vector<double> *points = 0;
134 
135  for (std::size_t arrayId = 0; arrayId < names.size(); ++arrayId) {
136  switch (arrayId) {
137  case (0):
138  points = &positions_;
139  break;
140  case (1):
141  points = &velocities_;
142  break;
143  case (2):
144  points = &accelerations_;
145  break;
146  case (3):
147  points = &efforts_;
148  break;
149  default:
150  assert(0);
151  }
152 
153  std::vector<double>::const_iterator it_db;
154  os << names[arrayId] << std::endl << "---------" << std::endl;
155  for (it_db = points->begin(); it_db != points->end(); it_db++) {
156  os << *it_db << std::endl;
157  }
158  }
159  }
160 
161  void transfer(const std::vector<double> &src, std::size_t vecId) {
162  switch (vecId) {
163  case (0):
164  positions_ = src;
165  break;
166  case (1):
167  velocities_ = src;
168  break;
169  case (2):
170  accelerations_ = src;
171  break;
172  case (3):
173  efforts_ = src;
174  break;
175  default:
176  assert(0);
177  }
178  }
179 };
180 
182  public:
183  Trajectory();
184  Trajectory(const Trajectory &copy);
185  virtual ~Trajectory();
186 
187  std::vector<std::string> joint_names_;
188 
191 
192  std::vector<JointTrajectoryPoint> points_;
193 
194  size_type deserialize(std::istringstream &is);
195  void display(std::ostream &) const;
196 };
197 } // namespace sot
198 
199 template <>
200 struct signal_io<sot::Trajectory> : signal_io_unimplemented<sot::Trajectory> {};
201 
202 } // namespace dynamicgraph
203 
204 #endif /* #ifndef SOT_TRAJECTORY_H__ */
dynamicgraph::sot::RulesJointTrajectory::seq_str_re
std::string seq_str_re
Definition: trajectory.hh:37
dynamicgraph::sot::Header::Header
Header()
Definition: trajectory.hh:117
dynamicgraph::sot::RulesJointTrajectory::parse_header
void parse_header(std::string &text, std::string &sub_text1)
Find and store the header. This method is looking for: std::size_t seq. std::size_t sec,...
Definition: trajectory.cpp:99
dynamicgraph::sot::RulesJointTrajectory
Definition: trajectory.hh:29
dynamicgraph::sot::JointTrajectoryPoint::accelerations_
std::vector< double > accelerations_
Definition: trajectory.hh:124
points
Vec3f * points
dynamicgraph::sot::timestamp::timestamp
timestamp()
Definition: trajectory.hh:88
dynamicgraph::sot::RulesJointTrajectory::bg_liste_of_pts_re
boost::regex bg_liste_of_pts_re
Definition: trajectory.hh:43
SOT_CORE_EXPORT
#define SOT_CORE_EXPORT
Definition: api.hh:20
dynamicgraph::sot::RulesJointTrajectory::point_value_str_re
std::string point_value_str_re
Definition: trajectory.hh:38
dynamicgraph
dynamicgraph::sot::RulesJointTrajectory::end_pt_str_re
std::string end_pt_str_re
Definition: trajectory.hh:39
dynamicgraph::sot::RulesJointTrajectory::joint_name_str_re
std::string joint_name_str_re
Definition: trajectory.hh:38
dynamicgraph::sot::RulesJointTrajectory::search_exp_sub_string
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
dynamicgraph::sot::timestamp::operator==
bool operator==(const timestamp &other) const
Definition: trajectory.hh:97
dynamicgraph::sot::timestamp
Definition: trajectory.hh:84
dynamicgraph::sot::JointTrajectoryPoint::display
void display(std::ostream &os) const
Definition: trajectory.hh:129
dynamicgraph::sot::RulesJointTrajectory::RulesJointTrajectory
RulesJointTrajectory(Trajectory &TrajectoryToFill)
Constructor TrajectoryToFill is the structure where to store the parsed information.
Definition: trajectory.cpp:32
dynamicgraph::sot::RulesJointTrajectory::list_of_pv_re
boost::regex list_of_pv_re
Definition: trajectory.hh:42
dynamicgraph::sot::JointTrajectoryPoint::positions_
std::vector< double > positions_
Definition: trajectory.hh:122
dynamicgraph::sot::timestamp::secs_
unsigned long int secs_
Definition: trajectory.hh:86
dynamicgraph::sot::timestamp::nsecs_
unsigned long int nsecs_
Definition: trajectory.hh:87
dynamicgraph::sot::RulesJointTrajectory::header_re
boost::regex header_re
Boost regular expressions implementing the grammar.
Definition: trajectory.hh:42
dynamicgraph::sot::Trajectory::time_from_start_
double time_from_start_
Definition: trajectory.hh:190
copy
ReturnMatrix copy(const Eigen::MatrixBase< Matrix > &mat)
dynamicgraph::sot::Header::frame_id_
std::string frame_id_
Definition: trajectory.hh:116
dynamicgraph::sot::RulesJointTrajectory::parse_joint_names
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
dynamicgraph::sot::RulesJointTrajectory::comma_pt_str_re
std::string comma_pt_str_re
Definition: trajectory.hh:39
api.hh
dynamicgraph::sot::RulesJointTrajectory::parse_point
bool parse_point(std::string &trajectory, std::string &sub_text1)
Extract a point description.
Definition: trajectory.cpp:196
dynamicgraph::sot::RulesJointTrajectory::TrajectoryToFill_
Trajectory & TrajectoryToFill_
Definition: trajectory.hh:31
dynamicgraph::sot::Header
Definition: trajectory.hh:112
dynamicgraph::sot::RulesJointTrajectory::parse_seq
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
dynamicgraph::signal_io
dynamicgraph::sot::JointTrajectoryPoint::efforts_
std::vector< double > efforts_
Definition: trajectory.hh:125
dynamicgraph::sot::Trajectory::joint_names_
std::vector< std::string > joint_names_
Definition: trajectory.hh:187
dynamicgraph::sot::RulesJointTrajectory::dbg_level
std::size_t dbg_level
Definition: trajectory.hh:34
dynamicgraph::sot::JointTrajectoryPoint::velocities_
std::vector< double > velocities_
Definition: trajectory.hh:123
dynamicgraph::size_type
Matrix::Index size_type
display
signal-caster.h
dynamicgraph::sot::RulesJointTrajectory::parse_points
bool parse_points(std::string &trajectory, std::string &sub_text1)
Extract a sequence of points.
Definition: trajectory.cpp:233
dynamicgraph::sot::RulesJointTrajectory::bg_liste_of_pts_str_re
std::string bg_liste_of_pts_str_re
Definition: trajectory.hh:40
dynamicgraph::sot::timestamp::operator=
timestamp & operator=(const timestamp &other)
Definition: trajectory.hh:101
linear-algebra.h
dynamicgraph::sot::Trajectory
Definition: trajectory.hh:181
dynamicgraph::sot::JointTrajectoryPoint::vec_ref
std::vector< double > vec_ref
Definition: trajectory.hh:127
dynamicgraph::sot::RulesJointTrajectory::joint_names
std::vector< std::string > joint_names
Definition: trajectory.hh:44
dynamicgraph::sot::double
double
Definition: fir-filter.cpp:49
dynamicgraph::sot::timestamp::operator<<
friend std::ostream & operator<<(std::ostream &stream, const timestamp &ats)
Definition: trajectory.hh:106
dynamicgraph::sot::RulesJointTrajectory::list_of_jn_str_re
std::string list_of_jn_str_re
Definition: trajectory.hh:38
dynamicgraph::sot::JointTrajectoryPoint
Definition: trajectory.hh:120
compile.src
src
Definition: compile.py:30
dynamicgraph::sot::Trajectory::header_
Header header_
Definition: trajectory.hh:189
dynamicgraph::sot::RulesJointTrajectory::end_pt_re
boost::regex end_pt_re
Definition: trajectory.hh:42
dynamicgraph::sot::RulesJointTrajectory::parse_string
void parse_string(std::string &atext)
parse_string will fill TrajectoryToFill with string atext.
Definition: trajectory.cpp:268
dynamicgraph::sot::JointTrajectoryPoint::transfer
void transfer(const std::vector< double > &src, std::size_t vecId)
Definition: trajectory.hh:161
dynamicgraph::sot::RulesJointTrajectory::comma_pt_re
boost::regex comma_pt_re
Definition: trajectory.hh:43
dynamicgraph::sot::timestamp::timestamp
timestamp(const timestamp &ats)
Definition: trajectory.hh:89
dynamicgraph::sot::Trajectory::points_
std::vector< JointTrajectoryPoint > points_
Definition: trajectory.hh:192
dynamicgraph::sot::Header::stamp_
timestamp stamp_
Definition: trajectory.hh:115
dynamicgraph::signal_io_unimplemented
dynamicgraph::sot::RulesJointTrajectory::list_of_pv_str_re
std::string list_of_pv_str_re
Definition: trajectory.hh:39
dynamicgraph::sot::RulesJointTrajectory::float_str_re
std::string float_str_re
Strings specifying the grammar of the structure.
Definition: trajectory.hh:37
dynamicgraph::sot::RulesJointTrajectory::bg_pt_str_re
std::string bg_pt_str_re
Definition: trajectory.hh:39
dynamicgraph::sot::Header::seq_
std::size_t seq_
Definition: trajectory.hh:114
dynamicgraph::sot::RulesJointTrajectory::bg_pt_re
boost::regex bg_pt_re
Definition: trajectory.hh:42
dynamicgraph::sot::RulesJointTrajectory::timestamp_str_re
std::string timestamp_str_re
Definition: trajectory.hh:37
dynamicgraph::sot::RulesJointTrajectory::frame_id_str_re
std::string frame_id_str_re
Definition: trajectory.hh:37
dynamicgraph::sot::RulesJointTrajectory::list_of_jn_re
boost::regex list_of_jn_re
Definition: trajectory.hh:42
dynamicgraph::sot::timestamp::timestamp
timestamp(unsigned long int lsecs, unsigned long int lnsecs)
Definition: trajectory.hh:93
dynamicgraph::sot::RulesJointTrajectory::header_str_re
std::string header_str_re
Definition: trajectory.hh:38


sot-core
Author(s): Olivier Stasse, ostasse@laas.fr
autogenerated on Tue Oct 24 2023 02:26:32