time-stamp.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 */
15 #include <dynamic-graph/factory.h>
16 
19 #include <sot/core/time-stamp.hh>
20 
21 /* --------------------------------------------------------------------- */
22 /* --- CLASS ----------------------------------------------------------- */
23 /* --------------------------------------------------------------------- */
24 
25 using namespace dynamicgraph;
26 using namespace dynamicgraph::sot;
27 
29 
30 /* --- CONSTRUCTION ---------------------------------------------------- */
31 TimeStamp::TimeStamp(const std::string &name)
32  : Entity(name),
33  offsetValue(0),
34  offsetSet(false),
35  timeSOUT("TimeStamp(" + name + ")::output(vector2)::time"),
36  timeDoubleSOUT("TimeStamp(" + name + ")::output(double)::timeDouble"),
37  timeOnceSOUT(boost::bind(&TimeStamp::getTimeStamp, this, _1, _2),
39  "TimeStamp(" + name + ")::output(vector2)::synchro"),
40  timeOnceDoubleSOUT(
41  boost::bind(&TimeStamp::getTimeStampDouble, this,
42  SOT_CALL_SIG(timeSOUT, dynamicgraph::Vector), _1),
43  timeSOUT, "TimeStamp(" + name + ")::output(double)::synchroDouble") {
44  sotDEBUGIN(15);
45 
46  timeSOUT.setFunction(boost::bind(&TimeStamp::getTimeStamp, this, _1, _2));
48  boost::bind(&TimeStamp::getTimeStampDouble, this,
54 
55  gettimeofday(&val, NULL);
56 
57  sotDEBUGOUT(15);
58 }
59 
60 /* --- DISPLAY --------------------------------------------------------- */
61 void TimeStamp::display(std::ostream &os) const {
62  os << "TimeStamp <> : " << val.tv_sec << "s; " << val.tv_usec << "us."
63  << std::endl;
64 }
65 
66 /* --------------------------------------------------------------------- */
67 /* --- CONTROL --------------------------------------------------------- */
68 /* --------------------------------------------------------------------- */
69 
71  const int & /*time*/) {
72  sotDEBUGIN(15);
73  gettimeofday(&val, NULL);
74  if (res.size() != 2) res.resize(2);
75 
76  res(0) = static_cast<double>(val.tv_sec);
77  res(1) = static_cast<double>(val.tv_usec);
78  sotDEBUGOUT(15);
79  return res;
80 }
81 
83  double &res) {
84  sotDEBUGIN(15);
85 
86  if (offsetSet)
87  res = (vect(0) - offsetValue) * 1000;
88  else
89  res = vect(0) * 1000;
90  res += vect(1) / 1000;
91  sotDEBUGOUT(15);
92  return res;
93 }
#define SOT_CALL_SIG(sotName, sotType)
Eigen::VectorXd Vector
SignalArray< int > sotNOSIGNAL(0)
dynamicgraph::Vector & getTimeStamp(dynamicgraph::Vector &res, const int &time)
Definition: time-stamp.cpp:70
void signalRegistration(const SignalArray< int > &signals)
#define sotDEBUGOUT(level)
Definition: debug.hh:212
void setNeedUpdateFromAllChildren(const bool b=true)
dynamicgraph::Signal< double, int > timeDoubleSOUT
Definition: time-stamp.hh:75
double & getTimeStampDouble(const dynamicgraph::Vector &vect, double &res)
Definition: time-stamp.cpp:82
DYNAMICGRAPH_FACTORY_ENTITY_PLUGIN(FeaturePosture, "FeaturePosture")
#define sotDEBUGIN(level)
Definition: debug.hh:211
TimeStamp(const std::string &name)
Definition: time-stamp.cpp:31
dynamicgraph::SignalTimeDependent< dynamicgraph::Vector, int > timeOnceSOUT
Definition: time-stamp.hh:79
virtual void display(std::ostream &os) const
Definition: time-stamp.cpp:61
dynamicgraph::Signal< dynamicgraph::Vector, int > timeSOUT
Definition: time-stamp.hh:74
dynamicgraph::SignalTimeDependent< double, int > timeOnceDoubleSOUT
Definition: time-stamp.hh:80
virtual void setFunction(boost::function2< T &, T &, Time > t, Mutex *mutexref=NULL)


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