oscillator.cc
Go to the documentation of this file.
1 //
2 // Copyright (C) 2012 LAAS-CNRS
3 //
4 // Author: Florent Lamiraux,
5 // Mehdi Benallegue <mehdi@benallegue.com>
6 //
7 
9 
10 #include <limits>
11 
12 namespace dynamicgraph {
13 namespace sot {
18 namespace tools {
19 
20 DYNAMICGRAPH_FACTORY_ENTITY_PLUGIN(Oscillator, "Oscillator");
21 
22 Oscillator::Oscillator(const std::string name)
23  : Entity(name),
24  angularFrequencySIN_(0, "Oscillator(" + name + ")::input(double)::omega"),
25  magnitudeSIN_(0, "Oscillator(" + name + ")::input(double)::magnitude"),
26  phaseSIN_(0, "Oscillator(" + name + ")::input(double)::phase"),
27  biasSIN_(0, "Oscillator(" + name + ")::input(double)::bias"),
28  soutSOUT_("Oscillator(" + name + ")::output(double)::sout"),
29  vectorSoutSOUT_("Oscillator(" + name + ")::output(vector)::vectorSout"),
30  epsilon_(1e-3),
31  started_(true),
32  continuous_(false),
33  dt_(0.),
34  lastValue_(0.0) {
36  << biasSIN_ << soutSOUT_
37  << vectorSoutSOUT_);
42 
48  soutSOUT_.setFunction(boost::bind(&Oscillator::computeSignal, this, _1, _2));
50  boost::bind(&Oscillator::computeVectorSignal, this, _1, _2));
53 
54  addCommand(
55  "setTimePeriod",
56  makeDirectSetter(*this, &dt_, docDirectSetter("time period", "double")));
57  addCommand(
58  "getTimePeriod",
59  makeDirectGetter(*this, &dt_, docDirectGetter("time period", "double")));
60 
61  addCommand(
62  "setActivated",
63  makeDirectSetter(*this, &started_, docDirectSetter("activated", "bool")));
64 
65  addCommand(
66  "getActivated",
67  makeDirectGetter(*this, &started_, docDirectGetter("activated", "bool")));
68 
71  addCommand("setEpsilon",
73  *this, &epsilon_,
74  docDirectSetter("ocillator zero-sensitivity", "double")));
75 
76  addCommand("getEpsilon",
78  *this, &epsilon_,
79  docDirectGetter("ocillator zero-sensitivity", "double")));
80 
81  addCommand("setValue",
83  *this, &lastValue_,
84  docDirectSetter("init value of the oscillator", "double")));
85 
86  addCommand("getValue",
88  *this, &lastValue_,
89  docDirectGetter("current value of the oscillator", "double")));
90 
91  addCommand("setContinuous",
93  docDirectSetter("continuous", "bool")));
94 
95  addCommand("getContinuous",
97  docDirectGetter("continuous", "bool")));
98 }
99 
100 double Oscillator::value(double dt, double t, double omega, double phase,
101  double m, double bias) {
102  double tau = dt * t;
103  return m * sin(omega * tau + phase) + bias;
104 }
105 
107  dynamicgraph::Vector& vsout, const int& t) {
108  vsout.resize(1);
109  vsout(0) = soutSOUT_.access(t);
110  return vsout;
111 }
112 
113 double& Oscillator::computeSignal(double& sout, const int& t) {
114  double eps;
115 
116  if (continuous_)
117  eps = epsilon_;
118  else
119  eps = std::numeric_limits<double>::max();
120 
121  double omega = angularFrequencySIN_.access(t);
122  double m = magnitudeSIN_.access(t);
123  double phase = phaseSIN_.access(t);
124  double bias = biasSIN_.access(t);
125 
126  if (started_) {
127  double current = value(dt_, t, omega, phase, m, bias);
128 
129  if (fabs(lastValue_ - current) < eps)
130  lastValue_ = sout = current;
131  else
132  sout = lastValue_;
133  } else {
134  if (fabs(lastValue_) < eps)
135  lastValue_ = sout = 0;
136  else
137  lastValue_ = sout = value(dt_, t, omega, phase, m, bias);
138  }
139 
140  return sout;
141 }
142 } // namespace tools
143 } // namespace sot
144 } // namespace dynamicgraph
float eps
const T & access(const Time &t1)
std::string docDirectGetter(const std::string &name, const std::string &type)
double value(double dt, double time, double omega, double phase, double amplitude, double bias)
Definition: oscillator.cc:100
SignalPtr< double, int > biasSIN_
Definition: oscillator.hh:41
Eigen::VectorXd Vector
DirectGetter< E, T > * makeDirectGetter(E &entity, T *ptr, const std::string &docString)
tau
SignalPtr< double, int > angularFrequencySIN_
Definition: oscillator.hh:38
void signalRegistration(const SignalArray< int > &signals)
SignalPtr< double, int > phaseSIN_
Definition: oscillator.hh:40
void setNeedUpdateFromAllChildren(const bool b=true)
SignalTimeDependent< dynamicgraph::Vector, int > vectorSoutSOUT_
Definition: oscillator.hh:43
void setDependencyType(DependencyType dep)
SignalPtr< double, int > magnitudeSIN_
Definition: oscillator.hh:39
virtual void setConstant(const T &t)
dynamicgraph::Vector & computeVectorSignal(dynamicgraph::Vector &vsout, const int &t)
Definition: oscillator.cc:106
virtual const T & access(const Time &t)
virtual void addDependency(const SignalBase< Time > &signal)
float m
MotionTpl< Scalar, Options > bias(const JointDataTpl< Scalar, Options, JointCollectionTpl > &jdata)
SignalTimeDependent< double, int > soutSOUT_
Definition: oscillator.hh:42
Transform3f t
Oscillator(const std::string name)
Definition: oscillator.cc:22
double & computeSignal(double &sout, const int &t)
Definition: oscillator.cc:113
void addCommand(const std::string &name, command::Command *command)
std::string docDirectSetter(const std::string &name, const std::string &type)
virtual void setFunction(boost::function2< T &, T &, Time > t, Mutex *mutexref=NULL)
DYNAMICGRAPH_FACTORY_ENTITY_PLUGIN(CubicInterpolationSE3, "CubicInterpolationSE3")
DirectSetter< E, T > * makeDirectSetter(E &entity, T *ptr, const std::string &docString)


sot-tools
Author(s): Mehdi Benallegue, Francois Keith, Florent Lamiraux, Thomas Moulard, Olivier Stasse, Jorrit T'Hooft
autogenerated on Sun Jun 25 2023 02:10:08