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") {
38  motionSOUT.setNeedUpdateFromAllChildren(true);
39  resize(0);
40 }
41 
42 /* --------------------------------------------------------------------- */
43 /* --------------------------------------------------------------------- */
44 /* --------------------------------------------------------------------- */
45 
47  const sigtime_t &time) {
48  sotDEBUGIN(15);
49 
50  res.resize(size);
51  for (std::size_t i = 0; i < size; ++i) {
52  const sotMotionParam &p = motionParams[i];
53  double x = (double)((time - p.initPeriod) % p.period) / (double)(p.period);
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 std::size_t &_size) {
77  size = _size;
78  motionParams.resize(size);
79  for (std::size_t 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  std::size_t 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  }
dynamicgraph::sot::MotionPeriod::MOTION_SIN
@ MOTION_SIN
Definition: motion-period.hh:56
dynamicgraph::sot::MotionPeriod::motionParams
std::vector< sotMotionParam > motionParams
Definition: motion-period.hh:67
motion-period.hh
factory.hh
dynamicgraph
i
int i
dynamicgraph::Entity
boost
dynamicgraph::Entity::name
std::string name
DYNAMICGRAPH_FACTORY_ENTITY_PLUGIN
DYNAMICGRAPH_FACTORY_ENTITY_PLUGIN(MotionPeriod, "MotionPeriod")
dynamicgraph::sot::MotionPeriod::sotMotionParam
Definition: motion-period.hh:58
debug.hh
p
p
res
res
sotDEBUGOUT
#define sotDEBUGOUT(level)
Definition: debug.hh:215
dynamicgraph::sigtime_t
int64_t sigtime_t
dynamicgraph::sot::MotionPeriod
Definition: motion-period.hh:50
dynamicgraph::sot::MotionPeriod::display
virtual void display(std::ostream &os) const
Definition: motion-period.cpp:88
dynamicgraph::sot::MotionPeriod::motionSOUT
dynamicgraph::SignalTimeDependent< dynamicgraph::Vector, sigtime_t > motionSOUT
Definition: motion-period.hh:73
sotDEBUGIN
#define sotDEBUGIN(level)
Definition: debug.hh:214
x
x
dynamicgraph::sot::MotionPeriod::MOTION_COS
@ MOTION_COS
Definition: motion-period.hh:56
dynamicgraph::Vector
Eigen::VectorXd Vector
exception-feature.hh
dynamicgraph::sot::MotionPeriod::resize
void resize(const std::size_t &size)
Definition: motion-period.cpp:76
linear-algebra.h
dynamicgraph::sot::double
double
Definition: fir-filter.cpp:49
M_PI
#define M_PI
dynamicgraph::sot::MotionPeriod::size
std::size_t size
Definition: motion-period.hh:66
dynamicgraph::sot::MotionPeriod::computeMotion
dynamicgraph::Vector & computeMotion(dynamicgraph::Vector &res, const sigtime_t &time)
Definition: motion-period.cpp:46
dynamicgraph::sot
dynamicgraph::sot::MotionPeriod::MOTION_CONSTANT
@ MOTION_CONSTANT
Definition: motion-period.hh:56
dynamicgraph::Entity::signalRegistration
void signalRegistration(const SignalArray< sigtime_t > &signals)
sotNOSIGNAL
DYNAMIC_GRAPH_DLLAPI SignalArray< sigtime_t > sotNOSIGNAL
compile.name
name
Definition: compile.py:23


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