Skip to content

Commit 4d2722c

Browse files
committed
[tools/switch] Create a switch entity. Returns a boolean on/off output signal
1 parent 12b595c commit 4d2722c

File tree

4 files changed

+110
-0
lines changed

4 files changed

+110
-0
lines changed

include/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ SET(NEWHEADERS
3131
sot/core/exception-tools.hh
3232
sot/core/binary-op.hh
3333
sot/core/derivator.hh
34+
sot/core/switch.hh
3435
sot/core/fir-filter.hh
3536
sot/core/integrator-abstract.hh
3637
sot/core/integrator-euler.hh

include/sot/core/switch.hh

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
/*
2+
* Copyright 2017-, Rohan Budhiraja, CNRS
3+
*
4+
* This file is part of sot-core.
5+
* sot-core is free software: you can redistribute it and/or
6+
* modify it under the terms of the GNU Lesser General Public License
7+
* as published by the Free Software Foundation, either version 3 of
8+
* the License, or (at your option) any later version.
9+
* sot-core is distributed in the hope that it will be
10+
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty
11+
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU Lesser General Public License for more details. You should
13+
* have received a copy of the GNU Lesser General Public License along
14+
* with sot-core. If not, see <http://www.gnu.org/licenses/>.
15+
*/
16+
17+
#ifndef __SOT_SWITCH_H__
18+
#define __SOT_SWITCH_H__
19+
20+
/* --------------------------------------------------------------------- */
21+
/* --- INCLUDE --------------------------------------------------------- */
22+
/* --------------------------------------------------------------------- */
23+
24+
/* SOT */
25+
#include <dynamic-graph/command-bind.h>
26+
#include <sot/core/pool.hh>
27+
#include <dynamic-graph/entity.h>
28+
#include <dynamic-graph/all-signals.h>
29+
30+
/* STD */
31+
#include <string>
32+
33+
namespace dynamicgraph {
34+
namespace sot {
35+
36+
/* --------------------------------------------------------------------- */
37+
/* --- CLASS ----------------------------------------------------------- */
38+
/* --------------------------------------------------------------------- */
39+
using dynamicgraph::Entity;
40+
using dynamicgraph::command::makeCommandVoid0;
41+
using dynamicgraph::command::docCommandVoid0;
42+
43+
class Switch : public Entity
44+
{
45+
46+
public: /* --- SIGNAL --- */
47+
DYNAMIC_GRAPH_ENTITY_DECL();
48+
dynamicgraph::SignalTimeDependent<bool,int> outSOUT;
49+
50+
protected:
51+
bool signalOutput;
52+
void turnOn(){ signalOutput = true; }
53+
54+
void turnOff(){ signalOutput = false; }
55+
56+
bool& switchOutput(bool& res, int){ res = signalOutput; return res; }
57+
58+
public:
59+
Switch( const std::string& name )
60+
: Entity(name)
61+
,outSOUT( boost::bind(&Switch::switchOutput,this,_1,_2),
62+
sotNOSIGNAL,"Switch("+name+")::output(bool)::out")
63+
{
64+
signalOutput = false;
65+
signalRegistration (outSOUT );
66+
addCommand ("turnOn",
67+
makeCommandVoid0 (*this, &Switch::turnOn,
68+
docCommandVoid0 ("Turn on the switch")));
69+
addCommand ("turnOff",
70+
makeCommandVoid0 (*this, &Switch::turnOff,
71+
docCommandVoid0 ("Turn off the switch")));
72+
}
73+
74+
virtual ~Switch( void ) {};
75+
76+
};
77+
} /* namespace sot */
78+
} /* namespace dynamicgraph */
79+
80+
81+
82+
#endif // #ifndef __SOT_SWITCH_H__

src/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ SET(plugins
9191
tools/binary-int-to-uint
9292
tools/periodic-call-entity
9393
tools/joint-trajectory-entity
94+
tools/switch
9495

9596
control/control-gr
9697
control/control-pd

src/tools/switch.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* Copyright 2017-, Rohan Budhiraja, CNRS
3+
*
4+
* CNRS/AIST
5+
*
6+
* This file is part of sot-core.
7+
* sot-core is free software: you can redistribute it and/or
8+
* modify it under the terms of the GNU Lesser General Public License
9+
* as published by the Free Software Foundation, either version 3 of
10+
* the License, or (at your option) any later version.
11+
* sot-core is distributed in the hope that it will be
12+
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty
13+
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU Lesser General Public License for more details. You should
15+
* have received a copy of the GNU Lesser General Public License along
16+
* with sot-core. If not, see <http://www.gnu.org/licenses/>.
17+
*/
18+
19+
#include <sot/core/switch.hh>
20+
#include <sot/core/factory.hh>
21+
22+
namespace dynamicgraph {
23+
namespace sot {
24+
DYNAMICGRAPH_FACTORY_ENTITY_PLUGIN (Switch, "Switch");
25+
} // namespace sot
26+
} // namespace dynamicgraph

0 commit comments

Comments
 (0)