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"),
45  boost::bind(&MyEntity::update, this, _1, _2), m_sigdSIN,
46  "MyEntity(" + name + ")::input(double)::out2double")
47 
48  {
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 sigtime_t &inTime) {
60  const double &aDouble = m_sigdSIN(inTime);
61  res = aDouble;
62  return res;
63  }
64 
65  Vector &updateVector(Vector &res, const sigtime_t &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 
76 
77 BOOST_AUTO_TEST_CASE(test_tracer) {
79 
80  // Creates a tracer.
81  dynamicgraph::Tracer &atracer = *dynamic_cast<dynamicgraph::Tracer *>(
83  "my-tracer"));
84 
85  dynamicgraph::Entity &entity =
87  "my-entity");
88 
89  std::string rootdir("/tmp");
90  std::string basename("my-tracer");
91  std::string suffix(".dat");
92 
94  atracer.openFiles(rootdir, basename, suffix);
95 
97  atracer.addSignalToTraceByName("my-entity.out_double", "output");
99  atracer.addSignalToTraceByName("my-entity.out_vector", "output-vector");
100 
101  dynamicgraph::SignalBase<sigtime_t> &aSignal = entity.getSignal("out2double");
102 
104  *(dynamic_cast<dynamicgraph::Signal<double, sigtime_t> *>(
105  &entity.getSignal("in_double")));
106 
108  *(dynamic_cast<dynamicgraph::Signal<Vector, sigtime_t> *>(
109  &entity.getSignal("out_vector")));
110 
112  atracer.addSignalToTrace(aSignal, "output2");
113 
114  aSignalInt.setConstant(1.5);
115 
116  atracer.start();
117 
118  for (sigtime_t i = 0; i < 1000; i++) {
119  aSignal.setTime(i);
120  aSignalInt.access(i);
121  aSignalInt.setTime(i);
122  aSignalVector.recompute(i);
123  aSignalVector.setTime(i);
124  atracer.recordTrigger(i, i);
125  }
126 
127  atracer.stop();
128  atracer.clearSignalToTrace();
129  atracer.closeFiles();
130 
131  atracer.record();
132 }
dynamicgraph::Signal::recompute
virtual void recompute(const Time &t)
Definition: include/dynamic-graph/signal.h:96
entity.h
dynamicgraph::Signal< double, sigtime_t >
dynamicgraph::SignalBase::setTime
virtual void setTime(const Time &t)
Definition: signal-base.h:38
signal-time-dependent.h
dynamicgraph::Tracer::closeFiles
virtual void closeFiles()
Definition: tracer.cpp:181
dynamicgraph::Tracer::recordTrigger
sigtime_t & recordTrigger(sigtime_t &dummy, const sigtime_t &time)
Definition: tracer.cpp:251
dynamicgraph::Tracer::addSignalToTraceByName
void addSignalToTraceByName(const std::string &signame, const std::string &filename="")
Definition: tracer.cpp:111
dynamicgraph
dynamicgraph::MyEntity::updateVector
Vector & updateVector(Vector &res, const sigtime_t &inTime)
Definition: debug-tracer.cpp:65
dynamicgraph::MyEntity::getClassName
virtual const std::string & getClassName() const
Definition: debug-tracer.cpp:57
dynamicgraph::MyEntity::update
double & update(double &res, const sigtime_t &inTime)
Definition: debug-real-time-tracer.cpp:49
dynamicgraph::Entity
This class represents an entity, i.e. a generic computational unit that provides input and output sig...
Definition: include/dynamic-graph/entity.h:52
dynamicgraph::Tracer::record
void record()
Definition: tracer.cpp:198
dynamicgraph::MyEntity
Definition: debug-real-time-tracer.cpp:28
dynamicgraph::Signal::access
virtual const T & access(const Time &t)
Definition: signal.t.cpp:139
dynamicgraph::Tracer::stop
void stop()
Definition: tracer.h:89
sigtime_t
dynamicgraph::sigtime_t sigtime_t
Definition: debug-tracer.cpp:75
dynamicgraph::DYNAMICGRAPH_FACTORY_ENTITY_PLUGIN
DYNAMICGRAPH_FACTORY_ENTITY_PLUGIN(CustomEntity, "CustomEntity")
dynamicgraph::Entity::name
std::string name
Definition: include/dynamic-graph/entity.h:174
dynamicgraph::MyEntity::m_sigdTwoTimeDepSOUT
dynamicgraph::SignalTimeDependent< double, sigtime_t > m_sigdTwoTimeDepSOUT
Definition: debug-real-time-tracer.cpp:33
dynamicgraph::Tracer::clearSignalToTrace
void clearSignalToTrace()
Definition: tracer.cpp:124
signal-ptr.h
dynamicgraph::Tracer::addSignalToTrace
void addSignalToTrace(const SignalBase< sigtime_t > &sig, const std::string &filename="")
Definition: tracer.cpp:99
dynamicgraph::MyEntity::display
virtual void display(std::ostream &os) const
Display information on the entity inside the output stream os.
Definition: debug-tracer.cpp:53
dynamicgraph::Entity::getName
const std::string & getName() const
Definition: include/dynamic-graph/entity.h:60
dynamicgraph::MyEntity::CLASS_NAME
static const std::string CLASS_NAME
Definition: debug-real-time-tracer.cpp:29
dynamicgraph::MyEntity::m_sigdTimeDepSOUT
dynamicgraph::SignalTimeDependent< double, sigtime_t > m_sigdTimeDepSOUT
Definition: debug-real-time-tracer.cpp:32
tracer.h
dynamicgraph::MyEntity::m_sigVTimeDepSOUT
dynamicgraph::SignalTimeDependent< Vector, sigtime_t > m_sigVTimeDepSOUT
Definition: debug-tracer.cpp:32
dynamicgraph::sigtime_t
int64_t sigtime_t
Definition: fwd.hh:12
dynamicgraph::MyEntity::MyEntity
MyEntity(const std::string &name)
Definition: debug-tracer.cpp:35
BOOST_AUTO_TEST_CASE
BOOST_AUTO_TEST_CASE(test_tracer)
Definition: debug-tracer.cpp:77
dynamicgraph::Vector
Eigen::VectorXd Vector
Definition: linear-algebra.h:14
dynamicgraph::MyEntity::m_sigdSIN
dynamicgraph::Signal< double, sigtime_t > m_sigdSIN
Definition: debug-real-time-tracer.cpp:31
dynamicgraph::Signal::setConstant
virtual void setConstant(const T &t)
Definition: signal.t.cpp:98
exception-factory.h
factory.h
dynamicgraph::SignalTimeDependent< double, sigtime_t >
dynamicgraph::Entity::getSignal
SignalBase< sigtime_t > & getSignal(const std::string &signalName)
Provides a reference to the signal named signalName.
MyEntity
Definition: tests/pool.cpp:26
dynamicgraph::SignalBase< sigtime_t >
dynamicgraph::Tracer::start
void start()
Definition: tracer.h:88
dynamicgraph::Tracer
Tracer plug-in main class.
Definition: tracer.h:24
dynamicgraph::Entity::signalRegistration
void signalRegistration(const SignalArray< sigtime_t > &signals)
Definition: src/dgraph/entity.cpp:59
dynamicgraph::Tracer::openFiles
void openFiles(const std::string &rootdir, const std::string &basename, const std::string &suffix)
Definition: tracer.cpp:136
dynamicgraph::FactoryStorage::newEntity
Entity * newEntity(const std::string &classname, const std::string &objname) const
Instantiate (and allocate) an entity.
Definition: src/dgraph/factory.cpp:79
pool.h
dynamicgraph::FactoryStorage::getInstance
static FactoryStorage * getInstance()
Get pointer to unique object of the class.
Definition: src/dgraph/factory.cpp:15


dynamic-graph
Author(s): Nicolas Mansard, Olivier Stasse
autogenerated on Fri Aug 2 2024 08:36:38