custom_entity.cpp 2.28 KB
Newer Older
1
2
3
4
5
6
7
/* Copyright 2010-2019 LAAS, CNRS
 * Thomas Moulard.
 *
 */

#define ENABLE_RT_LOG

Joseph Mirabel's avatar
Joseph Mirabel committed
8
#include "custom_entity.h"
Guilhem Saurel's avatar
Guilhem Saurel committed
9
#include <boost/bind.hpp>
Joseph Mirabel's avatar
Joseph Mirabel committed
10
11

#include <dynamic-graph/command-bind.h>
12
13
#include <dynamic-graph/entity.h>
#include <dynamic-graph/exception-factory.h>
Guilhem Saurel's avatar
Guilhem Saurel committed
14
15
#include <dynamic-graph/factory.h>
#include <dynamic-graph/pool.h>
16
17
18
19
#include <dynamic-graph/real-time-logger.h>
#include <dynamic-graph/signal-ptr.h>
#include <dynamic-graph/signal-time-dependent.h>

Guilhem Saurel's avatar
format    
Guilhem Saurel committed
20
21
namespace dynamicgraph {

Joseph Mirabel's avatar
Joseph Mirabel committed
22
23
24
CustomEntity::CustomEntity(const std::string n)
    : Entity(n),
      m_sigdSIN(NULL, "CustomEntity(" + name + ")::input(double)::in_double"),
Guilhem Saurel's avatar
Format    
Guilhem Saurel committed
25
      m_sigdTimeDepSOUT(boost::bind(&CustomEntity::update, this, _1, _2), m_sigdSIN,
Joseph Mirabel's avatar
Joseph Mirabel committed
26
27
28
29
                        "CustomEntity(" + name + ")::input(double)::out_double")

{
  addSignal();
30

Joseph Mirabel's avatar
Joseph Mirabel committed
31
  using namespace dynamicgraph::command;
Guilhem Saurel's avatar
Guilhem Saurel committed
32

Guilhem Saurel's avatar
Format    
Guilhem Saurel committed
33
  this->addCommand("act", makeCommandVoid0(*this, &CustomEntity::act, docCommandVoid0("act on input signal")));
Joseph Mirabel's avatar
Joseph Mirabel committed
34
}
Guilhem Saurel's avatar
Guilhem Saurel committed
35

Guilhem Saurel's avatar
Format    
Guilhem Saurel committed
36
void CustomEntity::addSignal() { signalRegistration(m_sigdSIN << m_sigdTimeDepSOUT); }
Guilhem Saurel's avatar
format    
Guilhem Saurel committed
37

Joseph Mirabel's avatar
Joseph Mirabel committed
38
39
40
41
void CustomEntity::rmValidSignal() {
  signalDeregistration("in_double");
  signalDeregistration("out_double");
}
Guilhem Saurel's avatar
format    
Guilhem Saurel committed
42

Joseph Mirabel's avatar
Joseph Mirabel committed
43
44
45
46
double &CustomEntity::update(double &res, const int &inTime) {
  const double &aDouble = m_sigdSIN(inTime);
  res = aDouble;
  logger().stream(MSG_TYPE_ERROR) << "start update " << res << '\n';
Guilhem Saurel's avatar
Format    
Guilhem Saurel committed
47
48
49
50
51
52
53
54
  DYNAMIC_GRAPH_ENTITY_DEBUG(*this) << "This is a message of level MSG_TYPE_DEBUG\n";
  DYNAMIC_GRAPH_ENTITY_INFO(*this) << "This is a message of level MSG_TYPE_INFO\n";
  DYNAMIC_GRAPH_ENTITY_WARNING(*this) << "This is a message of level MSG_TYPE_WARNING\n";
  DYNAMIC_GRAPH_ENTITY_ERROR(*this) << "This is a message of level MSG_TYPE_ERROR\n";
  DYNAMIC_GRAPH_ENTITY_DEBUG_STREAM(*this) << "This is a message of level MSG_TYPE_DEBUG_STREAM\n";
  DYNAMIC_GRAPH_ENTITY_INFO_STREAM(*this) << "This is a message of level MSG_TYPE_INFO_STREAM\n";
  DYNAMIC_GRAPH_ENTITY_WARNING_STREAM(*this) << "This is a message of level MSG_TYPE_WARNING_STREAM\n";
  DYNAMIC_GRAPH_ENTITY_ERROR_STREAM(*this) << "This is a message of level MSG_TYPE_ERROR_STREAM\n";
Joseph Mirabel's avatar
Joseph Mirabel committed
55
56
57
  logger().stream(MSG_TYPE_ERROR) << "end update\n";
  return res;
}
Guilhem Saurel's avatar
format    
Guilhem Saurel committed
58

Joseph Mirabel's avatar
Joseph Mirabel committed
59
void CustomEntity::act() { m_sigdSIN.accessCopy(); }
Guilhem Saurel's avatar
Guilhem Saurel committed
60

Guilhem Saurel's avatar
format    
Guilhem Saurel committed
61
62
DYNAMICGRAPH_FACTORY_ENTITY_PLUGIN(CustomEntity, "CustomEntity");
}  // namespace dynamicgraph