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/factory.h> |
16 |
|
|
|
17 |
|
|
#include <sot/core/macros-signal.hh> |
18 |
|
|
#include <sot/core/matrix-geometry.hh> |
19 |
|
|
#include <sot/core/time-stamp.hh> |
20 |
|
|
|
21 |
|
|
/* --------------------------------------------------------------------- */ |
22 |
|
|
/* --- CLASS ----------------------------------------------------------- */ |
23 |
|
|
/* --------------------------------------------------------------------- */ |
24 |
|
|
|
25 |
|
|
using namespace dynamicgraph; |
26 |
|
|
using namespace dynamicgraph::sot; |
27 |
|
|
|
28 |
|
✗ |
DYNAMICGRAPH_FACTORY_ENTITY_PLUGIN(TimeStamp, "TimeStamp"); |
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), |
38 |
|
|
sotNOSIGNAL, |
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)); |
47 |
|
✗ |
timeDoubleSOUT.setFunction( |
48 |
|
|
boost::bind(&TimeStamp::getTimeStampDouble, this, |
49 |
|
|
SOT_CALL_SIG(timeSOUT, dynamicgraph::Vector), _1)); |
50 |
|
✗ |
timeOnceSOUT.setNeedUpdateFromAllChildren(true); |
51 |
|
✗ |
timeOnceDoubleSOUT.setNeedUpdateFromAllChildren(true); |
52 |
|
✗ |
signalRegistration(timeSOUT << timeDoubleSOUT << timeOnceSOUT |
53 |
|
✗ |
<< timeOnceDoubleSOUT); |
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 |
|
|
|
70 |
|
✗ |
dynamicgraph::Vector &TimeStamp::getTimeStamp(dynamicgraph::Vector &res, |
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 |
|
|
|
82 |
|
✗ |
double &TimeStamp::getTimeStampDouble(const dynamicgraph::Vector &vect, |
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 |
|
|
} |
94 |
|
|
|