sot-core  4.11.8
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 
18 #include <sot/core/pool.hh>
19 
20 /* STD */
21 #include <string>
22 
23 namespace dynamicgraph {
24 namespace sot {
25 
26 /* --------------------------------------------------------------------- */
27 /* --- CLASS ----------------------------------------------------------- */
28 /* --------------------------------------------------------------------- */
29 using dynamicgraph::Entity;
30 using dynamicgraph::command::docCommandVoid0;
31 using dynamicgraph::command::makeCommandVoid0;
32 
33 class Latch : public Entity {
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),
62  outSOUT("Latch(" + name + ")::output(bool)::out"),
63  turnOnSOUT("Latch(" + name + ")::output(bool)::turnOnSout"),
64  turnOffSOUT("Latch(" + name + ")::output(bool)::turnOffSout") {
65  outSOUT.setFunction(boost::bind(&Latch::latchOutput, this, _1, _2));
66  turnOnSOUT.setFunction(boost::bind(&Latch::turnOnLatch, this, _1, _2));
67  turnOffSOUT.setFunction(boost::bind(&Latch::turnOffLatch, this, _1, _2));
68  signalOutput = false;
69  signalRegistration(outSOUT << turnOnSOUT << turnOffSOUT);
70  addCommand("turnOn",
71  makeCommandVoid0(*this, &Latch::turnOn,
72  docCommandVoid0("Turn on the latch")));
73  addCommand("turnOff",
74  makeCommandVoid0(*this, &Latch::turnOff,
75  docCommandVoid0("Turn off the latch")));
76  }
77 
78  virtual ~Latch(void){};
79 };
80 } /* namespace sot */
81 } /* namespace dynamicgraph */
82 
83 #endif // #ifndef __SOT_LATCH_H__
Definition: latch.hh:33
Signal< bool, int > turnOnSOUT
Definition: latch.hh:37
bool & latchOutput(bool &res, int)
Definition: latch.hh:54
Signal< bool, int > turnOffSOUT
Definition: latch.hh:38
void turnOff()
Definition: latch.hh:48
bool & turnOffLatch(bool &res, int)
Definition: latch.hh:49
virtual ~Latch(void)
Definition: latch.hh:78
bool & turnOnLatch(bool &res, int)
Definition: latch.hh:43
Latch(const std::string &name)
Definition: latch.hh:60
Signal< bool, int > outSOUT
Definition: latch.hh:36
bool signalOutput
Definition: latch.hh:41
void turnOn()
Definition: latch.hh:42
Definition: abstract-sot-external-interface.hh:17