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/all-commands.h> |
16 |
|
|
#include <dynamic-graph/exception-factory.h> |
17 |
|
|
#include <dynamic-graph/pool.h> |
18 |
|
|
|
19 |
|
|
#include <algorithm> |
20 |
|
|
#include <sot/core/debug.hh> |
21 |
|
|
#include <sot/core/exception-tools.hh> |
22 |
|
|
#include <sot/core/periodic-call.hh> |
23 |
|
|
|
24 |
|
|
using namespace std; |
25 |
|
|
using namespace dynamicgraph; |
26 |
|
|
using namespace dynamicgraph::sot; |
27 |
|
|
|
28 |
|
|
/* --------------------------------------------------------------------- */ |
29 |
|
|
/* --- CLASS ----------------------------------------------------------- */ |
30 |
|
|
/* --------------------------------------------------------------------- */ |
31 |
|
|
|
32 |
|
4 |
PeriodicCall::PeriodicCall(void) : signalMap(), innerTime(0) {} |
33 |
|
|
|
34 |
|
|
/* --------------------------------------------------------------------- */ |
35 |
|
|
/* --------------------------------------------------------------------- */ |
36 |
|
|
/* --------------------------------------------------------------------- */ |
37 |
|
✗ |
void PeriodicCall::addSignal(const std::string &name, SignalBase<int> &sig) { |
38 |
|
✗ |
signalMap[name] = SignalToCall(&sig); |
39 |
|
✗ |
return; |
40 |
|
|
} |
41 |
|
|
|
42 |
|
✗ |
void PeriodicCall::addSignal(const std::string &sigpath) { |
43 |
|
✗ |
istringstream sigISS(sigpath); |
44 |
|
|
SignalBase<int> &signal = |
45 |
|
✗ |
::dynamicgraph::PoolStorage::getInstance()->getSignal(sigISS); |
46 |
|
✗ |
addSignal(sigpath, signal); |
47 |
|
✗ |
return; |
48 |
|
|
} |
49 |
|
|
|
50 |
|
✗ |
void PeriodicCall::addDownsampledSignal( |
51 |
|
|
const std::string &name, SignalBase<int> &sig, |
52 |
|
|
const unsigned int &downsamplingFactor) { |
53 |
|
✗ |
signalMap[name] = SignalToCall(&sig, downsamplingFactor); |
54 |
|
✗ |
return; |
55 |
|
|
} |
56 |
|
|
|
57 |
|
✗ |
void PeriodicCall::addDownsampledSignal( |
58 |
|
|
const std::string &sigpath, const unsigned int &downsamplingFactor) { |
59 |
|
✗ |
istringstream sigISS(sigpath); |
60 |
|
|
SignalBase<int> &signal = |
61 |
|
✗ |
::dynamicgraph::PoolStorage::getInstance()->getSignal(sigISS); |
62 |
|
✗ |
addDownsampledSignal(sigpath, signal, downsamplingFactor); |
63 |
|
✗ |
return; |
64 |
|
|
} |
65 |
|
|
|
66 |
|
✗ |
void PeriodicCall::rmSignal(const std::string &name) { |
67 |
|
✗ |
signalMap.erase(name); |
68 |
|
✗ |
return; |
69 |
|
|
} |
70 |
|
|
|
71 |
|
|
/* --------------------------------------------------------------------- */ |
72 |
|
|
/* --------------------------------------------------------------------- */ |
73 |
|
|
/* --------------------------------------------------------------------- */ |
74 |
|
4000 |
void PeriodicCall::runSignals(const int &t) { |
75 |
|
4000 |
for (SignalMapType::iterator iter = signalMap.begin(); |
76 |
1/2
✗ Branch 3 not taken.
✓ Branch 4 taken 4000 times.
|
4000 |
signalMap.end() != iter; ++iter) { |
77 |
|
✗ |
if (t % iter->second.downsamplingFactor == 0) |
78 |
|
✗ |
(*iter).second.signal->recompute(t); |
79 |
|
|
} |
80 |
|
4000 |
return; |
81 |
|
|
} |
82 |
|
|
|
83 |
|
4000 |
void PeriodicCall::run(const int &t) { |
84 |
|
4000 |
runSignals(t); |
85 |
|
4000 |
return; |
86 |
|
|
} |
87 |
|
|
|
88 |
|
|
/* --------------------------------------------------------------------- */ |
89 |
|
|
/* --------------------------------------------------------------------- */ |
90 |
|
|
/* --------------------------------------------------------------------- */ |
91 |
|
|
|
92 |
|
✗ |
void PeriodicCall::display(std::ostream &os) const { |
93 |
|
✗ |
os << " (t=" << innerTime << ")" << endl; |
94 |
|
|
|
95 |
|
✗ |
os << " -> SIGNALS:" << endl; |
96 |
|
✗ |
for (SignalMapType::const_iterator iter = signalMap.begin(); |
97 |
|
✗ |
signalMap.end() != iter; ++iter) { |
98 |
|
✗ |
os << " - " << (*iter).first << endl; |
99 |
|
|
} |
100 |
|
|
} |
101 |
|
|
|
102 |
|
|
/* |
103 |
|
|
static std::string readLineStr( istringstream& args ) |
104 |
|
|
{ |
105 |
|
|
stringbuf* pbuf=args.rdbuf(); |
106 |
|
|
const std::streamsize size = pbuf->in_avail(); |
107 |
|
|
char * buffer = new char[ size+1 ]; |
108 |
|
|
pbuf->sgetn( buffer,size ); |
109 |
|
|
|
110 |
|
|
buffer[size]='\0'; |
111 |
|
|
std::string res( buffer ); |
112 |
|
|
delete [] buffer; |
113 |
|
|
return res; |
114 |
|
|
} |
115 |
|
|
*/ |
116 |
|
|
|
117 |
|
|
/* |
118 |
|
|
* Local variables: |
119 |
|
|
* c-basic-offset: 2 |
120 |
|
|
* End: |
121 |
|
|
*/ |
122 |
|
|
|