sot-core  4.11.6
Hierarchical task solver plug-in for dynamic-graph.
latch.hh
Go to the documentation of this file.
1 /*
2  * Copyright 2017-, Rohan Budhiraja, Joseph Mirabel, CNRS
3  *
4  */
5 
6 #ifndef __SOT_LATCH_H__
7 #define __SOT_LATCH_H__
8 
9 /* --------------------------------------------------------------------- */
10 /* --- INCLUDE --------------------------------------------------------- */
11 /* --------------------------------------------------------------------- */
12 
13 /* SOT */
14 #include <dynamic-graph/all-signals.h>
15 #include <dynamic-graph/command-bind.h>
16 #include <dynamic-graph/entity.h>
17 #include <sot/core/pool.hh>
18 
19 /* STD */
20 #include <string>
21 
22 namespace dynamicgraph {
23 namespace sot {
24 
25 /* --------------------------------------------------------------------- */
26 /* --- CLASS ----------------------------------------------------------- */
27 /* --------------------------------------------------------------------- */
28 using dynamicgraph::Entity;
29 using dynamicgraph::command::docCommandVoid0;
30 using dynamicgraph::command::makeCommandVoid0;
31 
32 class Latch : public Entity {
33 
34 public: /* --- SIGNAL --- */
36  Signal<bool, int> outSOUT;
37  Signal<bool, int> turnOnSOUT;
38  Signal<bool, int> turnOffSOUT;
39 
40 protected:
42  void turnOn() { signalOutput = true; }
43  bool &turnOnLatch(bool &res, int) {
44  res = signalOutput = true;
45  return res;
46  }
47 
48  void turnOff() { signalOutput = false; }
49  bool &turnOffLatch(bool &res, int) {
50  res = signalOutput = false;
51  return res;
52  }
53 
54  bool &latchOutput(bool &res, int) {
55  res = signalOutput;
56  return res;
57  }
58 
59 public:
60  Latch(const std::string &name)
61  : Entity(name), outSOUT("Latch(" + name + ")::output(bool)::out"),
62  turnOnSOUT("Latch(" + name + ")::output(bool)::turnOnSout"),
63  turnOffSOUT("Latch(" + name + ")::output(bool)::turnOffSout") {
64  outSOUT.setFunction(boost::bind(&Latch::latchOutput, this, _1, _2));
65  turnOnSOUT.setFunction(boost::bind(&Latch::turnOnLatch, this, _1, _2));
66  turnOffSOUT.setFunction(boost::bind(&Latch::turnOffLatch, this, _1, _2));
67  signalOutput = false;
68  signalRegistration(outSOUT << turnOnSOUT << turnOffSOUT);
69  addCommand("turnOn",
70  makeCommandVoid0(*this, &Latch::turnOn,
71  docCommandVoid0("Turn on the latch")));
72  addCommand("turnOff",
73  makeCommandVoid0(*this, &Latch::turnOff,
74  docCommandVoid0("Turn off the latch")));
75  }
76 
77  virtual ~Latch(void){};
78 };
79 } /* namespace sot */
80 } /* namespace dynamicgraph */
81 
82 #endif // #ifndef __SOT_LATCH_H__
Signal< bool, int > turnOffSOUT
Definition: latch.hh:38
bool & turnOnLatch(bool &res, int)
Definition: latch.hh:43
Signal< bool, int > outSOUT
Definition: latch.hh:36
bool signalOutput
Definition: latch.hh:41
Definition: latch.hh:32
void turnOn()
Definition: latch.hh:42
bool & latchOutput(bool &res, int)
Definition: latch.hh:54
virtual ~Latch(void)
Definition: latch.hh:77
bool & turnOffLatch(bool &res, int)
Definition: latch.hh:49
void turnOff()
Definition: latch.hh:48
Definition: abstract-sot-external-interface.hh:17
Signal< bool, int > turnOnSOUT
Definition: latch.hh:37
Latch(const std::string &name)
Definition: latch.hh:60