motion-period.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2010,
3  * François Bleibel,
4  * Olivier Stasse,
5  *
6  * CNRS/AIST
7  *
8  */
9 
10 /* --------------------------------------------------------------------- */
11 /* --- INCLUDE --------------------------------------------------------- */
12 /* --------------------------------------------------------------------- */
13 
14 /* --- SOT --- */
16 
17 #include <sot/core/debug.hh>
19 #include <sot/core/factory.hh>
21 using namespace std;
22 using namespace dynamicgraph::sot;
23 using namespace dynamicgraph;
24 
26 
27 /* --------------------------------------------------------------------- */
28 /* --- CLASS ----------------------------------------------------------- */
29 /* --------------------------------------------------------------------- */
30 
31 MotionPeriod::MotionPeriod(const string &fName)
32  : Entity(fName),
33  motionParams(0),
34  motionSOUT(boost::bind(&MotionPeriod::computeMotion, this, _1, _2),
36  "MotionPeriod(" + name + ")::output(vector)::motion") {
39  resize(0);
40 }
41 
42 /* --------------------------------------------------------------------- */
43 /* --------------------------------------------------------------------- */
44 /* --------------------------------------------------------------------- */
45 
47  const int &time) {
48  sotDEBUGIN(15);
49 
50  res.resize(size);
51  for (unsigned int i = 0; i < size; ++i) {
52  const sotMotionParam &p = motionParams[i];
53  double x = ((((time - p.initPeriod) % p.period) + 0.0) / (p.period + 0.0));
54  res(i) = p.initAmplitude;
55  switch (p.motionType) {
56  case MOTION_CONSTANT: {
57  res(i) += p.amplitude;
58  break;
59  }
60  case MOTION_SIN: {
61  res(i) += p.amplitude * sin(M_PI * 2 * x);
62  break;
63  }
64  case MOTION_COS: {
65  res(i) += p.amplitude * cos(M_PI * 2 * x);
66  break;
67  }
68  // case MOTION_: {res(i)+= p.amplitude; break}
69  }
70  }
71 
72  sotDEBUGOUT(15);
73  return res;
74 }
75 
76 void MotionPeriod::resize(const unsigned int &_size) {
77  size = _size;
78  motionParams.resize(size);
79  for (unsigned int i = 0; i < size; ++i) {
80  motionParams[i].motionType = MOTION_CONSTANT;
81  motionParams[i].amplitude = 0;
82  motionParams[i].initPeriod = 0;
83  motionParams[i].period = 1;
84  motionParams[i].initAmplitude = 0;
85  }
86 }
87 
88 void MotionPeriod::display(std::ostream &os) const {
89  os << "MotionPeriod <" << name << "> ... TODO";
90 }
91 
92 #define SOT_PARAMS_CONFIG(ARGname, ARGtype) \
93  else if (cmdLine == #ARGname) { \
94  unsigned int rank; \
95  ARGtype period; \
96  cmdArgs >> rank >> std::ws; \
97  if (rank >= this->size) { \
98  os << "!! Error: size size too large." << std::endl; \
99  } \
100  if (cmdArgs.good()) { \
101  cmdArgs >> period; \
102  motionParams[rank].ARGname = period; \
103  } else { \
104  os << #ARGname << "[" << rank << "] = " << motionParams[rank].ARGname \
105  << std::endl; \
106  } \
107  }
Eigen::VectorXd Vector
int i
void signalRegistration(const SignalArray< int > &signals)
void resize(const unsigned int &size)
#define sotDEBUGOUT(level)
Definition: debug.hh:212
void setNeedUpdateFromAllChildren(const bool b=true)
#define M_PI
#define sotDEBUGIN(level)
Definition: debug.hh:211
virtual void display(std::ostream &os) const
dynamicgraph::SignalTimeDependent< dynamicgraph::Vector, int > motionSOUT
x
dynamicgraph::Vector & computeMotion(dynamicgraph::Vector &res, const int &time)
DYNAMIC_GRAPH_DLLAPI SignalArray< int > sotNOSIGNAL
p
std::vector< sotMotionParam > motionParams
DYNAMICGRAPH_FACTORY_ENTITY_PLUGIN(MotionPeriod, "MotionPeriod")


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