text-file.hpp
Go to the documentation of this file.
1 
7 #ifndef _parameteric_curves_text_file_hpp
8 #define _parameteric_curves_text_file_hpp
9 
12 
13 namespace parametriccurves {
14 
17 template <typename Numeric = double, Eigen::Index Dim = Eigen::Dynamic,
18  typename Point = Eigen::Matrix<Numeric, Dim, 1> >
19 struct TextFile : public AbstractCurve<Numeric, Point> {
20  typedef Point point_t;
21  typedef Numeric time_t;
22  typedef Numeric num_t;
23  typedef Eigen::Matrix<Numeric, Dim, Eigen::Dynamic> pos_t;
24  typedef Eigen::Matrix<Numeric, Dim, Eigen::Dynamic> vel_t;
25  typedef Eigen::Matrix<Numeric, Dim, Eigen::Dynamic> acc_t;
26 
28 
29  public:
31 
32  TextFile(const time_t& dt_, const std::size_t& size_)
33  : curve_abc_t(-1, -1), timeStep(dt_), size(size_) {}
34 
36  ~TextFile() {}
37 
38  public:
39  virtual const point_t operator()(const time_t& t) const {
40  Eigen::VectorXd::Index i = (Eigen::VectorXd::Index)std::floor(t / timeStep);
41  return posValues.row(i);
42  }
43 
44  virtual const point_t derivate(const time_t& t,
45  const std::size_t& order) const {
46  Eigen::VectorXd::Index i = (Eigen::VectorXd::Index)std::floor(t / timeStep);
47  if (order == 1)
48  return velValues.row(i);
49  else if (order == 2)
50  return accValues.row(i);
51  else {
52  std::cerr << "Higher order derivatives not supported" << std::endl;
53  return point_t::Zero(size);
54  }
55  }
56 
57  public:
58  virtual bool loadTextFile(const std::string& fileName) {
59  Eigen::MatrixXd data =
61  if (data.cols() == size) {
62  std::cout << fileName << ": setting derivatives to zero" << std::endl;
63  posValues = data;
64  velValues.setZero(data.rows(), size);
65  accValues.setZero(data.rows(), size);
66  } else if (data.cols() == 2 * size) {
67  std::cout << fileName << ": setting second derivative to zero"
68  << std::endl;
69  posValues = data.leftCols(size);
70  velValues = data.rightCols(size);
71  accValues = accValues.setZero(data.rows(), size);
72  } else if (data.cols() == 3 * size) {
73  posValues = data.leftCols(size);
74  velValues = data.middleCols(size, size);
75  accValues = data.rightCols(size);
76  } else {
77  std::cout << "Unexpected number of columns (expected " << size << " or "
78  << 2 * size << " or " << 3 * size << ", found " << data.cols()
79  << ")\n";
80  return false;
81  }
82  this->t_max = timeStep * (double)data.rows();
83  this->t_min = 0.0;
84  x_init = posValues.row(0);
85  return true;
86  }
87 
88  virtual bool setInitialPoint(const point_t& /*x_init*/) { return false; }
89  virtual bool setInitialPoint(const num_t& /*x_init*/) { return false; }
90 
91  const point_t& getInitialPoint(void) const { return x_init; }
92 
93  protected:
94  /*Attributes*/
100  std::size_t size;
101 };
102 } // namespace parametriccurves
103 #endif //_CLASS_EXACTCUBIC
const Eigen::MatrixXd readMatrixFromFile(const std::string &filename)
Definition: file-io.hpp:12
Definition: abstract-curve.hpp:16
Eigen::Matrix< Numeric, 3, 1 > Point
Definition: effector_spline.h:28
double Numeric
Definition: effector_spline.h:26
Represents a curve of dimension Dim is Safe is false, no verification is made on the evaluation of th...
Definition: abstract-curve.hpp:21
Loads curve from file.
Definition: text-file.hpp:19
time_t timeStep
Definition: text-file.hpp:99
Eigen::Matrix< Numeric, Dim, Eigen::Dynamic > vel_t
Definition: text-file.hpp:24
Eigen::Matrix< Numeric, Dim, Eigen::Dynamic > acc_t
Definition: text-file.hpp:25
Eigen::Matrix< Numeric, Dim, Eigen::Dynamic > pos_t
Definition: text-file.hpp:23
acc_t accValues
Definition: text-file.hpp:98
virtual bool loadTextFile(const std::string &fileName)
Definition: text-file.hpp:58
Numeric num_t
Definition: text-file.hpp:22
point_t x_init
Definition: text-file.hpp:95
virtual bool setInitialPoint(const num_t &)
Definition: text-file.hpp:89
virtual bool setInitialPoint(const point_t &)
Definition: text-file.hpp:88
vel_t velValues
Definition: text-file.hpp:97
virtual const point_t operator()(const time_t &t) const
Definition: text-file.hpp:39
virtual const point_t derivate(const time_t &t, const std::size_t &order) const
Definition: text-file.hpp:44
std::size_t size
Definition: text-file.hpp:100
Point point_t
Definition: text-file.hpp:20
AbstractCurve< Numeric, Point > curve_abc_t
Definition: text-file.hpp:27
pos_t posValues
Definition: text-file.hpp:96
Numeric time_t
Definition: text-file.hpp:21
TextFile(const time_t &dt_, const std::size_t &size_)
Constructor.
Definition: text-file.hpp:32
~TextFile()
Destructor.
Definition: text-file.hpp:36
const point_t & getInitialPoint(void) const
Definition: text-file.hpp:91