Trajectory.h
Go to the documentation of this file.
1 /*
2  * This file is part of ArmarX.
3  *
4  * Copyright (C) 2011-2016, 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 ArmarX
19  * @author Mirko Waechter( mirko.waechter at kit dot edu)
20  * @date 2016
21  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22  * GNU General Public License
23  */
24 #pragma once
25 
26 #include <RobotAPI/interface/core/Trajectory.h>
27 
32 
33 #include <boost/multi_index_container.hpp>
34 #include <boost/multi_index/hashed_index.hpp>
35 #include <boost/multi_index/random_access_index.hpp>
36 #include <boost/multi_index/ordered_index.hpp>
37 #include <boost/multi_index/member.hpp>
38 
39 #include <Eigen/Core>
40 
41 namespace armarx::VariantType
42 {
43  // Variant types
44  const VariantTypeId Trajectory = Variant::addTypeName("::armarx::TrajectoryBase");
45 }
46 
47 namespace armarx
48 {
49  using DoubleSeqPtr = std::shared_ptr<Ice::DoubleSeq>;
50 
51  class Trajectory;
53 
54  /**
55  * @class Trajectory
56  * @brief The Trajectory class represents n-dimensional sampled trajectories.
57  * @ingroup VariantsGrp
58  *
59  * The class interpolates all missing values with linear interpolation and calculates derivations.
60  * This means trajectories with different timestamps can easily be used.
61  * Velocities or accelerations can easily be queried with the *derivation* parameters of many functions.
62  * Access complexity for a query with a timestamp is like from an unordered_map.
63  *
64  * \image html tut-img-traj-1.svg "Internal structure of the Trajectory class"
65  *
66  * Basic usage:
67  * @snippet RobotAPI/libraries/core/test/TrajectoryTest.cpp TrajectoryDocumentation BasicUsage
68  *
69  * The trajectory offers normal iterator capabilities:
70  * @snippet RobotAPI/libraries/core/test/TrajectoryTest.cpp TrajectoryDocumentation IteratorUsage
71  * @note Only const iterators are currently available.
72  *
73  * With the iterators it can be used like a std container:
74  * @snippet RobotAPI/libraries/core/test/TrajectoryTest.cpp TrajectoryDocumentation CopyIf
75  */
76  class Trajectory : public TrajectoryBase
77  {
78  protected:
79  ~Trajectory() override;
80  public:
81 
82 
83  using TrajMap = std::map<double, std::vector< DoubleSeqPtr > >;
84 
85  struct TrajData
86  {
87  TrajData() {}
88  TrajData(Trajectory* traj);
89  DoubleSeqPtr operator[](size_t dim) const;
90  inline TrajData& operator=(const TrajData& s)
91  {
92  timestamp = s.timestamp;
93  data.resize(s.data.size());
94  int i = 0;
95  for (auto& elem : s.data)
96  {
97  data[i++].reset(new Ice::DoubleSeq(*elem));
98  }
99  trajectory = nullptr;
100  return *this;
101  }
102 
103 
104  double getTimestamp() const;
105  double getPosition(size_t dim) const;
106 
107  template<class T = double>
108  std::vector<T> getPositionsAs() const
109  {
110  if (!trajectory)
111  {
112  throw LocalException("Ptr to trajectory is NULL");
113  }
114  auto numDim = trajectory->dim();
115  std::vector<T> result;
116  result.reserve(numDim);
117  for (std::size_t i = 0; i < numDim; ++i)
118  {
119  result.emplace_back(getPosition(i));
120  }
121  return result;
122  }
123  std::vector<double> getPositions() const
124  {
125  return getPositionsAs<double>();
126  }
127  Eigen::VectorXf getPositionsAsVectorXf() const;
128  Eigen::VectorXd getPositionsAsVectorXd() const;
129 
130 
131  template<class T>
132  void writePositionsToNameValueMap(std::map<std::string, T>& map) const
133  {
134  if (!trajectory)
135  {
136  throw LocalException("Ptr to trajectory is NULL");
137  }
138  auto numDim = trajectory->dim();
139  for (std::size_t i = 0; i < numDim; ++i)
140  {
142  }
143  }
144  template<class T>
145  std::map<std::string, T> getPositionsAsNameValueMap() const
146  {
147  std::map<std::string, T> result;
149  return result;
150  }
151 
152 
153  double getDeriv(size_t dim, size_t derivation) const;
154  const std::vector< DoubleSeqPtr >& getData() const;
155 
156  friend std::ostream& operator<<(std::ostream& stream, const TrajData& rhs)
157  {
158  stream << rhs.timestamp << ": ";
159  for (size_t d = 0; d < rhs.data.size(); ++d)
160  {
161  stream << (rhs.data[d] && rhs.data[d]->size() > 0 ? to_string(rhs.data[d]->at(0)) : std::string("-"));
162  if (d <= rhs.data.size() - 1)
163  {
164  stream << ", ";
165  }
166  }
167  return stream;
168  }
169 
170  double timestamp;
171  mutable std::vector< DoubleSeqPtr > data; // mutable so that it can be changed
172  protected:
173  Trajectory* trajectory = nullptr;
174  // friend class Trajectory;
175 
176  };
177 
178  // structs for indices
179  struct TagTimestamp {};
180  struct TagOrdered {};
181 
182 
183  // Trajectory data container
184  typedef boost::multi_index::multi_index_container <
185  TrajData,
186  boost::multi_index::indexed_by <
187  boost::multi_index::hashed_unique<boost::multi_index::tag<TagTimestamp>, boost::multi_index::member<TrajData, double, &TrajData::timestamp> >,
188  boost::multi_index::ordered_unique<boost::multi_index::tag<TagOrdered>, boost::multi_index::member<TrajData, double, &TrajData::timestamp> > // this index represents timestamp incremental order
189  >
191  using timestamp_view = typename boost::multi_index::index<TrajDataContainer, TagTimestamp>::type;
192  using ordered_view = typename boost::multi_index::index<TrajDataContainer, TagOrdered>::type;
193 
194 
195 
197  Trajectory(const Trajectory& source);
198  template <typename T>
199  Trajectory(const std::vector<T>& data, const Ice::DoubleSeq timestamps = Ice::DoubleSeq(), const std::string& dimensionName = "", typename std::enable_if_t<std::is_arithmetic_v< T > >* t = 0)
200  {
201  if (data.size() == 0)
202  {
203  return;
204  }
205  Ice::DoubleSeq dvec(data.begin(), data.end());
206  addDimension(dvec, timestamps, dimensionName);
207  }
208 
209  /**
210  * Constructor to add n-dimensions with m-values.
211  * @param data data vector (size n) with positions (size m). Dimension 1 is the joint dimension and Dimension 2 is the position of that joint.
212  * @param timestamps timestamps of the trajectory. If not empty, need to be of same size as the inner values of data.
213  * If empty, timestamps from 0..1 are generated with a stepsize aligned with the size of the inner vector of data.
214  *
215  */
216  template <typename T>
217  Trajectory(const std::vector<std::vector<T>>& data, const Ice::DoubleSeq timestamps = Ice::DoubleSeq(), const Ice::StringSeq& dimensionNames = {})
218  {
219  if (data.size() == 0)
220  {
221  return;
222  }
223  const auto& tempTimestamps = timestamps.size() > 0 ? timestamps : GenerateTimestamps(data.at(0));
224  size_t i = 0;
225  for (const auto& subvec : data)
226  {
227  Ice::DoubleSeq dvec(subvec.begin(), subvec.end());
228  addDimension(dvec, tempTimestamps, i < dimensionNames.size() ? dimensionNames.at(i++) : "");
229  }
230  }
231 
232 
233 
234  template <typename T>
235  Trajectory(const std::vector<std::vector<std::vector<T> > >& data, const Ice::DoubleSeq timestamps = Ice::DoubleSeq(), const Ice::StringSeq& dimensionNames = {})
236  {
237  this->dataVec = data;
238  this->timestamps = timestamps;
239  this->dimensionNames = dimensionNames;
240 
242  }
243 
244  Trajectory(const std::map<double, Ice::DoubleSeq>& data);
245 
246 
248 
249  // Basic Manipulators
250  size_t addDimension(const Ice::DoubleSeq& values, const Ice::DoubleSeq& timestamps = Ice::DoubleSeq(), const std::string name = "");
251  void addPositionsToDimension(size_t dimension, const Ice::DoubleSeq& values, const Ice::DoubleSeq& timestamps);
252  void addDerivationsToDimension(size_t dimension, const double t, const Ice::DoubleSeq& derivs);
253  Trajectory& operator+=(const Trajectory traj);
254  void removeDimension(size_t dimension);
255  void removeDerivation(size_t derivation);
256  void removeDerivation(size_t dimension, size_t derivation);
257 
258  // iterators
259  /**
260  * @brief Iterators that iterates in incremental order of the timestamps through the trajectory.
261  * @note Only const versions are available currently.
262  * @see end(), rbegin(), rend()
263  */
264  typename ordered_view::const_iterator begin() const;
265  typename ordered_view::const_iterator end() const;
266  typename ordered_view::const_reverse_iterator rbegin() const;
267  typename ordered_view::const_reverse_iterator rend() const;
268 
269  ///// getters
270  std::vector<DoubleSeqPtr>& operator[](double timestamp);
271  Ice::DoubleSeq getTimestamps() const;
272  Ice::FloatSeq getTimestampsFloat() const;
273  std::vector<DoubleSeqPtr>& getStates(double t);
274  std::vector<DoubleSeqPtr> getStates(double t) const;
275  Ice::DoubleSeq getStates(double t, size_t derivation) const;
276  template<typename T>
277  std::map<std::string, T> getStatesMap(double t, size_t derivation = 0) const
278  {
279  std::map<std::string, T> result;
280  size_t dimensions = dim();
281 
282  for (size_t dim = 0; dim < dimensions; dim++)
283  {
284  result[getDimensionName(dim)] = getState(t, dim, derivation);
285  }
286 
287  return result;
288  }
289 
290  double getState(double t, size_t dim = 0, size_t derivation = 0);
291  double getState(double t, size_t dim = 0, size_t derivation = 0) const;
292  std::vector<Ice::DoubleSeq > getAllStates(double t, int maxDeriv = 1);
293  Ice::DoubleSeq getDerivations(double t, size_t dimension, size_t derivations) const;
294  std::string getDimensionName(size_t dim) const;
295  const Ice::StringSeq& getDimensionNames() const;
296 
298 
299  /**
300  * @brief getDimensionData gets all entries for one dimensions with order of increasing timestamps
301  * @param dimension
302  * @param derivation
303  * @return
304  */
305  Ice::DoubleSeq getDimensionData(size_t dimension, size_t derivation = 0) const;
306  Eigen::VectorXd getDimensionDataAsEigen(size_t dimension, size_t derivation) const;
307  Eigen::VectorXd getDimensionDataAsEigen(size_t dimension, size_t derivation, double startTime, double endTime) const;
308  Eigen::MatrixXd toEigen(size_t derivation, double startTime, double endTime) const;
309  Eigen::MatrixXd toEigen(size_t derivation = 0) const;
310  TrajectoryPtr getPart(double startTime, double endTime, size_t numberOfDerivations = 0) const;
311  /**
312  * @brief dim returns the trajectory dimension count for this trajectory (e.g. taskspace w/o orientation would be 3)
313  * @return
314  */
315  size_t dim() const;
316 
317  /**
318  * @brief Returns number of data entries (i.e. positions) in the trajectory.
319  */
320  size_t size() const;
321 
322  /**
323  * @brief Difference between biggest and smallest timestamp. If size() <=1 -> return 0.
324  */
325  double getTimeLength() const;
326 
327  /**
328  * @brief Returns the sum of a all subsequent distances of the entries in the trajectories over all dimensions
329  * @param derivation Derivation for which the length is calculated
330  */
331  double getLength(size_t derivation = 0) const;
332  double getLength(size_t derivation, double startTime, double endTime) const;
333  double getLength(size_t dimension, size_t derivation) const;
334  double getLength(size_t dimension, size_t derivation, double startTime, double endTime) const;
335  double getSquaredLength(size_t dimension, size_t derivation) const;
336  double getSquaredLength(size_t dimension, size_t derivation, double startTime, double endTime) const;
337  double getMax(size_t dimension, size_t derivation, double startTime, double endTime) const;
338  double getMin(size_t dimension, size_t derivation, double startTime, double endTime) const;
339  double getWithFunc(const double & (*foo)(const double&, const double&), double initValue, size_t dimension, size_t derivation, double startTime, double endTime) const;
340  double getAmplitude(size_t dimension, size_t derivation, double startTime, double endTime) const;
341 
342  /**
343  * @brief Calculate *all* minima.
344  * @param dimension
345  * @param derivation
346  * @param startTime
347  * @param endTime
348  * @return
349  */
350  Ice::DoubleSeq getMinima(size_t dimension, size_t derivation, double startTime, double endTime) const;
351  Ice::DoubleSeq getMaxima(size_t dimension, size_t derivation, double startTime, double endTime) const;
352  Ice::DoubleSeq getMinimaTimestamps(size_t dimension, size_t derivation, double startTime, double endTime) const;
353  Ice::DoubleSeq getMaximaTimestamps(size_t dimension, size_t derivation, double startTime, double endTime) const;
354 
355  // calculations
356 
357  Ice::DoubleSeq getDiscreteDifferentiationForDim(size_t trajDimension, size_t derivation) const;
358  static Ice::DoubleSeq DifferentiateDiscretly(const Ice::DoubleSeq& timestamps, const Ice::DoubleSeq& values, int derivationCount = 1);
359  double getDiscretDifferentiationForDimAtT(double t, size_t trajDimension, size_t derivation) const;
360 
361  void differentiateDiscretlyForDim(size_t trajDimension, size_t derivation);
362  void differentiateDiscretly(size_t derivation);
363  void reconstructFromDerivativeForDim(double valueAtFirstTimestamp, size_t trajDimension, size_t sourceDimOfSystemState, size_t targetDimOfSystemState);
364 
365  /**
366  * @brief negateDim changes the sign of all values of the given dimension.
367  */
368  void negateDim(size_t trajDimension);
369 
370  /**
371  * @brief gaussianFilter smoothes the trajectory
372  * @param filterRadius, in easy words: time range to left and right from center that
373  * influences the resulting center value
374  */
375  void gaussianFilter(double filterRadius);
376 
377  static Trajectory NormalizeTimestamps(const Trajectory& traj, const double startTime = 0.0, const double endTime = 1.0);
378  TrajectoryPtr normalize(const double startTime = 0.0, const double endTime = 1.0);
379  TrajectoryPtr calculateTimeOptimalTrajectory(double maxVelocity, double maxAcceleration, double maxDeviation, IceUtil::Time const& timestep);
380  TrajectoryPtr calculateTimeOptimalTrajectory(const Eigen::VectorXd& maxVelocities, const Eigen::VectorXd& maxAccelerations, double maxDeviation, IceUtil::Time const& timestep);
381  static Ice::DoubleSeq NormalizeTimestamps(const Ice::DoubleSeq& timestamps, const double startTime = 0.0, const double endTime = 1.0);
382  static Ice::DoubleSeq GenerateTimestamps(double startTime = 0.0, double endTime = 1.0, double stepSize = 0.001);
383  template <typename T>
384  static Ice::DoubleSeq GenerateTimestamps(const std::vector<T>& values)
385  {
386  return GenerateTimestamps(0, 1, 1.0 / (values.size() - 1));
387  }
388 
389  void shiftTime(double shift);
390  void shiftValue(const Ice::DoubleSeq& shift);
391  void scaleValue(const Ice::DoubleSeq& factor);
392 
393 
394  static void CopyData(const Trajectory& source, Trajectory& destination);
395  static void CopyMetaData(const Trajectory& source, Trajectory& destination);
396 
397  void clear(bool keepMetaData = false);
398  void setPositionEntry(const double t, const size_t dimIndex, const double& y);
399  void setEntries(const double t, const size_t dimIndex, const Ice::DoubleSeq& y);
400  bool dataExists(double t, size_t dimension = 0, size_t derivation = 0) const;
401 
402 
403  std::map<double, Ice::DoubleSeq> getStatesAround(double t, size_t derivation, size_t extend) const;
404 
405 
406  // Object interface
407  void ice_preMarshal() override;
408  void ice_postUnmarshal() override;
409 
410  // Serializable interface
411  void serialize(const ObjectSerializerBasePtr& obj, const Ice::Current& = Ice::emptyCurrent) const override;
412  void deserialize(const ObjectSerializerBasePtr&, const Ice::Current& = Ice::emptyCurrent) override;
413 
414  // VariantDataClass interface
415  VariantDataClassPtr clone(const Ice::Current& c = Ice::emptyCurrent) const override;
417  std::string output(const Ice::Current& c = Ice::emptyCurrent) const override;
418  Ice::Int getType(const Ice::Current& c = Ice::emptyCurrent) const override;
419  bool validate(const Ice::Current& c = Ice::emptyCurrent) override;
420 
421  Ice::ObjectPtr ice_clone() const override;
422 
423  void setDimensionNames(const Ice::StringSeq dimNames)
424  {
425  dimensionNames = dimNames;
426  }
427 
428  void setLimitless(const LimitlessStateSeq& limitlessStates);
429  LimitlessStateSeq getLimitless() const;
430 
431  protected:
432  void __addDimension();
433  void __fillAllEmptyFields();
434  double __interpolate(typename ordered_view::const_iterator itMap, size_t dimension, size_t derivation) const;
435  double __gaussianFilter(double filterRadius, typename ordered_view::iterator centerIt, size_t trajNum, size_t dim);
436  timestamp_view::iterator __fillBaseDataAtTimestamp(const double& t);
437  std::vector<DoubleSeqPtr> __calcBaseDataAtTimestamp(const double& t) const;
438 
439 
441 
442  virtual double __interpolate(double t, ordered_view::const_iterator itPrev, ordered_view::const_iterator itNext, size_t dimension, size_t derivation) const;
443  double __interpolate(double t, size_t dimension, size_t derivation) const;
444 
445 
446  };
447 
448 }
449 
armarx::Trajectory::clone
VariantDataClassPtr clone(const Ice::Current &c=Ice::emptyCurrent) const override
Definition: Trajectory.cpp:131
armarx::Trajectory::TrajData::getTimestamp
double getTimestamp() const
Definition: Trajectory.cpp:1966
armarx::Trajectory::cloneMetaData
TrajectoryPtr cloneMetaData() const
Definition: Trajectory.cpp:136
armarx::Trajectory::CopyMetaData
static void CopyMetaData(const Trajectory &source, Trajectory &destination)
Definition: Trajectory.cpp:1643
armarx::Trajectory::getMinimaTimestamps
Ice::DoubleSeq getMinimaTimestamps(size_t dimension, size_t derivation, double startTime, double endTime) const
Definition: Trajectory.cpp:726
armarx::Trajectory::getMin
double getMin(size_t dimension, size_t derivation, double startTime, double endTime) const
Definition: Trajectory.cpp:659
armarx::Trajectory::gaussianFilter
void gaussianFilter(double filterRadius)
gaussianFilter smoothes the trajectory
Definition: Trajectory.cpp:1551
armarx::Trajectory::scaleValue
void scaleValue(const Ice::DoubleSeq &factor)
Definition: Trajectory.cpp:2062
armarx::Trajectory::TrajData::getPositionsAsVectorXd
Eigen::VectorXd getPositionsAsVectorXd() const
Definition: Trajectory.cpp:1991
armarx::Trajectory::getSquaredLength
double getSquaredLength(size_t dimension, size_t derivation) const
Definition: Trajectory.cpp:624
armarx::Trajectory::addDerivationsToDimension
void addDerivationsToDimension(size_t dimension, const double t, const Ice::DoubleSeq &derivs)
Definition: Trajectory.cpp:1951
armarx::Trajectory::normalize
TrajectoryPtr normalize(const double startTime=0.0, const double endTime=1.0)
Definition: Trajectory.cpp:1733
armarx::Trajectory::TrajData::operator<<
friend std::ostream & operator<<(std::ostream &stream, const TrajData &rhs)
Definition: Trajectory.h:156
armarx::Trajectory::getAllStates
std::vector< Ice::DoubleSeq > getAllStates(double t, int maxDeriv=1)
Definition: Trajectory.cpp:318
armarx::Trajectory::setLimitless
void setLimitless(const LimitlessStateSeq &limitlessStates)
Definition: Trajectory.cpp:2084
armarx::Trajectory::TrajData::getPositionsAsNameValueMap
std::map< std::string, T > getPositionsAsNameValueMap() const
Definition: Trajectory.h:145
armarx::Trajectory::TrajData::TrajData
TrajData()
Definition: Trajectory.h:87
armarx::Trajectory::negateDim
void negateDim(size_t trajDimension)
negateDim changes the sign of all values of the given dimension.
Definition: Trajectory.cpp:1428
armarx::Trajectory::clear
void clear(bool keepMetaData=false)
Definition: Trajectory.cpp:1651
armarx::Trajectory::timestamp_view
typename boost::multi_index::index< TrajDataContainer, TagTimestamp >::type timestamp_view
Definition: Trajectory.h:191
armarx::Trajectory::ice_clone
Ice::ObjectPtr ice_clone() const override
Definition: Trajectory.cpp:172
armarx::Trajectory::TrajData
Definition: Trajectory.h:85
armarx::Trajectory::data
TrajDataContainer & data()
Definition: Trajectory.cpp:364
armarx::Trajectory::TagOrdered
Definition: Trajectory.h:180
ProsthesisInterface.values
values
Definition: ProsthesisInterface.py:190
armarx::Trajectory::GenerateTimestamps
static Ice::DoubleSeq GenerateTimestamps(double startTime=0.0, double endTime=1.0, double stepSize=0.001)
Definition: Trajectory.cpp:1663
armarx::Trajectory::TrajData::operator=
TrajData & operator=(const TrajData &s)
Definition: Trajectory.h:90
armarx::Trajectory::TagTimestamp
Definition: Trajectory.h:179
armarx::Trajectory::__fillAllEmptyFields
void __fillAllEmptyFields()
Definition: Trajectory.cpp:1083
armarx::Trajectory::getDiscreteDifferentiationForDim
Ice::DoubleSeq getDiscreteDifferentiationForDim(size_t trajDimension, size_t derivation) const
Definition: Trajectory.cpp:1136
c
constexpr T c
Definition: UnscentedKalmanFilterTest.cpp:43
armarx::Trajectory::getStatesAround
std::map< double, Ice::DoubleSeq > getStatesAround(double t, size_t derivation, size_t extend) const
Definition: Trajectory.cpp:946
armarx::Trajectory::getState
double getState(double t, size_t dim=0, size_t derivation=0)
Definition: Trajectory.cpp:225
armarx::Trajectory::rbegin
ordered_view::const_reverse_iterator rbegin() const
Definition: Trajectory.cpp:1914
armarx::Trajectory::getDiscretDifferentiationForDimAtT
double getDiscretDifferentiationForDimAtT(double t, size_t trajDimension, size_t derivation) const
Definition: Trajectory.cpp:1228
armarx::Trajectory::addDimension
size_t addDimension(const Ice::DoubleSeq &values, const Ice::DoubleSeq &timestamps=Ice::DoubleSeq(), const std::string name="")
Definition: Trajectory.cpp:1831
armarx::Trajectory::end
ordered_view::const_iterator end() const
Definition: Trajectory.cpp:1909
armarx::Trajectory::operator[]
std::vector< DoubleSeqPtr > & operator[](double timestamp)
Definition: Trajectory.cpp:1924
armarx::Trajectory::~Trajectory
~Trajectory() override
armarx::Trajectory::getDimensionDataAsEigen
Eigen::VectorXd getDimensionDataAsEigen(size_t dimension, size_t derivation) const
Definition: Trajectory.cpp:395
armarx::Trajectory::TrajMap
std::map< double, std::vector< DoubleSeqPtr > > TrajMap
Definition: Trajectory.h:83
armarx::Trajectory::getLength
double getLength(size_t derivation=0) const
Returns the sum of a all subsequent distances of the entries in the trajectories over all dimensions.
Definition: Trajectory.cpp:524
armarx::Trajectory::TrajData::getPositionsAs
std::vector< T > getPositionsAs() const
Definition: Trajectory.h:108
armarx::Trajectory::TrajData::writePositionsToNameValueMap
void writePositionsToNameValueMap(std::map< std::string, T > &map) const
Definition: Trajectory.h:132
armarx::Trajectory::rend
ordered_view::const_reverse_iterator rend() const
Definition: Trajectory.cpp:1919
StringHelpers.h
armarx::Trajectory::calculateTimeOptimalTrajectory
TrajectoryPtr calculateTimeOptimalTrajectory(double maxVelocity, double maxAcceleration, double maxDeviation, IceUtil::Time const &timestep)
Definition: Trajectory.cpp:1740
armarx::Trajectory::getType
Ice::Int getType(const Ice::Current &c=Ice::emptyCurrent) const override
Definition: Trajectory.cpp:162
armarx::Trajectory::ice_preMarshal
void ice_preMarshal() override
Definition: Trajectory.cpp:41
armarx::Trajectory::getPart
TrajectoryPtr getPart(double startTime, double endTime, size_t numberOfDerivations=0) const
Definition: Trajectory.cpp:462
armarx::Trajectory::dataMap
TrajDataContainer dataMap
Definition: Trajectory.h:440
IceInternal::Handle< Trajectory >
armarx::Trajectory::Trajectory
Trajectory(const std::vector< std::vector< std::vector< T > > > &data, const Ice::DoubleSeq timestamps=Ice::DoubleSeq(), const Ice::StringSeq &dimensionNames={})
Definition: Trajectory.h:235
armarx::Trajectory::getMax
double getMax(size_t dimension, size_t derivation, double startTime, double endTime) const
Definition: Trajectory.cpp:654
armarx::Trajectory::shiftValue
void shiftValue(const Ice::DoubleSeq &shift)
Definition: Trajectory.cpp:2041
armarx::Trajectory::begin
ordered_view::const_iterator begin() const
Iterators that iterates in incremental order of the timestamps through the trajectory.
Definition: Trajectory.cpp:1904
armarx::Trajectory::removeDerivation
void removeDerivation(size_t derivation)
Definition: Trajectory.cpp:1871
armarx::Trajectory::reconstructFromDerivativeForDim
void reconstructFromDerivativeForDim(double valueAtFirstTimestamp, size_t trajDimension, size_t sourceDimOfSystemState, size_t targetDimOfSystemState)
Definition: Trajectory.cpp:1392
armarx::Trajectory::__gaussianFilter
double __gaussianFilter(double filterRadius, typename ordered_view::iterator centerIt, size_t trajNum, size_t dim)
Definition: Trajectory.cpp:1575
armarx::Trajectory::GenerateTimestamps
static Ice::DoubleSeq GenerateTimestamps(const std::vector< T > &values)
Definition: Trajectory.h:384
armarx::Trajectory::ice_postUnmarshal
void ice_postUnmarshal() override
Definition: Trajectory.cpp:67
armarx::Trajectory::output
std::string output(const Ice::Current &c=Ice::emptyCurrent) const override
Definition: Trajectory.cpp:143
armarx::Trajectory::differentiateDiscretly
void differentiateDiscretly(size_t derivation)
Definition: Trajectory.cpp:1371
armarx::Trajectory::TrajData::getPositionsAsVectorXf
Eigen::VectorXf getPositionsAsVectorXf() const
Definition: Trajectory.cpp:1976
armarx::Trajectory::getMinima
Ice::DoubleSeq getMinima(size_t dimension, size_t derivation, double startTime, double endTime) const
Calculate all minima.
Definition: Trajectory.cpp:691
armarx::Trajectory::getDimensionName
std::string getDimensionName(size_t dim) const
Definition: Trajectory.cpp:354
armarx::Trajectory::setDimensionNames
void setDimensionNames(const Ice::StringSeq dimNames)
Definition: Trajectory.h:423
armarx::Trajectory::TrajData::operator[]
DoubleSeqPtr operator[](size_t dim) const
Definition: Trajectory.cpp:1961
armarx::Trajectory::NormalizeTimestamps
static Trajectory NormalizeTimestamps(const Trajectory &traj, const double startTime=0.0, const double endTime=1.0)
Definition: Trajectory.cpp:1706
armarx::Trajectory::getDimensionNames
const Ice::StringSeq & getDimensionNames() const
Definition: Trajectory.cpp:359
armarx::Trajectory::setEntries
void setEntries(const double t, const size_t dimIndex, const Ice::DoubleSeq &y)
Definition: Trajectory.cpp:1025
armarx::VariantType
Definition: ChannelRef.h:160
armarx::Trajectory::__calcBaseDataAtTimestamp
std::vector< DoubleSeqPtr > __calcBaseDataAtTimestamp(const double &t) const
Definition: Trajectory.cpp:831
armarx::Trajectory::differentiateDiscretlyForDim
void differentiateDiscretlyForDim(size_t trajDimension, size_t derivation)
Definition: Trajectory.cpp:1380
armarx::Trajectory::getStates
std::vector< DoubleSeqPtr > & getStates(double t)
Definition: Trajectory.cpp:903
armarx::Trajectory::ordered_view
typename boost::multi_index::index< TrajDataContainer, TagOrdered >::type ordered_view
Definition: Trajectory.h:192
armarx::Trajectory::getStatesMap
std::map< std::string, T > getStatesMap(double t, size_t derivation=0) const
Definition: Trajectory.h:277
armarx::Trajectory::size
size_t size() const
Returns number of data entries (i.e.
Definition: Trajectory.cpp:503
armarx::Trajectory::getDimensionData
Ice::DoubleSeq getDimensionData(size_t dimension, size_t derivation=0) const
getDimensionData gets all entries for one dimensions with order of increasing timestamps
Definition: Trajectory.cpp:370
armarx::VariantTypeId
Ice::Int VariantTypeId
Definition: Variant.h:44
boost::source
Vertex source(const detail::edge_base< Directed, Vertex > &e, const PCG &)
Definition: point_cloud_graph.h:681
armarx::Trajectory::shiftTime
void shiftTime(double shift)
Definition: Trajectory.cpp:2023
armarx::armem::Time
armarx::core::time::DateTime Time
Definition: forward_declarations.h:13
armarx::to_string
const std::string & to_string(const std::string &s)
Definition: StringHelpers.h:40
armarx::Trajectory::removeDimension
void removeDimension(size_t dimension)
Definition: Trajectory.cpp:1852
armarx::Trajectory::getMaxima
Ice::DoubleSeq getMaxima(size_t dimension, size_t derivation, double startTime, double endTime) const
Definition: Trajectory.cpp:761
armarx::Trajectory::Trajectory
Trajectory()
Definition: Trajectory.h:196
armarx::Trajectory::addPositionsToDimension
void addPositionsToDimension(size_t dimension, const Ice::DoubleSeq &values, const Ice::DoubleSeq &timestamps)
Definition: Trajectory.cpp:1931
armarx::Trajectory::TrajData::getDeriv
double getDeriv(size_t dim, size_t derivation) const
Definition: Trajectory.cpp:2006
armarx::Trajectory::operator+=
Trajectory & operator+=(const Trajectory traj)
Definition: Trajectory.cpp:999
armarx::Trajectory::DifferentiateDiscretly
static Ice::DoubleSeq DifferentiateDiscretly(const Ice::DoubleSeq &timestamps, const Ice::DoubleSeq &values, int derivationCount=1)
Definition: Trajectory.cpp:1185
armarx::Trajectory::__fillBaseDataAtTimestamp
timestamp_view::iterator __fillBaseDataAtTimestamp(const double &t)
Definition: Trajectory.cpp:865
ExpressionException.h
armarx::Trajectory::__addDimension
void __addDimension()
Definition: Trajectory.cpp:1013
armarx::Trajectory::toEigen
Eigen::MatrixXd toEigen(size_t derivation, double startTime, double endTime) const
Definition: Trajectory.cpp:431
armarx::Trajectory::getAmplitude
double getAmplitude(size_t dimension, size_t derivation, double startTime, double endTime) const
Definition: Trajectory.cpp:686
armarx::Trajectory::TrajData::timestamp
double timestamp
Definition: Trajectory.h:170
armarx::Trajectory::TrajDataContainer
boost::multi_index::multi_index_container< TrajData, boost::multi_index::indexed_by< boost::multi_index::hashed_unique< boost::multi_index::tag< TagTimestamp >, boost::multi_index::member< TrajData, double, &TrajData::timestamp > >, boost::multi_index::ordered_unique< boost::multi_index::tag< TagOrdered >, boost::multi_index::member< TrajData, double, &TrajData::timestamp > > > > TrajDataContainer
Definition: Trajectory.h:190
armarx::Trajectory::Trajectory
Trajectory(const std::vector< T > &data, const Ice::DoubleSeq timestamps=Ice::DoubleSeq(), const std::string &dimensionName="", typename std::enable_if_t< std::is_arithmetic_v< T > > *t=0)
Definition: Trajectory.h:199
armarx::Trajectory::getTimestampsFloat
Ice::FloatSeq getTimestampsFloat() const
Definition: Trajectory.cpp:1118
armarx::Trajectory
The Trajectory class represents n-dimensional sampled trajectories.
Definition: Trajectory.h:76
armarx::VariantType::Int
const VariantTypeId Int
Definition: Variant.h:916
armarx::Trajectory::TrajData::data
std::vector< DoubleSeqPtr > data
Definition: Trajectory.h:171
armarx::Trajectory::operator=
Trajectory & operator=(const Trajectory &source)
Definition: Trajectory.cpp:218
armarx::Trajectory::TrajData::getPositions
std::vector< double > getPositions() const
Definition: Trajectory.h:123
armarx::aron::type::ObjectPtr
std::shared_ptr< Object > ObjectPtr
Definition: Object.h:36
armarx::Trajectory::validate
bool validate(const Ice::Current &c=Ice::emptyCurrent) override
Definition: Trajectory.cpp:167
armarx::Trajectory::dim
size_t dim() const
dim returns the trajectory dimension count for this trajectory (e.g.
Definition: Trajectory.cpp:491
armarx::Trajectory::serialize
void serialize(const ObjectSerializerBasePtr &obj, const Ice::Current &=Ice::emptyCurrent) const override
Definition: Trajectory.cpp:85
armarx::Trajectory::getTimeLength
double getTimeLength() const
Difference between biggest and smallest timestamp.
Definition: Trajectory.cpp:510
armarx::Trajectory::dataExists
bool dataExists(double t, size_t dimension=0, size_t derivation=0) const
Definition: Trajectory.cpp:850
armarx::Trajectory::getTimestamps
Ice::DoubleSeq getTimestamps() const
Definition: Trajectory.cpp:1103
armarx::Trajectory::getWithFunc
double getWithFunc(const double &(*foo)(const double &, const double &), double initValue, size_t dimension, size_t derivation, double startTime, double endTime) const
Definition: Trajectory.cpp:664
armarx::Trajectory::CopyData
static void CopyData(const Trajectory &source, Trajectory &destination)
Definition: Trajectory.cpp:1624
Variant.h
armarx::Trajectory::getMaximaTimestamps
Ice::DoubleSeq getMaximaTimestamps(size_t dimension, size_t derivation, double startTime, double endTime) const
Definition: Trajectory.cpp:795
armarx::Trajectory::TrajData::getPosition
double getPosition(size_t dim) const
Definition: Trajectory.cpp:1971
armarx::ctrlutil::s
double s(double t, double s0, double v0, double a0, double j)
Definition: CtrlUtil.h:33
armarx::Trajectory::__interpolate
double __interpolate(typename ordered_view::const_iterator itMap, size_t dimension, size_t derivation) const
Definition: Trajectory.cpp:1475
armarx::Trajectory::getDerivations
Ice::DoubleSeq getDerivations(double t, size_t dimension, size_t derivations) const
Definition: Trajectory.cpp:337
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
armarx::Trajectory::Trajectory
Trajectory(const std::vector< std::vector< T >> &data, const Ice::DoubleSeq timestamps=Ice::DoubleSeq(), const Ice::StringSeq &dimensionNames={})
Constructor to add n-dimensions with m-values.
Definition: Trajectory.h:217
Exception.h
armarx::Variant::addTypeName
static VariantTypeId addTypeName(const std::string &typeName)
Register a new type for the use in a Variant.
Definition: Variant.cpp:751
armarx::Trajectory::TrajData::trajectory
Trajectory * trajectory
Definition: Trajectory.h:173
armarx::DoubleSeqPtr
std::shared_ptr< Ice::DoubleSeq > DoubleSeqPtr
Definition: Trajectory.h:49
armarx::Trajectory::TrajData::getData
const std::vector< DoubleSeqPtr > & getData() const
Definition: Trajectory.cpp:2015
armarx::Trajectory::deserialize
void deserialize(const ObjectSerializerBasePtr &, const Ice::Current &=Ice::emptyCurrent) override
Definition: Trajectory.cpp:108
armarx::Trajectory::getLimitless
LimitlessStateSeq getLimitless() const
Definition: Trajectory.cpp:2089
armarx::Trajectory::setPositionEntry
void setPositionEntry(const double t, const size_t dimIndex, const double &y)
Definition: Trajectory.cpp:1055