event.hh
Go to the documentation of this file.
1 // Copyright (c) 2018, Joseph Mirabel
2 // Authors: Joseph Mirabel (joseph.mirabel@laas.fr)
3 
4 #ifndef __SOT_EVENT_H__
5 #define __SOT_EVENT_H__
6 
10 #include <dynamic-graph/entity.h>
11 #include <dynamic-graph/pool.h>
14 #include <dynamic-graph/signal.h>
15 
16 #include <sot/core/config.hh>
17 
18 namespace dynamicgraph {
19 namespace sot {
43 
44 class SOT_CORE_DLLAPI Event : public dynamicgraph::Entity {
46 
47  Event(const std::string &name)
48  : Entity(name),
49  checkSOUT("Event(" + name + ")::output(bool)::check"),
50  conditionSIN(NULL, "Event(" + name + ")::input(bool)::condition"),
51  lastVal_(2), // lastVal_ should be different true and false.
52  timeSinceUp_(0),
53  repeatAfterNIterations_(0) {
54  checkSOUT.setFunction(boost::bind(&Event::check, this, _1, _2));
55  signalRegistration(conditionSIN);
56  signalRegistration(checkSOUT);
57 
59  std::string docstring =
60  "\n"
61  " Add a signal\n";
62  addCommand("addSignal",
63  makeCommandVoid1(*this, &Event::addSignal, docstring));
64 
65  docstring =
66  "\n"
67  " Get list of signals\n";
68  addCommand("list", new command::Getter<Event, std::string>(
69  *this, &Event::getSignalsByName, docstring));
70 
71  docstring =
72  "\n"
73  " Repease event if input signal remains True for a while\n"
74  " Input: number of iterations before repeating output\n."
75  " 0 for no repetition";
76  addCommand("repeat", new command::Setter<Event, sigtime_t>(
77  *this, &Event::repeat, docstring));
78  }
79 
80  ~Event() {}
81 
83  virtual std::string getDocString() const {
84  return "Send an event when the input changes\n\n"
85  " The signal triggered is called whenever the condition is "
86  "satisfied.\n";
87  }
88 
89  void addSignal(const std::string &signal) {
90  std::istringstream iss(signal);
91  triggers.push_back(&PoolStorage::getInstance()->getSignal(iss));
92  }
93 
94  // Returns the Python string representation of the list of signal names.
95  std::string getSignalsByName() const {
96  std::ostringstream oss;
97  oss << "(";
98  for (Triggers_t::const_iterator _sig = triggers.begin();
99  _sig != triggers.end(); ++_sig)
100  oss << '\'' << (*_sig)->getName() << "\', ";
101  oss << ")";
102  return oss.str();
103  }
104 
105  void repeat(const sigtime_t &nbIterations) {
106  repeatAfterNIterations_ = nbIterations;
107  }
108 
109  private:
111  typedef std::vector<Trigger_t> Triggers_t;
112 
113  bool &check(bool &ret, const int64_t &time);
114 
116 
119 
120  bool lastVal_;
121  sigtime_t timeSinceUp_, repeatAfterNIterations_;
122 };
123 } // namespace sot
124 } // namespace dynamicgraph
125 #endif // __SOT_EVENT_H__
dynamicgraph::sot::Event::lastVal_
bool lastVal_
Definition: event.hh:120
signal-ptr.h
dynamicgraph::Signal< bool, sigtime_t >
dynamicgraph::sot::Event::checkSOUT
Signal< bool, sigtime_t > checkSOUT
Definition: event.hh:115
dynamicgraph::sot::Event::getDocString
virtual std::string getDocString() const
Header documentation of the python class.
Definition: event.hh:83
signal-time-dependent.h
dynamicgraph::sot::Event::conditionSIN
SignalPtr< bool, sigtime_t > conditionSIN
Definition: event.hh:118
dynamicgraph::SignalPtr< bool, sigtime_t >
dynamicgraph
getSignal
dg::SignalBase< dg::sigtime_t > * getSignal(dg::Entity &e, const std::string &name)
dynamicgraph::sot::Event::check
bool & check(bool &ret, const int64_t &time)
Definition: event.cpp:11
dynamicgraph::Entity
command-getter.h
dynamicgraph::sot::Event::Triggers_t
std::vector< Trigger_t > Triggers_t
Definition: event.hh:111
command-bind.h
DYNAMIC_GRAPH_ENTITY_DECL
#define DYNAMIC_GRAPH_ENTITY_DECL()
dynamicgraph::sot::Event::timeSinceUp_
sigtime_t timeSinceUp_
Definition: event.hh:121
command-setter.h
dynamicgraph::sigtime_t
int64_t sigtime_t
dynamicgraph::sot::Event::getSignalsByName
std::string getSignalsByName() const
Definition: event.hh:95
dynamicgraph::sot::Event::repeat
void repeat(const sigtime_t &nbIterations)
Definition: event.hh:105
check
bool check(const T &value, const T &other)
dynamicgraph::sot::Event::~Event
~Event()
Definition: event.hh:80
dynamicgraph::sot::Event::triggers
Triggers_t triggers
Definition: event.hh:117
dynamicgraph::PoolStorage::getInstance
static PoolStorage * getInstance()
Definition: pool.cpp:147
dynamicgraph::SignalBase< sigtime_t >
dynamicgraph::sot::Event::Event
Event(const std::string &name)
Definition: event.hh:47
dynamicgraph::command::Setter
dynamicgraph::sot::Event::addSignal
void addSignal(const std::string &signal)
Definition: event.hh:89
dynamicgraph::sot::Event::Trigger_t
SignalBase< sigtime_t > * Trigger_t
Definition: event.hh:110
dynamicgraph::command::Getter
dynamicgraph::sot::Event
Definition: event.hh:44
dynamicgraph::command::makeCommandVoid1
CommandVoid1< E, T > * makeCommandVoid1(E &entity, boost::function< void(const T &)> function, const std::string &docString)
compile.name
name
Definition: compile.py:23


sot-core
Author(s): Olivier Stasse, ostasse@laas.fr
autogenerated on Tue Oct 24 2023 02:26:31