| Line |
Branch |
Exec |
Source |
| 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 --- */ |
| 15 |
|
|
#include <dynamic-graph/linear-algebra.h> |
| 16 |
|
|
|
| 17 |
|
|
#include <sot/core/debug.hh> |
| 18 |
|
|
#include <sot/core/exception-feature.hh> |
| 19 |
|
|
#include <sot/core/factory.hh> |
| 20 |
|
|
#include <sot/core/motion-period.hh> |
| 21 |
|
|
using namespace std; |
| 22 |
|
|
using namespace dynamicgraph::sot; |
| 23 |
|
|
using namespace dynamicgraph; |
| 24 |
|
|
|
| 25 |
|
✗ |
DYNAMICGRAPH_FACTORY_ENTITY_PLUGIN(MotionPeriod, "MotionPeriod"); |
| 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), |
| 35 |
|
|
sotNOSIGNAL, |
| 36 |
|
✗ |
"MotionPeriod(" + name + ")::output(vector)::motion") { |
| 37 |
|
✗ |
signalRegistration(motionSOUT); |
| 38 |
|
✗ |
motionSOUT.setNeedUpdateFromAllChildren(true); |
| 39 |
|
✗ |
resize(0); |
| 40 |
|
|
} |
| 41 |
|
|
|
| 42 |
|
|
/* --------------------------------------------------------------------- */ |
| 43 |
|
|
/* --------------------------------------------------------------------- */ |
| 44 |
|
|
/* --------------------------------------------------------------------- */ |
| 45 |
|
|
|
| 46 |
|
✗ |
dynamicgraph::Vector &MotionPeriod::computeMotion(dynamicgraph::Vector &res, |
| 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 |
|
|
} |
| 108 |
|
|
|