periodic-call.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 --- */
17 #include <dynamic-graph/pool.h>
18 
19 #include <algorithm>
20 #include <sot/core/debug.hh>
23 
24 using namespace std;
25 using namespace dynamicgraph;
26 using namespace dynamicgraph::sot;
27 
28 /* --------------------------------------------------------------------- */
29 /* --- CLASS ----------------------------------------------------------- */
30 /* --------------------------------------------------------------------- */
31 
32 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 =
46  addSignal(sigpath, signal);
47  return;
48 }
49 
51  const std::string &name, SignalBase<int> &sig,
52  const unsigned int &downsamplingFactor) {
53  signalMap[name] = SignalToCall(&sig, downsamplingFactor);
54  return;
55 }
56 
58  const std::string &sigpath, const unsigned int &downsamplingFactor) {
59  istringstream sigISS(sigpath);
60  SignalBase<int> &signal =
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 void PeriodicCall::runSignals(const int &t) {
75  for (SignalMapType::iterator iter = signalMap.begin();
76  signalMap.end() != iter; ++iter) {
77  if (t % iter->second.downsamplingFactor == 0)
78  (*iter).second.signal->recompute(t);
79  }
80  return;
81 }
82 
83 void PeriodicCall::run(const int &t) {
84  runSignals(t);
85  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  */
void addDownsampledSignal(const std::string &name, dynamicgraph::SignalBase< int > &sig, const unsigned int &downsamplingFactor)
Signal< dynamicgraph::Matrix, int > sig("matrix")
void rmSignal(const std::string &name)
void display(std::ostream &os) const
static PoolStorage * getInstance()
Definition: pool.cpp:147
Transform3f t
void addSignal(const std::string &name, dynamicgraph::SignalBase< int > &sig)
SignalBase< int > & getSignal(std::istringstream &sigpath)


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