debug-tracer.cpp
Go to the documentation of this file.
1 /* Copyright 2019, LAAS-CNRS
2  *
3  * Olivier Stasse
4  *
5  */
6 
7 #include <dynamic-graph/entity.h>
10 #include <dynamic-graph/pool.h>
13 #include <dynamic-graph/tracer.h>
14 
15 #include <iostream>
16 
17 #define BOOST_TEST_MODULE debug - tracer
18 
19 #if BOOST_VERSION >= 105900
20 #include <boost/test/tools/output_test_stream.hpp>
21 #else
22 #include <boost/test/output_test_stream.hpp>
23 #endif
24 #include <boost/test/unit_test.hpp>
25 
26 namespace dynamicgraph {
27 struct MyEntity : public dynamicgraph::Entity {
28  static const std::string CLASS_NAME;
29 
34 
35  explicit MyEntity(const std::string &name)
36  : Entity(name),
37  m_sigdSIN("MyEntity(" + name + ")::input(double)::in_double"),
38  m_sigdTimeDepSOUT(boost::bind(&MyEntity::update, this, _1, _2),
39  m_sigdSIN,
40  "MyEntity(" + name + ")::input(double)::out_double"),
41  m_sigVTimeDepSOUT(boost::bind(&MyEntity::updateVector, this, _1, _2),
42  m_sigdSIN,
43  "MyEntity(" + name + ")::input(vector)::out_vector"),
44  m_sigdTwoTimeDepSOUT(
45  boost::bind(&MyEntity::update, this, _1, _2), m_sigdSIN,
46  "MyEntity(" + name + ")::input(double)::out2double")
47 
48  {
49  signalRegistration(m_sigdSIN << m_sigdTimeDepSOUT << m_sigVTimeDepSOUT
50  << m_sigdTwoTimeDepSOUT);
51  }
52 
53  virtual void display(std::ostream &os) const {
54  os << "Hello! My name is " << getName() << " !" << std::endl;
55  }
56 
57  virtual const std::string &getClassName() const { return CLASS_NAME; }
58 
59  double &update(double &res, const int &inTime) {
60  const double &aDouble = m_sigdSIN(inTime);
61  res = aDouble;
62  return res;
63  }
64 
65  Vector &updateVector(Vector &res, const int &inTime) {
66  const double &aDouble = m_sigdSIN(inTime);
67  res.resize(2);
68  res << aDouble, 2 * aDouble;
69  return res;
70  }
71 };
73 } // namespace dynamicgraph
74 
75 BOOST_AUTO_TEST_CASE(test_tracer) {
77 
78  // Creates a tracer.
79  dynamicgraph::Tracer &atracer = *dynamic_cast<dynamicgraph::Tracer *>(
81  "my-tracer"));
82 
83  dynamicgraph::Entity &entity =
85  "my-entity");
86 
87  std::string rootdir("/tmp");
88  std::string basename("my-tracer");
89  std::string suffix(".dat");
90 
92  atracer.openFiles(rootdir, basename, suffix);
93 
95  atracer.addSignalToTraceByName("my-entity.out_double", "output");
97  atracer.addSignalToTraceByName("my-entity.out_vector", "output-vector");
98 
99  dynamicgraph::SignalBase<int> &aSignal = entity.getSignal("out2double");
100 
102  *(dynamic_cast<dynamicgraph::Signal<double, int> *>(
103  &entity.getSignal("in_double")));
104 
105  dynamicgraph::Signal<Vector, int> &aSignalVector =
106  *(dynamic_cast<dynamicgraph::Signal<Vector, int> *>(
107  &entity.getSignal("out_vector")));
108 
110  atracer.addSignalToTrace(aSignal, "output2");
111 
112  aSignalInt.setConstant(1.5);
113 
114  atracer.start();
115 
116  for (int i = 0; i < 1000; i++) {
117  aSignal.setTime(i);
118  aSignalInt.access(i);
119  aSignalInt.setTime(i);
120  aSignalVector.recompute(i);
121  aSignalVector.setTime(i);
122  atracer.recordTrigger(i, i);
123  }
124 
125  atracer.stop();
126  atracer.clearSignalToTrace();
127  atracer.closeFiles();
128 
129  atracer.record();
130 }
dynamicgraph::SignalTimeDependent< double, int > m_sigdTimeDepSOUT
Eigen::VectorXd Vector
This class represents an entity, i.e. a generic computational unit that provides input and output sig...
void signalRegistration(const SignalArray< int > &signals)
void openFiles(const std::string &rootdir, const std::string &basename, const std::string &suffix)
Definition: tracer.cpp:136
void addSignalToTraceByName(const std::string &signame, const std::string &filename="")
Definition: tracer.cpp:111
virtual void display(std::ostream &os) const
Display information on the entity inside the output stream os.
virtual void setConstant(const T &t)
Definition: signal.t.cpp:98
MyEntity(const std::string &name)
int & recordTrigger(int &dummy, const int &time)
Definition: tracer.cpp:250
Vector & updateVector(Vector &res, const int &inTime)
void clearSignalToTrace()
Definition: tracer.cpp:124
virtual void closeFiles()
Definition: tracer.cpp:180
BOOST_AUTO_TEST_CASE(test_tracer)
virtual void recompute(const Time &t)
dynamicgraph::SignalTimeDependent< double, int > m_sigdTwoTimeDepSOUT
const std::string & getName() const
double & update(double &res, const int &inTime)
Tracer plug-in main class.
Definition: tracer.h:24
virtual const std::string & getClassName() const
Entity * newEntity(const std::string &classname, const std::string &objname) const
Instantiate (and allocate) an entity.
dynamicgraph::SignalTimeDependent< Vector, int > m_sigVTimeDepSOUT
void addSignalToTrace(const SignalBase< int > &sig, const std::string &filename="")
Definition: tracer.cpp:99
static FactoryStorage * getInstance()
Get pointer to unique object of the class.
DYNAMICGRAPH_FACTORY_ENTITY_PLUGIN(CustomEntity, "CustomEntity")
SignalBase< int > & getSignal(const std::string &signalName)
Provides a reference to the signal named signalName.
static const std::string CLASS_NAME
virtual void setTime(const Time &t)
Definition: signal-base.h:38
dynamicgraph::Signal< double, int > m_sigdSIN
virtual const T & access(const Time &t)
Definition: signal.t.cpp:139


dynamic-graph
Author(s): Nicolas Mansard, Olivier Stasse
autogenerated on Sun Jun 25 2023 02:06:03