Commit 4d2722c6 authored by Rohan Budhiraja's avatar Rohan Budhiraja
Browse files

[tools/switch] Create a switch entity. Returns a boolean on/off output signal

parent 12b595cf
......@@ -31,6 +31,7 @@ SET(NEWHEADERS
sot/core/exception-tools.hh
sot/core/binary-op.hh
sot/core/derivator.hh
sot/core/switch.hh
sot/core/fir-filter.hh
sot/core/integrator-abstract.hh
sot/core/integrator-euler.hh
......
/*
* Copyright 2017-, Rohan Budhiraja, CNRS
*
* This file is part of sot-core.
* sot-core is free software: you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
* sot-core is distributed in the hope that it will be
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details. You should
* have received a copy of the GNU Lesser General Public License along
* with sot-core. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __SOT_SWITCH_H__
#define __SOT_SWITCH_H__
/* --------------------------------------------------------------------- */
/* --- INCLUDE --------------------------------------------------------- */
/* --------------------------------------------------------------------- */
/* SOT */
#include <dynamic-graph/command-bind.h>
#include <sot/core/pool.hh>
#include <dynamic-graph/entity.h>
#include <dynamic-graph/all-signals.h>
/* STD */
#include <string>
namespace dynamicgraph {
namespace sot {
/* --------------------------------------------------------------------- */
/* --- CLASS ----------------------------------------------------------- */
/* --------------------------------------------------------------------- */
using dynamicgraph::Entity;
using dynamicgraph::command::makeCommandVoid0;
using dynamicgraph::command::docCommandVoid0;
class Switch : public Entity
{
public: /* --- SIGNAL --- */
DYNAMIC_GRAPH_ENTITY_DECL();
dynamicgraph::SignalTimeDependent<bool,int> outSOUT;
protected:
bool signalOutput;
void turnOn(){ signalOutput = true; }
void turnOff(){ signalOutput = false; }
bool& switchOutput(bool& res, int){ res = signalOutput; return res; }
public:
Switch( const std::string& name )
: Entity(name)
,outSOUT( boost::bind(&Switch::switchOutput,this,_1,_2),
sotNOSIGNAL,"Switch("+name+")::output(bool)::out")
{
signalOutput = false;
signalRegistration (outSOUT );
addCommand ("turnOn",
makeCommandVoid0 (*this, &Switch::turnOn,
docCommandVoid0 ("Turn on the switch")));
addCommand ("turnOff",
makeCommandVoid0 (*this, &Switch::turnOff,
docCommandVoid0 ("Turn off the switch")));
}
virtual ~Switch( void ) {};
};
} /* namespace sot */
} /* namespace dynamicgraph */
#endif // #ifndef __SOT_SWITCH_H__
......@@ -91,6 +91,7 @@ SET(plugins
tools/binary-int-to-uint
tools/periodic-call-entity
tools/joint-trajectory-entity
tools/switch
control/control-gr
control/control-pd
......
/*
* Copyright 2017-, Rohan Budhiraja, CNRS
*
* CNRS/AIST
*
* This file is part of sot-core.
* sot-core is free software: you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
* sot-core is distributed in the hope that it will be
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details. You should
* have received a copy of the GNU Lesser General Public License along
* with sot-core. If not, see <http://www.gnu.org/licenses/>.
*/
#include <sot/core/switch.hh>
#include <sot/core/factory.hh>
namespace dynamicgraph {
namespace sot {
DYNAMICGRAPH_FACTORY_ENTITY_PLUGIN (Switch, "Switch");
} // namespace sot
} // namespace dynamicgraph
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment